Using RsiOpcAuto.dll with VB.Net (visual basic) - Array problems

G

Thread Starter

gpstefansson

This issue deals with using RSLinx from Rockwell to communicate with a ControlLogix PLC using the RsiOpcAuto.dll in a VB.Net program.

Arrays in VB.Net do not support option base 1 to create arrays that start from position 1. VB.Net forces you to create arrays that start in position 0.
In an article here on this site (http://www.control.com/1003433372/index_html), Kris Grindstaff wrote that "It is important to dimension the associated input arrays with a base of 1. This is a requirement imposed in the OPC automation specification. otherwise you will get errors."

So my question is: How do I use the RsiOpcAuto.dll from VB.Net with the arrays that VB.Net offers?

Is there a workaround to this situation, or some way to make this work?

Any input would be greatly apreciated.

Regards,
G
 
G,

As I understand it, rsiopcauto.dll is an automation interface. .NET doesn't do automation very well as a rule. It may work sometimes but... Automation interfaces were very specific to VB (i.e. VB6).

Try our OPC to .NET interface assembly for free. We do arrays and lots more. There are VB.NET and C# sample projects. It will save you a lot of time.

[email protected]
 
<p>Try this:
<pre>
Imports RsiOPCAuto
Public Class Form1

Public Sub PageLoad()

End Sub

Public Sub ConnectServer()

Dim i As Long
Dim sRemoteMachine As String

On Error GoTo ErrorHandler

If txtMachine.Text.Length > 0 Then
txtStatus.Text = "Connecting to RSLinx Remote OPC Server on " & txtMachine.Text
Me.Refresh()
sRemoteMachine = txtMachine.Text
'attempt to connect to remote server
MyOPCServer.Connect("RSLinx Remote OPC Server", sRemoteMachine)
Else
txtStatus.Text = "Connecting to local RSLinx OPC Server ..."
Me.Refresh()
'attempt to connect to local server
MyOPCServer.Connect("RSLinx OPC Server")
End If

' Need to Create an OPC Group
MyOPCGroup = MyOPCServer.OPCGroups.Add("DCI_OPC_Conn")
'set default state subscription to capture data changes
MyOPCGroup.IsSubscribed = True
'Set group inactive
MyOPCGroup.IsActive = False
If Len(txtUpdate.Text) > 0 And IsNumeric(txtUpdate.Text) Then
MyOPCGroup.UpdateRate = txtUpdate.Text
Else
'use default
MyOPCGroup.UpdateRate = 1000
End If

btnConnect.Text = "Disconnect"
txtStatus.Text = "Connected to server"
' Enable Add Items button
btnAddRef.Enabled = True
MyOPCGroup.IsActive = True
Exit Sub

Private Sub RSLinxRead()

Dim lNumitems As Long
Dim myOPCItem As OPCItem
Dim i As Integer

Dim tmp As String

On Error GoTo ErrorHandler

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

'specify number of elements
lNumitems = MyOPCGroup.OPCItems.Count

' Dimension server handles array
For i = 1 To lNumitems
'pass in server handles
myOPCItem = MyOPCGroup.OPCItems.Item(i)
tmp = MyOPCGroup.OPCItems.Item(i).Value
Values(i - 1) = myOPCItem.Value.ToString
Next 'i
Exit Sub

End Class
<pre>
 
Top