What problems should be paid attention to in OPC automation interface programming?
This article mainly introduces the relevant knowledge of "what problems should be paid attention to in OPC automation interface programming". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "what problems need to be paid attention to in OPC automation interface programming" can help you solve the problem.
Notes are as follows:
(1) use SyncRead (synchronous group read) and AsyncRead (group asynchronous read) to read service data
C # code prototype:
SyncRead (short source,int NumItems,ref Arrray ServerHandles,out Values,outErrors,out Qualities,out
TimeStamps)
AsyncRead (int NumItems,ref Arrray ServerHandles,outErrors,int TransactionID,out int CancelID)
You can see that there is a ref Arrray ServerHandles in both functions.
If we pass parameters to the function,
Write as follows:
Int [] handle=new int [] {item.ServerHandle}
System.Array ServerHandles= (System.Array) handle
At this point, an "incorrect parameter" error exception occurs.
It should be changed to:
The internal data subscript of the int [] handle=new int [] {/ * function starts at 1, so leave the 0th bit free * / 0mem.ServerHandle}
System.Array ServerHandles= (System.Array) handle
OPCDAAuto.dll internal source code:
For (LONG ii = 1; ii GetServerHandle ())
PPItem [II-1] = pItem
}
}
(2) AsyncRead (asynchronous read of group) reads service data
When reading data asynchronously, the IsSubscribed parameter of the corresponding group must be set to true to read the data in subscription state; when we use asynchronous mode
When you read the data, there is an event that the asynchronous read completes:
Declaration:
Group.AsyncReadComplete + = new
OPCAutomation .DIOPCGroupEvent _ AsyncReadCompleteEventHandler (AsyncReadComplete)
Achieve:
Private void AsyncReadComplete (int TransactionID, int NumItems, ref System.Array ClientHandles, ref
System.Array ItemValues, ref System.Array Qualities, ref System.Array TimeStamps, ref System.Array
Errors)
{}
This is the end of the content about "what should be paid attention to in OPC automation interface programming". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.