MODBUS

Modbus is a protocol for exchanging data between electronic devices. In PacketTracer, we support TCP/IP Modbus which allows communication between modbus client and server over Ethernet.

 

Modbus Client and Server

Modbus communication utilizes a client-server architecture where clients request information from a server.

Modbus Server

 

In the illustration above, a ModbusServer is started on a PC. This ModbusServer will be listening to connection requests from another ModbusClient.

 

Modbus Client

 

A ModbusClient is started on another PC. This ModbusClient will try to make a connection with a ModbusServer at the IP Address 1.1.1.1 and send request when the connection is established between the two devices.

 

JavaScript API

Program Structure and Events

Function Return Type Description Example
Modbus Client:
setup()

N/A

Enables Modbus client on the device.

ModbusClient.setup()
Modbus Client:
connect(ip)

bool

Opens a TCP connection to the server.

ModbusClient.connect("1.1.1.1");
Modbus Client:
onConnectionEstablished()

N/A

Sets the callback for when the connection to the server is establised.

ModbusClient.onConnectionEstablished = function() {};
Modbus Client:
onReceive(data, sourceIp)

N/A

Sets the callback for when the requested data are received.

ModbusClient.onReceive = function(data, ip) {};
Modbus Client:
send(data)

N/A

Sends request to the server. Data can be in any structure. Users control how ModbusClient and ModbusServer process sent and received data.

ModbusClient.send('print');
Modbus Server:
setup()

N/A

Enables Modbus server functionalities on the device.

ModbusServer.setup();
Modbus Server:
start()

N/A

Starts the Modbus Server process.

ModbusServer.start();
Modbus Server:
onReceive(data, sourceIp)

N/A

Sets the callback for when the requested data are received.

ModbusServer.onReceive = function(data, ip) {};
Modbus Server:
send(ip, data)

N/A

Sends response to the client at a specific ip address. Data can be in any structure. Users control how ModbusClient and ModbusServer process sent and received data.

var ptObject1={"bit_1":index,"Bit_2":index+20};
ModbusServer.send('10.0.0.4', JSON.stringify(ptObject1));

 

 

Examples

Sample File Description

modbus.pkt

This file demonstrates how a Modbus Client communicates with a Modbus Server. Users can run the Modbus Server and Modbus Client programs to observe the Modbus traffic between them once a TCP connection is established.

 

Current Modeling Limitations

Packet Tracer only supports Modbus TCP/IP which runs over Ethernet. Modbus RTU is not supported.

Modbus packet can be viewed in simulation when a Modbus Client and Modbus Server communicate. The packet does not show all of Modbus data fields.

Packet Tracer does not support standard Modbus functions and registers. It’s up to users to define it in the json data that is being sent between Modbus Client and Modbus Server.