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
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
Writes one or multiple bits to a specific address in a Modbus slave.
Remarks:
  • This function blocks the application until the slave acknowledges the message or until the session timeout is exceeded.
  • The single-bit write operation corresponds to Modbus function code 05 (Write Single Coil).
  • The multiple-bit write operation corresponds to Modbus function code 15 (Write Multiple Coils).
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
// Create a session and connect to a Modbus server
Session is modbusSession
Session = ModbusConnectTCP("192.168.1.7")

// If the connection fails, display the error
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
ELSE
// Write a sequence of 5 bits starting at address 0x42.
IF NOT ModbusWriteBit(Session, 0x42, [1,0,1,1,0]) THEN
Trace(ErrorInfo())
END
END    

// Disconnection
ModbusDisconnect(Session)
Syntax

Writing 1 bit to a Mobdus slave Hide the details

<Result> = ModbusWriteBit(<Session> , <Address> , <Bit>)
<Result>: Boolean
  • True if written successfully,
  • False otherwise. To get more details on the error, use ErrorInfo with the errMessage constant.
<Session>: modbusSession variable
Name of the modbusSession variable that corresponds to the communication session with the Modbus slave.
<Address>: Integer
Value between 0 and 65,535 that corresponds to the address (slave) to which the bit must be written.
<Bit>: Boolean
Value of the bit to be written: True or False.

Writing multiple bits to a Modbus slave Hide the details

<Result> = ModbusWriteBit(<Session> , <Address> , <Bits to be sent>)
<Result>: Boolean
  • True if written successfully,
  • False otherwise. To get more details on the error, use ErrorInfo with the errMessage constant.
<Session>: modbusSession variable
Name of the modbusSession variable that corresponds to the communication session with the Modbus slave.
<Address>: Integer
Value between 0 and 65,535 that corresponds to the address (slave) to which the bits must be written.
<Bits to be sent>: Array of boolean
Name of the Array variable that contains the bits to be sent.
Remarks
CAUTION: Since write operations make it possible to control PLCs, it is recommended to test the different commands before the production phase to make sure the PLCs perform the required operations.
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: 12/14/2023

Send a report | Local help