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
ModbusConnectTCP (Function)
In french: ModbusConnecteTCP
Connects a client to a Modbus server via transmission control protocol (TCP).
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
// On crée une session et on se connecte au serveur Modbus Ã  l'adresse 192.168.1.18 sur le port 3275
Session is modbusSession
Session = ModbusConnectTCP("192.168.1.18",3275)

// Si la connexion Ã©choue, affiche l'erreur
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
ELSE
// Ecrit une valeur dans le registre 0x42 du serveur.
ModbusWriteRegister(Session, 0x42,0xCAFE)
END

// Déconnection du serveur
ModbusDisconnect(Session)
Syntax
<Session> = ModbusConnectTCP(<Address> [, <Port> [, <Slave ID> [, <Connection timeout>]]])
<Session>: modbusSession variable
modbusSession variable used to communicate with the Modbus server.
<Address>: Character string
Modbus server address. This address can correspond to:
  • an IPv4 or IPv6 address,
  • a domain name (e.g., "modbusserver.com").
<Port>: Optional integer
Port number to be used for the TCP connection.
By default, this parameter is set to 502, the standard port for Modbus TCP.
<Slave ID>: Optional integer
Number between 0 and 255 that indicates which slave to connect to if it is behind a gateway (e.g., a Modbus TCP to Modbus RTU gateway).
By default, this parameter is set to 255 (broadcast address).
<Connection timeout>: Optional integer
Timeout for connecting to the Modbus server, expressed in milliseconds. This parameter can be:
  • an integer corresponding to the number of milliseconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 20s or 10 ms).
Remarks
  • After calling ModbusConnectTCP, it is recommended to check the ErrorOccurred variable to make sure there are no errors.
  • ModbusConnectTCP blocks the application until a connection is established or the connection timeout is exceeded.
  • 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