How do I implement AsyncRead in C#?|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
How do I implement AsyncRead in C#?
Avatar
Denis Pozarko
Member
Members
Forum Posts: 8
Member Since:
04/11/2021
sp_UserOfflineSmall Offline
1
05/19/2021 - 00:30
sp_Permalink sp_Print

I can't find exact solution on github samples. Can you please provide the link to it?

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
05/19/2021 - 02:21
sp_Permalink sp_Print

What are you calling AsyncRead?

UA does not support the AsyncRead features of COM.

Any AsyncRead is implemented using client side features of the programming language.

Avatar
Denis Pozarko
Member
Members
Forum Posts: 8
Member Since:
04/11/2021
sp_UserOfflineSmall Offline
3
05/19/2021 - 04:22
sp_Permalink sp_Print sp_EditHistory

Oh I accidently posted in wrong subforum. It is in DA.

This is what I've tried so far, I keep getting "Value does not fall withing expected range". Why is that?

public void AsyncReadStart(string groupName, ListView formListView) { newListView = formListView; asyncGroupNames.Add(groupName); int numItems = structOPCServers[selectedNodeindex].opcServer.OPCGroups.GetOPCGroup(groupName).OPCItems.Count+1; structOPCServers[selectedNodeindex].a_serverHandles = new int[numItems]; int i = 1; foreach(OPCItem item in structOPCServers[selectedNodeindex].opcGroup.OPCItems) { structOPCServers[selectedNodeindex].a_serverHandles.SetValue(item.ServerHandle, i); i++; } int transID = 1231; //int NumItems, ref Array ServerHandles, out Array Errors, int TransactionID, out int cancelIDs structOPCServers[selectedNodeindex].opcServer.OPCGroups.GetOPCGroup(groupName).AsyncRead(numItems, ref structOPCServers[selectedNodeindex].a_serverHandles, out structOPCServers[selectedNodeindex].a_errors, transID, out int cancelID); //Exception appears in line above. structOPCServers[selectedNodeindex].opcServer.OPCGroups.GetOPCGroup(groupName).AsyncReadComplete += OPC_Logic_AsyncReadComplete; }
Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
05/19/2021 - 05:41
sp_Permalink sp_Print

VB is fussy about Variants vs simple types.

You likely need a cast.

Avatar
Denis Pozarko
Member
Members
Forum Posts: 8
Member Since:
04/11/2021
sp_UserOfflineSmall Offline
5
05/20/2021 - 00:26
sp_Permalink sp_Print

Can you please provide me with example code, I've tried to cast it to different types and much more none seem to work.

This is metadata from IOPCGroup:

void AsyncRead(int NumItems, ref Array ServerHandles, out Array Errors, int TransactionID, out int CancelID);

 

AsyncRead(numItems, ref structOPCServers[selectedNodeindex].a_serverHandles, out structOPCServers[selectedNodeindex].a_errors, transID, out cancelID);

In my code:

numItems is int

structOPCServers[selectedNodeindex].a_serverHandles is Array

structOPCServers[selectedNodeindex].a_errors is Array

transID is int

cancelID is int

I really have no idea what to do.

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
05/20/2021 - 06:21
sp_Permalink sp_Print

There is no C# sample code that uses the VB automation wrapper that I am aware of.

You may have more success of you use VB.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 28
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1435
Posts: 4855