Combine low and high modbus register

I need some help regarding combining LOW and HIGH modbus registers.

currently iam reading modbus register 7000 and 7001, where 7000 is INT16 and holds LOW values and 7001 is also INT 16 and holds HIGH. I need to combine LOW and HIGH and create a new INT32, how can this be done with template sensor?

i have same problem

7000
count: 2
uint32

May need byte swap

Daam, is it that easy? With count 2 it read two consecutive registers?

With count 2 it read two consecutive registers?

Yes

yes it works, but the problem is that the combination of the two registers are wrong, i tried swap: byte but its not working right,

swap string (optional, default: none)

Swap the order of bytes/words, options are none, byte, word, word_byte.

yes i see this, but its not working like it should.

i have two uint16 registers that are combined, i would think that swap: byte is the right to use in this case

google is my friend: EdgeXpert Support

Nice, got it working right now. swap should be word in my case.

Thank you for your help :slight_smile:

1 Like

Hello,

Could you show me the code how you solved it?
Thnx

Hi, I ran into the same issue while geting wrong data on an orno 515 power meter.
Another solution (not needing to combine the two adresses yourself) is to specify the correct datatype stored in the 2 16bit modbus adress, and specifying the first adress as the reading address like:

data_type: uint32
address: 40960

this will read 16 bits from 40960 and 16 bits from 40961

so iff the low address is high byte data no need to manually read two addresses and combine them yourself.

yes, modbus has support for this now and pretty much fixes this under the hood.