Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you refer to the RSLinx Gateway Server

Status
Not open for further replies.

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 RsiOPCAuto_OPCServer
Public WithEvents oGroup As RsiOPCAuto_OPCGroup
Public oItem1 As RsiOPCAuto_OPCItem
Public oItem2 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") '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
 
Replies continue below

Recommended for you

Hi,

I think you do this

oServer.Connect("RSLinx OPC Server", "Servername")

There is an optional variable of nodename ("Servername")

Hope this helps!
Jenn

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor