One, install the KEPware.Enhanced.OPC.DDE.KEPServer. (plc data transfer to Kepserver, developed program with Opcserver read kepserver)
Open the Quick client to view the value of the pass
Two. C # program code
Reference Opcdaauto.dll
Under win7 64 bit kepserver = new Opcserver () The problem is error,
Retrieving a component in a COM class factory with a CLSID of <28e68f9a-8d75-11d1-8dc3-3c302a000000> failed because of the following error: 80040154
1. Be sure to open the Cmd.exe Run command file (instead of running open) in the C:\Windows\SysWOW64 path, and register the "OPCDAAuto.dll" command: REGSVR32 OPCDAAuto.dll;
2. Compile tool target to select x86
Kepserver.connect ("KEPware.KEPServerEx.V4", "127.0.0.1"); The IP address here is the IP address where the KEPware.Enhanced.OPC.DDE.KEPServer computer is installed.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingopcautomation;usingSystem.Threading;namespacespctest{ Public Partial classForm2:form {PrivateOpcserver Kepserver; Privateopcgroups kepgroups; PrivateOpcgroup Kepgroup; PrivateOpcitems Kepitems; //Bearing net weight, grease amount, dust cover press into depth, dust cover flatness press into Ok/ng PrivateOpcitem item1, item2, Item3; PublicForm2 () {InitializeComponent (); } #regionOPC ServerPrivate voidkepserverload () {Try{kepserver=NewOpcserver (); Kepserver.connect ("KEPware.KEPServerEx.V4","127.0.0.1"); if(Kepserver.serverstate = = (int) {opcserverstate.opcrunning) {//statuslabelconnectinfo.text = "OPC server connection succeeded"; } Else { //statuslabelconnectinfo.text = "OPC server connection failed"; return; } } Catch(Exception ex) {//statuslabelconnectinfo.text = "OPC Server connection failed," + ex. Message; return; } kepgroups=kepserver.opcgroups; Thread T1; //open 1 threads for reading dataT1 =NewThread (NewThreadStart (kepprocess)); T1. Start (); } Public voidkepprocess () {//Kepgroup = Kepgroups.add ("Channel.Device.Group");Kepgroup = Kepgroups.add ("Channel1.Device1.Group"); Kepgroup.updaterate= -; Kepgroup.isactive=true; Kepgroup.issubscribed=true; //triggering events when data changes in the KepgroupKepgroup.datachange + =NewDiopcgroupevent_datachangeeventhandler (Kepgroup_datachange); Kepitems=Kepgroup.opcitems; Item1= Kepitems.additem ("Channel1.Device1.A01",1); ITEM2= Kepitems.additem ("Channel1.Device1.A02",2); Item3= Kepitems.additem ("Channel1.Device1.A03",3); } //events that are triggered when data changes Public Delegate voidDelegateshowmessage (stringstr); Public voidKepgroup_datachange (intTransactionID,intNumItems,refArray Clienthandles,refArray Itemvalues,refArray qualities,refArray Timestamps) { stringstr =""; Delegateshowmessage Show1=Newdelegateshowmessage (showmessage); for(inti =1; I <= NumItems; i++) { if(Clienthandles.getvalue (i). Equals (1) ) {str="A01:"+Itemvalues.getvalue (i). ToString (); } if(Clienthandles.getvalue (i). Equals (2) ) {str="A02:"+Itemvalues.getvalue (i). ToString (); } if(Clienthandles.getvalue (i). Equals (3) ) {str="A03:"+Itemvalues.getvalue (i). ToString (); } BeginInvoke (Show1,New string[] {str}); } } Public voidShowMessage (stringstr) {Richtextbox1.appendtext (str+","); } #endregion Private voidForm2_load (Objectsender, EventArgs e) {kepserverload (); } Private voidForm2_formclosing (Objectsender, FormClosingEventArgs e) {Kepserver.disconnect (); } }}
Opcserver Modbus Usage and configuration