|
|
|
|
ModbusConnectRTU (Function) In french: ModbusConnecteRTU Connects a client to a Modbus slave via a serial port. New in version 2024 // Creates a session and connects to the Modbus slave through the COM4 serial port Session is modbusSession Session = ModbusConnectRTU("COM4",1) Â // If the connection fails, display the error. IF ErrorOccurred = True THEN Trace(ErrorInfo()) ELSE // Write a value to register 0x42 in the slave. ModbusWriteRegister(Session, 0x42,0xCAFE) END Â // Release serial port ModbusDisconnect(Session)
Syntax
<Session> = ModbusConnectRTU(<Serial port> [, <Slave ID> [, <Rate> [, <Parity> [, <Nb data Bits> [, <Nb stop Bits>]]]]])
<Session>: modbusSession variable modbusSession variable used to communicate with the Modbus slave. <Serial port>: Character string Name of the serial port to be used: COM1, COM2, COM3, ... COM256. <Slave ID>: Optional integer Slave identifier, between 0 and 255. By default, this parameter is set to 0 (broadcast address).
Remark: The value 0 can also be specified if the slave ID is to be specified later via the SlaveID property of the modbusSession variable. <Rate>: Optional integer Data transfer rate (expressed in baud or bits per second) to be used for serial connection. By default, this parameter is set to 9600 baud. <Parity>: Optional integer Transfer parity on the port:
| | 0 | No parity | 1 | Even parity | 2 | Odd parity | Remark: There is no default parity. <Nb data Bits>: Optional integer Number of data bits on the serial port: 5, 6, 7 or 8. <Nb stop Bits>: Optional integer Number of stop bits on the serial port:
| | 0 (Default value) | 1 stop bit | 1 | 1.5 stop bits | 2 | 2 stop bits |
Remarks - After calling ModbusConnectRTU, it is recommended to check the ErrorOccurred variable to make sure there are no errors.
- The slave identifier is in the modbusSession variable. If an operation is to be performed on several different slaves, you can change the slave identifier in the modbusSession variable to avoid reopening the session.
Business / UI classification: Business Logic
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|