Reading modbus RS-485 in settings C07W

Prev Next

Understanding settings

The settings are always processed by the system in JSON format, before they are sent to the gateway, and are divided into 2 parts:

slaveDefinitions

In slaveDefinitions, you decide what you will read. There are a number of settings for each slave:

Field

Value (as in example)

Description

"address"

3

The slave id of the modbus slave.

"type"

"generic-rtu"

To choose which register you want to read, specify generic-rtu.

"baudrate"

9600

The transmission rate in bits per second. Set the same baud rate here as on the modbus slave.

"bus""

101

The expansion bush where the RTU expansion card is inserted:

  • 101: expansion bus 2.

  • 102: expansion bus 1.

"serialConfig"

{

   "baudrate": 19200,

   "parity": 0,

   "stopbits": 2,

   "handshake": 0,

   "databits": 8

}

Use this notation to set advanced serial communication parameters, such as the number of data bits, stop bits and parity bits, and the handshake protocol.

"databits"

8

The number of bits used for data transmission per character.

"parity"

0

The type of parity check you want:

  • 0 (None): no parity check.

  • 1 (Odd): the total number of data bits is always an odd number.

  • 2 (Even): the total number of data bits is always an even number.

  • 3 (Mark): the parity bit is always 1.

  • 4 (Space): the parity bit is always 0.

"stopbits"

2

The number of stop bits per character:

  • 0 (One): one stop bit.

  • 1 (OnePointFive): one-and-a-half stop bits.

  • 2 (Two): two stop bits.

"handshake"

0

Transmission control type:

  • 0 (None): no handshake protocol.

  • 1 (RequestToSend/ClearToSend): RTS/CTS flow-control.

  • 2 (XOn/XOff): software-based flow control.

Example of a slaveDefinitions block

"slaveDefinitions": [
    {
        "name": "modbus.rtu",
        "slaves": [
            {
                "address": 3,
                "type": "generic-rtu",
                "busdefinitiontype": 100,
                "baudrate": 9600,
                "bus": "101"
            },
            {
                "address": 4,
                "type": "generic-rtu",
                "busdefinitiontype": 100,
                "bus": "101",
                "serialconfig": {
                    "baudrate": 19200,
                    "parity": 0,
                    "stopbits": 2,
                    "handshake": 0,
                    "databits": 8
                }
            }
        ]
    }
]

slaveSettings

For each slave that you have defined in slaveDefinitions, you can determine in slaveSettings which registers you actually want to read. First of all, you start by determining the name, always in the following format:

modbus.rtu.mb_uart{bus_id}. {slave_id}

  • bus_id: the last digit of the bus that you wrote in slaveDefinitions. For bus 101 it is 1 and for bus 102 it is 2.

  • slave_id: the slave ID that you have specified in slaveDefinitions.

For example: modbus.rtu.mb_uart1.3 → Bus 101 = 1, Slave ID = 3.

Furthermore, in measurementPaths you determine which modbus registers you want to read.

Field

Value (as in example)

Description

"measurementPath"

"voltage.uv"

The name of the path on which the data is put.

"functionCode"

4

Type of register to be read:

  • 1: Read Coil Status

  • 2: Read Input Status

  • 3: Read Holding Register

  • 4: Read Input Register

  • 5: Force Single Coil

  • 6: Preset Single Register

  • 15: Force Multiple Coils

  • 16: Preset Multiple Registers

"startAddress"

0

The modbus address you want to read.

"dataType"

1

Type of data to be read:

  • 1: Int16

  • 2: Int32

  • 3: Int64

  • 11: UInt16

  • 12: UInt32

  • 13: UInt64

  • 21: Float

  • 22: Double

  • 30: Bool

"factor"

1

This determines the factorization of the read value.

  • Factor: 1 → value * 1 → returns the value unchanged.

  • Factor: 0.1 → value * 0.1 → divides the value by 10.

  • Factor: 10 → value * 10 → multiplies the value by 10.

"minValue" (Optional)

0

If a minimum value has been entered, it will not be forwarded if the measurement is below this value.

"maxValue" (Optional)

500

If a maximum value has been entered, it will not be forwarded if the measurement is above this value.

"firstBit" (optional)

7

If you want to read one or more bits from a register, enter the first bit here. Choose Int16 as the data type (type 1 in the gateway settings).

  • You want to read bit X: "0000 0X00" → "FirstBit": 2 and "LastBit": 2.

  • You want to read bits XX: "XX00 0000" → "FirstBit": 6 and "LastBit": 7.

"lastBit" (optional)

7

If you want to read one or more bits from a register, enter the last bit here. Choose Int16 as the data type (type 1 in the gateway settings).

  • You want to read bit X: "0000 0X00" → "FirstBit": 2 and "LastBit": 2.

  • You want to read bits XX: "XX00 0000" → "FirstBit": 6 and "LastBit": 7.

Example of a slaveSettings block

"slaveSettings": [
    {
        "name": "modbus.rtu.mb_uart1.3",
        "settings": {
            "measurementPaths": [
                {
                    "measurementPath": "voltage.uv",
                    "functionCode": 4,
                    "startAddress": 0,
                    "dataType": 1,
                    "factor": 1,
                    "minValue": 0,
                    "maxValue": 500
                }
            ]
        }
    },
    {
        "name": "modbus.rtu.mb_uart1.4",
        "settings": {
            "measurementPaths": [
                {
                    "measurementPath": "alarm_1",
                    "functionCode": 3,
                    "startAddress": 1,
                    "dataType": 1,
                    "factor": 1,
                    "minValue": 0,
                    "maxValue": 1,
                    "firstBit": 7,
                    "lastBit": 7
                }
            ]
        }
    }
]

Example of a complete settings definition

{
    "slaveDefinitions": [
        {
            "name": "modbus.rtu",
            "slaves": [
                {
                    "address": 3,
                    "type": "generic-rtu",
                    "busdefinitiontype": 100,
                    "baudrate": 9600,
                    "bus": "101"
                },
                {
                    "address": 4,
                    "type": "generic-rtu",
                    "busdefinitiontype": 100,
                    "baudrate": 9600,
                    "bus": "101"
                }
            ]
        }
    ],
    "slaveSettings": [
        {
            "name": "modbus.rtu.mb_uart1.3",
            "settings": {
                "measurementPaths": [
                    {
                        "measurementPath": "voltage.uv",
                        "functionCode": 4,
                        "startAddress": 0,
                        "dataType": 1,
                        "factor": 1,
                        "minValue": 0,
                        "maxValue": 500
                    }
                ]
            }
        },
        {
            "name": "modbus.rtu.mb_uart1.4",
            "settings": {
                "measurementPaths": [
                   {
                        "measurementPath": "alarm_1",
                        "functionCode": 3,
                        "startAddress": 1,
                        "dataType": 1,
                        "factor": 1,
                        "minValue": 0,
                        "maxValue": 1,
                        "firstBit": 7,
                        "lastBit": 7
                    }
                ]
            }
        }
    ]
}