Code readingHow-to

Barcode scanner capture without a prefix: preamble and serial

Why a keyboard-wedge barcode scanner cannot be captured without prefix, which preamble and suffix to program, and when to switch to serial capture or USB-CDC.

LumaSpec Vision11 min read Share on LinkedIn

On this page 8 sections
  1. 01Why does a keyboard-wedge scanner need a preamble at all?
  2. 02Which preamble and suffix should you program?
  3. 03How do you program a preamble into a mixed scanner fleet?
  4. 04Does the preamble change what is stored in the barcode?
  5. 05When should you abandon keyboard wedge for serial capture?
  6. 06How do you read a USB-CDC scanner as a serial port?
  7. 07What should you check before rolling the fleet out?
  8. 08Questions

You configured a screen-based scanner component, scanned a label, and the capture failed until you typed a preamble into the field — and the tool refuses to save with it empty. The barcodes carry plain text with no prefix of their own, and the station will see several scanner brands over its life. This guide gives the pair to program, how to load it on every scanner, and the two capture paths that need no preamble at all: reading the scanner as a serial device, or replacing it with a triggered fixed reader. You will leave with a fleet standard, the settings to check, and the arithmetic that shows why framing matters.

Why does a keyboard-wedge scanner need a preamble at all?

A keyboard-wedge listener taps the whole keyboard stream, so without a preamble it has no way to tell a 25-character scan from an operator typing the same characters, and that is why every such component refuses to save with the field empty. In HID keyboard mode the scanner is a second keyboard: the operating system receives keystrokes with no flag saying they came from a scanner rather than a person. A component that captures without focus does it by listening globally, and global listening needs markers. The preamble marks where a scan starts; the suffix or terminator marks where it ends and the buffer flushes.

Vendors name the same bytes differently on each side of the cable. The scanner's manual says prefix and suffix; the listener's screen says preamble, postamble and separator. Program one side, match the other, and the naming stops mattering.

Which preamble and suffix should you program?

Program the preamble "!" (ASCII 33) and the suffix CR+LF (the Enter key) into every scanner, because "!" almost never occurs in plain-text label data and Enter gives the listener an unambiguous end-of-scan marker. If your data set can contain "!", use "~" (ASCII 126) instead. Enter the same two values in the component's preamble and terminator fields, and the capture works no matter which field on the screen has focus.

One layout check before you commit: HID scanners send key positions, and the operating system's keyboard layout turns them into characters. On a station set to a non-US layout the same programmed key can arrive as a different glyph, so test the preamble character on the runtime layout, not on your office PC.

Control characters are the alternative framing: STX (0x02) in front of the data and ETX (0x03) behind it. In keyboard mode those travel as Ctrl+B and Ctrl+C keystrokes, which some listeners and layouts mishandle; keep STX/ETX for serial mode, where the bytes go through untouched. An STX preamble fixing a barcode input character problem on an HMI shows the pattern on a panel screen.

  1. Collect a day of production labels and search the decoded strings for the character you plan to use. If it appears anywhere, pick another.
  2. Program prefix "!" and suffix CR+LF with the scanner's programming barcodes or its USB configuration utility; a preamble and separator configuration walkthrough for a desk scanner shows the flow end to end.
  3. Open a text editor and scan a label: you should see "!DATA" with the cursor on the next line.
  4. Enter "!" as the preamble and CR+LF as the terminator in the component, then save.
  5. Click nowhere on the screen and scan again: the value must land in the component's tag with no field focused.

How do you program a preamble into a mixed scanner fleet?

Every scanner family sets prefixes and suffixes the same two ways — by scanning the programming barcodes printed in its quick-start guide or through the maker's USB configuration utility — and both write the setting into the scanner's non-volatile memory. The settings survive power cycles and cable swaps; a factory reset or a firmware reflash clears them, which is when your paperwork earns its keep. The programming barcodes differ from model to model, but the pages are always named the same way: add prefix, add suffix, save.

