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 template
Edit 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-.jar to your S3 bucket.
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 jarFor 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 is502.Timeout: (Optional) Modbus TCP communication timeout in seconds. Default is5.Devices: Modbus TCP device (unit) configuration.
Name: Name of the device (unit).UnitId: (Optional) Unit id of the device (unit). Default is0
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: string
An arbitrary ID for the request. Use this property to map an input request to an output response.
Request
function: "ReadCoils"address: integer
Starting address of the coils for read.quantity: integer
Quantity of the coils for read.
Response
type: "ReadCoils"bits: [boolean]
Values of the coils.
Read discrete inputs
Request
function: "ReadDiscreteInputs"address: integer
Starting address of the discrete inputs for read.quantity: integer
Quantity of the discrete inputs for read.
Response
type: "ReadDiscreteInputs"bits: [boolean]
Values of the discrete inputs.
Read holding registers
Request
function: "ReadHoldingRegisters"address: integer
Starting address of the holding registers for read.quantity: integer
Quantity of the holding registers for read.
Response
type: "ReadHoldingRegisters"bytes: [integer]
Values of the holding registers.
Read input registers
Request
function: "ReadInputRegisters"address: integer
Starting address of the input registers for read.quantity: integer
Quantity of the input registers for read.
Response
type: "ReadInputRegisters"bytes: [integer]
Values of the input registers.
Write single coil
Request
function: "WriteSingleCoil"address: integer
Address of the coil for write.value: boolean
Value for write
Response
type: "WriteSingleCoil"address: integervalue: boolean
Same as the request
Write single register
Request
function: "WriteSingleRegister"address: integer
Address of the register for write.value: integer
Value for write
Response
type: "WriteSingleRegister"address: integervalue: integer
Same as the request
Write multiple coils
Request
function: "WriteMultipleCoils"address: integer
Starting address of the coils for write.bits: [boolean]
Values for write.
Response
type: "WriteMultipleCoils"address: integer
Same as the requestquantity: integer
Quantity of written values
Write multiple registers
Request
function: "WriteMultipleRegisters"address: integer
Starting address of the registers for write.bytes: [integer]
Values for write.
Response
type: "WriteMultipleRegisters"address: integer
Same as the requestquantity: integer
Quantity of written values
Mask write register
Request
function: "MaskWriteRegister"address: integer
Address of the register for mask.andMask: integer
AND maskorMask: integer
OR mask
Response
type: "MaskWriteRegister"address: integerandMask: integerorMask: integer
Same as the request
Read and write multiple registers
Request
function: "ReadWriteMultipleRegisters"readAddress: integer
Starting address of the registers for read.readQuantity: integer
Quantity of the registers for read.writeAddress: integer
Starting address of the registers for write.bytes: [integer]
Values for write.
Response
type: "ReadWriteMultipleRegisters"bytes: [integer]
Values of the registers.
type: "ExceptionCode"code: string
Exception code of the error.
This component includes the following external libraries:
- Digital Petri Modbus
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.