ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / Modbus functions
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Reads one or more registers from a Modbus slave, starting at a specific address.
Example
// Crée une session et connexion à un serveur Modbus
Session is modbusSession
Session = ModbusConnectTCP("192.168.1.7")

tabRéponse is array of 5 2-byte int

// Si la connexion échoue, affiche l'erreur
IF ErrorOccurred = True THEN
	Trace(ErrorInfo())
ELSE
	// Lit une séquence de 5 registres en lecture-écriture à partir de l'adresse 0x42.
	tabRéponse = ModbusReadRegister(Session, 0x42, 5, False)
	// Si il y a eu une erreur on l'affiche.
	IF ErrorOccurred = True THEN
		Trace(ErrorInfo())
	END
END

// Déconnexion
ModbusDisconnect(Session)
Syntax

Reading 1 register from a Modbus slave Hide the details

<Result> = ModbusReadRegister(<Session> , <Address> , <Read-only>)
<Result>: Integer
Value of the register read (16-bit integer).
<Session>: modbusSession variable
Name of the modbusSession variable that corresponds to the communication session with the Modbus slave.
<Address>: Integer
Address of the register in the slave (between 0 and 65,535).
<Read-only>: Boolean
  • True if the registers to be read are part of read-only data (Modbus function code 4 (Read Input Registers)).
  • False if the registers to be read are part of read-write data (Modbus function code 3 (Read Multiple Holding Registers)).

Reading multiple registers from a Modbus slave Hide the details

<Result> = ModbusReadRegister(<Session> , <Address> , <Number of registers> , <Read-only>)
<Result>: Array
Array of 16-bit integers that contains the values of the registers read.
<Session>: modbusSession variable
Name of the modbusSession variable that corresponds to the communication session with the Modbus slave.
<Address>: Integer
Starting address of the registers in the slave (between 0 and 65,535).
<Number of registers>: Integer
Number of registers to be read.
<Read-only>: Boolean
  • True if the registers to be read are part of read-only data (Modbus function code 4 (Read Input Registers)).
  • False if the registers to be read are part of read-write data (Modbus function code 3 (Read Multiple Holding Registers)).
Remarks
  • This function blocks the application until the slave responds to the message or until the session timeout is exceeded.
  • After calling ModbusReadRegister, it is recommended to check the ErrorOccurred variable to make sure there are no errors.
Business / UI classification: Neutral code
Component: wd300com.dll
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/28/2025

Send a report | Local help