Make one fleet standard: the same preamble and suffix on every model, written on one sheet with the exact programming barcodes or utility screenshots per model. When a unit dies under time pressure, you reprogram the replacement from the sheet in a minute. Treat the sheet like configuration itself and back up every reader configuration before troubleshooting starts.

Does the preamble change what is stored in the barcode?

No: the preamble and suffix are added by the scanner after decoding and before transmission, so the label content stays exactly what was encoded and no relabeling is ever needed. Every scanner runs the same pipeline — decode the symbol, apply the format rules, transmit — and the format rules are where your pair lives. Strip the framing characters in the listener or in your ingest code, and the string in the database is the barcode content alone. If you archive the raw transmitted string, keep the framing out of the data field: a stored preamble breaks downstream lookups that compare against clean values.

When should you abandon keyboard wedge for serial capture?

Switch to serial (USB-CDC) capture when you run a mixed fleet of scanner brands, when operators share stations with keyboards, or when you cannot program every scanner, because serial needs no preamble: the line terminator frames each decode. Serial also gives you the exact bytes and a timestamp per scan, which an audit trail can quote.

In USB-CDC mode — often called serial emulation — the scanner stops being a keyboard and enumerates a COM port. Each decode arrives as one line ended by the CR+LF you programmed, and a background task reads lines without caring what brand produced them. For capture-side questions on the USB path generally, USB barcode scanner data capture in your application covers the host side. Over the network, handheld code readers do the same job without occupying a PC port: the LS-HCR-0002 is a wireless industrial handheld code reader with a 1.0 MP sensor and an Ethernet interface.

Handheld code readersHandheld industrial barcode reader, 1.0 MP (LS-HCR-0002)LS-HCR-0002
Resolution
Up to 3 MP
Shutter
Global
Interface
Ethernet
Connection
Wireless
$539.00View part

For a fixed station, fixed code readers remove the handheld and the operator from the loop: a photoeye or PLC signal triggers the read and the decode arrives over Ethernet or RS-232 as a framed message. The LS-CRD-0052 is a dual aviation plug fixed reader with a 12 mm focal length and an Ethernet interface; the LS-CRD-0047 is a compact USB 2.0 unit with a 60-120 mm reading distance.

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
$559.00View part
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
$559.00View part

The timing is deterministic, which is worth seeing once with numbers:

transmitted characters = 1 preamble + data characters + 2 (CR + LF) line time (ms) = transmitted characters × 10 bits × 1000 / baud

A 22-character decode framed with "!" and CR+LF is 1 + 22 + 2 = 25 characters. At 8N1 each character is 10 bits — one start, eight data, one stop — so 25 × 10 = 250 bits. At 9600 baud that is 250 / 9600 = 0.026 s, about 26 ms per scan, so the port clears roughly 38 scans per second; at 115200 baud the same line takes 2.2 ms. Keyboard wedge injects a similar count of keystrokes, so speed is a wash — choose serial for the framing, the focus-free capture and the mixed fleet.

Capture path Needs focus Framing Preamble needed Mixed fleet
Keyboard wedge (HID) No Preamble and suffix you program Yes Only if every scanner is programmed
USB-CDC serial No CR/LF line terminator No Any scanner that emits lines
Fixed reader, triggered No Trigger plus framed message No One reader per station

For a PC-based controller rather than a screen client, connecting a barcode scanner over serial to the controller walks the same port settings end to end.

How do you read a USB-CDC scanner as a serial port?

Scan the scanner's USB-CDC programming barcode, open the COM port it enumerates at 9600 baud with 8 data bits, no parity and 1 stop bit, and read complete lines terminated by CR+LF in a background task that writes each decode to a tag. That is the whole change; the steps below fill in the details.

  1. Scan the scanner's USB-CDC or serial-emulation programming barcode from its guide. Windows lists the new port in the device manager; Linux exposes it as /dev/ttyACM0, with later devices taking the next number.
  2. Match the serial parameters. Most scanners ship at 9600 baud, 8 data bits, no parity, 1 stop bit; if you read garbage characters, the unit is almost certainly at 115200.
  3. Keep CR+LF as the terminator so one decode equals one line, exactly as in keyboard mode.
  4. Run one background task in the client: open the port, read to the terminator, strip the CR/LF, and write the decode to a tag or a database row. Start the task at client startup so it owns the port for the whole session.
  5. Guard the tag write: writing from inside the read handler can retrigger the handler, and scan event handling without recursive updates is the pattern that stops it.
  6. When two scanners share one host, pin each COM port to the device serial number — identifying barcode scanners by serial number after reconnects — so a replug cannot route line A's scans to line B.

