Home > Net >  C # and kepsever server communication error asynchronous read/write variables
C # and kepsever server communication error asynchronous read/write variables

Time:12-03

Recently doing a project with S7-1200 PLC communication, and communication with PLC by kepsever in c #, according to the website reference Interop. OPCAutomation. DLL files,
Read data from KEPSERVER is no problem, but distributed data occurs "of COM component invocation returns the error HRESULT E_FAIL"
Has not been solved, hope everybody to help
The code is as follows: (mainly write code)
Public void Write_PLC ()
{
Array AsyncValue_Wt;
Array SerHandles;
Object [] tmpWtData=https://bbs.csdn.net/topics/new object [8].//write data type must be the object, otherwise an error
Int [] tmpSerHdles=new int [8].
//to assign the input data Array, and then converted to an Array type to AsyncValue_Wt
TmpWtData [1]=(object) Pub_Var. Valve_Set;
TmpWtData [2]=(object) Pub_Var. Pinlv_Set;
TmpWtData [3]=(object) Pub_Var. Shuju [1].
TmpWtData [4]=(object) Pub_Var. Shuju [2].
TmpWtData [5]=(object) Pub_Var. Shuju [3].
TmpWtData [6]=(object) Pub_Var. Shuju [4].
TmpWtData [7]=(object) Pub_Var. Shuju [5].
//tmpWtData [4]=(object) Pub_Var. Percent_LD [1].
AsyncValue_Wt=(Array) tmpWtData;
//handle to the Item corresponding to the server send the input data to assign an Array, and then converted to an Array type to SerHandles
TmpSerHdles [1]=the Convert. ToInt32 (lserverhandles. GetValue (30));//set determine channel???????
TmpSerHdles [2]=the Convert. ToInt32 (lserverhandles. GetValue (28));
TmpSerHdles [3]=the Convert. ToInt32 (lserverhandles. GetValue (2));
TmpSerHdles [4]=the Convert. ToInt32 (lserverhandles. GetValue (1));
TmpSerHdles [5]=the Convert. ToInt32 (lserverhandles. GetValue (3));
TmpSerHdles [6]=the Convert. ToInt32 (lserverhandles. GetValue (4));
TmpSerHdles [7]=the Convert. ToInt32 (lserverhandles. GetValue (5));
SerHandles=(Array) tmpSerHdles;
ObjGroup. AsyncWrite (7, ref SerHandles, ref AsyncValue_Wt, out lErrors_Wt, lTransID_Wt, out lCancelID_Wt);
}


  •  Tags:  
  • C#
  • Related