modbus_lib icon indicating copy to clipboard operation
modbus_lib copied to clipboard

Endian dependens

Open Jonas-Meyer97 opened this issue 3 years ago • 1 comments

I implemented the modbus library into my project and noticed while debugging that the union CRC_t, MbDataField is endian dependent. It would really help if the dependence on endianness would be documented in comments and Readme/Usage guide. Also is there any plan to implement some sort of configuration with macros like

#ifndef LITTLE_ENDIAN
	#define LITTLE_ENDIAN 1234
#endif

#ifndef BIG_ENDIAN
	#define BIG_ENDIAN 4321
#endif

#ifndef BYTE_ORDER
	#define BYTE_ORDER LITTLE_ENDIAN
#endif

#if BYTE_ORDER == LITTLE_ENDIAN
    struct {
        uint8_t low;
        uint8_t high;
    } bytes;
#else
    struct {
        uint8_t high;
        uint8_t low;
    } bytes;
#endif

Jonas-Meyer97 avatar Mar 07 '22 15:03 Jonas-Meyer97

I read a little bit history about that and it seems like this Little/Big endian dictation is not clarified. Adding an endianness configuration would be nice. However, I've no test setup ATM to implement/test this option. I will add such an option as soon as possible, but I can't promise any time frame.

ceremcem avatar Mar 07 '22 15:03 ceremcem