Fieldbus coupler Communication example

The following page describes the communication between a Modbus TCP fieldbus coupler and horstFX.

In this example, the Wago 750-362 with inserted input and output cards serves as the fieldbus coupler. However, this example can easily be applied to fieldbus couplers from other manufacturers.

In this setup, the robot acts as the client, while the fieldbus coupler functions as the server.

One of the key uses of the fieldbus coupler is to expand the number of digital inputs and outputs of the robot.

 

Version Information:

From horstFX Version 2021.04

1. Establishing Communication

To enable communication between the robot and the fieldbus coupler, both participants need to be brought into the same subnet. This means that the first 3 sections of the IP address must be the same, while the last section must be different. Instructions on how to change the robot's IP address can be found in the following article: Changing IP Address.

The IP address of the fieldbus coupler can be set through the web interface or using the dip switches. For further details, refer to the fieldbus coupler's documentation.

Once a successful connection is made between the front RJ45 socket of the robot control cabinet and the RJ45 socket of the fieldbus coupler, both participants can now communicate with each other.

2. Command Set

The following commands are available for communication purposes.

2.1 Establishing the Connection

With the following command, the connection can be established:

var modbusClient = modbusConnect(addr, port);

2.2 Reading Data

The following commands can be used to read data from the fieldbus coupler. You can find information about the address management of the fieldbus coupler in its documentation or web interface.

// Input cards
var InputData = null;
 
InputData = modbusReadInputsDiscrete(modbusClient, ref, count);
InputData = modbusReadInputDiscrete(modbusClient, ref);
InputData = modbusReadInputRegisters(modbusClient, ref, count);
InputData = modbusReadInputRegister(modbusClient, ref);  

// Output Cards
var OutputData = null;

OutputData = modbusReadCoils(modbusClient, ref, count);
OutputData = modbusReadCoil(modbusClient, ref);
OutputData = modbusReadRegisters(modbusClient, ref, count);
OutputData = modbusReadRegister(modbusClient, ref);

2.3  Writing Data

The following commands can be used to send data to the fieldbus coupler. Information on the address management of the fieldbus coupler can be found in its documentation or web interface.

 

modbusWriteCoils(modbusClient, ref, values);
modbusWriteCoil(modbusClient, ref, value);
modbusWriteRegisters(modbusClient, ref, values);
modbusWriteRegister(modbusClient, ref, value);

3.  Programming Example

In this example, we establish the connection to the fieldbus coupler and describe the outputs of the output card, as well as read the inputs of the input card.

var ModbusServerAdrr = "192.168.1.2";
var Port = 502;
var InputData = null;
var modbusClient = modbusConnect(ModbusServerAdrr, Port);

try

{

// Set the third output of the output card.
modbusWriteCoil(modbusClient, 2, true);


// Set the outputs 1-4 of the output card.
modbusWriteCoils(modbusClient, 0, [false, false, true, true]);


// Read inputs 1-8 of the input card.
InputData = modbusReadInputsDiscrete(modbusClient, 0, 8);

showInfo("Eingang 1-8: " + InputData);

//Read input 1 of the input card.
InputData = modbusReadInputDiscrete(modbusClient, 0);

showInfo("Eingang 1: " + InputData);


}

finally

{
modbusClient.closeConnection()
}

You can download the example program here:

Modbus Wago Fieldbus Coupler