Overview – Modbus
The Modbus connector is a device driver with the following features:
- Master and Slave connection methods
- Ethernet and Serial communication types
- TCP, RTU and ASCII payload types
- Support for Enron Modbus variant
- Failover IP or port
- Configurable parity, data bits, stop bits and RTS
- Configurable timeouts and retries
- Transaction logging
- Communication counters
👉 Use the Getting Started Modbus page to configure a driver.
Driver Properties
The following sections describes properties that relate to the driver configuration.
Type
Master | Slave
When you choose a Slave connection type you will be able to specify a Device Address. This is the device address that any Modbus master clients must use to connect to this slave instance.
Connection
Ethernet | Serial | Simulation
Serial/Ethernet Type
RTU | ASCII | TCP | Enron RTU | Enron ASCII | Enron TCP
These options are available on both serial and Ethernet connection types. This gives you the ability to choose between native protocols and protocol conversion such as Ethernet to serial converters.
For example:
- Choosing Ethernet and TCP will result in a standard Modbus TCP connection.
- Choosing Ethernet and RTU will result in a Modbus RTU over TCP connection.
- Choosing Serial and RTU will result in a Modbus RTU connection.
Address and Port
Ethernet
The Ethernet connection type allows you to specify:
- IP Address: The IP address of the Modbus device listening for connections
- Port Number: The port number of the Modbus device listening for connections [502]
Serial
The Serial connection type allows you to specify:
- Serial Port Number: The COM port number (Windows) [1]
- Linux Port Name: The TTY port address (Linux) [/dev/ttyS0]
- Baud Rate: 110 to 921600 [Baud Rate 9600]
- Parity: None | Odd | Even | Mark | Space [None]
- Data Bits: 7 | 8 [Data Bits 8]
- Stop Bits: None | One | Two | One Point Five [One]
- RTS Enable: True | False [False]
Timeouts and Retries
For both Master and Slave as well as Ethernet and serial connections you can manage the timeouts and retries that OAS will apply to the connection. You can tweak the following configuration properties depending on your requirements:
- Timeout: The timeout when sending a message in milliseconds [1000]
- Connection Timeout: The timeout when opening a connection in milliseconds [2500]
- Number of Retries: The number retires before it is deemed a failure [3]
- Delay Between Packets: Time to wait between each packet in seconds (Ethernet only) [0]
- Bad Msgs to Offline: After this many messages have failed, the driver will be disconnected [3]
- Return to Online: When a driver is disconnected due to bad messages, a new connection will be attempted after this many seconds [60]
Write Behaviors
You can use the Enable Single Write and Enable Multiple Write configuration properties to manage the behavior of the Modbus driver when writing to one or more registers.
Enable Single Write
When this option is disabled, the driver will use function code 15 for output coils and function code 16 for holding registers even if only one register is being written to.
When this option is enabled, the driver will use function code 05 when only one output coil needs to be written and 06 when only one holding register needs to be written to.
Enable Multiple Write
When this option is disabled, the driver will write holding registers one at a time using function code 06. The number of words that are written depends on the data type of the Tag that is using this driver.
- Int16 = 1 (short)
- UInt16 = 1 (unsigned short)
- Int32 = 2 (int)
- UInt32 = 2 (unsigned int)
- Int64 = 4 (long)
- Uint64 = 4 (unsigned long)
- Float32 = 2 (single)
- Float64 = 4 (double)
When this option is enabled, the driver will write multiple holding registers using function code 16.
Counters
The Modbus driver provides the option to enable one or more communication quality monitoring counters for both reads and writes. The following are provided:
- Bad Count: The number of transitions from good to bad
- Bad Read Count: The number of failed reads
- Bad Time: The total number of seconds the driver has been in a bad state
- Bad Write Count: The number of failed writes
- Good Count: The number transitions from bad to good
- Good Read Count: The number of successful reads
- Good Time: The total number of seconds the driver has been in a good state
- Good Write Count: The number of successful writes
To reset the above counters, set a boolean Tag in the Count Reset property and then set the value of the Tag to TRUE. You can also use the Tag’s Reset Value To False property to make sure the Tag’s value automatically goes back to FALSE so that you can reset the counters again next time without having to manually set the Tag back to FALSE.
Failover
When using the Master communication type, you can enable the Enable Failover property and configure a secondary IP address or serial port depending on whether you have an Ethernet or Serial connection. When a secondary interface is configured, OAS will attempt to use it if the primary interface fails to send a message after the given Number of Retries and Bad Msgs to Offline attempts.
Logging
You can enable detailed message and transaction logging for Modbus drivers by configuring the logging option in the Configure > Options > System Logging menu.
Enable the Log Modbus Communications property and optionally specify the name of the driver interface you wish to log. Note that this kind of logging consumes additional CPU and storage resources if left enabled.