|
Simple Visual Basic Read Tutorial - No Code Needed!
This example shows you how easy it is to connect the OPC Data ActiveX to an OPC server to read data
without writing any code. If you want to do this example on your computer, you will need to have the demo of the OPC Data ActiveX control and you will need a copy of Visual Basic 5.0 or 6.0. After installing the OPC Data ActiveX control, open Visual Basic and start a new project. This simple 5 step process gets you up and reading live data without writing a line of code.
1.
Add the OPC Data Control to your VB Project - click on Project-->Properties or press Ctrl-T in Visual Basic to bring up the dialog below. Select "OPC Data Control" in the dialog and check it and click OK. Your VB toolbar will now show the OPC Data control as shown here.
2.
Place some VB objects and the OPC Data Control on a form - here we have placed one copy
of the OPC Data ActiveX control and 2 Text Boxes named "Text1" and "Text2" (by default) on the
form. When you place the OPC Data ActiveX on the form a licensing dialog will be shown - you can dismiss it if you have a 10 day demo.
3. Connect to the OPC server of your choice (browsing built in) - place your mouse over the
OPC Data ActiveX on the form and right-click - select Properties on the menu that appears and the
custom properties page for the OPC Data control is shown. Select the "OPC Server" tab - by default
our Simulation server is listed as "OPCDataCtrl.OPCSimServer.1" -- you can leave that as is if you
want to use our simulation server and click Apply to continue.
To use an a different OPC server then click browse and you will be able to connect to OPC servers
of your choice. Keep in mind that if you are connecting to an OPC server on another machine over a
network using DCOM, you will need to have appropriate security access over your network to do so.
4. Browse your OPC server(s) for data points and connect to object properties (i.e. Text box
.Text property) -
- Select the Connections tab on the OPC Data ActiveX properties page and you will see in the
"Controls" box a list of all the controls on the form - go to Text1 and select it's Text property by clicking on it
- Click on the "Browse" button and through the dialog below pick a data point from our
simulation server or if you are using your own OPC server then pick a point appropriate to
your server by highlighting it in the items pane. You will see that an itemID is automatically
created for you. Click "apply" and then "OK' to dismiss the Properties page dialog.
5. Run your program to get live OPC process data - run your VB program by selecting Run-
->Start in the VB menu or pressing the F5 function key and you will see your live data automatically appearing in the text boxes.
Ready to write some data ? Proceed to our "Simple Write" example.
|