The modbus
object has the following properties.
Property | Transport Type | Description |
---|---|---|
'DeviceAddress' | TCP/IP only | IP address or host name of MODBUS server, for example, '192.168.2.1' .
Required during object creation if transport is TCP/IP.
|
Port | TCP/IP only | Remote port used by MODBUS server. The default is 502. Optional
during object creation if transport is TCP/IP.
|
'Port' | Serial RTU only | Serial port MODBUS server is connected to, for example, 'COM1' .
Required during object creation if transport is Serial RTU.
|
Timeout | Both TCP/IP and Serial RTU | Maximum time in seconds to wait for a response from the MODBUS
server, specified as a positive value of type double .
The default is 10 . You can change the value either
during object creation, or after you create the object.
|
NumRetries | Both TCP/IP and Serial RTU | Number of retries to perform if there is no reply from the
server after a timeout. If using the Serial RTU transport, the message
is resent. If using the TCP/IP transport, the connection is closed
and reopened.
|
'ByteOrder' | Both TCP/IP and Serial RTU | Byte order of values written to or read from 16-bit registers.
Valid choices are 'big-endian' and 'little-endian' .
The default is 'big-endian' , as specified by the
MODBUS standard.
|
'WordOrder' | Both TCP/IP and Serial RTU | Word order for register reads and writes that span multiple
16-bit registers. Valid choices are 'big-endian' and 'little-endian' .
The default is 'big-endian' , and it is device-dependent.
|
BaudRate | Serial RTU only | Bit transmission rate for serial port communication. Default
is 9600 bits per seconds, but the actual required value is device-dependent.
|
DataBits | Serial RTU only | Number of data bits to transmit. Default is 8, which is the
MODBUS standard for Serial RTU. Other valid values are 5, 6, and 7.
|
Parity | Serial RTU only | Type of parity checking. Valid choices are 'none' (default), 'even' , 'odd' , 'mark' ,
and 'space' . The actual required value is device-dependent.
If set to the default of none , parity checking
is not performed, and the parity bit is not transmitted.
|
StopBits | Serial RTU only | Number of bits used to indicate the end of data transmission.
Valid choices are 1 (default) and 2. Actual required value is device-dependent,
though 1 is typical for even/odd parity and 2 for no parity.
|
Set a Property During Object Creation
You can change property values either during object creation or after you create the object.
You can create the modbus
object using a
name-value pair to set a value during object creation.
This example creates the MODBUS object and increases the Timeout
to 20
seconds.
m = modbus('serialrtu','COM3','Timeout',20) m = Modbus Serial RTU with properties: Port: 'COM3' BaudRate: 9600 DataBits: 8 Parity: 'none' StopBits: 1 Status: 'open' NumRetries: 1 Timeout: 20 (seconds) ByteOrder: 'big-endian' WordOrder: 'big-endian'
The output reflects the Timeout
property
change from the default of 10
seconds to 20
seconds.
Set a Property After Object Creation
You can change a property anytime by setting the property value using this syntax after you have created a MODBUS object.
<object_name>.<property_name> = <property_value>
This example using the same object named m
increases
the Timeout
to 30 seconds.
m = modbus('serialrtu','COM3'); m.Timeout = 30
This example changes the Parity
from the
default of none
to even
.
m = modbus('serialrtu','COM3'); m.Parity = 'even';