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 Client (Windows GUI)

Introduction

TINE console client applications play an important role in middle-layer servers, automatic servers, scripts, diagnostic checks, etc. Client applications requiring a user interface are best written as GUI applications.

The example below is a simple client code module which obtains the sine curve from the above server examples. This illustrates both synchronous and asynchronous calls. Where Visual Basic 3.0 and 6.0 differ, we shall present both and note the differences.
Furthermore, as Visual Basic 6.0 supports ACOP, we shall also show the ACOP example for obtaining the sine curve.

eqp.vbx, eqp.ocx

We’ll make use of one VB form called form1. The client component should be added to the project (either eqp.vbx in VB 3.0 or Eqp.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 parameters used in a data link to the server of Example 3 or 1. Here we have set the data format (EqpFormat) to DOUBLE, the exported equipment name (EqpName) to “SINEWAVE”, the device instance number (EqpNumber) to 0 (this will show up as DevName = “#0” at the server), the remote polling mode (EqpPollMode) to POLL, the remote polling rate (EqpPollRate) to 1000 milliseconds, the device property (EqpProperty) to “SINE”, and the data array size (EqpSize) to 1024.

Put a picture box component on the same form. Set the ScaleLeft and ScaleWidth properties to 0 and 1024, respectively, and set the ScaleTop and ScaleHeight properties to 600 and –600 respectively. Also put two command buttons on the form. Call one of them “StartStop” and the other “Reference”. For the “StartStop” control, set its caption to “Start”.

You should create the following global variables:

Dim sinbuf(1024) As Double
Dim refbuf(1024) As Double
Dim DEVNAME$

In the FormLoad() routine, place the simple line of text:

Sub Form_Load ()
DEVNAME$ = "SINEWAVE"
End Sub

This sets a global string to refer to the exported equipment name. This step is unnecessary, if we stick to the design time input of “EqpName” in the component (see above), however we’ll store it in a global variable for convenience, since this example will also demonstrate a synchronous command to the same server.

In the Receive event of the Eqp1 instance, place the following code:

Sub Eqp1_Receive ()
Dim ts&
If Eqp1.EqpStatus Then
picture1.Print "ERROR : " + RPCERROR(Eqp1.EqpStatus)
Exit Sub
End If
rc% = GETRPCDATA(Eqp1.EqpIndex, sinbuf(0), ts&)
picture1.Cls
For i% = 1 To 1023
picture1.Line (i% - 1, sinbuf(i% - 1))-(i%, sinbuf(i%))
Next
End Sub

Note, that we always check the incoming status code for errors. The Receive event will be triggered upon any error condition as well as incoming data. Thus, blindly plotting the data array can give an erroneous picture if the error code is not checked.

In the Reference command button click event, place the following code:

Sub Reference_Click ()
Dim dout As DBLK, din As DBLK
dout.dArrayLength = 1024
dout.dFormat = CF_DOUBLE
rc% = EXECLINK(DEVNAME$, "SINE", dout, refbuf(0), din, 0, CA_READ)
If rc% Then
MsgBox RPCERROR(rc%)
Exit Sub
End If
picture1.AutoRedraw = True
picture1.ForeColor = &HFF
For i% = 1 To 1023
picture1.Line (i% - 1, refbuf(i% - 1))-(i%, refbuf(i%))
Next
picture1.ForeColor = 0
picture1.AutoRedraw = False
End Sub

This serves as an example for synchronous data acquisition. When EXECLINK completes, either data have been returned or there is an error condition.

In the StartStop command button click event, place the following code:

Sub StartStop_Click ()
If startstop.Caption = "Start" Then
Eqp1.EqpName = DEVNAME$
Eqp1.Enabled = True
startstop.Caption = "Stop"
Else
Eqp1.Enabled = False
startstop.Caption = "Start"
End If
End Sub

We set the EqpName property once again here at run time, just for completeness sake.
This step is unnecessary, but does let you trivially tailor the program to other servers by merely changing one line in the Form_load procedure.

Acop.ocx

The above example uses the eqp.vbx or eqp.ocx component. In Win32 you have the (preferred) alternative to use the ACOP component. Below we show the above client example re-written for acop.

We’ll make use of one VB form called form1. The ACOP component should be added to the project. Place an instance of the ACOP on the form and call up its property page.
Go to the Device Tab and Set the following properties:

Now select the Axis tab, and set the following properties

You can add labels if you like. The important thing is to set the Max and Min values for the axes appropriately. Alternatively, we can either use the Autoscale method of ACOP, or select the query EGU box on the device Tab. If the server has been configured to return the information on the Engineering Units for the selected property, then the Max, Min and Y-Axis labels will be filled in automatically. But let’s not worry about that here.

On the same form, place two command buttons, and as in the above example, call them “StartStop” and “Reference”, and change the caption for StartStop to read “Start”.

Now, you need to define three global variables as shown below:

Dim sinbuf(1023) As Double
Dim refbuf(1023) As Double
Dim hSineDisplay As Long

We want to be able to freeze a reference plot on the display. To do this, we’ll keep track of our normal updated display by storing its display handle in a global variable. So in the Form_load routine, place the following lines of code:

Private Sub Form_Load()
hSineDisplay = ACOP1.Draw(sinbuf)
End Sub

And now in the Receive event of the ACOP control place the following code:

Private Sub ACOP1_Receive(ByVal LinkIndex As Long, ByVal StatusCode As Long)
If StatusCode Then
ACOP1.ClearText
ACOP1.PrintText ACOP1.Status
End If
ACOP1.ClearScreen hSineDisplay
ACOP1.RefreshScreen sinbuf, hSineDisplay
End Sub

Now we can fill in the StartStop and Reference click events. In StartStop_click, you should place the following code:

Private Sub StartStop_Click()
If StartStop.Caption = "Start" Then
StartStop.Caption = "Stop"
ACOP1.AccessMode = "POLL"
If ACOP1.AttachLink(sinbuf) < 0 Then MsgBox ACOP1.Status
Else
StartStop.Caption = "Start"
ACOP1.CloseLink
End If
End Sub

And in Reference_click, you should place the following:

Private Sub Reference_Click()
ACOP1.AccessMode = "READ"
If ACOP1.Execute(refbuf) Then
MsgBox ACOP1.Status
Else
ACOP1.ForeColor = &HFF
ACOP1.Draw refbuf
ACOP1.ForeColor = 0
End If
End Sub

Note, that we should in general check the completion codes of our calls, and the status codes of the incoming data. For brevity, we have left some of the error checking out of the above example. For instance, the hSineDisplay handle returned from the call to the ACOP draw method could have been a “-1” indicating a problem.


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