Code readingExplainer

PLC USB port and barcode scanners: why serial still wins

Why a PLC's USB port rejects a barcode scanner, and the three paths that work: RS-232 through a serial module, industrial Ethernet, or USB on an HMI or PC.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01The USB port on a compact PLC is a device, not a host
  2. 02Three paths that get code data into a ladder
  3. 03Path 1: RS-232 through a serial expansion module
    1. Wiring and distance
    2. Framing and the ladder
  4. 04Worked example: a 21-character scan across a 9600 baud port
  5. 05Path 2: industrial Ethernet and socket instructions
  6. 06Path 3: an HMI or PC with a USB host port
  7. 07Matching the reader to the port
  8. 08Checks before you commission
  9. 09The decision, case by case
  10. 10Questions

A USB barcode scanner and a compact PLC look like a two-piece kit: plug the scanner into the PLC's USB port and read strings in the ladder. That port will not take it. On most compact controllers the USB connector sits on the device side of the bus, reserved for the programming cable, so a scanner never enumerates there. This guide explains what that port actually is, then walks the three paths that do work: an RS-232 reader into a serial expansion module, a Fast Ethernet reader into the PLC's Ethernet module, or a USB scanner on an HMI or PC that hands the string to the PLC as a tag. It also times a 21-character scan across a 9600 baud port, so you can match the path to the cycle time you have.

The USB port on a compact PLC is a device, not a host

USB has two sides. A host supplies power, drives enumeration and loads drivers; a device answers the host. The USB connector on a compact PLC sits on the device side: your laptop is the host, and the PLC enumerates to the programming software the way a memory stick enumerates to a PC. Hosting a scanner takes the opposite equipment, a USB host controller and a keyboard (HID) driver stack in the controller firmware, and compact PLC firmware carries neither. Switching the scanner to HID keyboard mode with its configuration barcode changes nothing, because the characters have nowhere to arrive.

The exception is worth checking before you buy anything: some mid-size controllers and panel controllers document a USB host port that accepts scanners in HID keyboard mode. Where the manual lists host mode for your model, USB is the right answer, and this setup guide for a barcode scanner on a controller USB host port is one documented example of that configuration. Where the manual says programming port or device port only, plan one of the three paths below.

Three paths that get code data into a ladder

The scanner payload has to cross into PLC memory as characters. Three hardware paths do that, and they differ in wiring, latency and what the PLC side must already have.

Path PLC side Reader side Best for
RS-232 serial expansion module serial card in an expansion slot; ASCII instructions build the string reader with a native serial output compact PLC with a free slot; one reader at a fixed point
Industrial Ethernet Ethernet module opening a TCP socket Fast Ethernet fixed reader line-mounted readers; long runs; several readers on one switch
HMI or PC with USB host HMI tag or PC program passes the string on USB HID keyboard scanner retrofits and manual benches with no free PLC slots

The full menu of input options, with the trade-offs per port, sits in Barcode scanner input methods to a PLC: serial, USB and Ethernet. The sections below put numbers on each path.

Path 1: RS-232 through a serial expansion module

Serial is the path the compact-PLC world was built around. You add a serial expansion module, often one card bundling digital I/O with an RS-232 port, set the reader output to serial in its own configuration menu, and the ladder collects characters as they arrive. The whole chain, reader to CPU module, is walked step by step in Reading a barcode scanner into a PLC CPU module over serial. Shortlist hardware in the fixed code readers category, which filters by interface, including serial output.

One wrong turn to rule out early: a USB-to-RS-232 converter turns a computer's USB host port into a COM port. It does not turn a USB keyboard scanner into an RS-232 device, which the USB or RS-232 interface wiring conversion explains. The clean fix is a reader with a native serial output.

Wiring and distance

RS-232 crosses three conductors: reader TX into module RX, reader RX from module TX, signal ground common to both. Swap TX and RX and the link goes silent; drop the ground and characters arrive scrambled. Plan runs of up to about 15 m, the distance the RS-232 standard was written around; go farther with RS-485 or Ethernet. A pin-by-pin serial scanner-to-PLC port hookup shows the wiring end to end.

Framing and the ladder

Set both ends to the same framing before anything else: 9600 baud, 8 data bits, no parity, 1 stop bit, CR terminator on the reader. A mismatch shows up as shifted or garbage characters, not silence, and the serial-link garbage-character fix walks that fault tree.

In the ladder, buffer the incoming bytes, strip the terminator and compare against the expected string. Storing ASCII barcode strings in PLC memory lays out the registers and clears, and PLC ladder logic to compare barcode strings adds a three-read count. Readers that speak Modbus RTU instead of plain ASCII land the string in holding registers, as in Read a barcode reader into a PLC over Modbus RTU. For a classic integration with the protocol frame included, see this worked serial ASCII barcode integration.

