-
-
Notifications
You must be signed in to change notification settings - Fork 44
Type casting of Data response #8
Comments
On data you get a pointer to a byte array with the length: If you look carefully, the example casts the data to a float pointer (which get dereferenced to print):
Beware: this is only possible because in this case I know I get 4 bytes of data which are convertible to a float (as specified in the SMA's docs). |
Exactly , I'm not getting expected values(except for float data type). |
Several things come to mind (endianess, memory structure...) Yu have to read your modbus device's manual and see how the data is returned. From then on you can build your code. That's not something I can do for you. why don't you print the raw data you receive:
Mind that onData returns the number of bytes, and not the number of words/registers/... |
I think we miss communicated here , Maybe I'll pull request once I'm done with parsing data with all data types. then I'll be in a better position to explain you :) |
How would the lib know the endianess or the data format? It is modbus slave specific and not part of this lib. It is also not mentioned in the modbus specification. |
I have another idea: we try to create a inherited class with esp32ModbusRTU as base class. The inherited class can add the desired functionality. What is the device you are trying to communicate to? |
It's true that specification doesn't mention endianess or byte ordering. This differs from slave to slave Have a look https://www.modbustools.com/poll_display_formats.html The user will define the data type based on his slave machine let's say these data types can be included in library
Planning to add these defines in library with some modifications in the ondata() handle for multiple read and write function. |
Initially it was a energy meter which had 32-bit float format. Here code worked fined and data was handled properly. Then I jumped to Simply Modbus Slave simulator and started tinkering with all possible data types along with byte ordering. Kind of trying to create test cases for multiple function codes/ different data types for testing!! |
Hi Bert,
Is there any method to extract data from response and convert it to other data types? There aren't any examples /methods on this. Tried typecasting but data gets changed and overflows sometimes. Can you please explain with a example ?
The text was updated successfully, but these errors were encountered: