-
Now I'm working on different types. int/uint16/32 are working fine. But I've some questions:
Example: expected MAC: via modbus using "type":"string","length":"32" (same result with "48" or "64") 1 byte (here: "B" from end) is missing and wrong order. Same result with BIG_ENDIAN and BIG_ENDIAN_LOW_WORD_FIRST.
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
For string default (global) endian is used to extract value. This meant for your case that BIG_ENDIAN_LOW_WORD_FIRST was used. Characters are in weird order (reverse pairs) because of big-endian and little endian are bytes in reverse order when compared and You might want to read this https://www.simplymodbus.ca/FAQ.htm#Order I have added way to set endian when extracting strings with v2.3.0 See You can try LITTLE_ENDIAN to read that string - probably it will give better results.
As it says. PHP can not handle all uint64 values. Change your data type to int64 and if your values are not extremely large you are fine. NB: NB: if you really need to use uint64 and that value is contant problem you could set This test shows usage:
Bit returns N-th bit of returned register. Each register is 2 bytes (16 bits). This is handy when your device memory for Byte allows you to return first or second byte of a register (2 byte value).. for example if you store uint8 value in register. |
Beta Was this translation helpful? Give feedback.
-
Are you passing endian value as string or int? It should be int.
true/false, and if you send some string usual string to int PHP conversion rules apply. p.s. You really should use debugger to see what code does (step through each executed line of code by line by line). If you are using VS Code then see |
Beta Was this translation helpful? Give feedback.
-
I wondered two times..
Results contains now... Thank you, Martti! Perfect now! 😄 If somebody else comes to this pitfall, too... here are the values: |
Beta Was this translation helpful? Give feedback.
-
...and thank you for your coding advices... by now just nano and |
Beta Was this translation helpful? Give feedback.
I wondered two times..
Results contains now...
["MAC"] => 00:40:AD:91:D2:8B
Thank you, Martti! Perfect now! 😄
If somebody else comes to this pitfall, too... here are the values:
1 = BIG_ENDIAN
5 = BIG_ENDIAN_LOW_WORD_FIRST
2 = LITTLE_ENDIAN
6 = LITTLE_ENDIAN_LOW_WORD_FIRST