OPC Server It is a set of architectures that use Microsoft COM/DCOM technology to achieve industrial automation data acquisition.OPC Server provides an OPC interface, which returns the information values of the physical devices (PLC s) connected to it to the client application through the interface.That is, through these interfaces, clients can get information about the physical devices connected to OPC Server.For integrated applications, as long as the OPC interface is supported, physical devices can be easily accessed without technical information.Programmer can use the same program code to operate different hardware devices to achieve the purpose of software reuse.
This API makes it easy to read and write data from both VC# and VB.NET opc clients at once.
Simple API List
The following functions are prepared in DLL (DxpSimpleAPI.dll) of C#'s simple API.
namespace DxpSimpleAPI { public class DxpSimpleClass { public DxpSimpleClass(); public bool Connect(string sNodeName, string sServerName); public bool Disconnect(); public bool EnumServerList(string sNodeName, out string[] sServerNameArray); public bool Read(string[] sItemIDArray, out object[] oValueArray, out short[] wQualityArray, out FILETIME[] fTimeArray, out int[] nErrorArray); public bool Write(string[] sItemIDArray, object[] oValArray, out int[] nErrorArray); } }
It mainly uses the following four functions.
Connect (connect to OPC server)
arg1: node name (in)
arg2:OPC server name (in)
Return: true: success, false: failure
Disconnect (disconnect from OPC server)
arg: none
return: true: success,false: failure
Read (one-time read)
arg1: ItemID(in)
Array arg2: Read value array (out)
arg3: mass array (out)
arg4: timestamp array (out)
arg5: error array (out)
Return: true: success, false: unexpected error
Write (once)
arg1: ItemID(in)
Array arg2: Write value array (in)
arg3: error array (out)
Return: true: success, false: unexpected error
The enumeration of OPC servers can be accomplished with the following functions.
EnumServerList (enumeration of OPC servers)
arg1: node name (in)
arg2: an array of OPC server names installed on a specified node (out)
Return: true: success, false: failure
Usage of DLL
Create a VC# project using Visual Studio and add a reference configuration.Add references to this DLL and OPCRcw.Da.DLL from the additional menu of Visual Studio's reference configuration.
Use the using statement to define OpcRcw.Da, as shown below.
using OpcRcw.Da;
Usage of functions
Simple API s can be used in the following ways.
Connection
// Create OPC access instance DxpSimpleAPI.DxpSimpleClass opc = new DxpSimpleAPI.DxpSimpleClass(); // Connect: node name("localhost") and Server Prog.ID("Takebishi.Dxp") bool ret = opc.Connect("localhost", "Takebishi.Dxp");
Read
// Read 3 points string[] sItemNameArray = new string[3]; sItemNameArray[0] = "Device1.D0"; sItemNameArray[1] = "Device1.D1"; sItemNameArray[2] = "Device1.D2"; object[] oValueArray; short[] wQualityArray; OpcRcw.Da.FILETIME[] fTimeArray; int[] nErrorArray; bool ret = opc.Read(sItemNameArray, out oValueArray, out wQualityArray, out fTimeArray, out nErrorArray);
Write
// Write 3 points object[] oValArray = new object[3]; oValArray[0] = "1234"; oValArray[1] = "5678"; oValArray[2] = "9012"; int[] nErrorArray; bool ret = opc.Write(sItemNameArray, oValArray, out nErrorArray);
Disconnect
// Disconnect opc.Disconnect();
Implement Demo
The sample program for the VC # client (VS2008) is easier to download than the downloadable program linked below.
Notes
Use this DLL starting with Visual Studio 2008.Also, it requires.NET Framework 3.5 as the runtime engine.
Connecting to the target OPC server should respond to OPC DA3.0 because the DLL uses the IOPCItemIO interface of OPC DA3.0.