Code readingExplainer

USB barcode scanner on a PLC HMI: HID keyboard mode or serial port

How a USB barcode scanner works on a PLC HMI in HID keyboard mode, why each scan needs a tapped text box, and when to switch to RS232 instead.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01The decision first
  2. 02What the scanner sends in HID keyboard mode
  3. 03Why the buffer stays empty or garbles characters
  4. 04Keyboard wedge, USB serial or RS232 side by side
  5. 05Worked example: a 24-character GS1-128 scan into a 7-inch panel
  6. 06Choosing the reader for each path
  7. 07Checks before you order
  8. 08When the keyboard wedge is the wrong answer
  9. 09Checklist: USB scanner on a panel PLC
  10. 10Questions

You plugged a handheld barcode scanner into the USB host port of a panel PLC, and it half-works. The panel accepts it as a keyboard, each scan lands in whatever on-screen field has focus, and the COM Rx block wired for the job reads nothing. Worse, some scans arrive with shifted characters where symbols should be. None of this is a fault: it is exactly how a USB HID keyboard wedge behaves, and it forces one decision. Keep keyboard mode and design the screen around it, or move the scanner to a serial or Ethernet interface and read scans as data. This explainer covers what the wedge sends, why buffers misread it, the timing numbers for each path, and which reader to order for each.

The decision first

Keep the scanner in USB HID keyboard mode when a person drives the screen. The operator taps the message composer or entry field, pulls the trigger, and the code arrives as typed characters followed by a carriage return — a drop-in replacement for typing a lot number by hand. Nothing else on the panel has to change.

Switch to serial — the scanner's RS232 output into a serial port module on the controller — whenever the program must capture scans on its own: an auto-triggered station, a traceability buffer, a pallet interlock, any scan that has to reach a tag without a finger on the glass. Ethernet replaces serial where the controller already has a network port, and on some readers it carries power on the same cable.

USB serial (the CDC class) sits between the two and works only if the panel's USB host supports it. Most panel PLC USB hosts list HID keyboard, mouse and mass storage, then stop — no CDC class, no COM port for the scanner. With that host, the RS232 port module is the reliable route to a buffer read. For the wider map of interfaces into a controller, read barcode scanner input methods to a PLC: serial, USB and Ethernet.

What the scanner sends in HID keyboard mode

In keyboard mode the scanner is a keyboard, nothing more. It enumerates on the USB host port as a Human Interface Device and sends 8-byte keyboard reports: one modifier byte carrying Shift, Ctrl and Alt, followed by up to six key codes. The panel's keyboard service maps those codes to characters through a national layout and injects them into the focused field. Three consequences follow, and they set every limit of the wedge.

Focus rules everything. Keystrokes land wherever focus sits, so an untouched screen quietly eats the scan. "Tap the box, then scan" is the permanent workflow, and it belongs in the work instruction.

The wedge is one-way and deaf. The scanner cannot hear the PLC: no host trigger, no poll, no acknowledge — the trigger is the operator's finger. When the controller must fire the read itself, barcode scanner serial trigger: fix silent host commands covers the command side of a serial or Ethernet scanner.

Pacing is a scanner setting. Keyboard-wedge scanners space characters with an inter-key delay that commonly ships near 5 ms and adjusts across roughly 1-30 ms. A slow panel drops trailing characters when the delay is too short; lengthen it before blaming the reader.

On a PC or SCADA host you can intercept the keystrokes in software and write straight into a controller tag, which is the route barcode scanner to a PLC tag: keyboard wedge scripting covers. Configuring an HID wedge in a SCADA package walks through the same idea from the software side. A panel PLC rarely offers that hook, which is why the focused field itself must be the target.

Why the buffer stays empty or garbles characters

A COM Rx block reads a UART: bytes arriving on an RS232 or RS485 port, onboard or on an expansion module. A HID keyboard never touches a UART. Its data arrives on a USB interrupt pipe and becomes keystrokes before your logic sees a single byte, so the block reads nothing. That is the entire mystery of the empty buffer.

If the panel's USB host does support the CDC serial class, a scanner switched to USB serial mode appears as a COM port and the block works. Framing then decides whether the parse works; barcode scanner to an HMI serial port: framing data without headers is the guide for that wiring.

The shifted-character symptom has two classic causes, both on the interpretation side. A national-layout mismatch sends symbols through the wrong mapping: letters survive, but @, # and ~ land on each other's keys, because those differ between layouts. A lightweight panel USB stack can also drop the Shift modifier between reports, so ! arrives as 1 and ? arrives as /. A scanner that decodes perfectly into a word processor and garbles into the panel is pointing at the panel's keyboard stack, not at the reader.

Fix it in this order: set the scanner's keyboard layout to the panel's, usually US on both, then slow the inter-key delay one notch. If symbols still corrupt, stop wedging and change interface. A field repair of USB keyboard emulation on an HMI panel follows the same order and is worth ten minutes before you buy hardware.

