|
Basic Tutorial
In this tutorial we will connect an ActiveX control gauge in Visual Basic to an
item in an OPC Data Access server to illustrate how to use the OPC client capabilities in the controls.
If you wish to try this on your own computer, you will need to have our Instrumentation ActiveX controls evaluation software and any OPC Data Access server on your machine. You may connect to any OPC server if you wish with these ActiveX controls. We are using our TOP Server product running in simulation mode so that no PLC hardware is required. A free evaluation copy of the TOP server is also available if you wish to use the same OPC server we are using in this tutorial. This tutorial expects that you have a copy of Visual Basic and that you have basic familiarity with Visual Basic.
Optional Step:
If you are using your own OPC server you may skip this step but should have your OPC server configured with items and ready to be used. Install the TOP server evaluation software and launch it by clicking
Start->Programs->Software Toolbox->TOP Server->TOP Server. Once the application is running click File->Open and open the file \Program Files\Software Toolbox\TOP
Server\Projects\Simdemo.opf. This step sets up the
TOP server to run in simulation mode.
In simulation mode there are a number of items that will increment automatically. These items may also be written to, although the simulation signal will then begin incrementing the value you write automatically.
Step 1: Launch Visual Basic and create a new EXE project.
Step 2:
Click on Project->Components on the VB menu or press the Ctrl-T to bring up the list of available components on your machine. You should see 4 component groups listed as shown here.
Select the IOComp Analog Pack, click the check box so that it is selected, and
click the Apply button, followed by the OK button. This will add a number of components to your VB components toolbar as shown here.
Step 3: Select the Angular Gauge Icon from the VB Toolbar by double clicking
on it on the VB toolbar, which will place a copy of the Angular Gauge onto your Visual Basic Form as shown below.
Step 4:
Right click over the control on the form and select "Properties" from the
menu that appears. This will bring up the Custom Properties page for the control.
Step 5:
On the General tab of the properties page, set the Position Max to 1000 if
you are using the TOP Server running with it's built in Simulation demonstration. If
you are using your own OPC server, you should set the Position Max and Min to
the range of the item in your OPC server that you will be connecting to.
Step 6: Select the OPC Tab on the properties page.
From this tab you can connect as many properties of the gauge control to OPC
items as you like. To add a property, click the Add button on the OPC tab and from the resulting dialog select an item to add.
We will use the Position property. Select it and click OK.
Step 7: Click on the button next to the text box labeled Computer which will
bring up a list of avialable computers on your network. We will leave the selection as "local" for this tutorial.
Step 8: Click on the next to the text box labeled OPC Server which will cause
the OPC server dialog to be displayed. This dialog shows the available OPC servers on the computer selected in the Computer dialog.
Select the server named "SWToolbox.TOPServer" and click OK.
Step 9: Click on the next to the text box labeled Item which will cause the
Items dialog to be displayed. From this dialog you may browse the available items
on your OPC server (assuming your OPC server supports tag browsing).
Double click on Channel_1, then Device_1 and select Tag_1 for this example.
Click OK.
Step 10: You have now completed the configuration of the Angular Gauge and your properties page should appear as shown here.
The Update Rate field defines the time rate in milliseconds (ms) that the gauge will
request the OPC server update it at. These controls use OPC Asynchronous
reads meaning they connect to the OPC server and ask that the OPC server advise
the object whenever data changes for the requested item, at the update rate
specified. This minimizes communications time between the client object and the
OPC server by only communicating when data changes.
The Auto Connect check box means the control will automatically connect to the
OPC server when it is launched at runtime. If you disable this box, you will later
need to enable the item via your code. This feature is valuable to allow you to
create objects that only connect to the OPC server under certain conditions.
Click Apply, then OK to dismiss the properties page.
Step 11: You may now run your VB project and observe the gauge moving in synchronization with the changing OPC data point.
If you now wanted to go back and add some other items to your VB form, you may.
As a suggestion, you could add a copy of the slider object (using icon shown here found on the VB components toolbar) and tie the Position property of that
object to the SAME tag as you tied the Angular Gauge. At runtime you will be
able to drag the slider and see the gauge change position accordingly. Controls
with user input capabilities will automatically do a Synchronous Write of changed
data values to the OPC server if you have their Enabled property set to true. |