gmichaelpark
Computer
- Nov 17, 2005
- 1
I can get the code below to work if I have RSLinx OEM or higher installed on the local pc, but I want to go through RSLinx Gateway which is installed on our server. How do I get this code to point to the RSLinx Gateway server? I tried replacing:
oServer.Connect("RSLinx OPC Server")
with:
oServer.Connect("\\ServerName\RSLinx OPC Server")
but it fails to connect.
Any help would be much appreciated as I am at wits end.
Thanks in advance.
Example Code:
Imports RsiOPCAuto
Public Class Form1
Public oServer As RsiOPCAut
PCServer
Public WithEvents oGroup As RsiOPCAut
PCGroup
Public oItem1 As RsiOPCAut
PCItem
Public oItem2 As RsiOPCAut
PCItem
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
oServer = New RsiOPCAut
PCServer
oServer.Connect("RSLinx OPC Server")
oGroup = oServer.OPCGroups.Add("TestGroup") 'Group name can be anything you want it to be
oGroup.IsActive = True 'Enables updates of the data and creates events
oGroup.UpdateRate = 500 'In milliseconds (1000 = 1 second)
oGroup.IsSubscribed = True
'Now that we've created our group, we can add some items
oItem1 = oGroup.OPCItems.AddItem("[TopicName]PLCAdress", 1)
oItem2 = oGroup.OPCItems.AddItem("[TopicName]PLCAdress", 2)
'In the code above, the text in the quotes is the OPC item. The number following it is a UNIQUE identifier
'that is given and referred back to if needed later.
'The data event handler below gets fired whenever an opc item inside of it gets its value updated
AddHandler (oGroup.DataChange), AddressOf DataChanged
End Sub
Private Sub DataChanged(ByVal TransactionID As Integer, ByVal NumItems As Integer, _
ByRef ClientHandles As System.Array, ByRef ItemValues As System.Array, _
ByRef ItemQualities As System.Array, ByRef Qualities As System.Array)
'{i
'This event gets fired whenever the data changes for one of the tags added to the OPCGroup.
'It is my recommendation that if you are going to have a lot of items in the OPCGroup, that you
'create a collection class for the OPCItems, instead of using a separate variable for each one.
Static iStatus As Integer
If iStatus <> CType(oItem2.Value, Integer) Then
If CType(oItem2.Value, Integer) = 0 Then
lblStatus.Text = "Press Down - Waiting For Response"
Else
lblStatus.Text = "Press Running - Production"
End If
iStatus = CType(oItem2.Value, Integer)
TextBox1.Text = TextBox1.Text & lblStatus.Text & " " & Now() & vbCrLf
End If
Static iLabel As Integer
If iLabel <> CType(oItem1.Value, Integer) Then
If CType(oItem1.Value, Integer) = 0 Then
Label1.Text = "Down"
Else
Label1.Text = "Up"
End If
iLabel = CType(oItem1.Value, Integer)
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'{
'This sub demonstrates getting the value of an item. The item values are always passed back
'from the OPCItem group as a type Object. The Object can then be cast to whatever you need
'to use it as.
'Basically this just flips the value of the item in the PLC. I was using it to start a timer that triggered
'the TEST_ALARM value when the timer expired.
If CType(oItem1.Value, Integer) = 1 Then
oItem1.Write(0)
Else
oItem1.Write(1)
End If
'Data is also written back to the item as Object, but the interop will automatically convert most types
'to Object before passing it into the OPC item. If it won't, then you'll need to do a typecast back to
'the Object type. The .Write method blocks during operation, so it is not advised if you are using it
'to write a lot of data. There are methods for synchronous and asynchronous writes back to the
'OPC server, which are not described here (mostly because I haven't gotten them to work yet, I'm
'doing all of this by trial-and-error).
'}
End Sub
End Class
oServer.Connect("RSLinx OPC Server")
with:
oServer.Connect("\\ServerName\RSLinx OPC Server")
but it fails to connect.
Any help would be much appreciated as I am at wits end.
Thanks in advance.
Example Code:
Imports RsiOPCAuto
Public Class Form1
Public oServer As RsiOPCAut
Public WithEvents oGroup As RsiOPCAut
Public oItem1 As RsiOPCAut
Public oItem2 As RsiOPCAut
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
oServer = New RsiOPCAut
oServer.Connect("RSLinx OPC Server")
oGroup = oServer.OPCGroups.Add("TestGroup") 'Group name can be anything you want it to be
oGroup.IsActive = True 'Enables updates of the data and creates events
oGroup.UpdateRate = 500 'In milliseconds (1000 = 1 second)
oGroup.IsSubscribed = True
'Now that we've created our group, we can add some items
oItem1 = oGroup.OPCItems.AddItem("[TopicName]PLCAdress", 1)
oItem2 = oGroup.OPCItems.AddItem("[TopicName]PLCAdress", 2)
'In the code above, the text in the quotes is the OPC item. The number following it is a UNIQUE identifier
'that is given and referred back to if needed later.
'The data event handler below gets fired whenever an opc item inside of it gets its value updated
AddHandler (oGroup.DataChange), AddressOf DataChanged
End Sub
Private Sub DataChanged(ByVal TransactionID As Integer, ByVal NumItems As Integer, _
ByRef ClientHandles As System.Array, ByRef ItemValues As System.Array, _
ByRef ItemQualities As System.Array, ByRef Qualities As System.Array)
'{i
'This event gets fired whenever the data changes for one of the tags added to the OPCGroup.
'It is my recommendation that if you are going to have a lot of items in the OPCGroup, that you
'create a collection class for the OPCItems, instead of using a separate variable for each one.
Static iStatus As Integer
If iStatus <> CType(oItem2.Value, Integer) Then
If CType(oItem2.Value, Integer) = 0 Then
lblStatus.Text = "Press Down - Waiting For Response"
Else
lblStatus.Text = "Press Running - Production"
End If
iStatus = CType(oItem2.Value, Integer)
TextBox1.Text = TextBox1.Text & lblStatus.Text & " " & Now() & vbCrLf
End If
Static iLabel As Integer
If iLabel <> CType(oItem1.Value, Integer) Then
If CType(oItem1.Value, Integer) = 0 Then
Label1.Text = "Down"
Else
Label1.Text = "Up"
End If
iLabel = CType(oItem1.Value, Integer)
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'{
'This sub demonstrates getting the value of an item. The item values are always passed back
'from the OPCItem group as a type Object. The Object can then be cast to whatever you need
'to use it as.
'Basically this just flips the value of the item in the PLC. I was using it to start a timer that triggered
'the TEST_ALARM value when the timer expired.
If CType(oItem1.Value, Integer) = 1 Then
oItem1.Write(0)
Else
oItem1.Write(1)
End If
'Data is also written back to the item as Object, but the interop will automatically convert most types
'to Object before passing it into the OPC item. If it won't, then you'll need to do a typecast back to
'the Object type. The .Write method blocks during operation, so it is not advised if you are using it
'to write a lot of data. There are methods for synchronous and asynchronous writes back to the
'OPC server, which are not described here (mostly because I haven't gotten them to work yet, I'm
'doing all of this by trial-and-error).
'}
End Sub
End Class