Skip to content

EtherNet/IP Device Service Examples

The EtherNet/IP Device Service component can be used for implicit or explicit communication, as shown in the following examples:

Example O2T Device Resource

The following example shows the output IO mapping of an EtherNet/IP device. We use the following mapping:

EtherNet/IP input mapping

In this example, we control the state of the single output of DO4. The DO4 device resource is defined in the device profile as follows:

{
 "name": "DO4",
 "description": "Digital Output 4",
 "attributes": {
  "type": "O2T",
  "offsetBytes": "1",
  "offsetBits": "4"
 },
 "properties": {
  "value": {
   "type": "Bool",
   "readWrite": "RW"
  }
 }
}

This example device resource covers states DO3 to DO6 and uses the Binary data type:

{
 "name": "DO2_6",
 "description": "Digital Outputs 2 to 6",
 "attributes": {
  "type": "O2T",
  "offsetBytes": "1",
  "offsetBits": "2",
  "bitLength": "5"
 },
  "properties": {
   "value": {
    "type": "Binary",
    "readWrite": "RW"
  }
 }
}
An example payload is provided for this device resource, as follows:

Outputs High Outputs Low Payload
DO3, DO6 DO2, DO4, DO5 00010010 → Eg==

Example T2O Device Resource

The following example shows the input IO mapping of an EtherNet/IP device. We use the following mapping:

EtherNet/IP input mapping

In this example, we read the state of the DI4 single input. The DI4 device resource is defined as follows:

{
 "name": "DI4",
 "description": "Digital Input 4",
 "attributes": {
  "type": "T2O",
  "offsetBytes": "0",
  "offsetBits": "4",
  "readOnChange": "true"
 },
 "properties": {
  "value": {
   "type": "Bool",
   "readWrite": "R"
  }
 }
}

This example covers the input states DI0 to DI7 using the Binary data type. This means that readings are returned as base64 encoded values.

{
 "name": "DI0_7",
 "description": "Digital Inputs 0 to 7",
 "attributes": {
  "type": "T2O",
  "offsetBytes": "0",
  "offsetBits": "0",
  "bitLength": "8",
  "readOnChange": "true"
 },
 "properties": {
  "value": {
   "type": "Binary",
   "readWrite": "R"
  }
 }
}

An example reading is provided for the resource, which shows how the data appears when read, as follows:

Inputs High Inputs Low Reading
DI0, DI1, DI3, DI4, DI5, DI7 DI2, DI6 uw== → 10111011

Get Attributes All Example

The following extract defines a resource that retrieves all the attributes of the identity object and returns them to the user in String format. The Device Service knows the format of the identity object, which means that it can generate each attribute name value pair from the response:

{
 "name": "Get All Identity Attributes",
 "description": "This will retrieve all of the attributes of the identity object and return it to the user in a string format",
 "attributes": {
  "type": "EM",
  "objClass": "0x01",
  "instID": "1",
  "serviceCode": "0x01"
 },
 "properties": {
  "value": {
   "type": "String",
   "readWrite": "R"
  }
 }
}

Note

The EtherNet/IP Device Service only supports the identity object for this service code and data type string combination

If you want to issue a Get Attributes All request to a class or class instance that the Device Service does not know how to parse, the Binary data type can be used.

For example in the following extract, instance 1 of the Ethernet Link object class is requested and the data is returned as a base64 encoded value:

{
 "name": "Get All Ethernet Link Class Attributes",
 "description": "This will retrieve all of the attributes of the Ethernet Link Class object and return it as base64 encoded value",
 "attributes": {
  "type": "EM",
  "objClass": "0xF6",
  "instID": "1",
  "serviceCode": "0x01"
 },
 "properties": {
  "value": {
  "type": "Binary",
  "readWrite": "R"
  }
 }
}

Get Attribute Single Example

The Get Attribute Single command returns a specified attribute. The following examples define resources for the UInt32 Serial Number identity object attribute and a UInt16 Assembly Input attribute.

The following extract defines a resource for the UInt32 Serial Number identity object attribute:

{
 "name": "Serial Number - Identity Object",
 "description": "Reading the serial number of the device",
 "attributes": {
  "type": "EM",
  "objClass": "0x01",
  "instID": "1",
  "attrID": "6",
  "serviceCode": "0x0E"
 },
 "properties": {
  "value": {
  "type": "Uint32",
  "readWrite": "R"
  }
 }
}

{
 "name": "Assembly Input - Assembly Object",
 "description": "Reading the assembly input instance of the device",
 "attributes": {
  "type": "EM",
  "objClass": "0x04",
  "instID": "102",
  "attrID": "3",
  "serviceCode": "0x0E"
 },
 "properties": {
  "value": {
   "type": "Uint16",
   "readWrite": "R"
  }
 }
}

Set Attributes Single Example

The Set Attribute Single command writes to a specified attribute. The following example defines a resource to write to a UInt16 Assembly Output attribute:

{
 "name": "Assembly Output - Assembly Object",
 "description": "Writing to the assembly output instance of the device",
 "attributes": {
  "type": "EM",
  "objClass": "0x04",
  "instID": "101",
  "attrID": "3",
  "serviceCode": "0x10"
 },
 "properties": {
  "value": {
   "type": "Uint16",
   "readWrite": "W"
  }
 }
}

Reset Example

The Reset service can perform different functions, depending on the value provided. For example, the first two value are as follows:

Value Function
0 Emulate power cycle
1 Perform factory reset, then emulate power cycle

If you need to use the Reset service, you must add the Reset device resource to the device resource as follows:

{
 "name": "Reset",
 "description": "Triggers the device to emulate a power cycle",
 "attributes": {
  "type": "EM",
  "objClass": "0x01",
  "instID": "1",
  "serviceCode": "0x05"
 },
 "properties": {
  "value": {
   "type": "Uint8",
   "readWrite": "W"
  }
 }
}
When triggered, the Device Service attempts to reinitialize all connections for the specified device.

Back to top