Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What problems should be paid attention to in OPC automation interface programming?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report