05-02-2025 06:22 AM
@K C escreveu:
65554 is larger than 16 bits.
If it is 65535 than it could also be -1
Depends on the number format.
Kees
65504 = -33
65502 = -35
65512 = -24
Yes, yes — if what I wrote down isn't wrong, the values I'm seeing are pretty close to the ones you listed above.
Right now, I'm trying to apply a filter where I take the unique value from the array, and if that value is less than zero, I set it to 0. Then I convert it back into an array so it can be processed later.
But I’m having some trouble with this. Could you take a look and tell me what I might be doing wrong?
After that, I still need to figure out how to display the values properly — since it's in an array, it's not very easy to interpret as-is. I’m thinking that maybe if I handle the data individually first, and only reassemble it into an array afterwards, it might be easier to manage and visualize.
I also have to be careful with the data type — apparently it's sending the data as U16, but I was interpreting it as I16, while what I probably need is DBL.
05-02-2025 07:10 AM
The Modbus protocol only knows u16 registers, which is why the driver has a u16 output. Whether that is the correct datatype depends on the device that sends it. You have to convert it to the correct type yourself. Use the Numeric>>Conversion palette or Type Cast from Numeric>>Data Manipulation.
It is an array because you can potentially read more than one register at a time. If you read one register, you get a one-element array. You can just index it.
Is this what you are trying to do?
05-02-2025 07:25 AM
It's more or less this
I'm trying to filter the values, and if they are above 65000 — it's just because, as was mentioned, 65535 could actually be -1, so this was the best workaround I could think of for now.
Then, if the value is negative, I clamp it to 0. After that, I rebuild the array.
To be honest, I'm not really sure if this is the correct way to do it.
05-06-2025 12:43 PM
Maybe you tell more about the device that are reading.
btw. if the value is a I16 numbers above 32767 are negative.
Do you have more information about your ModBus device or post the manual here.
Kees
05-06-2025 01:27 PM
Hi Kees,
Thanks for your help! I was able to solve the problem — it turned out to be a loose wire, which has already been fixed.
Right now, when the reader receives the value, it's converted to I16. If the value is negative, I set it to 0. Then I convert the data from Newtons (N) to metric tons (tf), generate a new array, and pass it through a shift register to build the final array.
Thanks again for your support — it really helped me get through this!
Best regards,
Marcus