Two side checks: if the scanner hangs off a hub or a long cable, run the power and interface checks for USB barcode scanner adapters before blaming the capture code; and if your host must command each read instead of free-running, send the scanner's serial trigger command — when nothing comes back, diagnosing a silent serial trigger walks the usual causes. A legacy host with a physical COM port is the same job in older clothing: connect the scanner over RS232 to an embedded host.

What should you check before rolling the fleet out?

Before rollout, scan one label of every symbology at production speed, type on the keyboard during a scan, and confirm the captured string equals the label data with the framing characters stripped. Then run the rest of the list; every item on it has ended someone's go-live at least once.

  • Scan every symbology in use at production cadence: each decode arrives whole, one event per scan.
  • Type on the station keyboard mid-scan: the typing must not merge into the captured value.
  • Compare captured values against the physical labels, framing stripped. To grade how trustworthy a marginal decode is, see judging whether a barcode read is trustworthy.
  • Unplug and replug the scanner: the port returns and the background task reconnects without a client restart.
  • Factory-reset one scanner on purpose and reprogram it from the sheet — that is the drill for a night-shift failure.
  • If a fixed reader replaced the handheld, check trigger timing: part present, read fired, value logged before the part leaves the station.

Decide per case: one controlled scanner fleet on shared screens — program "!" and CR+LF everywhere and keep the sheet. Customer- or operator-owned scanners, or any station you do not configure — switch to USB-CDC and read lines. One fixed point where parts pass anyway — put a triggered reader there and drop the handheld. Filter both reader families by interface in the code reader finder, or send the station count and label details through the contact page and we will spec the readers and the configuration with you.

Questions

Can the preamble field be left empty if nobody types at that station?

No. The component watches the whole keyboard stream, so it needs a start marker even on a station with no physical keyboard — service laptops get plugged in eventually, and a remote desktop session counts as typing too. Program the pair everywhere; an empty preamble leaves the listener guessing with no way to separate a scan from stray input.

What makes a character a bad preamble choice?

Any character that can appear in decoded data: digits and letters are out, and so is Enter on its own, which only ends the scan. Accented and layout-dependent keys are risky because HID sends key positions that the OS layout remaps. Control characters such as STX work best in serial mode; in keyboard mode they travel as Ctrl keystrokes that some listeners drop.

Do you need both the preamble and the suffix, or is one enough?

Both. The preamble tells the listener to start buffering and lets it ignore typing between scans; the suffix or terminator tells it to flush immediately. A preamble alone works, but every scan then waits on a timeout to close, which slows the line and can stitch two fast scans together. A suffix alone cannot tell a scan from typing at all.

How fast is one serial scan compared with keyboard wedge?

Frame a 22-character decode with a preamble and CR+LF and you send 25 characters; at 8N1 that is 250 bits, about 26 ms at 9600 baud or 2.2 ms at 115200. Keyboard wedge sends a similar count as keystrokes, so speed is roughly a wash — at 26 ms per scan, 9600 baud still clears about 38 scans per second. Choose serial for the framing and the mixed fleet, not the milliseconds.

Do fixed code readers need a preamble and suffix too?

No. A fixed reader is triggered — by a photoeye, a PLC signal or a serial command — and each trigger returns one framed message over Ethernet or RS-232. The trigger marks the start and the message framing marks the end, which is the same job a preamble does in keyboard mode, done by hardware that cannot mistake an operator for a barcode.