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.
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:
In the FormLoad() routine, place the simple line of text:
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:
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:
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:
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.
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:
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:
And now in the Receive event of the ACOP control place the following code:
Now we can fill in the StartStop and Reference click events. In StartStop_click, you should place the following code:
And in Reference_click, you should place the following:
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.