Document toolboxDocument toolbox

Revolution Pi Gateway Tutorial

You want to exchange data between different interfaces and wonder if this is possible and how? For example, between Modbus TCP and digital IO interfaces? Then you are right here.

Instructions

  1. Create a concept

  2. Create a hardware configuration

  3. Convert the application into software

  4. Take a test (yes, really)

It is important that your concept contains and specifies your requirements.

Implementation

  1. Create a concept

    1. It should be possible to switch 14 digital output channels via Modbus TCP

    2. The first input register (16 bit) of a Modbus TCP Slave should be mapped to digital output channels

    3. It should be possible to read the 14 digital input channels via Modbus TCP

    4. The first output register (16 bit) of a Modbus TCP Slave should be mapped to digital input channels

  2. Create a hardware configuration

    1. A Revolution Pi Connect Module and a DIO module.

  3. Convert the application into software

    1. Create a PiCtory configuration

    2. Create an application, i.e., a script which connects the I/O data

  4. Take a test

    1. We can use an interactive Modbus TCP master software

PiCtory configuration

  1. RevPi DIO Module

  2. RevPi Connect SE Module

  3. Modbus TCP Slave Module

  4. Variant 17 Outputs, 19 Inputs

  5. Variable “Output” is a bit field for all the digital outputs

 

Don’t forget to save and reset driver to apply your configuration

Here is the RSC configuration file:

You can copy it to your RevPi device like soRevolution Pi Copy Files i.e., to /tmp/

Afterward, you have to activate this configuration like so on your device:

cp /tmp/GatwayModbusDIO.rsc /var/www/revpi/pictory/projects/_config.rsc sudo chown www-data:www-data /var/www/revpi/pictory/projects/_config.rsc piTest -x

Application

We decided to implement it in Python.

I like to use the IPython3 shell, which is really great for development. You may install it via:

sudo apt install ipython3

Afterward, you can start it via

ipython3

Copy this script, which covers all the code to perform this task. Yes, it really consists of seven (7) lines of code.

Application test

With the application QModMaster we can connect and write data to the Modbus TCP Slave.

We are writing a “7” to the first Modbus TCP Slave register. This equals “0b000 0111” which sets the first three digital output channels high. You have to apply the data after establishing a successful connection to the Modbus TCP slave.

QModMaster

We are receiving that value on the process image:

And that value is applied to the DIO:

Hints

  • Autostart the application on boot

https://revpimodio.org/en/revpipyplc-2/revpipyload/

 Related articles