The easiest way to get started writing TINE servers is to use the Server Wizard to create the skeleton to be used to provide the desired functionality. Likewise, 'buffered' servers are also very easy to put together and use, as they 'hide' numerous details that the novice server writer either doesn't want to see or is prone to forget. Buffered servers also offer only a reduced set of functionality, however.
It is nonetheless straightforward to write your own TINE server, either from scratch or beginning from a clone of a working project. To this end, we present here a brief tutorial on writing a simple Windows GUI TINE server from scratch. The example shown uses Visual Basic.
The example below is a simple server code module which contains one equipment function and supports one property “SINE”. It simulates data IO by using a Visual Basic timer to regularly poll its “hardware”. Where Visual Basic 3.0 and 6.0 differ, we shall present both and note the differences. We’ll make use of one VB form called form1. The server component should be added to the project (either winsrv.vbx in VB 3.0 or srv.ocx in VB 6.0). Place an instance of the control on the form and set its properties according to:
This establishes at design time the 6-character local Equipment module name as SINSIM as in the simple console example 1 and the 16-character global exported equipment name as SINEWAVE (please see “What’s in a Name” for clarification). You can also set these properties at run time, which might indeed be desired for cases where the same server code is to run on different machines and the system-wide unique ExportName must be determined via environment variable or command line. Also note that the Enabled property should be left as False in design mode.
Create three global arrays to use as simulated data and two global arrays to use as input and output data
In the Form_load routine, include the following:
Note that we have explicitly registered the property "SINE" in code. In Win32 you can also make use of the 'exports.csv' file to register properties. If you do so, and you use the 'fecid.csv' to register the FEC name, then you should not have multiply entries and rely on an 'Export' column to latch the FEC name from the file. An 'exports.csv' will contain the exported device server and will not be accessed until after the 'fecid.csv' is accessed. In most cases, the preferred method of property registration for Visual Basic servers is via the API call.
Now, add a timer control to the VB form. We can use the timer to make our data IO.
In this case, we are only simulating data, so we’ll update our data buffer (dbuf) with a noisy sine curve. Set the timer interval to 1000 milliseconds (or faster if you want) and enable it. In the timer event, write the following code:
In the EqpFcn event of the component (default will be Eqp1 in winsrv.vbx and Srv1 in srv.ocx), write the following lines of code. If you are using winsrv.vbx, you can rename the control to Srv1 in order to correspond the lines of code below. In this case you should also pay attention to the comment lines referring to winsrv.vbx.
Make sure that you include tine.bas in your project, so that you have all of the necessary definitions concerning error codes such as “illegal_property”, etc, and that you have the prototypes for routines such as CADDR(), etc.
The above example does not call RegisterFecName(), but instead relies on the local file “fecid.csv” to be found in the directory pointed to by the environment variable “FEC_HOME”.
Make sure that this variable is set along with the “TINE_HOME” environment variable (which gives the location of the equipment name server address file, cshosts.csv”).