Reading SNAP-AIMA-i from CODESYS via Modbus

I have a SNAP PAC R1 controller running a strategy that includes two scaled inputs from a SNAP-AIMA-i module in channel 3 on the rack. In the PAC Control strategy, the inputs are scaled such that 4 mA = 0 and 20 mA = 100.

I need to leave the PAC Control strategy alone, but I would like to read the unscaled mA from the two inputs on this module. I checked the Modbus TCP Protocol Guide and saw that the a SNAP 2-Ch Analog Input in the third channel on a rack uses registers 25 and 26 (first input) and 27 and 28 (second input).

I’'m running a CODESYS program on a Groov EPIC PR1 on the same subnet. I have configured a Modbus TCP Master Device on the EPIC and added the R1 as a Modbus TCP Slave Device. I set up the Modbus channel on the slave device as follows:

  • Access Type: Read Input Registers (Function 4)
  • READ Register Offset: 0x0019
  • READ Register Length: 4

I’m connecting to the R1 and getting values into the WORD variables in CODESYS, but I’m having trouble making sense of the data I’m getting.

First, should these registers contain the raw mA or will the contain the scaled/EU value? If they contain the scaled value, is there a way to get the raw mA?

Second, how can I combine the two words into a single float value?

Analog values will come in as 2 words, you will need to convert the 2 WORDs into a DWORD and then a REAL:

So Here we map gvl.w2 and gvl.w1:

Then you can use the below code to get the REAL value:

gvl.dw1 := oscat_basic.DWORD_OF_WORD(gvl.w2, gvl.w1);
gvl.real1 := oscat_basic.DW_TO_REAL(gvl.dw1);
1 Like

@greichert: Thank you for pointing me in the right direction in terms of the oscat_basic functions. Does my configuration seem right: I want to read input registers, starting at 0x0019, for a length of 4 to read both inputs from that module in position 3 on my rack?

When I do read those registers, will I get the actual measured mA or the scaled EU?

For SNAP Analog:

If it is in slot 3, then channel 0 would be 25-26(0h19-0h1A).

I believe they would be whatever they are configured as in PAC Control.

Thank you, @greichert. I’m not sure what I did wrong, but when I deleted everything and started fresh, I got it working. One thing to note: the screenshot above shows register numbers, and the config in CODESYS asks for an offset, so I had to subtract 1. To read both inputs on a SNAP-AIMA-i in position 3, I had to use 0x0018 as an offset with a length of 4. It definitely makes sense, but it took me a minute to get there.

1 Like