Reading the CIP Identity of any Ethernet/IP device

From AdvancedHMI
Jump to: navigation, search

Reading the CIP Identity for Any Ethernet/IP Device

Note : Version 3.99r or higher

The CIP protocol references everything in a device by ClassID, InstanceID, and AttributeID. The AdvancedHMI EthernetIP driver allows you to access this data. This example will show how to read the identity of a device. According to the CIP specification, the Identity Object Class is ID 0x01. Instance 0x01 has a number of attributes and one is the human readable identity of the device. So we will use Class 0x01, Instance 0x01, and Attribute 0x07 to retrieve this human readable value.

When using the EthernetIPforCLXCom driver, the communication packets enter an Ethernet device, then leaves through the backplane and finally to the processor. This is known as the route path. From a Micro800 series perspective, the Ethernet port is not treated as a separate device, therefore the messages do not route through a backplane.

A little known detail about the Micro800 driver versus the CLX driver is the fact that they are based on the same underlying driver. The only difference is the CLX driver provides a property ProcessorSlot that is used to build a routing path. While the Micro800 does not. The main purpose of the ProcessorSlot property is to make it easier to get started for those not familiar with the routing complexities.

For this demo we will be using the Micro800 driver so that we can control whether we want a route path to be used or not. In cases where you want to communicate directly with an Ethernet/IP adapter, you do not want a route path.

Here are the steps to read the Identity of any Ethernet/IP device:

1) Add an EthernetIPforMicro800 driver to the form
2) Set the IPAddress property to that of the target device
3) Double click in a blank area of the form to get back to the Form Load event handler
4) Enter this code:

   Private AttributeReadTNS As Integer
   Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       AttributeReadTNS = EthernetIPforMicro800Com1.BeginGetAttributeSingle(1, 1, 7)
   End Sub

5) Go back to the Design View of the MainForm
6) Double click on the EthernetIPforMicro800Com1 driver instance to get back to the code
7) Enter this code:

   Private Sub EthernetIPforMicro800Com1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforMicro800Com1.DataReceived
       If e.ErrorId = 0 AndAlso e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
           If e.TransactionNumber = AttributeReadTNS Then
               Dim StringLength As Integer = e.Values(0)
               Dim index As Integer
               Dim Identity As String = ""
               While index < e.Values.Count - 1 AndAlso index < StringLength
                   Identity &= Chr(CInt(e.Values(index + 1)))
                   index += 1
               End While
               MsgBox(Identity)
           End If
       End If
   End Sub