grid-x / modbus

BSD 3-Clause "New" or "Revised" License
78 stars 26 forks source link

Add support for common register encoding/decoding orders #64

Closed dammarco closed 1 year ago

dammarco commented 1 year ago

We often have to use "mid-little-endian" encoding for 32bit registers but the CLI tool didn't offer support for it. With this PR, I propose to add new CLI flags that can force the order for reading and writing registers.

The supported orders are: "AB", "BA", "ABCD", "DCBA", "BADC", and "CDAB".

I also found out that writing a float32 was not possible as the encoding was wrong. Thus, I replaced the encoding mechanism here as well.

Note: Since this is now extending the Modbus CLI significantly, I will do a PR afterwards to generate the binaries easier :D

andig commented 1 year ago

Nice idea. Lets put the decoders somewhere accessible for library consumers, too!

dammarco commented 1 year ago

Note: https://github.com/grid-x/modbus/pull/65 needs to be merged before this PR

dammarco commented 1 year ago

@andig yeah, I'll do that in another PR afterwards to keep it more clean ;) We have a cool encoding/decoding package in our app that we now can use here as well :)

andig commented 1 year ago

We have a ton of encodings in https://github.com/evcc-io/evcc but our naming is odd. Maybe start an entirely new repo for encoding? Would be happy to contribute!

dammarco commented 1 year ago

Yes, we are internally working on a separate encoding/decode repo already. We might use it here later :)

andig commented 1 year ago

@tretmar feel free to spy on https://github.com/volkszaehler/mbmd/tree/master/encoding and don't forget the strings ;)

dammarco commented 1 year ago

Will do that @andig thanks 😊