Barcode Looks Correct but the PLC Rejects It? Reveal the Hidden Characters
- PLC Play Ground
- 0
- Posted on
Two barcode strings can look identical while differing in length, terminators, spaces, or character encoding. A normal HMI text field may conceal those differences. Compare the received bytes and declared string length before changing the scanner or relaxing the validation rule.
Scanner-interface example; string length and byte storage depend on the PLC and driver.
What is happening?
Scanner framing and PLC string storage are separate conventions. A scanner may append carriage return, line feed, or another delimiter. A string structure can also retain unused storage beyond its valid length. Compare the meaningful data according to the platform's string definition rather than assuming every byte belongs to the barcode.
Check these five things
-
Read the scanner's configured prefix, suffix, delimiter, and encoding against the interface specification.
-
Display the received length and valid bytes in hexadecimal in an approved diagnostic view.
-
Check receive-complete handling so validation does not run on a partial message.
-
Normalize only the characters the interface specification explicitly permits removing or converting.
-
Test short, long, invalid, repeated, and incomplete messages in a bench setup.
Worked example
The bytes for ABC123 followed by carriage return and line feed are longer than the six-character identifier ABC123. A screen may show only the visible identifier, while an exact comparison correctly sees additional characters. Whether to remove them depends on the agreed message framing.
Quick diagnostic reference
| Hidden difference | Evidence |
|---|---|
| Trailing delimiter | Hex bytes and length |
| Partial receive | Message-complete state |
| Case or encoding | Interface specification |
The mistake to avoid
Trimming all nonalphanumeric characters may corrupt a legitimate identifier or conceal a framing defect. Keep validation tied to the actual data contract.
How to verify the fix
Confirm accepted identifiers remain exact, rejected messages produce a useful reason, and buffer contents from an earlier scan cannot leak into the next result.
Field-work boundary: These are educational diagnostic guides. Use the exact equipment manuals and approved site procedures. Electrical testing and machinery changes belong to qualified, authorized personnel; control hazardous energy and validate affected functions before release.
Technical reference
Rockwell Automation: string data and controller design considerations. The examples and diagnostic tables above are original teaching material; they do not replace the product manual.
