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.
You can either use a prebuilt binary or build yourself.
Download the following files from releases page.
ModbusTCP-<version>.jar
: Executable JAR fileaws.greengrass.labs.ModbusTCP-<version>.yaml
: Recipe templateEdit the following placeholders in recipe template.
<MODBUS_TCP_HOST>
: Host name or IP address of Modbus TCP device.<MODBUS_TCP_PORT>
: Port number of Modbus TCP device.<MODBUS_TCP_UNIT_NAME>
: Unique name of Modbus TCP device. Used as the last part of IPC topic.<BUCKET_NAME>
: S3 bucket name, if uploaded ModbusTCP-Follow the developer guide to publish Modbus TCP protocol adapter or deploy locally.
If you choose to build yourself, you can build by the following steps below.
Install Java Development Kit 11 or above. We recommend that you use Amazon Corretto 11 or OpenJDK 11.
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
.
This component has the following ComponentConfiguration
items.
Modbus
: Root of Modbus related configuration.Endpoints
: Modbus TCP endpoint configuration.Host
: Host name or IP address of the Modbus TCP server.Port
: (Optional) Port number of the Modbus TCP server. Default is 502
.Timeout
: (Optional) Modbus TCP communication timeout in seconds. Default is 5
.Devices
: Modbus TCP device (unit) configuration.Name
: Name of the device (unit).UnitId
: (Optional) Unit id of the device (unit). Default is 0
ComponentConfiguration:
DefaultConfiguration:
Modbus:
Endpoints:
- Host: "localhost"
Port: 5020
Devices:
- Name: "test"
UnitId: 0
You can send a command to Modbus device by publishing a request to the following topic.
modbus/request/{device name}
{
"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.
modbus/response/{device name}
{
"id": "TestRequest",
"type": "ReadCoils",
"bits": [true]
}
{
"id": "TestRequest",
"type": "ExceptionCode",
"code": "IllegalDataAddress"
}
{
"id": "TestRequest",
"type": "Timeout"
}
{
"type": "BadRequest"
}
id
: stringRequest
function
: "ReadCoils"address
: integerquantity
: integerResponse
type
: "ReadCoils"bits
: [boolean]Read discrete inputs
Request
function
: "ReadDiscreteInputs"address
: integerquantity
: integerResponse
type
: "ReadDiscreteInputs"bits
: [boolean]Read holding registers
Request
function
: "ReadHoldingRegisters"address
: integerquantity
: integerResponse
type
: "ReadHoldingRegisters"bytes
: [integer]Read input registers
Request
function
: "ReadInputRegisters"address
: integerquantity
: integerResponse
type
: "ReadInputRegisters"bytes
: [integer]Write single coil
Request
function
: "WriteSingleCoil"address
: integervalue
: booleanResponse
type
: "WriteSingleCoil"address
: integervalue
: booleanWrite single register
Request
function
: "WriteSingleRegister"address
: integervalue
: integerResponse
type
: "WriteSingleRegister"address
: integervalue
: integerWrite multiple coils
Request
function
: "WriteMultipleCoils"address
: integerbits
: [boolean]Response
type
: "WriteMultipleCoils"address
: integerquantity
: integerWrite multiple registers
Request
function
: "WriteMultipleRegisters"address
: integerbytes
: [integer]Response
type
: "WriteMultipleRegisters"address
: integerquantity
: integerMask write register
Request
function
: "MaskWriteRegister"address
: integerandMask
: integerorMask
: integerResponse
type
: "MaskWriteRegister"address
: integerandMask
: integerorMask
: integerRead and write multiple registers
Request
function
: "ReadWriteMultipleRegisters"readAddress
: integerreadQuantity
: integerwriteAddress
: integerbytes
: [integer]Response
type
: "ReadWriteMultipleRegisters"bytes
: [integer]type
: "ExceptionCode"code
: stringThis component includes the following external libraries:
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.