plc - how to connect and read values from kepware using OPCAutomation.dll -


i creating small c# program connect , read value kepware server using opcautomation.dll, unable syntax?

opcautomation.opcserver _opcserver = new opcautomation.opcserver(); _opcserver.connect("", ""......); 

what values come inside these brackets?

opcautomation.opcserver _opcserver = new opcautomation.opcserver(); _opcserver.connect("kepware.kepserverex.v5", ""); 

the second parameter opc server node , can left string.empty.

from reflector:

public virtual extern void connect([in, marshalas(unmanagedtype.bstr)] string progid, [in, optional, marshalas(unmanagedtype.struct)] object node); 

i'm adding explample read , write values:

// set variables opcserver connectedopc = new opcserver(); array opcitemids = array.createinstance(typeof(string), 10); array itemserverhandles = array.createinstance(typeof(int32), 10); array itemservererrors = array.createinstance(typeof(int32), 10); array clienthandles = array.createinstance(typeof(int32), 10); array requesteddatatypes = array.createinstance(typeof(int16), 10); array accesspaths = array.createinstance(typeof(string), 10); opcgroup opcgroupnames;  // connect kepserverex connectedopc.connect("kepware.kepserverex.v5", "");  // add tags , opc group. // set tags opcitemids.setvalue("counting.plc.station1.loggedon", 1); opcitemids.setvalue("counting.plc.station2.loggedon", 2); opcitemids.setvalue("counting.plc.station3.loggedon", 3); opcitemids.setvalue("counting.plc.station1.operator", 4); opcitemids.setvalue("counting.plc.station2.operator", 5); opcitemids.setvalue("counting.plc.station3.operator", 6);  // set opc group opcgroupnames = connectedopc.opcgroups.add("group01"); opcgroupnames.deadband = 0; opcgroupnames.updaterate = 100; opcgroupnames.issubscribed = true; opcgroupnames.isactive = true; opcgroupnames.opcitems.additems(6, ref opcitemids, ref clienthandles, out itemserverhandles, out itemservererrors, requesteddatatypes, accesspaths);  // read values server tags. // read array itemserverreadvalues = array.createinstance(typeof(string), 10); object a; object b; opcgroupnames.syncread((short)opcautomation.opcdatasource.opcdevice, 6, ref itemserverhandles, out itemserverreadvalues, out itemservererrors, out a, out b); console.writeline((string)itemserverreadvalues.getvalue(4)); console.writeline((string)itemserverreadvalues.getvalue(5)); console.writeline((string)itemserverreadvalues.getvalue(6));  // write values server tags. // write array itemserverwritevalues = array.createinstance(typeof(object), 7); itemserverwritevalues.setvalue(1, 1); itemserverwritevalues.setvalue(1, 2); itemserverwritevalues.setvalue(1, 3); itemserverwritevalues.setvalue("test op 1", 4); itemserverwritevalues.setvalue("test op 2", 5); itemserverwritevalues.setvalue("test op 3", 6); opcgroupnames.syncwrite(6, ref itemserverhandles, ref itemserverreadvalues, out itemservererrors); 

this example adapted from: http://lifeisunderconstruction.blogspot.mx/2011/03/opc-client-in-asp-net-c.html, have added in case link gets broken.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -