# Twin Config

Modbus slave setup and global settings are configured in the Module Twin, in the IoT Hub.\
The slave configuration supports both TCP and RTU connections and little / big Endian formats (if the slave uses reverse byte order / word order or not). In general, all slave id's must be unique.

In the desired properties, the following 3 keys can be used:

**Settings**\
The common settings include the interval between each publish of measurements from the Modbus Module, in milliseconds.\
If the value is not set, a default of 30 seconds is used.\
It also contains the basic scan interval that the modbus module executes read by. All tag sampling rates must be able to be factored into multipla of this scan rate. If it is set too low, the module will spend too much time on house keeping tasks.

**TcpConfig**\
A list of TCP slave connections, including ip address and information about byte/word order (dependent on processor architecture and individual implementations on the Modbus servers).

Required information\
SlaveConnection: Ip adress of the Modbus server

**RtuConfig**\
A list of RTU slave connections, including com port properties and information about byte/word order (dependent on processor architecture and individual implementations on the Modbus servers).

Required information\
**SlaveConnection**: Name of the com port\
**BaudRate**: Possible values are 9600, 14400 and 19200\
**DataBits**: Possible values are 7 and 8\
**StopBits**: Possible values are 0, 1, 2 and 3 (meaning 1,5 stopbits)\
**Parity**: Possible values are 0 = none, 1 = odd, 2 = even

Both ModbusTCPConfiguration and ModbusRTUConfiguration support an option to change the ByteOrder and WordOrder that the Modbus client should expect from the slave

Example configuration of tcp and rtu slaves, including common settings:

```

"settings": {
    "publishIntervalMs": 5000,
    "scanIntervalMs": 1000
},
"tcpConfig": {
    "slave01": {
        "name": "Slave01",
        "slaveConnection": "tc-site-dev.northeurope.cloudapp.azure.com",
        "hwId": "ModBusSimulator",
        "byteOrder": 1,
        "wordOrder": 0
    }
},
"rtuConfig": {
    "slave02": {
        "name": "Slave02",
        "slaveConnection": "<ip address>",
        "baudRate": 19200,
        "dataBits": 8,
        "stopBits": "None",
        "parity": "ODD",
        "byteOrder": 1,
        "wordOrder": 0
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tricloudnexus.io/edge/nexus-modules/data-connector-modules/modbusmodule/twin-config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
