awslabs / aws-greengrass-labs-modbus-tcp-protocol-adapter

Apache License 2.0
12 stars 2 forks source link

Greengrass Modbus TCP Protocol Adapter

This component provides the ability to read / write device data using Modbus TCP protocol.
The basic usage of this component is based on the same concept as Modbus RTU protocol adapter.
In addition, planning to provide read / write capabilities for asset data based on simple asset modeling feature.

Installation

You can either use a prebuilt binary or build yourself.

Use prebuilt binary

Download the following files from releases page.

Edit the following placeholders in recipe template.

Follow the developer guide to publish Modbus TCP protocol adapter or deploy locally.

How to build

If you choose to build yourself, you can build by the following steps below.

Prerequisite

Install Java Development Kit 11 or above. We recommend that you use Amazon Corretto 11 or OpenJDK 11.

Build

Checkout this repository, cd to the repository root, and execute the following command.

For Linux

./gradlew jar

For Windows

.\gradlew jar

If successful, a JAR file will be created in build/libs.

Usage

Configure the component

This component has the following ComponentConfiguration items.

Example

ComponentConfiguration:
  DefaultConfiguration:
    Modbus:
      Endpoints:
      - Host: "localhost"
        Port: 5020
        Devices:
        - Name: "test"
          UnitId: 0

Send Modbus TCP command using Greengrass IPC local messages

You can send a command to Modbus device by publishing a request to the following topic.

Sample request

{
  "id": "TestRequest",
  "function": "ReadCoils",
  "address": 1,
  "quantity": 1
}

And you can receive the result from the device as a response by subscribing to the following topic.

Sample response

{
  "id": "TestRequest",
  "type": "ReadCoils",
  "bits": [true]
}

Sample error response

{
  "id": "TestRequest",
  "type": "ExceptionCode",
  "code": "IllegalDataAddress"
}
{
  "id": "TestRequest",
  "type": "Timeout"
}
{
  "type": "BadRequest"
}

Supported commands

Common parameters

ReadCoils

Request

Response

ReadDiscreteInputs

Read discrete inputs

Request

Response

ReadHoldingRegisters

Read holding registers

Request

Response

ReadInputRegisters

Read input registers

Request

Response

WriteSingleCoil

Write single coil

Request

Response

WriteSingleRegister

Write single register

Request

Response

WriteMultipleCoils

Write multiple coils

Request

Response

WriteMultipleRegisters

Write multiple registers

Request

Response

MaskWriteRegister

Mask write register

Request

Response

ReadWriteMultipleRegisters

Read and write multiple registers

Request

Response

Error response

External libraries

This component includes the following external libraries:

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.