modbus object has the following properties.
|TCP/IP only||IP address or host name of MODBUS server, for example, |
|TCP/IP only||Remote port used by MODBUS server. The default is 502. Optional
during object creation if transport is TCP/IP.|
|Serial RTU only||Serial port MODBUS server is connected to, for example, |
|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 |
|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. |
|Both TCP/IP and Serial RTU||Byte order of values written to or read from 16-bit registers.
Valid choices are |
|Both TCP/IP and Serial RTU||Word order for register reads and writes that span multiple
16-bit registers. Valid choices are |
|Serial RTU only||Bit transmission rate for serial port communication. Default
is 9600 bits per seconds, but the actual required value is device-dependent.|
|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.|
|Serial RTU only||Type of parity checking. Valid choices are |
|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
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
change from the default of
10 seconds to
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
Timeout to 30 seconds.
m = modbus('serialrtu','COM3'); m.Timeout = 30
This example changes the
Parity from the
m = modbus('serialrtu','COM3'); m.Parity = 'even';