Class: Modbus

Modbus

Provides methods and properties for using the Modbus protocol


Example
var modbus = $wat.load('modbus')[0];

Methods


createSerialClient(port)

Creates a client for accessing Modbus via a serial port.

Parameters:
Name Type Description
port wat.SerialPort

The serial port to use for communications.

Since:
  • 0.1 (WAT 2.4)
Returns:
Type
modbus.ModbusSerialClient
Example
var sys = $wat.load('sys')[0];
var serial = sys.serials[0];
serial.mode = serial.modes[1]
serial.halfDuplex = true;
serial.baud = 19200;
serial.bits = 8;
serial.stop = 1;
serial.parity = serial.Parity.Even;
var client = modbus.createSerialClient(serial);

createTcpClient(address, port)

Creates a client for accessing Modbus via TCP.

Parameters:
Name Type Description
address string

Host address for network communication

port int

Network port

Since:
  • 0.1 (WAT 2.4)
Returns:
Type
modbus.ModbusTcpClient
Example
var address = '192.168.2.100';
var port = 502;
var client = modbus.createTcpClient(address, port);

destroy(obj)

Destroys a client created using one of the create* methods. To avoid memory leaks, an application must destroy every client it creates when it is no longer using it. Client instances are automatically cleaned up when a page is unloaded. However, with single-page applications, a page may not be unloaded for extended periods. In this case, the application must use this function to clean up unused clients.

Parameters:
Name Type Description
obj Object

A client created using one of the create* methods

Since:
  • 0.1 (WAT 2.4)
Example
modbus.destroy(client);