Page 1 of 1

Map DIO to Modbus/TCP

Posted: 26 Jul 2018, 18:14
by Scott_Thompson
Greetings Kunbus!

My hardware configuration is as follows:

LEFT: RevPi Core 3
MIDDLE: RevPi DIO
Right: Gateway Modbus TCP

Although a virtual device can be added as a Modbus slave, I am restricted to only Analog. My concern is getting the status of DIO to an HMI through Modbus/TCP.

What I want to accomplish is reading and writing coils and reading discrete inputs on the DIO through the Gateway. Is there a standard mapping of address areas for O1 - O14 (Coils) and I1 - I14 (Discrete Inputs) on the gateway?

Best Regards,
Scott

Re: Map DIO to Modbus/TCP

Posted: 27 Jul 2018, 06:11
by volker
Hi Scott,
let me summarize what I've understand so far...

You want to operate the 14 Inputs and 14 Outputs of a DIO over Mobus TCP by having slave functionality which offers "read discrete inputs" and "write coils" function codes. Is that correct?
If yes, then here is how you can do this:

Alternative 1) using a Modbus TCP slave Gateway module
Using the RevPi gate module you would get a second Ehternet RJ45 with a Core 3 so you could separate Modbus physically from e.g. internet access. Using our new RevPi Connect you would already have 2 independent Ethernet channels. You need to set up some kind of data broker which would cyclically copy 1 of the slave gateway module "inputs" to the DIO outputs (2 bytes) and 1 of the gateway modules "output" to the DIO inputs (2 bytes). This could be done by a tiny Python script which is auto-started but you could of course also use any other program language including C, Java script, Node-Red, ST (using logi.CAD 3), even using a bash script and so on. Please note that both modules (DIO and gateway) would be accessed in our process image using 2 bytes to exchange the data for all 14 inputs or outputs although the physical outputs and inputs of the DIO are mapped as bits into these 2 bytes of our process image and although you can use the "read discrete input" function to get the information of 14 inputs of the first 2 bytes mapped to the gateways output section in our process image or "write coil" function to set the 14 outputs of the first 2 bytes mapped to the gateways input section in our process image (Modbus outputs are always inputs for a slave process image and vice versa).

Alternative 2) using a virtual Modbus TCP slave module
You would need to use RevPi Connect to get 2 independent Ethernet connectors (if you need to have 2 independent). You could use the same technique to copy data between your 2 input and 2 output bytes in the process image of the virtual module to or from the DIO input/output bytes in the process image. BUT: (As you may have already recognized by saying the virtual module would be restricted to "Analog") the Modbus function codes of a virtual module Modbus TCP are limited to
Read Holding Registers (0x03)
Read Input Registers (0x04)
Write Single Register (0x06)
Write Multiple Registers (0x10)
Nevertheless you could use these function codes to read 1 input register (fc 04) or write 1 register (fc 06) to get all 14 DIO inputs or set all 14 DIO outputs. Your HMI would only need to map the 14 single bits into the 2 bytes of a modbus register. If the HMI can do so then you could save the costs for a RevPi Gate Module.