Communication protocols
PROGRAMMING MANUAL 219
Revision 1.0
4.3.3 ModbusRTU
The ModbusRTU protocol provides single point to point communication
between the TJ2-MC64 and a ModbusRTU master. Implementation of
the protocol is provided on serial port 1 for RS232 and port 2 for RS485.
Baud rate and slave address can be set in the BASIC program during serial
port initialisation.
The Modbus protocol is initialised by setting the mode parameter of the
SETCOM instruction to 4. The ADDRESS parameter must also be set
before the Modbus protocol is activated.
Example
ADDRESS=1
SETCOM(9600,8,1,2,1,4) ‘Port 1 as MODBUS port at 9600 baud
ADDRESS=1
SETCOM(19200,8,1,2,2,4) ‘set up the RS485 port at 19200 baud
The protocol can be de-selected by setting the option to 0 in the SETCOM
command.
SETCOM(19200,8,1,2,2,0) ‘set the RS485 port to normal mode.
Functions
The following Modbus functions are supported:
/i
Code Function name Action
1 Read Coil Status Read I/O
2 Read Input Status Read I/O
3 Read Holding Registers Read VR variables or TABLE memory in both
integer or IEEE floating point format
5 Force Single Coil Write I/O
6 Set Single Holding Register Write to a VR variable or a TABLE location in
both integer or IEEE floating point format
16 Set Multiple Holding Registers Write to multiple VR variables or TABLE loca-
tions in both integer or IEEE floating point for-
mat
23 Read & Write Multiple Holding
Registers
in both integer or IEEE floating point format
Code Function name Action