Application Note: Handheld OCR & Barcode to Modbus TCP ArchitectureThe Problem: Interfacing handheld scanners or optical text recognition (lot codes, batch numbers, mold IDs) into a PLC usually requires an industrial vision controller, a dedicated PC running proprietary middleware, or a custom serial gateway.
The Solution: We built a dedicated Android utility designed to read 1D barcodes, QR codes, and alphanumeric text via device camera or hardware scan engines, and stream the string data directly into PLC holding registers over standard Modbus TCP.
How It Works:
Fully offline architecture—no external cloud calls or factory data leaks. Feedback and feature requests from fellow controls engineers are welcome!
- Direct Socket Connection: Connects over Wi-Fi / local industrial WLAN straight to Port 502 on any Modbus TCP server (Mitsubishi, Siemens, Omron, Wecon, Schneider, Beckhoff, Codesys).
- Configurable Register Mapping: Select Target IP, Port, Unit ID/Slave ID, Start Register (e.g., 40001 / D100), and data length limits.
- Endianness & Word Ordering: Includes selectable Big-Endian / Little-Endian and High/Low byte-swapping to ensure ASCII strings unpack correctly into 16-bit registers without manual ladder logic bit-shifting.
- Handshake & Triggers: Automatic write trigger with optional "Data Ready" strobe bit and ACK register handshake for synchronized verification sequences.
- Hardware Support: Works on standard Android mobile devices as well as rugged Android warehouse PDAs with integrated scan heads.
1. System Architecture Diagram
[ Printed Label / Part Text ]
│
(Camera / Laser)
▼
[ Android Device / Industrial PDA ]
└── Local Parsing Engine (ASCII String Encoding + Byte Swap)
│
(Wi-Fi / AP)
▼
[ Industrial Managed Switch ]
│
(Cat6 / Port 502)
▼
[ PLC Ethernet Port (Modbus TCP Server) ]
├── Holding Registers (D100 - D115) : ASCII Payload
├── Register (D116) : String Length / Character Count
└── Bit Flag (M100) : Data Ready Trigger Strobe
| Register Address | PLC Equivalent (Example) | Data Type | Description |
| 40001 – 40015 | D100 – D114 | ASCII (16-bit words) | Parsed barcode or OCR string payload (up to 30 characters). |
| 40016 | D115 | INT (16-bit) | Character count (actual length of parsed string). |
| 40017 | D116 | UINT (16-bit) | Trigger flag (1 = New Scan Available, 0 = Idle). |
| 40018 | D117 | UINT (16-bit) | PLC Handshake ACK (1 = PLC Processed Data, cleared by app). |
3. Example PLC Ladder Logic Handshake (Structured Text / Ladder Principle)
// Example Logic Flow:
// 1. App writes ASCII payload to D100..D114
// 2. App sets D116 = 1 (Data Ready)
// 3. PLC executes recipe check / tank match logic
// 4. PLC sets D117 = 1 (ACK) and resets its internal sequence
// 5. App clears D116 back to 0
IF (D116 = 1) AND (D117 = 0) THEN
// Execute string comparison or recipe validation
IF Verify_String(D100, Target_Recipe_String) THEN
Pass_Signal := TRUE;
ELSE
Fail_Signal := TRUE;
END_IF;
// Acknowledge read completion
D117 := 1;
END_IF;
// Example Logic Flow:
// 1. App writes ASCII payload to D100..D114
// 2. App sets D116 = 1 (Data Ready)
// 3. PLC executes recipe check / tank match logic
// 4. PLC sets D117 = 1 (ACK) and resets its internal sequence
// 5. App clears D116 back to 0
IF (D116 = 1) AND (D117 = 0) THEN
// Execute string comparison or recipe validation
IF Verify_String(D100, Target_Recipe_String) THEN
Pass_Signal := TRUE;
ELSE
Fail_Signal := TRUE;
END_IF;
// Acknowledge read completion
D117 := 1;
END_IF;
4. Implementation Checklist for Field Testing
- Configure static IP or DHCP reservation on the mobile device to avoid ARP lease disconnects.
- Set ping/keep-alive interval to 1000 ms to detect Wi-Fi handoff drops immediately.
- Test endianness with a known 4-character string (e.g., ABCD → verify whether the first register reads 4142h or 4241h).
https://play.google.com/store/apps/details?id=com.pdtecheng.qr_ocrreaderplc