Worked example: a 21-character scan across a 9600 baud port

Inputs, each with its source:

  • Port speed 9600 bit/s, the default serial setting on most readers and serial expansion modules.
  • Framing 8 data bits, no parity, 1 stop bit, which puts 10 bits on the wire per character including the start bit.
  • Payload 20 characters, a typical part-number Code 128 string for a station like this.
  • Suffix 1 CR character, the terminator the reader appends to each read.

The rule: a serial link carries one character at a time, so wire time equals the character count times the bits per character, divided by the bit rate.

t_wire = characters × bits per character ÷ baud rate = (20 + 1) × 10 bits ÷ 9600 bit/s = 210 bits ÷ 9600 bit/s ≈ 0.0219 s = 21.9 ms

The same port moves a single character in 10 ÷ 9600 = 1.04 ms. Result: roughly 22 ms of wire time, spent once per scan, because a scanner reads on event rather than continuously.

Decision: if the ladder must hold the part number within 25 ms of the decode, 9600 baud is marginal, because the wire alone consumes 21.9 ms of that budget before the decode time and one PLC scan cycle are counted. Set the port to 115200 bit/s and the same string costs 210 ÷ 115200 = 1.8 ms, which takes the wire out of the equation. Where the process tolerates 100 ms, normal for part tracking and MES posting, 9600 baud is plenty. The buffer side of the scan-to-flag path, terminator races included, is covered in ASCII barcode data framing in the PLC receive buffer: nulls and races.

Path 2: industrial Ethernet and socket instructions

Where the panel has an Ethernet module, or gets one anyway, a Fast Ethernet fixed reader is the stronger build. The reader works as a TCP server or client, the PLC opens a socket and reads the string with its ASCII socket instructions, and the 15 m serial horizon disappears into the plant switch topology. A 21-character string crosses a 100 Mbit/s link in well under a millisecond even with protocol headers counted.

Get the socket roles right first: Barcode reader as TCP server: wire your PLC as the client covers the handshake, and Barcode reader to PLC over raw TCP sockets covers panels with no protocol driver. ASCII instructions typically execute once on a rising edge, so a scan that never seems to arrive is usually a retriggering problem, as in ARL and AWA ASCII instructions execute once: retrigger each scan. Existing serial scanners can also cross through a serial-to-Ethernet converter at the panel, landing in plant data tags via Barcode scanner serial to Ethernet converter into plant data tags.

The MV-ID3013PM-12M-WBN is a compact fixed reader built for this path, a 1.3 MP sensor with a 12 mm lens on Fast Ethernet for close-range label work.

Fixed code readersHikrobot MV-ID3013PM-12M-WBN 12mm focal length 1.3 MP Compact Industrial Code ReaderMV-ID3013PM-12M-WBN
Interface
Fast Ethernet
Resolution
Up to 3 MP
Shutter
Global
Lens mount
M12
$1,979.00View part

The LS-CRD-0028 takes the higher-throughput stations, reading 2560 x 2048 frames at 30 fps and up to 60 codes per second over Fast Ethernet.

Fixed code readers2560 x 2048 fixed code reader, 30 fps, 60 codes/s, 8 mm lens (LS-CRD-0028)LS-CRD-0028
Interface
Fast Ethernet
Resolution
5 MP
Sensor format
1/1.7"
Shutter
Global
$920.00View part

Path 3: an HMI or PC with a USB host port

Panels and panel PCs ship USB host ports that accept scanners in HID keyboard mode: connect to the panel USB port, focus the input field, scan, and the panel hands the string to the PLC as a tag. The PLC stays untouched, which is why this path wins retrofits with no free expansion slot and no Ethernet module. The cost is that the scanner now types into a window, so results land wherever focus sits; Keyboard wedge barcode readers and focus in your HMI covers that fault, and USB barcode scanner on a PLC HMI: HID keyboard mode or serial port weighs this path against serial at the controller. The tag side, scripted once and reused, is in Barcode scanner to a PLC tag: keyboard wedge scripting.

Fixed read points suit a compact USB reader: the LS-CRD-0047 is a fixed reader on USB 2.0, set up for labels at 60–120 mm.

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

Manual benches do the same job with a handheld: the LS-HCR-0001 is a handheld industrial barcode reader with a 1.0 MP sensor on USB 2.0.

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
Interface
USB
Connection
Wired
$539.00View part

Matching the reader to the port

