Modbus Node

      Modbus Node


        Article summary

        Modbus Node

        The Modbus node requests data from remote PLCs via the Modbus protocol over an IP connection. The Modbus node will make requests at the specified update rate for the designated field addresses. Each Modbus address will be returned as a separate field and added to the JSON object.

        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.

        A single physical output is called a coil; a single physical input is called a discrete input or a contact. 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

        Prior to setting up the Modbus node, you should have at least one device configured with an IP address. The IP Address can be set up in the device list under Device Management. 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).


        Adding a Modbus node to your workflow

        1. First, select your desired solution and navigate to Rayven Workflow.
        2. Select ‘Inputs’ from the left-hand panel.
        3. Find the Modbus node and drag it onto the canvas.
        4. Double click on the Modbus node to open its configuration window.


        Configuring your Modbus node

        1. Give your node a Name. Choose something simple that clearly explains its purpose. You must pick a name that has three or more characters.
        2. Under 'Update Rate', define how often you want to call the data (in minutes). For example, entering '10' would result in a request every 10 minutes. 
        3. Under 'Field Name', enter the name for the field where you want to store this data.
        4. Enter the Modbus Field Type (e.g., 'Holding Register').
        5. Enter the Modbus Field Address (e.g., 40001). 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).
        6. 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.

        Testing your Modbus connection

        You can 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.


        This 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, 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;

        }


        Grouping by device label

        You might want to set how data should be grouped. To group data by device label, you must first create at least one label in the Device Labels section of the Workspace. See Creating Device Labels and Configuring Nodes Using Labels for more information.

        1. Select the label you will be using to filter devices and enter it under Device label name.
        2. Select a method for grouping data from the dropdown options:
          • No Grouping (widget per device): one Pie Chart widget will appear for each device.
          • Group by device label value (widget per label value): one widget will appear for each unique label value. For example, if the device label is ‘Color’ and the label values are ‘Green’ and ‘Gold’, the dashboard will display two widgets. One will show data for devices labeled ‘Green’, and the other for devices labeled ‘Gold’.
          • Group by device label name (one widget): only one widget will be displayed, containing data from all devices with the chosen device label.



        What's Next