aldas / modbus-tcp-client

PHP client for Modbus TCP and Modbus RTU over TCP (can be used for serial)
Apache License 2.0
191 stars 55 forks source link

Exception with "Endian::LITTLE_ENDIAN_LOW_WORD_FIRST" #89

Closed gutschein closed 3 years ago

gutschein commented 3 years ago

Hi Martti,

Endian::$defaultEndian = Endian::LITTLE_ENDIAN_LOW_WORD_FIRST;

I get an exception "Undefined class constant 'LITTLE_ENDIAN_LOW_WORD_FIRST'" Do I have a typo or a missunderstanding about the 4th possible endian option? The other 3 work as expected.

aldas commented 3 years ago

Endian is actually bitmask that consist of byte order (LE or BE) and word order (low word first or "high word first")

See this: https://github.com/aldas/modbus-tcp-client/blob/1fb85de630c45154c015f779c0785987d54c70e1/src/Utils/Endian.php#L44

If you want to set LE+LWF use:

Endian::$defaultEndian = Endian::LITTLE_ENDIAN | Endian::LOW_WORD_FIRST;
gutschein commented 3 years ago

Usage wasn't clear for me in the help; i assumed that it wold work as for BIG_ENDIAN.

But with your hint: Works now as expetced! :) Thank you.