Create a connectionModbus

Modbus

Modbus is a serial communication protocol developed in 1979 by Modicon (now Schneider Electric) for use with programmable logic controllers (PLCs). It has become a standard protocol for industrial communication due to its simplicity and reliability.

In essence, Modbus allows devices to communicate over various types of networks, including serial lines (Modbus RTU and Modbus ASCII) and Ethernet (Modbus TCP). It operates on a master/slave or client/server architecture, where the master (or client) sends requests to the slaves (or servers), which then respond with the requested data.

Modbus is widely used in industrial environments for connecting and transmitting data between devices like sensors, controllers, and computers.

Modbus

Basics

Modbus contains registers with addresses. Each register addres contains 8 bits. A 8 bit value can not be more that 255. To overcome this low number. In Modbus, you can combine multiple registers to form a number.

  • Two 8 bit registers become 16 bit
  • Four 8 bit registers become 32 bit
  • Eight 8 bit registers become 64 bit

This represent;

OrderMinMax
8 bit-128127
16-bit-32.76832.767
32-bit-2.147.483.6482.147.483.647
64-bit-(9 x 10^19)9 x 10^19 -1

Or for unsigned bits this represent;

OrderMinMax
8 bit0255
16-bit065.535
32-bit04.294.967.295
64-bit018 x 10^19

If you read from address 1 and read a 64 bit value, UpBlue will read register 1 to 9 and combine this to one value.

Modbus supports 4 different type or registers;

  1. Coil
  2. Discrete
  3. Holding
  4. Input

Coil and Discrete registers are on/off 1 bit registers. Holding and Input can contain more than 1 bit, namely 8 bits.

Create a Connection with Modbus

Name connection

A connection is created within an organisation. Go to the UpBLue Management Environment to open an organisation. Go to the connection page to create a connection. You can also create a connection from the collector page. This will automatically attach the connection to the collector. You can always detach the connection after and attach it to a different collector.

Click in the connection or collector page on:

Give the connection a name. This name is only for identification and can be changed later. Also select the Modbus connection. The selection for Modbus TCP or RTU will be done later.

Click on:

Labels

A connection needs labels to work. Read more about labels..

Fill the Enterprise, Site, Area, Cell and Unit labels The Cell and Unit labels can be overwritten per rule. The Enterprise and Site labels are prefilled. This can be changed when needed.

⚠️

Think good about the labels you choose! Changing them later will have effect on your dashboards!. Read more about this here.

Create Connection

Click on: to create the connection. The connection will open.

Connection details

Fields

Connection name

This is the name given earlier when creating the connection. This is only for identification in the UpBlue Management Environment.

Address

This is the address of the Modbus Client. This can be an IP address for Modbus TCP or UDP or a com port for Modbus RTU. For Modus TCP or UDP, add a port. Normally this is port 502.

No need to add http://, https:// or something else. Based on the selected Protocol , the right prefix will be used.

⚠️

If you use a prefix, the connection will not work.

Example or an Modbus IP address: 192.168.0.152:502, localhost:502 or COM6.

⚠️

Don’t forward any ports in your router! The collector runs locally and the connection will be run and test locally on the Collector. Use a local IP address or hostname.

Slave ID

The slave id the client is running on. If there are multiple clients (slaves) on the same IP address, don’t create multiple connections. Override de slave ID in the rule.

Protocol

UpBlue support the following protocols;

  • TCP (default)
  • UDP
  • RTU (serial)
  • RTU over TCP

For RTU, some extra configuration like speed, data bits, stop bit and parity need to be set

Security

Because Modbus is so simple; username, password or other security measures are not part of the standaard.

Endianness and Word order

In Modbus, it differs per manufacturer the order bytes are send in. Endianness and Word order refers to the order in which bytes are transmitted over the network. Modbus typically uses big-endian format and HIGH word first. There are four possible combinations for a 32 bit number;

  1. ABCD
  2. BADC
  3. DCBA
  4. CDAB

In this example each letter represent 8 bit. 16 bits is seen as a pair. Byte swapping (Endianness) is swapping the two 8 bits(2x one byte). Word swapping (word order) is swapping the 16 bit pair in a 32 bit group.

OrderEndiannessWord order
AB CDBIGHIGH
BA DCLITTLEHIGH
DC BALITTLELOW
CD ABBIGLOW

When using 16 bits, Word order does not apply. When using 8 bit, both word order and endianess does not apply.

When the Endianness and Word order is not know, you can find the order by trial and error. You do need to know the what registers there are and what values they represent.

Start with a 16 bit number to find out the Endianness, then move to a 32 or 64 bit number to find the word order.

Test connection

When all fields are set, click on: to test the connection. A new windows will open that will display the result. If the connection is ok, proceed by making a rule.
💡

If the button is gray, first attach a collector. If there are no collectors available, first install a collector. For more details, see the collector installation page..

Rules

A rule is configuration that will retrieve a specific set of information from the Modbus client. It instructs the Collector to retrieve this information and send it to the Cloud.

Fields

Name

The name is only used for identification in the UpBlue Platform.

Tag

The tag name.

Register

Modbus supports 4 different type or registers;

  1. Coil
  2. Discrete
  3. Holding
  4. Input

Coil and Discrete registers are on/off 1 bit registers. Holding and Input can contain more than 1 bit, namely 8 bits.

Datatype

Select the datatype. You to get the datatype from the client documentation.

Boolean datatype

Some manufacturers use input- or holdingsregister as coil/discrete register. For example a 16 bit number is used as 16 times true/false.

For example; This this a representation of a 16 bit number; 1000000000000000 Each number is one bit. In this case only the first bit is “on”. If the mapping is created as this, two tags are created. machine_on with value 1 and machine_error with value 0. Value select

If the value changes to 1100000000000000. machine_error tag will change to 1

The tag on the rule will be ignored.

Address

The address to read from.

Poll rate

The time between measurements.

Data deduplication

If this option is off, each measurement is saved to UpBlue. Most of the time this is not needed. When this option is on, the current measurement is compared to the pervious measurement. When there are equal, the measurement is ignored. When the measurements are equal for one hour, a new value is sent to UpBlue.

Transform values

If the payload is not a value, but text, we can transform the text to a value. Text can be saved in the database by itself, but no calculations can be done on text in the dashboards. It is advice to transform text to values when possible.

You can map text to a value like so; Result should be this; Value select

Override Slave ID

When multiple slave devices on the same IP address or COM port, the rule can be pointed to the right device. If the device has an other Endianness or an other Word order, this can also be changed here.

Labels

You can override the labels Cell and Unit or add extra labels. Read more about this here.

Test rule

By clicking on this button: the rule will be test.

A new window will open with the test results.

⚠️

Some Modbus clients don’t accept two or more connections. This means that after the connection is started, testing a rule wil stop working, because the connection is already taken by the Collector.