What to do when PLC’s are returning negative values (garbage values)?
This troubleshooting guide describes how to solve the problem when a PLC data tags return negative values
Problem
When extracting data from a PLC, e.g., a Mitsubishi, it can happen that the extraction program assumes the value from the PLC is signed, when it is actually unsigned. This can result in a difference of 127 or 32768. If the difference is something else it can be caused by using different endianness.
To verify this, you should compare the given value from the PLC with the display on the HMI.
Solution #1: signed/unsigned
Option a)
- You need to either change the extraction program to use the correct method signed or unsigned. Convert between unsigned and signed - Online Tools
Option b)
- Alternatively, you can correct it by adding 127 or 32768
Solution #2: endianness
- You need to either change the extraction program to do a different method (big-endian, little-endian). Endianness It basically means in which order the bytes of a multi-byte value like an integer should be interpreted. #
- To solve this, google for your programming language, e.g., “js convert big-endian to little-endian” (How do I swap endian-ness (byte order) of a variable in javascript )
Last modified February 17, 2023:
update (#208) (ea731fc)