Open Automation Software
Moving Data From Anywhere to Anywhere
1-303-679-0898

Getting Started – .NET Data Connector

The following steps can be used to add real-time read and write data functions to a C#, C++, or Visual Basic.NET WinForm or Windows Service application.

The OPC Controls data component can also be used in ASP.NET Web applications. Refer to the Read Values and Write Values Forms in the VB.NET example for programmatic interface of using the OPC Controls Data component.

All properties are programmatically accessible. The component can also be used with Visual Studio 2003 with the older 1.1 Framework version of Open Automation Software.

Step 1

Start Visual Studio and select File->New->Project to create a new C#, C++, or VB.

.NET WinForm HMI 292

Step 2

Select Windows Application as the project type.

.Net Trend 359

Step 3

From the Toolbox if OPCControls Data component is not available right click in the Toolbox and select Choose Items. If it is available to Step 4.

.NET WinForm HMI 294

From the .NET Framework Components select the OPC Controls Data component and then select OK.

.NET WinForm HMI 295

Step 4

Add an OPCControlsData component to the Form.

.NET Data Connector 409

Step 5

Add a Button component onto the Form.

.NET Data Connector 410

Change the Name of the button to buttonAddTags.

.NET Data Connector 411

Change the Text property of the button to Add Tags.

.NET Data Connector 412

Double click on the button and enter the following code:

For VB:

For C#:

Note: If you wish to run this application on remote PCs make sure to include the Network Node or IP Address of the OAS Service source.  To connect to remote tags simply include a network node name or IP address as follows.

“\192.168.0.1Ramp.Value”

or

“\www.opcsystemsserver.comRamp.Value”

You can also use the OPCControlsNetworkNodes component to alias one network node for another. Refer to the VB.NET Example for a working demonstration.

Note: All Tag names are case sensitive.  Ramp.Value is valid, ramp.value is not.

Note: You can additionally use DirectOPC items with the OPC Controls Data component to connect directly to OPC Server Items without having to create Open Automation Software Tags. To see the full syntax of a DirectOPC Item use an OPC Control Label and browse an Open Automation Software Tag for the Text_OPCSystems_Tag property and select DirectOPC.

The following is an example of a DirectOPC Item:

[DirectOPC:KEPware.KEPServerEx.V4Channel_1.Device_1.Tag_1:DirectOPCUpdateRate:1:DirectOPCDataType:Double Float:DirectOPCAccessPath:]

OPC Server: KEPware.KEPServerEx.V4

OPC Item: Channel_1.Device_1.Tag_1

OPC Update Rate: 1

Data Type: Double Float

All client components can use this alternative syntax for connecting directly to OPC Servers.  This provides a direct pass through for OPC Items on local and remote systems.

Step 6

For Visual Basic view the code of Form1.

Select OpcControlsData1 from the object list.

.NET Data Connector 413

Select ValuesChangedAll from the event list.

.NET Data Connector 414

Enter the following code or your own code to do what every you desire with the data. Make sure to first check the Quality as True before using the Value as a valid value.

All values are queued in the order they are received from the Service and you may receive multiple values for the same tag in the same event.

Step 7

Run the application in Debug or Release mode.

.NET WinForm HMI 305

Step 8

To deploy the application to remote nodes first make sure the Tags as described in Step 5 are set to a Network Node or IP Address. You can also use the OPCControlsNetworkNodes component to alias the “localhost” node for another IP Address or node name. Registered domain names are also allowed.

Then simply copy the files in the binRelease directory to the target systems or follow the Smart Client deployment section in this help file to deploy your application using Click Once Deployment.

Step 9

Refer to the VB.NET example for demonstration example of all properties of all components.

The Read Values Form is a good resource for programmatic interface for reading values and working with both a Queue and a Hashtable.

The Write Values Form is a good resource on how to programmatically write values.