visual basic.net and asyncread

D

Thread Starter

dale

<p>Does anyone have an example of doing a simple read of 2 or more integers from an Allen Bradley SLC or controllogix controller?

<p>I can read data using the addhandler(datachange) - but I can't seem to get an asyncread to work. Apparently I'm not getting my system.arrays for the serverhandles and errors configured correctly.

<p>I get a "Specified array was not of the expected type." on the asyncread.
<pre>
Imports RsiOPCAuto
Public Class Form1
Public WithEvents oServer As RsiOPCAuto_OPCServer
Public WithEvents oGroup As RsiOPCAuto_OPCGroup
Public oItem1 As RsiOPCAuto_OPCItem
Public oItem2 As RsiOPCAuto_OPCItem
Public oItem3 As RsiOPCAuto_OPCItem
Public oItem4 As RsiOPCAuto_OPCItem Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
oServer = New RsiOPCAuto_OPCServer
oServer.Connect("RSLinx OPC Server")
oGroup = oServer.OPCGroups.Add("TestGroup") oGroup.IsActive = True oGroup.UpdateRate = 500
oGroup.IsSubscribed = True oItem1 = oGroup.OPCItems.AddItem ("[Dale99]N7:0", 1)

Dim arHandles(9) As Object
Dim arerrors(9) As Object
Dim arTransID As Integer
Dim arCancelID As Integer
Dim i As Integer

i = 0
arHandles(i) = Group.OPCItems.ServerHandle
oGroup.AsyncRead(1, arHandles, arerrors, arTransID, arCancelID)
</pre>
 
A

Andrew Smith

Did you get an answer? I have exactly same problem. VB.net using RSiOPCAuto.dll. The problem has to do with base 1 arrays I know. Did you find a workaround?

Cheers,

Andrew
[email protected]
 
<p>I am very close to a solution. This should work, but unfortunately, I have an error: "Value does not fall within the expected range" on all calls. Can someone let me know which value is out of range?
<pre>
Private Sub cmdAsyncRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAsyncRead.Click
' This function demonstrates how to perform an OPC Group Asynchronous Read operation.
' The data is returned in the callback function MyOPCGroup_AsyncReadComplete

Dim lNumitems As Long
Dim arHandles() As Integer
Dim arErrors() As Integer
Dim lTransID As Long = 1975
Dim lCancelID As Long = 1
Dim myOPCItem As OPCItems
Dim i As Integer

Dim tmp As Integer

On Error GoTo ErrorHandler

txtStatus.Text = "OPC Group Async Read in progress ..."

'specify number of elements
lNumitems = MyOPCGroup.OPCItems.Count - 1
ReDim arHandles(lNumitems)
ReDim arErrors(lNumitems)

' Dimension server handles array
For i = 0 To lNumitems
'pass in server handles
tmp = MyOPCGroup.OPCItems.Item(i + 1).ClientHandle

arHandles(i) = MyOPCGroup.OPCItems.Item(i + 1).ClientHandle
arErrors(i) = 0

Next 'i

' perform async read
MyOPCGroup.IsActive = False
MyOPCGroup.AsyncRead(itemCount, arHandles, arErrors, lTransID, lCancelID)

' check for error in passing parameters to server
Exit Sub

ErrorHandler:
MsgBox("Async Read Error: " & Err.Number & " " & Err.Description & ", " & Err.LastDllError)
End Sub
</pre>
 
W
Did you get your problem worked out? If not E-mail me and I will send info on what you want. My E-Mail: tom1fox @ suddenlink. net
 
Your example will probably work if you change the i value to a 1. OPC just wants all values at the number 1 index of the array. I didn't test your code to see if it would work, but, thats what it looks like to me. I have E-mailed a demonstration VB.Net program to you. If anyone would like to have it, simply send me an E-Mail and you will get it.

[email protected]
 
New E-mail Address- [email protected]

>Your example will probably work if you change the i value
>to a 1. OPC just wants all values at the number 1 index of
>the array. I didn't test your code to see if it would work,
>but, thats what it looks like to me. I have E-mailed a
>demonstration VB.Net program to you. If anyone would like to
>have it, simply send me an E-Mail and you will get it.
 
Top