Keyboard wedge, USB serial or RS232 side by side

USB HID keyboard USB serial (CDC) RS232 + port module Ethernet
Scan lands in focused screen field COM Rx buffer COM Rx buffer PLC tag over the network
Operator tap needed yes no no no
Panel-side requirement USB host, HID class USB host, CDC class serial port or expansion module Ethernet port and a protocol
PLC can trigger a read no yes yes yes
Practical cable length 5 m per USB segment 5 m per USB segment about 15 m at 19,200 baud 100 m per run
Best fit manual entry on the panel buffer reads on modern hosts buffer reads on any panel line stations, data and power on one cable

The RS-232 figure is the old capacitance rule: about 2500 pF of cable, which works out near 15 m at 19,200 baud. At 115,200 baud halve the run or drop the rate for long cables. If a column of that table is closed to you — no CDC class on the host, no spare Ethernet port — the table has already told you the answer.

Worked example: a 24-character GS1-128 scan into a 7-inch panel

Inputs, each with its origin. The payload is a common traceability label: AI (01) with a 14-digit GTIN gives 16 characters, AI (10) with a 6-character lot gives 8 more, 24 characters in total. The keyboard path runs at a 5 ms inter-key delay, the scanner's typical default, with a CR suffix and the field in focus. The serial path runs RS232 into a port module at 115,200 baud, 8 data bits, no parity, 1 stop bit, with a CR LF terminator.

The two transmission times:

t_keyboard = characters x inter-key delay t_serial = bytes x 10 bits per byte / baud rate

Keyboard: 24 characters x 5 ms = 120 ms, plus the carriage return, so about 125 ms from trigger to committed field.

Serial: 24 data bytes + 2 terminator bytes = 26 bytes; 26 x 10 bits = 260 bits; 260 bits / 115,200 bit/s = 2.3 ms.

Serial is roughly 54 times faster (125 / 2.3), and both finish long before the operator reaches the next package, so speed does not decide this case. The landing place does. Decision: a human watching a field — keep keyboard mode, because 125 ms is invisible. Logic reading unprompted — take the serial path, because the wedge cannot even start without focus. If trailing characters vanish at 5 ms on a slow panel, raise the delay to 15 ms: 24 x 15 = 360 ms, still comfortable for manual entry.

Choosing the reader for each path

For the wedge path, any handheld with a USB interface does the job. The LS-HCR-0001 is a 1.0 MP handheld with a USB 2.0 interface and a global shutter. Three wired USB handhelds that cover most bench jobs:

Handheld code readersHandheld industrial barcode reader, 1.0 MP, USB 2.0 (LS-HCR-0001)LS-HCR-0001
Resolution
Up to 3 MP
Shutter
Global
$539.00View part
Handheld code readersHikrobot MV-IDH2000P/13NR/05RN/U Industial Wired Handheld Code ReaderMV-IDH2000P/13NR/05RN/U
Interface
USB
Connection
Wired
$179.00View part
Handheld code readersHikrobot MV-IDH5000P/13SR/04RN/U General-purpose wired industrial handheld code readerMV-IDH5000P/13SR/04RN/U
Interface
USB
Connection
Wired
$719.00View part

For the buffer-read path, filter the handheld code readers range by the Serial interface. Those RS232 models pair with the controller maker's serial port module and the scanner maker's RS232 adapter cable, bought as one line item. Handheld barcode scanner to a PLC without Ethernet: RS232 or USB? walks the module choice; if your host is an embedded controller rather than a panel, RS232 barcode scanner connection to an embedded host is the closer fit.

The handheld range at a glance:

Code readers & vision sensorsHandheld code readers

Handheld 1D/2D scanners

137 models · from $159.00

For Ethernet, filter the same range by the Fast Ethernet interface: the wired network handheld below gives the controller a LAN link, and the PoE model takes its power over that same cable:

Handheld code readersHikrobot MV-IDH3000/13NR/05RN/LE Industrial Wired Handheld Code Reader (IP LAN)MV-IDH3000/13NR/05RN/LE
Interface
Fast Ethernet
Connection
Wired
$379.00View part

A fixed reader replaces the handheld where the part always presents in the same spot. For USB at a bench station, the LS-CRD-0047 is a 1.2 MP model with a 60-120 mm reading distance:

Fixed code readersCompact fixed industrial barcode reader, 1.2 MP, USB 2.0, 60-120 mm reading distance (LS-CRD-0047)LS-CRD-0047
Resolution
Up to 3 MP
Shutter
Global
Interface
USB
$559.00View part

For an Ethernet-fed line station, the LS-CRD-0028 decodes up to 60 codes per second over Fast Ethernet, and its 2560 x 2048 sensor covers a wide presentation window. Light boards, polarizing covers and I/O boxes for the fixed readers live in reader accessories; fixed code readers is the range itself.

