Modbus Node

A communication protocol developed for industrial applications. In IoT, Modbus is used to connect devices and sensors to controllers and management systems, enabling data collection and control over machinery and equipment.

Modbus is a commonly available means of connecting industrial electronic devices in industrial environments. It uses character serial communication lines, Ethernet, or the IP suite as a transport layer. Modbus supports communication between multiple devices connected to the same cable or network and is often used to connect a plant supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems.

Functionality

The Modbus node will make requests at the specified update rate for the designated field addresses.

Outputs

Each Modbus address will be returned as a separate field (defined by ‘Field Name’) and added to the JSON object.


A single physical output is called a coil, and a single physical input is called a discrete input or a contact and the data types are:

Object type

Access

Size

Address Space

Coil

Read-write

1 bit

0x0000 – 0xFFFF

Discrete input

Read-only

1 bit

0x0000 – 0xFFFF

Input register

Read-only

16 bits

0x0000 – 0xFFFF

Holding register

Read-write

16 bits

0x0000 – 0xFFFF


Inputs

The Modbus node has both mandatory and optional inputs. These are:

Input

Requirement

Comments

Name

Mandatory

This provides a handle to which you and others can refer, so it should be simple but meaningful and explain the node’s purpose.

Update Rate

Mandatory

Interval between Modbus requests to the designated IP address.

Field Name

Mandatory

Name for the resultant JSON field.

Field Type

Mandatory

Modbus field type (e.g. Holding Register).

Address

Mandatory

Modbus field address (e.g. 40001).

Slave ID

Mandatory

Modbus slave ID of the specific PLC (base slave address is 1).


You must identify at least one Modbus object to read and can add additional objects by clicking on the ⊕ Add Value button.


How to Use

Implementation

Prior to setting up the Modbus node, you should have at least one device configured with an IP address. To set the port, add a colon and the port to the end of the address for example: mydomain.com:502 (502 is the default port in Modbus installations).


In the Rayven Workflow Builder:

  • Select Inputs.
  • Drag the Modbus node to the canvas.
  • Double click on the Modbus node to open the configuration window

Configuration

Section: General

This section contains basic configuration elements required for any Modbus implementation

Field

Requirement

Comments

Node Name

Mandatory

Enter a name for this node.


This provides a handle to which you and others can refer, so it should be simple but meaningful and explain the node’s purpose.

Update Interval (minutes)

Mandatory

Define the interval between requests (in minutes). For example ‘5’ will result in a request every 5 minutes.

Output Field Name

Mandatory

Define a name for the JSON field that will hold this data.

Modbus Address Type

Mandatory

Select a Modbus Address type from the dropdown menu:

  • Coil Outputs
  • Digital Inputs
  • Analog Inputs
  • Holding Registers
  • Holding Registers Float
  • Extended Registers

Modbus Address

Mandatory

Enter Modbus field address (e.g. 40001) obtained from the Modbus configuration.


Note that: since Modbus has a field size of 16 bits, some data objects might be split across multiple addresses. 


For example, a 32 bit value will be stored in two registers as a 16 bit LSW and as a 16 bit MSW. In this case, both registers must be requested and then combined to reform the original 32 bit value (see example JavaScript below).

Slave ID

Mandatory

Enter the slave ID for the specific PLC. By default, the Master PLC is set to 1, with each PLC in a network assigned a unique unit address from 1 to 247.


You may test the Modbus connection by selecting the appropriate object type, address, device IP and slave ID and pressing ‘Check Now’. A pop-up will show the result of your connection test. It is good practice to test all of the fields to ensure that they have been entered correctly.
doc screenshot 1This JavaScript is an example of how two UInt16 words may be combined to form a 32 bit floating point value. You will notice that the two UInt16 words have been taken from separate registers and named (for example) Phase_Voltage_1a and Phase_Voltage_1b and are then combined into the output variable Phase_Voltage using the function  GetSingle(z1,z2).


var myObject = JSON.parse(input);


myObject.Phase_Voltage=GetSingle(Number(myObject.Phase_Voltage_1a),Number(myObject.Phase_Voltage_1b));

myObject.Phase_Voltage=myObject.Phase_Voltage.toFixed(2);


myObject.Frequency=GetSingle(Number(myObject.Frequency_1a),Number(myObject.Frequency_1b));

myObject.Frequency=myObject.Frequency.toFixed(2);


myObject.Current=GetSingle(Number(myObject.Current_1a),Number(myObject.Current_1b));

myObject.Current=myObject.Current.toFixed(2);


myObject.Active_Power=GetSingle(Number(myObject.Active_Power_1a),Number(myObject.Active_Power_1b));

var power = myObject.Active_Power.toFixed(2);

myObject.Active_Power=power*3;


var result = JSON.stringify(myObject);


function GetSingle(z1,z2){

  //Convert 2 Uint16 to a Float32

  var value = z2<<16 | z1;

  var b=value & 0x7fffff;

  var e=((value>>23) & 0xff)-127;

  var m=1+b*Math.pow(2, -23);

  var result=m*Math.pow(2, e);

  if (value & 0x80000000) {

    result=-result;

  }

  return result;

}



Section: Group by Device Label

Field

Requirement

Comments

Device label name

Mandatory

There are no labels available in this box until you have saved at least one in the Device Labels section of the Workspace. 


Select a Label to use to filter devices.

Grouped

Mandatory

Select a method for grouping the widget on the dashboard from the dropdown:


No Grouping (widget per device): one widget will appear for each device


Group by device label value (Widget per label value): One widget will appear for each value of a label. For example, if the Label is ‘Colour’ and there are the values ‘Green’ and ‘Gold’, then two widgets will be displayed, one with devices with Colour Label equal to “Green” and one with devices with Colour Label equal to “Gold”


Group by device label name (One widget): Only one widget will be displayed and this will contain data from all devices.

Activation

Once the node has been configured, click the Activate button and then click Save. The node is ready to receive data into the workflow.