AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Comunicación / Funciones Modbus
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Writes one or more registers (16-bit values) to a Modbus slave, starting at a specific address.
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 06 (Write Single Holding Register).
  • The multiple-bit write operation corresponds to Modbus function code 16 (Write Multiple Holding Registers).
Ejemplo
// 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 16-bit integers starting at address 0x42
	IF NOT ModbusWriteRegister(Session, 0x42, [0xF8C5, 1637, -1542, 0, 0x00A8]) THEN
		Trace(ErrorInfo())
	END
END

// Disconnection
ModbusDisconnect(Session)
Sintaxis

Writing a 16-bit value to a Modbus slave Ocultar los detalles

<Result> = ModbusWriteRegister(<Session> , <Address> , <Value>)
<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 value must be written.
<Value>: Integer
16-bit number that must be written to the register in the slave.

Writing multiple 16-bit values to a Modbus slave Ocultar los detalles

<Result> = ModbusWriteRegister(<Session> , <Address> , <Values>)
<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 values must be written.
<Values>: Array
Array of 16-bit integers that must be written to the registers in the slave.
Observaciones
CAUTION: As writing operations involve the manipulation of automation devices, it is advisable to test the various commands before putting them into production, to ensure that the devices perform the required operations.
Clasificación Lógica de negocio / UI: Código neutro
Componente: wd300com.dll
Versión mínima requerida
  • Versión 26
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 28/03/2025

Señalar un error o enviar una sugerencia | Ayuda local