ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Modbus functions
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
ModbusConnectRTU (Function)
In french: ModbusConnecteRTU
Connects a client to a Modbus slave via a serial port.
New in version 2024
WEBDEV - Server codeWindows This function is now available for WEBDEV websites in Windows.
WEBDEV - Server codeLinux This function is now available for WEBDEV websites in Linux.
Example
// 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:
0No parity
1Even parity
2Odd 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
11.5 stop bits
22 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
Component: wd290com.dll
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 11/17/2023

Send a report | Local help