How to check modbus comunication

Topics about the Hardware of Revolution Pi
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: How to check modbus comunication

Post by volker »

Wow! This is the last thing I would have thought... What do they expect to be connected to their two terminals D+/D-? (Just because I'm interested,, may be other users might also benefit from this information...)
Unser RevPi Motto: Don't just claim it - make it!
francescoizzi
Posts: 18
Joined: 17 Feb 2018, 12:10
Answers: 0

Re: How to check modbus comunication

Post by francescoizzi »

I don't know because not work... maybe Bticino want to sell other component ... and they want discourage in general the connection with RS485 ..., Tomorrow i will try with Shnider Meter i back to you with my test.
francescoizzi
Posts: 18
Joined: 17 Feb 2018, 12:10
Answers: 0

Re: How to check modbus comunication

Post by francescoizzi »

Ciao Volker,

the test with A9MEM2155 Modular single phase power meter iEM2155 - 230V - 63A with comm Modbus - MID going very good from first time :) (EVVIVA)

The RS485 comunication is good

http://download.schneider-electric.com/ ... 361-00.pdf
Schermata 2018-02-22 alle 12.37.46.png
Schermata 2018-02-22 alle 12.37.46.png (73.46 KiB) Viewed 6227 times
But i have a problem to interpretate the data.

As is describe on manual on register 3000 i can read the Current (in Amper) but when i read with piTest -r Corrente i retrieve this value:
Schermata 2018-02-22 alle 12.38.36.png
Schermata 2018-02-22 alle 12.38.36.png (11.94 KiB) Viewed 6227 times
I have to convert or i doing a wrong things?

This is my test connection:
Schermata 2018-02-22 alle 12.41.31.jpg
Schermata 2018-02-22 alle 12.41.31.jpg (57.67 KiB) Viewed 6227 times
francescoizzi
Posts: 18
Joined: 17 Feb 2018, 12:10
Answers: 0

Re: How to check modbus comunication

Post by francescoizzi »

With more test and studing ... i found a way to read the data correctly.

The register 3000 is a float32 type and with :

pyTest -r 11,4,h i have the right sequence of data.

in have to switch 1 and 2 .... and 3 and 4 and i have the right hexadecimal number that convert to float give me the right value in amper that i can see exactly as the meter.

There is a way to do this in piCtory?

Thanks,
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: How to check modbus comunication

Post by volker »

Hi,
before I comment on your Modbus value let me just comment on th e wiring I can see on your picture. Please invest a littel time to rework that for the final version_
I can't see that you have connected the protective earth to anything else but the energy meter. You also have not connected the functional earth of the RevPi to anything.
That is all togehter not a wise idea. Without connecting the functional earth of the RevPi there is just a very poor protection against any EMV pulses injected from your line power.
You should always connect ether the central earth of your cabinet or the protective earth of your line power cord (green/yellow) to your DIN rail using an earth clamp. Then connect the protective earth terminal of your power supply and the meter also to an earth clamp on the DIN rail. And please connect the functional earth to the DIN rail using a clamp too. Any high energy pulses can then (and only then) be directed to this earth path by the internal protection circuit.

Okay, but now to your Modbus current value. Your manual says it should be in the format "float32". So it consist of 4 bytes (2 Modbus registers).
You now have got 2 problems:
1) the process variable you named "Corrente" does only deliver 2 byte of this value (1 Modbus register). But you also need the following 2 bytes to calculate the actual value. So call it "Corrente_a" and the next input "Corrente_b". read both values and do a calculation with them to get the floating point value.
2) you need to know the type of coding floating point into 2 Modbus registers. Sad enough there is no common norm for it. Manufacturers can do it anyway they like... but they should document it. So may be there is some chapter in your manual describing how they have implemented the floating point for 2 regsisters.

As this is a very complex topic I would like to refer to some internet pages which have really good explanations. Basically I would say most implementations use high first and then low, just like the bytes in a modbus register. So in your case the hex 404c would show the highest byte to be 40, the second highest byte 4c, then in the next register (with register address being 3001) the second lowest byte comes first and then the lowest byte. If A is highest value byte and D lowest value byte this could be written as AB CD. But this is just the most common way. It could also well be any other combination like CD AB or DC BA or BA DC etc.
At the end of the day you need to pack these 4 bytes in the order ABCD into a 32 bit float variable in your application software. In Python you would write the 4 bytes into a byte array and then use "struct" to convert them as an IEEE754 32 bit floating value formatted number. If the order in your energy meter is ABCD, then you get the bytes in correct order when do a "piTest -r x,4" (x being the address offset of the first input word in your process image).
If you have read the bytes A, B, C and D from the process image in python 3 you would pack them into a byte array and then do a struct.unpack with format parameter "f" to convert them into a 32 bit single precision floating point:

bytearray = bytes([A, B, C, D])
current = struct.unpack('f', bytearray)

To check this first you use the piTest -r x,4 (use the actual first address for 'x'). You then could take the 4 hex numbers you get form the output and enter it into a float converter like this one here:
https://www.scadacore.com/tools/program ... converter/
On this page you also have possibilities for other byte sequences than ABCD.
It's a hardcore topic but you will make it! Just read and try!
Unser RevPi Motto: Don't just claim it - make it!
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: How to check modbus comunication

Post by volker »

Sorry my lost post was a crossover. I was writing while you also wrote...
No there is no easy way in PiCtory. Please use the arithmetic of your application program. The only option would be to write your own RAP file which would use float. But I'm even not sure that we have implemented float in the piControl driver which reads the RAP and PiCtory output to reserve space for each variable. So better go for your application software to do the conversion job...
Unser RevPi Motto: Don't just claim it - make it!
francescoizzi
Posts: 18
Joined: 17 Feb 2018, 12:10
Answers: 0

Re: How to check modbus comunication

Post by francescoizzi »

Thank for your suggestion for safety and thanks for your suggestion about to create 2 variable on piCtory for one Float32.
Schermata 2018-02-23 alle 16.53.42.jpg
Schermata 2018-02-23 alle 16.53.42.jpg (39.2 KiB) Viewed 6203 times
I write a python code to stream the correct data
and this is the result
Schermata 2018-02-23 alle 16.34.18.jpg
Schermata 2018-02-23 alle 16.34.18.jpg (68.8 KiB) Viewed 6203 times
My question about the READ HOLDING REGISTER (03) function that bind with WORD type.

There are on 32 Input_Word variable?

There is a way to extend this? In my case i have in total 20 registers to read and 40 variable on PiCtory to create.
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: How to check modbus comunication

Post by volker »

looks nice :-)
20 Modbus registers = 20 Input Words. So there should be no problem. I don't really understand why this should need 40 PiCtory variables? 1 PiCtory input = 1 Word = 16 Bit = 1 Modbus Register.
If you are talking about 20 32 Bit floating parameters then they are stored in 40 Modbus Registers which would need 40 Input Words in PiCtory. This can be done by simply using 2 masters requesting data from the same slave but different registers. You slave needs to be multi master capable.
Unser RevPi Motto: Don't just claim it - make it!
francescoizzi
Posts: 18
Joined: 17 Feb 2018, 12:10
Answers: 0

Re: How to check modbus comunication

Post by francescoizzi »

Yes i’m talking about all float32 registers
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: How to check modbus comunication

Post by volker »

So please try to use 2 masters and split the variables polled to both of them.
Unser RevPi Motto: Don't just claim it - make it!
Post Reply