Modbus TCP/RTU Protocol Adapter
This section presents the capabilities and configuration options of the Modbus TCP/RTU Protocol Adapter, which translates the Modbus communication protocol into objects understandable by the Gateway Agent.
For a step-by-step guide on how to install the Modbus Protocol Adapter, see the Installation Guide.
Configuring the Modbus Protocol Adapter
There are two configuration files of the Modbus Protocol Adapter:
Deployment configuration file - Configuration of the MQTT connection, PMQ connection and health monitoring.
Application configuration file - Configuration of connections, global adapter properties and device data (measurements, alerts, configuration parameters and metadata).
When you modify the Modbus Protocol Adapter configuration, restart the adapter to apply the changes by means of the following command:
systemctl restart gwa-modbus-adapter-c
The adapter configuration is then updated.
For an example of the Modbus Protocol Adapter configuration files, see here.
Deployment Configuration File
The deployment configuration file of the Modbus Protocol Adapter is located at:
/etc/relayr/gwa-modbus-adapter-c/gwa-modbus-adapter-config.json
To modify the file, edit it in a text editor.
The following configuration settings are available:
transport
- Communication channel used by the adapter. Available options:mqtt
orpmq
. By default,mqtt
.mqtt_connection
- Connection settings of the MQTT message broker:
Configuration Setting | Description | Default Value |
---|---|---|
host | IP address of the MQTT message broker. | localhost |
port | Port number for connecting to the MQTT broker. | 1883 |
keepalive | Keepalive value of the MQTT connection. | 20 |
max_inflight_messages | Maximum number of QoS 1 or 2 messages that can be in the process of being transmitted simultaneously. This includes messages currently going through handshakes and messages that are being retried. If set to 1 , it guarantees an in-order delivery of messages. | 100 |
qos_levels | Quality of Service level for each traffic type. | measurements: 0 , alerts: 1 . configuration: 1 , metadata: 1 |
health_monitor
- Health monitoring settings:
Configuration Setting | Description | Default Value |
---|---|---|
heartbeat_interval | Time interval at which the periodic heartbeat messages are sent, given in seconds. | 60 |
pmq_connection
- Configuration of the High Speed Bus (PMQ) connection. Configure this section to use thepmq
transport
:
Configuration Setting | Description | Default Value |
---|---|---|
output_queues | List of output PMQ queues, where the adapter reports all data, except for health monitoring messages, which are always reported via MQTT. Queue names must begin with / . | ["/modbus_out_queue"] |
input_queues | List of PMQ queues to monitor for inbound messages, e.g. configuration update tasks. Queue names must begin with / . | ["/modbus_in_queue"] |
message_size | Maximum size of a PMQ message, given in bytes. | 8192 |
message_count | Maximum number of messages in a PMQ queue. | 10 |
For an example of the deployment configuration file, see here.
Application Configuration File
The application configuration file of the Modbus Protocol Adapter is located at:
/etc/relayr/gwa-modbus-adapter-c/gwa-modbus-adapter-application-config.json
If you have the Configuration Manager installed, it becomes the primary way of editing application configuration files. If you do not have the Configuration Manager, edit the application configuration file in a text editor.
See sections below for information on:
Connections – List of connections to devices.
Global Adapter Properties – Configuration of a global sampling interval and custom prefix.
Devices - List of connected devices and their measurements, alerts, configuration parameters and metadata.
For an example of the application configuration file, see here.
Configuring Modbus Connections
Depending on the Modbus mode of communication (TCP or RTU), the connections
section of the configuration file is configured in a different way. See sections below to find out how to configure connections for:
Connections in Modbus TCP
For the Modbus TCP communication, configure the following settings for each connection you want to define:
Configuration Setting | Description |
---|---|
id | Unique connection identifier, which is then used to identify a device connection. See the Configuring a Device Connection section for more information. |
host | IP address of Modbus TCP device. |
port | Port number, by default: 502 . |
slave_id | ID of the Modbus device. |
timeout | Response timeout, given in milliseconds. |
conn_method | Connection method. Enter "tcp" to use Modbus TCP connection. |
keep_session_open | It determines if the TCP session is kept open or closed after each data pull. Possible values: true or false . By default, true . |
Here is an example of the Modbus TCP connections
configuration:
{
"connections": [
{
"id": "dev",
"host": "10.10.6.154",
"port": 502,
"slave_id": 1,
"timeout": 400,
"conn_method": "tcp",
"keep_session_open": true
}
],
Connections in Modbus RTU
For the Modbus RTU communication, configure the following settings for each connection you want to define:
Configuration Setting | Description |
---|---|
id | Unique connection identifier, which is then used to identify a device connection. See the Configuring a Device Connection section for more information. |
path | Serial port. |
baudrate | Baud rate used by the device. For the specification, refer to a device data sheet. |
bits | For the specification, refer to a device data sheet. |
parity | Parity used by the device. For the specification, refer to a device data sheet. |
stop_bits | The number of bits indicating the end of the transfer. For the specification, refer to a device data sheet. |
slave_id | ID of the Modbus device. |
timeout | Response timeout in milliseconds. |
conn_method | Connection method. Enter "rtu" to use Modbus RTU connection. |
Here is an example of the connection configuration:
{
"connections": [
{
"id" : "conn_id",
"path" : "/dev/ttyUSB0",
"baudrate" : 9600,
"stop_bits" : 1,
"bits" : 8,
"parity" : "N",
"slave_id" : 1,
"timeout" : 400,
"conn_method" : "rtu"
}
],
Global Adapter Properties
You can configure the following global settings that refer to the whole Protocol Adapter configuration:
Configuring Sampling Interval
The sampling interval determines how often the Agent gathers data from devices. It is a global setting that refers to retrieving data from all the connected devices.
The interval value is defined in milliseconds:
"sampling_interval" : 4000
Optionally, you can also define a local sampling interval for each object defined in the devices
section of the configuration file. In such a case, a local sampling interval overrides the global one.
The global sampling interval is set to
4000
and the sampling interval for a temperature measurement object is2000
, so the Agent retrieves data about this temperature object every two seconds.
If you configure a local sampling interval for each object defined in the
devices
section, you do not need to configure a global sampling interval. However, if at least one object has no local sampling interval defined, the global one must be provided. Otherwise, the adapter configuration is invalid.
Configuring Custom Prefix
The custom prefix determines where to report data. If not defined, all data is reported to v1/sb
, by default.
The custom_prefix
option enables setting a different prefix to publish data e.g. to a custom MQTT topic for local data processing, or directly to the Gateway Agent northbound interface.
It is a global setting that refers to all data retrieved from devices.
Example:
"custom_prefix": "v1/nb"
Optionally, you can also define a local custom prefix for each measurement, alert, configuration parameter and metadata configured in the devices section of the configuration file. In such a case, a local custom prefix overrides the global one.
Instead of the
custom_prefix
option, you can also use thecustom_mqtt_prefix
option, which was implemented in the older adapter versions. However, it is recommended to usecustom_prefix
.
Configuring a List of Devices
In the devices
section of the configuration file, you can configure a list of devices. For each device, the following configuration sections are available:
connection - Selecting a device connection.
measurements - List of measurements that can be reported by a device.
alerts - List of alerts that can be reported by a device.
configuration - Configuration parameters of a device.
metadata - List of metadata of a device.
The devices
section has the following structure:
"devices" :
[
{
"connection" : { ... },
"measurements" : [ ... ],
"alerts" : [ ... ],
"configuration" : [ ... ],
"metadata" : [ ... ]
}
]
Configuring a Device Connection
In the connection.id
field, enter a connection identifier for a given device. Possible ID values are defined in the connections
section of the configuration file. See the Configuring Modbus Connections section for details.
It is mandatory to configure a connection ID for each device.
Here is an example of the device connection configuration:
"devices": [
{
"connection": {
"id": "dev"
},
You can also configure a local connection ID for a specific measurement, alert, configuration parameter and metadata. If defined, the local connection ID overrides the global one, set in the
connection.id
field.
Configuring Measurements
You can define multiple measurements for a device, such as: temperature, humidity, pressure, etc.
To configure a measurement, define the following mandatory settings:
Configuration Setting | Description |
---|---|
id | Measurement identifier. A value provided here must match the measurement ID set in the device model version created in the relayr Cloud. For more information on creating device models and versions in the relayr Cloud, refer to the relayr Cloud API documentation. |
object | Protocol-specific object definition. See the Modbus Object Definition section for details. |
Optionally, you can define the following advanced settings for a measurement:
Configuration Setting | Description |
---|---|
filters.cov | Change of value functionality. If it is set to enabled , measurements are reported by a device only if their value differs from the latest reported value by at least a cov_delta value. |
filters.cov_delta | Delta for the change of value functionality. It specifies the minimum change of value (in relation to the latest reported value) that is required to report the measurement to the Agent. |
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for a temperature measurement, all data is published to the topic analytics/{did}/measurements/temperature . It overrides the global custom prefix. |
connection | Local connection ID used for a given measurement. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring Modbus Connections section for details. |
complex | Add this configuration section to configure a complex measurement. Specify how many data samples a complex measurement contains and, optionally, a collection_interval . For more information, see the Configuring Complex Measurements section. |
Here is an example of the measurement configuration:
{
"id" : "temperature",
"object" : { ... },
"sampling_interval" : 4000,
"filters" : {
"cov" : "enabled",
"cov_delta" : 0.04
}
},
In the example presented above, the temperature reading is reported by the device every four seconds (as defined in the
sampling_interval
field). The change of value (cov
) is enabled, and thecov_delta
is set to0.04
. It means that the temperature is reported only if it is different from the latest reported value by at least0.04
.
Configuring Complex Measurements
A complex measurement is a batch of measurement data, in which several samples of collected data values are published as a single message.
Complex measurements can be consumed by the Rule Engine and the GWA Analytics for further data processing and can be stored in the Storage Service. The Cloud Adapter supports publishing complex measurements to the relayr Cloud.
You can configure the size of a complex measurement by specifying how many data samples each batch contains. Optionally, you can also specify a collection interval. If specified, the adapter starts collecting data at every collection interval (e.g. 1h) and publishes a complex measurement when a configured number of samples are collected (e.g. 1000). Then, the adapter waits for the next collection interval and starts to acquire data again.
To configure a complex measurement, add the complex
section to the measurement configuration with the following settings:
Configuration Setting | Description |
---|---|
samples | Number of collected data samples in a complex measurement. For complex measurements, this setting is mandatory. |
collection_interval | Optional setting. Time interval, given in seconds, at which the adapter starts to acquire data for a complex measurement. |
Example:
{
"object": {},
"complex":
{
"samples": 10,
"collection_interval": 3600
}
}
If the
collection_interval
is lower than needed to collect the configured number of samples, the adapter collects data continuously. It starts to acquire data immediately after publishing the previous complex measurement.
If sensors stop sending data in the middle of data collection, e.g. due to connectivity problems, the adapter waits until the required number of samples are collected, despite the collection intervals. It publishes a complex measurement that contains data points not evenly distributed in time, e.g. with a 5h gap. Such a complex measurement may be considered as incorrect and may be discarded by the Rule Engine and/or the GWA Analytics, based on the
startTs
andendTs
values.
Complex Measurement Message
The collected data samples of a configured complex measurement are published as a complex measurement message. The Protocol Adapters support acquiring and publishing complex measurements in the time domain, but you can also use complex measurement messages to publish measurements in other domains, e.g. the frequency domain.
Complex measurements in the frequency domain may be reported by the Pico Adapter, or you may use the Rule Engine or the GWA Analytics to calculate them from the time-based measurements.
In a complex measurement message:
startTs
is a moment when data acquisition begins.endTs
is a moment when data acquisition finishes.xStart
is the first value on the X axis. ThexStart
unit depends on the measured value. For measurements in the time domain, it is a timestamp indicating the moment when the first data sample is collected. For measurements in the frequency domain, it is the first frequency on the X axis.xStep
represents a resolution of data on the X axis. For measurements in the time domain,xStep
is a time interval between consecutive data samples, given in milliseconds (you configure this interval in thesampling_interval
setting of the Protocol Adapters' configuration). ThexStep
value allows you to know the precise moment when each data sample was collected. For measurements in the frequency domain,xStep
represents the frequency resolution of data representation on the X axis.yValues
is an array of ordered measurement values.
Example 1: time-based measurement:
v1/sb/{UUID}/complex_measurements/temperature {
“id”:“temperature”,
“startTs”: 1492515087123,
“endTs”: 1492515092123,
“xStart”: 1492515087123,
“xStep”: 1000,
“yValues”: [42, 43, 39, 37, 40, 48, 45, 40, 38, 33, 30, 31...]
}
In this example,
temperature
is a time-based measurement. ThexStart
value is1492515087123
, which shows the moment when the first data sample (42
) was collected. ThexStep
value is1000
, which means that consecutive data samples were collected at the interval of 1000 milliseconds.
Example 2: frequency-based measurement:
v1/sb/{UUID}/complex_measurements/acceleration_xaxis_fft {
“id”:“acceleration_xaxis_fft”,
“startTs”: 1492515087123,
“endTs”: 1492515092123,
“xStart”: 90,
“xStep”: 10,
“yValues”: [3, 12, 48, 579, 644, 689, 711, 647, 78, 644, 669, 112, 638, 652, 617, 48...]
}
In this example,
acceleration_xaxis_fft
is a frequency-based measurement. ThexStart
value is90
, which shows that the first frequency on the X axis is 90 Hz. ThexStep
value is10
, which means that the frequency step on the X axis, between consecutive data samples, is 10 Hz.
Configuring Alerts
In the alerts
configuration section, you can define alerts for the configured devices.
To configure an alert, define the following mandatory settings:
Configuration Setting | Description |
---|---|
id | Alert identifier. A value provided here must match the alert ID of the device model created in the relayr Cloud. For more information on creating device models and versions in the relayr Cloud, refer to the relayr Cloud API documentation. |
measurement_id | Identifier of a measurement associated with the alert. The ID provided here must be configured in the measurements section of the configuration file. See the section above for details. Alternatively, you can configure the object section for an alert. See here for details. |
threshold_set | Threshold value based on which the alert is activated. |
logic_set | Logical relation for alert activation. Possible values are: "<", ">", "==", "">=", "<=". |
message_set | Message sent when the alert is activated. It is a free-form string. |
threshold_clear | Threshold value based on which the alert is cleared. |
logic_clear | Logical relation for clearing the alert. Possible values are: "<", ">", "==", "">=", "<=". |
message_clear | Message displayed when the alert is cleared. It is a free-form string. |
If both the
logic_clear
andlogic_set
conditions are fulfilled at the same time, the alert is set.
Optionally, you can define the following advanced settings for an alert:
Configuration Setting | Description |
---|---|
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for a temperature-based alert, all data is published to the topic analytics/{did}/alerts/alert_temp_high . It overrides the global custom prefix. |
connection | Local connection ID used for a given alert. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring Modbus Connections section for details. |
Here is an example of the alert configuration:
{
"id" : "alert_temp_high",
"measurement_id" : "temperature",
"threshold_set" : 38.5,
"logic_set" : ">=",
"message_set" : "TEMPERATURE IS TOO HIGH",
"threshold_clear" : 36.5,
"logic_clear" : "<=",
"message_clear" : "ALERT IS CLEAR",
"sampling_interval" : 4000
}
In the example presented above, the alert is activated if the temperature reaches a level defined in the
threshold_set
andlogic_set
fields, that is: if it is greater than or equal to 38.5. The message "TEMPERATURE IS TOO HIGH" is sent to the relayr Cloud when the alert is set.
When the temperature decreases and it is smaller than or equal to 36.5 (as specified in thethreshold_clear
andlogic_clear
fields), the alert is deactivated and the message "ALERT IS CLEAR" is sent to the relayr Cloud when the alert is deactivated.
The value provided in thesampling_interval
field means that the system verifies the alert data every four seconds.
Configuring Configuration Parameters
In the configuration
section, you can define the device configuration parameters.
To define a configuration parameter, define the following mandatory settings:
Configuration Setting | Description |
---|---|
id | Configuration object identifier. |
object | Protocol-specific object definition. See the Modbus Object Definition section for details. |
Optionally, you can define the following advanced settings for a configuration parameter:
Configuration Setting | Description |
---|---|
ro | This setting determines if a given configuration parameter is read-only (if set to true ) or the read/write permissions are granted to it (if set to false ). If no ro value is defined, the object has read/write permissions, by default. |
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for a configuration parameter xyz , all data is published to the topic analytics/{did}/configuration/xyz . It overrides the global custom prefix. |
connection | Local connection ID used for a given configuration parameter. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring Modbus Connections section for details. |
Here is an example of the configuration settings:
{
"id" : "parameter2045",
"object" : { ... },
"sampling_interval" : 4000,
"ro" : true
},
Configuring Metadata
The metadata
section of the configuration file allows you to define device attributes, such as the device ID, model, version, location, owner's email address, etc.
There are two ways to configure metadata:
Static metadata - metadata is an
id
andvalue
pair. It is sent only once, at the application startup.Dynamic metadata - metadata has a defined
object
. It is reported not only at the application startup, but also when the metadata value changes.
Static Metadata
Static metadata is configured as an id
and value
pair.
Static metadata is reported only once, at the application startup. To provide support for reporting a changing metadata value, configure dynamic metadata.
To configure the device static metadata, define the following values:
Configuration Setting | Description |
---|---|
id | Metadata identifier. |
value | Metadata value. |
Optionally, you can configure the following metadata settings:
Configuration Setting | Description |
---|---|
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for metadata serial_number , all data is published to the topic analytics/{did}/metadata/serial_number . It overrides the global custom prefix. |
It is mandatory to define the device ID (
did
) for each device. Thedid
value must match the UUID of the device created in the relayr Cloud.
For more information on creating devices in the Cloud, refer to the relayr Cloud API documentation.
The device
did
cannot contain spaces and plus (+) characters.
Here is an example of the device static metadata:
"metadata": [
{
"id": "did",
"value": "f33c6bah-b31e-4f5a-964h-13a935a8b25f"
}
]
Dynamic Metadata
Dynamic metadata is configured with a protocol-specific object
.
Dynamic metadata is published only if its value changes.
To report a metadata value dynamically, configure the following settings:
Configuration Setting | Description |
---|---|
id | Metadata identifier. |
object | Protocol-specific object definition. See the Modbus Object Definition section for details. |
Optionally, you can configure the following dynamic metadata settings:
Configuration Setting | Description |
---|---|
custom_prefix | Prefix of the MQTT topic that the object is reported to. An option to publish data to a custom MQTT topic for a local data processing or directly to the northbound interface. For example, if it is set to analytics for metadata serial_number , all data is published to the topic analytics/{did}/metadata/serial_number . It overrides the global custom prefix. |
sampling_interval | Local sampling interval value, given in milliseconds, that overrides the global sampling interval. |
connection | Local connection ID used for given metadata. It overrides the global connection set for the device. Possible ID values are defined in the connections section of the configuration file. See the Configuring Modbus Connections section for details. |
Here is an example of the device dynamic metadata:
"metadata": [
{
"id" : "serial_number",
"object" : { ... },
"sampling_interval" : 4000,
"custom_prefix" : "v1/nb"
},
Modbus Object Definition
For each configured measurement and configuration parameter, there is a protocol-specific object
configuration section.
In the Modbus Protocol Adapter, the following fields are mandatory to define an object
:
Configuration Setting | Description |
---|---|
address | Address of the first register that is read. Format: decimal, up to 4 digits. For a list of available registers, refer to a device datasheet. |
quantity | Number of coils/registers to be read, starting from the one specified in the address field. Format: integer. |
type | Data type: string , integer , bool , float . Depending on the selected type , additional settings may become available. See the table on the next page for a list of optional settings. |
function_code | Modbus Function Code. You can use a full name or its code in the FCX format, where X stands for the Function Code. For example, you can enter: Read Holding Registers or: FC3 . See table below for a list of supported Modbus Function Codes. |
The Modbus Protocol Adapter supports the following Modbus function codes:
Function Code | Register Type |
---|---|
1 | Read Coils |
2 | Read Discrete Inputs |
3 | Read Holding Registers |
4 | Read Input Registers |
The relayr Agent can only read a single coil, so if you set the
Read Coils
function code, thequantity
should be set to1
and the datatype
tobool
.
Here is an example of the Modbus object
configuration:
"object": {
"address": 7002,
"quantity": 1,
"function_code": "Read Holding Registers",
"type": "integer"
},
Optionally, you can define the following fields for an object
:
Configuration Setting | Description |
---|---|
encoding | It can be set for the string data type to generate a string encoded as hexstring (if set to hex ) or ASCII (if set to ascii ). The default value is ascii . For more information, refer to the String data type section below. |
source | It can be set for the float data type only. Possible values are: int16 or float32 . For more information, see the Float data type section. |
multiplier | Multiplier of the source values, which can be set for the float data type. It is used e.g. to convert int16 source values to floats. Format of the multiplier value: float. See the Int16 to Float data conversion section for details. |
offset | Value to be added to or subtracted from the value read from a device. It can be used e.g. to convert source values to different units. Format of the offset value: float. See the Int16 to Float data conversion section for details. |
byte_order | Order of bytes (abcd , dcba , badc , cdab ). It can be set for the float data type if the data source is set to float32 . For details, see the Floating point values section. |
word_order | Order of register readings in an integer (ab , ba ). If set to ab , bytes in the integer are in the same order as in the device. If set to ba , they are in the reverse order (the last byte read form the device becomes the first one in the integer). E.g. if the register readings from a device are CD and EF , the ab word_order results in CDEF , and the ba word_order results in EFCD . It can be set for the integer data type only. |
String Data Type
The relayr Modbus Protocol Adapter can encode data of string
type in two ways:
ASCII - The string characters are treated as ASCII characters.
Hexstring - The string characters are the hexadecimal representation of data gathered from PLC. A single byte of data is presented as a pair of hexadecimal digits (0-9, A-F), then all of them are concatenated, giving the result string.
In the Modbus object configuration, you can set the string type in the encoding
field, which is valid for the string
data type only. Possible values are:
ascii
(default)hex
When string values are interpreted, no endianness conversion is made, so any multibyte values read and presented in a string are in the same order they are stored in the PLC memory.
Here is an example of the measurement object
configuration with the encoding
field set to hex
for the string
data type.
"object": {
"address": 4002,
"quantity": 10,
"function_code": "Read Holding Registers",
"type": "string",
"encoding": "hex"
}
Float Data Type
When the float
data type is selected in the Modbus object definition, the source
field determines what kind of data is interpreted. Possible source
values are:
int16
- For many Modbus PLCs, floating point values are represented as integers (int16
) in the PLC registry and converted back to float values on the application level. See the Int16 to float data conversion section for more information.float32
- The relayr Modbus Adapter supports single-precision floating points (IEEE 754) in which floats are represented as two adjacent 16-bit registers. See the Floating point values for more information.
Int16 to Float Data Conversion
The relayr Modbus Protocol Adapter supports the int16 to float conversion to convert float values represented as integers (int16
) in Modbus PLCs back to float values.
The conversion is handled by the following configuration settings:
type
- Data type. Set it tofloat
.source
- Format of the source data. Set it toint16
.multiplier
- Multiplier of thesource
values, used to convert thesource
data. Format of themultiplier
value: float.offset
- Value to be added to or subtracted from the object value read from a device. Format of theoffset
value: float. Set it if you want to e.g. convert values to different units.
Here is an example of the Modbus object
configuration with data conversion:
"object": {
"address": 7002,
"quantity": 1,
"function_code": "Read Holding Registers",
"type": "float",
"source": "int16",
"multiplier": 0.1,
"offset": 60.0
}
Example: In the object definition presented above, the source integer values are divided by 10, because the
multiplier
is set to 0.1. For example, the reading represented in the Modbus PLC registry as 233 is converted to 23.3. Then, 60 is added to it, as defined in theoffset
field, so the final value is 83.3.
Floating Point Values
The relayr Modbus Adapter supports single-precision floating points (IEEE 754) in which floats are represented as two adjacent 16-bit registers.
IEEE 754 floats are handled by the following configuration options:
type
- Data type. Set it tofloat
.source
- Format of the source data. Set tofloat32
.byte_order
- Order of bytes for interpreting the 32-bit float value. Possible values:abcd
- no conversion (default)dcba
- inversed formatbadc
- swapped bytescdab
- swapped words
Here is an example of the object
configuration that defines the IEEE 754 float:
"object": {
"address": 7002,
"quantity": 2,
"function_code": "Read Holding Registers",
"type": "float",
"source": "float32",
"byte_order": "abcd"
}
To convert the obtained float values, you can use the multiplier
and offset
options:
multiplier
- Multiplier of thesource
values, used to convert thesource
data. Format of themultiplier
value: float.offset
- Value to be added to or subtracted from the object value read from a device. Format of theoffset
value: float. Set it if you want to e.g. convert values to different units.
Here is an example:
"object": {
"address": 7002,
"quantity": 2,
"function_code": "Read Holding Registers",
"type": "float",
"source": "float32",
"byte_order": "abcd",
"multiplier": 10.0,
"offset": 20.0
}
When you set the
multiplier
to10.0
andoffset
to20.0
, the value is multiplied by 10 and then added to 20.
Examples of Configuration Files
Deployment Configuration File
{
"transport": "mqtt",
"mqtt_connection": {
"host": "localhost",
"port": 1883,
"keepalive": 20,
"max_inflight_messages": 100,
"qos_levels": {
"measurements": 0,
"alerts": 1,
"configuration": 1,
"metadata": 1
}
},
"health_monitor": {
"heartbeat_interval": 60
},
"pmq_connection":
{
"output_queues": ["/modbus_out_queue"],
"input_queues": ["/modbus_in_queue"],
"message_size": 8192,
"message_count": 10
}
}
Application Configuration File
{
"connections": [
{
"id": "dev",
"host": "10.10.6.154",
"port": 502,
"slave_id": 1,
"timeout": 400,
"conn_method": "tcp",
"keep_session_open": true
}
],
"sampling_interval" : 4000,
"devices": [
{
"connection": {
"id": "dev"
},
"measurements": [
{
"object": {
"address": 7002,
"quantity": 1,
"function_code": "Read Holding Registers",
"type": "integer"
},
"id": "1",
"sampling_interval": 2000
},
{
"object": {
"address": 4002,
"quantity": 1,
"function_code": "Read Holding Registers",
"type": "integer",
"word_order": "AB"
},
"id": "2",
"sampling_interval": 4000
},
{
"object": {
"address": 3002,
"quantity": 1,
"function_code": "FC3",
"type": "integer",
"word_order": "AB"
},
"id": "3",
"sampling_interval": 4000
},
{
"object": {
"address": 2,
"quantity": 1,
"function_code": "Read Holding Registers",
"type": "float",
"source": "int16",
"multiplier": 0.2,
"offset" : -1.15
},
"id": "test_int16",
"sampling_interval": 4000
},
{
"object": {
"address": 3,
"quantity": 2,
"function_code": "Read Holding Registers",
"type": "float",
"source": "float32",
"byte_order": "ABCD",
"multiplier": 0.2,
"offset" : 4.32
},
"id": "test_ieee754",
"sampling_interval": 4000
},
{
"object": {
"address": 4002,
"quantity": 10,
"function_code": "Read Holding Registers",
"type": "string",
"encoding": "hex"
},
"id": "4",
"sampling_interval": 4000
},
{
"object": {
"address": 4002,
"quantity": 10,
"function_code": "Read Holding Registers",
"type": "string",
"encoding": "ascii"
},
"id": "4",
"sampling_interval": 4000
}
],
"alerts": [],
"configuration": [],
"metadata": [
{
"id": "did",
"value": "24aa7c85-f148-40bd-9436-90ddfd123369"
},
{
"id": "model_id",
"value": "F6A47A21"
},
{
"id": "model_version",
"value": "1"
}
]
}
]
}