c# - OpcNetApi DataChange Event does not fire -
i'm using opcnetapi connect opc server. able connect , read data without issues, however, when data changes need read again able see changes, i'm not being notified of changes event though have added handler datachanged event of subscription.
is there special need work?
opc.url url = new opc.url("opcda://localhost/archestra.fsgateway.3"); opccom.factory factory = new opccom.factory(); using (opc.da.server server = new opc.da.server(factory, url)) { server.connect(); console.writeline("server localid = {0}", server.locale); opc.da.subscriptionstate state = new opc.da.subscriptionstate(); using (opc.da.subscription group = server.createsubscription(new opc.da.subscriptionstate { name = "group1", updaterate = 40, deadband = 0, active = true }) opc.da.subscription) { // create itesm opc.da.item[] items = new opc.da.item[2]; items[0] = new opc.da.item { itemname = "value1", active = true, clienthandle = "6s1", activespecified = true }; items[1] = new opc.da.item { itemname = "value2", active = true, clienthandle = "6s2", activespecified = true }; opc.da.itemresult[] results = group.additems(items); (int = 0; < results.length; i++) { items[i].serverhandle = results[i].serverhandle; } group.datachanged += new opc.da.datachangedeventhandler(group_datachanged); group.state.active = true; opc.irequest request; group.read(group.items, 1234, new opc.da.readcompleteeventhandler(group_readcomplete), out request); // stop when 'q' pressed consolekeyinfo key = new consolekeyinfo(); while (key.key != consolekey.q) { key = console.readkey(); if (key.key == consolekey.r) { group.read(group.items, 1234, new opc.da.readcompleteeventhandler(group_readcomplete), out request); } } group.datachanged -= group_datachanged; group.removeitems(items); } server.disconnect(); } static void group_datachanged(object subscriptionhandle, object requesthandle, opc.da.itemvalueresult[] values) { console.writeline("data changed"); foreach (opc.da.itemvalueresult readresult in values) { console.writeline("\t{0}\tvalue:{1}", readresult.itemname, readresult.value); } console.writeline(); }
thank you,
jfercan
everything wrote seems show group_datachanged method called when @ least 1 of data of subscription has been updated.
Comments
Post a Comment