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


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)

  1. 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)

  1. Alternatively, you can correct it by adding 127 or 32768

Solution #2: endianness

  1. 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. #
  2. 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 October 5, 2022: Historian article (#107) (5f30dc0)