Work outward from the PLC. One free serial slot and one fixed read point: a reader with a native serial output. An Ethernet module in the panel or on the drawing: a Fast Ethernet fixed reader working as a TCP server. A retrofit with the HMI already mounted: USB into the panel, tag to the controller. A scanner that roams the cell: a wireless handheld whose base station still terminates in serial or Ethernet at the controller, as paired in Cordless barcode scanner to a PLC: base station and serial link.

Where the scan happens on the line and the string must land in the PLC without a panel in between, a wired Ethernet reader closes the gap. The LS-CRD-0052 is a fixed industrial barcode reader with a 1.2 MP sensor, a 12 mm focal length and an Ethernet interface.

Fixed code readersDual aviation plug fixed industrial barcode reader, 1.2 MP, focal length 12 mm (LS-CRD-0052)LS-CRD-0052
Resolution
Up to 3 MP
Shutter
Global
Interface
Ethernet
$559.00View part

Both families sit in the shop, with handheld code readers for manual stations alongside the fixed models above; the code reader finder filters both by interface, resolution and lens mount.

Checks before you commission

  • Read the port type in the controller documentation: USB device means no scanner, USB host with HID keyboard means USB works. This one line decides the whole build.
  • Count the free expansion slots and confirm what the Ethernet module supports, raw sockets or ASCII instructions, before choosing between paths 1 and 2.
  • On the reader, confirm the output you need, settable framing and a configurable terminator.
  • Size the string buffer to the longest code plus terminator, 21 characters in the example above, so no scan overwrites the last.
  • Keep RS-232 runs within about 15 m, cross TX and RX, and tie signal grounds at one point.
  • Trigger reads from a product-present sensor rather than free-running scans, so the buffer always holds a fresh, attributed read.
  • Commission with a known-good label and a deliberately damaged one, and log the scan-to-flag time once, turning the worked example's budget into a measurement.

The decision, case by case

Compact PLC, one read point, data wanted within about 100 ms: the serial expansion module at 9600 baud, where the example above shows 21.9 ms of wire for a 21-character string. The same panel with a budget tighter than 25 ms: same wiring, port set to 115200 bit/s and 1.8 ms on the wire. Line-mounted reading with an Ethernet module: a Fast Ethernet reader as a TCP server. Retrofit or manual bench with a panel in place: USB HID scanner into the HMI, tag to the controller. And when the controller documentation lists a USB host port with keyboard support, take the straightforward win: plug in, map the keys, done.

More PLC-side integration patterns sit on the code-reading topic page. To finish the build, step through the system configurator to pair the reader with trigger and cabling, or send your port audit and ladder sketch through the contact page and we will match the interface.

Questions

Can I plug a USB barcode scanner into the USB port on my PLC?

Only if the controller documentation calls that port a USB host with HID keyboard support. On most compact PLCs the port is a device port for the programming cable, and a scanner will never enumerate there: no host controller, no keyboard driver stack, no place for the characters to arrive. Use a serial expansion module, the Ethernet module, or an HMI or PC with a USB host port instead.

How long does a barcode string take to cross a serial link at 9600 baud?

With 8 data bits, no parity and 1 stop bit, each character costs 10 bits on the wire, so 9600 baud moves 960 characters per second. A 21-character string, 20 characters plus a CR terminator, occupies the wire for 210 / 9600 = 21.9 ms. Budget 30 ms or more scan-to-flag once the decode and a PLC scan cycle are added, and move to 115200 baud, about 1.8 ms for the same string, when the cycle demands better.

Does a USB-to-RS-232 adapter make a USB scanner work on a PLC serial card?

No. That adapter converts a computer's USB host port into a COM port; it cannot turn a USB HID scanner into an RS-232 device, and the PLC side has no USB host to run either end of the chain. Buy a reader with a native serial output, or keep the scanner on USB and land it on an HMI or PC that passes the string to the PLC as a tag.

Which reader interface is the better long-term choice for PLC integration?

Industrial Ethernet, when the panel has or is getting an Ethernet module. It removes the roughly 15 m serial distance limit, lets several readers share one switch, and moves a short string across the wire in well under a millisecond at 100 Mbit/s. Serial stays the right answer for a compact PLC with one free expansion slot and one fixed read point; USB belongs behind an HMI or PC host port.

Why do scans from my HID keyboard scanner end up in the wrong field on the HMI?

Because a HID scanner types: the panel delivers the characters to whatever field holds focus at that moment. After a screen change, an alarm popup or a cursor left in a numeric field, the next scan lands there. Tap the target field before each scan, use the panel's scanner-focus features where they are offered, or switch that station to a serial or Ethernet reader whose data the program collects directly.