Main Page | Features | Central Services | csv-Files | Types | Transfer | Access | API-C | API-.NET | API-Java | Examples | Downloads
page generated on 22.12.2024 - 04:45
A Simple TINE Server (Windows GUI)

Introduction

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

Dim sinbuf(1024) As Single
Dim noise(1024) As Single
Dim dbuf(1024) As Single
Dim rArray(1024) As Double
Dim wArray(1024) As Double

In the Form_load routine, include the following:

Private Sub Form_Load()
' fill in two array to simulate noisy data:
For i% = 0 To 1024
sinbuf(i%) = 256 * (Sin(6.2832 * CSng(i%) / CSng(1024)) + 1)
noise(i%) = 10 * Rnd
Next
‘ enable the server
Srv1.Enabled = True
If Srv1.EqpStatus Then MsgBox "ERR: " + Str$(Srv1.EqpStatus)
'"Extended" Property Registration:
id% = Srv1.EqpRegisterPropertyEx("SINE", NumValues%, CF_DOUBLE, "", NumValues%, _
CF_DOUBLE, "", CA_READ + CA_WRITE, "[-1:1]Sine function from Winfec")
If id% < 0 Then MsgBox "RegisterProperty ERR: " + Str$(-id%)
End Sub

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:

Private Sub Timer1_Timer()
'simulate data readout, ‘dbuf()’ will be our data buffer
For i% = 0 To 1023
dbuf(i%) = sinbuf(i%) + noise(i% Mod 1024)
Next
End Sub

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.

Private Sub Srv1_EqpFcn(ByVal devName As String, ByVal devProperty As String, _
ByVal outArrayLen As Long, ByVal inArrayLen As Long, ByVal devAccess As Integer)
Select Case devProperty
Case "SINE":
If devAccess And CA_WRITE Then ' something has come in
Srv1.EqpRecvData wArray
‘ or use the deprecated call: Srv1.EqpRecv CADDR(wArray(0))
‘ in winsrv.vbx, there are no methods, therefore EqpRecv is a property
‘ you need to set as:
‘ Srv1.EqpRecv = CADDR(wArray(0))
Else ' zero the WDAT array
For i% = 0 To NumValues% - 1: wArray(i) = 0: Next
End If
If outArrayLen = 0 Then ‘ make the caller read something
Srv1.EqpSetCompletion illegal_read_write, “”
‘ or use the deprecated property: Srv1.EqpStatus = illegal_read_write
‘ For historical reasons, the EqpStatus property is called simply Status in
‘ in winsrv.vbx, so you should in that case write:
‘ Srv1.Status = illegal_read_write
Exit Sub
End If
For i% = 0 To outArrayLen - 1: rArray(i%) = wArray(i%) + dbuf(i%): Next
Srv1.EqpSendData rArray
‘ or use the deprecated call: Srv1.EqpSend CADDR(rArray(0))
‘ in winsrv.vbx, there are no methods, therefore EqpRecv is a property
‘ you need to set as:
‘ Srv1.EqpSend = CADDR(rArray(0))
Case Else:
Srv1.EqpStatus = illegal_property
‘ For historical reasons, the EqpStatus property is called simply Status in
‘ in winsrv.vbx, so you should in that case write:
‘ Srv1.Status = illegal_ property
End Select
Srv1.EqpStatus = 0 ‘ success
‘ For historical reasons, the EqpStatus property is called simply Status in
‘ in winsrv.vbx, so you should in that case write:
‘ Srv1.Status = 0
End Sub

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”).


Impressum   |   Imprint   |   Datenschutzerklaerung   |   Data Privacy Policy   |   Declaration of Accessibility   |   Erklaerung zur Barrierefreiheit
Generated for TINE API by  doxygen 1.5.8