With modbus each assumption can be questioned. ;-)
Spec says big endian encoding for each word, but (according to openHAB
[1] which quotes it), there is no specification for 32 and 64 bit types.
So OH folks come with "swap" concept which reverse byte order of read
value. This lead to types such as int32 and int32_swap (same for uint,
float, int64 and uint64). I wouldn't be surprised if there would be
devices which return data in one encoding and expect writing in other!
Since data retrieved over modbus always goes over some sort of byte
array making it anything is not difficult. We just need to stick with
ReadBuffer/WriteBuffer apis or ship small overlay on top of it.
Cheers,
Łukasz
[1]
https://github.com/openhab/openhab-addons/tree/3.4.0/bundles/org.openhab.binding.modbus#uint64
On 16.01.2023 12:47, Christofer Dutz wrote:
Hi Jukka,
Well, I think right now we read everything as Big Endian, as the Spec generally
defines.
However, do we know that this is not sufficient for all devices.
One option we discussed, but which needs to find someone to volunteer to
implement, is that we generally assume big-endian, but make it possible to set
the connection to treat the words in different endianness.
Want to get your fingers dirty? ;-)
Chris
From: Jukka Sirviö <[email protected]>
Date: Monday, 16. January 2023 at 09:54
To: [email protected] <[email protected]>
Subject: modbus word/byte/bitorder on datatypes > 16bits
Hello,
How are you guys dealing with word ordering on modbus datatypes that are larger
than 16 bits (DINT, DWORD..)? There is variation between PLC vendors how they
handle this. Don't know if also the bitordering (little vs big endian) may
differ between PLC vendors.
for example:
word 1 byte 1
word 1 byte 2
word 2 byte 1
word 2 byte 2
vs
word 2 byte 1
word 2 byte 2
word 1 byte 1
word 1 byte 2
-Jukka
________________________________
Tämä sähköpostiviesti (liitteineen) saattaa sisältää luottamuksellista tietoa,
joka on tarkoitettu
vain vastaanottajalleen. Jos et ole oikea vastaanottaja, ilmoita viestin
lähettäjälle tapahtuneesta
virheestä ja tuhoa viesti välittömästi. Viestin luvaton julkaiseminen,
kopioiminen, jakelu tai muu
käyttö tai toimenpiteisiin ryhtyminen sen perusteella on ehdottomasti kielletty.
This message (including any attachments) may contain confidential information
intended for
the person or entity to which it is addressed. If you are not the intended
recipient, notify the
sender and delete this message immediately. Notice that disclosing, copying,
distributing or any
other use of the message and its information, or taking any action based on it,
is strictly prohibited.
________________________________