beckhoff TS6120 — 7.2 OPC .NET client : API sample for subscriptions

OPC Client sample code { Console.WriteLine("Read completed"); foreach(Opc.Da.ItemValueResultreadResultinresults) { Console.WriteLine("\t{0}\tval:{1}", readResult.ItemName, readResult.Value); } Console.WriteLine(); } 7.2 OPC .NET client : API sample for subscriptions https://infosys.beckhoff.com/content/1033/tcopcserver/Resources/12162185611/.zip To create a subsription from your C# applicatopn perform the following steps: Downlaod the Opc .Net Api from the OPC Foundation website (Go to:

Resources > Samples and Tools > Classic) Starte Visual Studio 2005 and create a new C# console applikation Navigate to the Solution Explorer and add references to the OpcNetApi.dllOpcNetApi.Com.dll Use the following code to create your subscriptions.

static void Main(string[] args) { // Create a server object and connect to the TwinCATOpcServer Opc.URL url = new Opc.URL("opcda://localhost/BECKHOFF.TwinCATOpcServerDA"); Opc.Da.Server server = null; OpcCom.Factory fact = new OpcCom.Factory(); server = new Opc.Da.Server(fact, null); server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential())); // Create a group Opc.Da.Subscription group; Opc.Da.SubscriptionState groupState = new Opc.Da.SubscriptionState(); groupState.Name = "Group"; groupState.Active = true; group = (Opc.Da.Subscription)server.CreateSubscription(groupState); // add items to the group.

Opc.Da.Item[] items = new Opc.Da.Item[3]; items[0] = new Opc.Da.Item(); items[0].ItemName = "PLC1.dyn_R8[1]"; items[1] = new Opc.Da.Item(); items[1].ItemName = "PLC1.dyn_R4[1]"; items[2] = new Opc.Da.Item(); items[2].ItemName = "PLC1.dyn_I4[1]"; items = group.AddItems(items); group.DataChanged += new Opc.Da.DataChangedEventHandler(OnTransactionCompleted); Console.ReadLine(); } staticvoid OnTransactionCompleted( object group, object hReq, Opc.Da.ItemValueResult[] items) { Console.WriteLine("------------------->"); Console.WriteLine("DataChanged ..."); for (int i = 0; i { Console.WriteLine("Item DataChange - ItemId: {0}", items[i].ItemName); Console.WriteLine(" Value:

{0,-20}", items[i].Value); Console.WriteLine(" TimeStamp: {0:00}:{1:00}:{2:00}.{3:000}", items[i].Timestamp.Hour, items[i].Timestamp.Minute, items[i].Timestamp.Second, items[i].Timestamp.Millisecond); } Console.WriteLine("------------------- } TS6120 62 Version: 1.2.0