Checks before you order

  1. Look up the panel's USB host class list in its specification. HID plus mass storage with no CDC closes the USB-serial route, so plan the RS232 module from day one.
  2. Match the keyboard layouts. Set the scanner's HID layout and the panel's to the same one, usually US on both; that alone clears most shifted-symbol garble.
  3. Set the terminator. CR commits the field, TAB commits and advances to the next one. Prefix and suffix framing for barcode scanner input lays out the options, and a suffix is what makes variable length barcode scanner input parseable.
  4. Size the COM Rx buffer for the longest code plus terminator; 64 bytes holds a 24-character GS1-128 nearly three times over.
  5. Check the cable run against the interface: 5 m per USB segment, about 15 m of RS232 at 19,200 baud and less at 115,200, 100 m of Ethernet.
  6. Decide who triggers. If the PLC must fire the read, keyboard mode is out; serial and Ethernet both carry a trigger command.
  7. If you pick a laser 1D model, mount the scan window above or away from eye height: an accidental glance at a Class 2 beam is safe, deliberate staring is not.

On Ethernet, settle whether the reader connects out as a TCP client or listens for the host: TCP client or listener: match your network barcode reader to your host decides it. Controllers that speak Modbus RTU can take a serial reader that way instead — see read a barcode reader into a PLC over Modbus RTU.

When the keyboard wedge is the wrong answer

Four situations close the wedge route. Nobody taps a field, as on an auto-triggered station. Scans must be timestamped and sequenced into a traceability store rather than displayed. Screen focus wanders because operators change screens mid-shift. Or several scanners share one panel, and the focus gamble multiplies. In all four, serial or Ethernet wins, and the reader choice follows the interface, not the other way round. One more boundary: if your host is a Linux control PC rather than a panel PLC, the USB-versus-RS232 calculus differs — handheld barcode scanner USB or RS232 for a Linux PLC handles that case.

Checklist: USB scanner on a panel PLC

  • Decide who triggers: operator means keyboard mode is enough; logic means serial or Ethernet only.
  • Confirm the panel's USB host classes before betting on USB serial.
  • Set scanner and panel keyboard layouts to the same national layout, usually US.
  • Configure the suffix: CR to commit the field, TAB to commit and advance.
  • Push a 24-character test scan end to end and confirm the last character arrives.
  • Keep USB under 5 m, RS232 near 15 m at 19,200 baud, Ethernet at 100 m.
  • Order the RS232 adapter cable and serial port module together when you take the serial path.

Filter interfaces in the code reader finder, browse the rest of the code reading topic, or ask us to match a scanner to your panel before you order.

Questions

Why does my USB scanner only scan after I tap the text box?

In HID keyboard mode the scanner is a keyboard, and the panel injects keystrokes into whatever field holds focus. With nothing focused, the characters go where the panel's focus sits, which is nowhere your logic can read. Make the tap part of the work instruction, or set the scanner's suffix to TAB so one scan fills a field and jumps to the next. For unprompted capture, move the scanner to a serial or Ethernet interface.

Why do symbols like @ and # arrive wrong on the panel but fine on a PC?

Both classic causes sit on the interpretation side, not in the scanner. A national-layout mismatch remaps shifted symbols while letters survive, and a lightweight panel USB stack can drop the Shift modifier byte between reports, turning ! into 1. Match the scanner's HID layout to the panel's national layout — US on both in most plants — and slow the inter-key delay one notch. If symbols still corrupt after that, change the interface rather than fighting the panel's keyboard stack.

Can a COM Rx block read a USB scanner directly?

Only if the scanner is switched to USB serial (CDC) mode and the panel's USB host supports the CDC class. In HID keyboard mode the data arrives as keystrokes on a USB pipe and never touches the UART, so the block reads zero bytes. Look up the panel's USB host class list first; if it stops at HID and mass storage, use the scanner's RS232 output into a serial port module and read the block from there.

How much faster is 115200 baud serial than a keyboard wedge?

For a 24-character scan, serial at 115,200 baud with 8N1 framing moves 26 bytes times 10 bits, or 260 bits, in about 2.3 ms. Keyboard mode at a 5 ms inter-key delay takes roughly 125 ms end to end, serial winning by about fifty times. Both finish long before the operator's next package, so pick the interface for where the data lands and who triggers the read, not for speed.

Which scanner should I buy for a panel PLC entry field?

Any USB handheld used in HID keyboard mode: the LS-HCR-0001 is a 1.0 MP USB 2.0 model with a global shutter and suits a bench station. Add a rugged housing only if the scanner leaves the bench. If the logic must read scans without an operator, buy the serial or Ethernet variant instead and budget the RS232 adapter cable and port module, or the network cable, in the same line.

How far can the scanner sit from the panel?

USB 2.0 allows 5 m per cable segment. RS-232 reaches about 15 m at 19,200 baud under the classic 2500 pF capacitance rule; at 115,200 baud keep the run to a few metres or drop the baud rate. Ethernet runs 100 m per segment, and a PoE-capable reader takes its power on that same cable, which often removes a separate supply from the station.