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
Reads one or more bits from a Modbus slave, starting at a specific address.
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")

arrResponse is array of 5 int

// If the connection fails, display the error
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
ELSE
// Read a sequence of 5 bits in read-write mode starting at address 0x42
arrResponse = ModbusReadBit(Session, 0x42, 5, False)
// Display the error, if any
IF ErrorOccurred = True THEN
Trace(ErrorInfo())
END
END

// Disconnection
ModbusDisconnect(Session)
Syntax

Reading 1 bit from a Modbus slave Hide the details

<Result> = ModbusReadBit(<Session> , <Address> , <Read-only>)
<Result>: Boolean
Value of the bit read (True or False).
<Session>: modbusSession variable
Name of the modbusSession variable that corresponds to the communication session with the Modbus slave.
<Address>: Integer
Address of the bit in the slave (between 0 and 65,535).
<Read-only>: Boolean
  • True if the bits to be read are part of read-only data (Modbus function code 2 (Read Discrete Inputs)).
  • False if the bits to be read are part of read-write data (Modbus function code 1 (Read Coils)).

Reading multiple bits from a Modbus slave Hide the details

<Result> = ModbusReadBit(<Session> , <Address> , <Number of bits> , <Read-only>)
<Result>: Array
Array of integers that contains the value of the bits read (True or False).
<Session>: modbusSession variable
Name of the modbusSession variable that corresponds to the communication session with the Modbus slave.
<Address>: Integer
Starting address of the bit in the slave (between 0 and 65,535).
<Number of bits>: Integer
Number of bits to be read (to be sent by the slave).
<Read-only>: Boolean
  • True if the bits to be read are part of read-only data (Modbus function code 2 (Read Discrete Inputs)).
  • False if the bits to be read are part of read-write data (Modbus function code 1 (Read Coils)).
Remarks
  • This function blocks the application until the slave responds to the message or until the session timeout is exceeded.
  • After calling ModbusReadBit, it is recommended to check the ErrorOccurred variable to make sure there are no errors.
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/13/2023

Send a report | Local help