Code readingHow-to

Wire a barcode scanner RS232 ASCII string to a PLC serial port

Wire a barcode scanner's RS232 ASCII output to a PLC serial port: matching 9600 8N1 settings, TX/RX crossover wiring and CR/LF delimiter framing.

LumaSpec Vision11 min read Share on LinkedIn

On this page 10 sections
  1. 01What you need
  2. 02Five settings that must match
  3. 03The one crossover: TX, RX and ground
  4. 04End every scan with CR and LF
  5. 05Bring the link up in seven steps
  6. 06Worked example: a 20-character code at 9600 baud, 8N1
  7. 07Copy the string, then prove it
  8. 08When plain RS232 ASCII is the wrong answer
  9. 09Pre-handover checklist
  10. 10Questions

Plenty of lines still run a PLC whose spare serial port is the simplest integration path to a barcode label: no network card, no gateway, no PC in the loop. Any scanner or fixed reader with RS232 ASCII output feeds that port directly. The scanner transmits the code's characters, closes them with a carriage return and line feed, and the PLC's ASCII receive logic copies the finished line into a string register. This guide gives the settings that must match, the one crossover that wires it, the delimiter framing and the receive logic, with the arithmetic for how long a scan takes to arrive. Budget an hour for the first commissioning.

What you need

Four items, plus one bench test that saves an afternoon:

  • A scanner or fixed code reader with an RS232 host mode and ASCII output. Filter the code reader finder by a Serial interface to see which fixed readers expose one; everything below applies to any of them.
  • The scanner's programming barcodes or manual. On most industrial scanners you set serial behaviour by scanning configuration codes, not through software.
  • A PLC serial port you can set to ASCII (user) mode. CPU ports and add-in communication modules both work, and the recipe runs on platforms as old as a SLC 5/03 barcode integration over the serial ASCII port. What matters is that the port can trigger its receive logic on a delimiter character.
  • A cable you can terminate on PLC terminals, and a power supply for the scanner — an RS232 port signals, it never powers a scanner. Add the supply from reader accessories if the scanner ships without one.

Among serial-interface fixed readers, the MV-ID6200PM-00C-NNG is a 20 MP logistics code reader with a C-mount lens mount and a serial interface.

Fixed code readersHikrobot MV-ID6200PM-00C-NNG 20 MP logistics code reader, high performanceMV-ID6200PM-00C-NNG
Interface
Serial
Resolution
16-25 MP
Sensor format
1"
Shutter
Global
$5,699.00 · quotedView and quote

On the cable side, the MV-IDA-PE-M12A17pF-openRJ45DB9-HF-5m is a 5 m high-flex code reader cable, 17-pin at the reader, with the far end as open leads, RJ45 or DB9. The open-lead version is what lands directly on PLC terminals.

CablesHikrobot MV-IDA-PE-M12A17pF-openRJ45DB9-HF-5m Integrated cable, GigE, high-flex, 5 m, 17-pin to open/RJ45/DB9MV-IDA-PE-M12A17pF-openRJ45DB9-HF-5m
Type
Code Reader Cables
$49.00View part

Five settings that must match

Both ends of the wire carry five settings, and one wrong value garbles every character:

Setting Commit to Why
Baud rate 9600 The common default on scanner RS232 host modes and PLC ports alike
Data bits 8 ASCII characters need the full 8 bits
Parity None Leftover even parity from an old printer link garbles everything
Stop bits 1 The standard pairing with 8 data bits and no parity
Flow control Off Only TX, RX and ground are wired; RTS and CTS play no part

Written together that is 9600 8N1. Program the scanner by scanning its RS232 host barcodes, then enter the same five values in the PLC port configuration. Garbled characters on a wire you know is good are a baud or parity mismatch at one end; the diagnosis is laid out in garbage characters from a barcode scanner on a PLC serial link.

The one crossover: TX, RX and ground

RS232 needs three lines, and one rule wires them:

  • scanner TX to PLC RX
  • scanner RX to PLC TX
  • scanner ground to PLC ground

Transmit lands on receive at the far end; that is the entire crossover. On a DE-9 connector (commonly called DB9) wired as DTE, pin 3 is TX, pin 2 is RX and pin 5 is ground, and a DCE-wired device swaps pins 2 and 3. Look up which lines your scanner actually drives before you solder. If the link powers up silent, swap pins 2 and 3 at one end — that single change clears most dead scanner-to-PLC links.

Keep the run under about 15 m, the design length the RS-232 standard was written around. Shielded code reader cables with the shield grounded at one end, routed away from drive and servo wiring, hold 9600 baud comfortably over that distance.

End every scan with CR and LF

A serial port has no message boundary — the delimiter is the boundary. Program the scanner suffix as carriage return plus line feed: CR is decimal 13 (hex 0D), LF is decimal 10 (hex 0A). The split is consistent across scanner families: serial host modes terminate with CR-LF, while keyboard-wedge and USB-keyboard hosts end with the Enter key, because that host expects keystrokes rather than a byte stream. Framing runs deeper than the suffix when devices also prepend headers — framing serial data without headers covers that case.

On the PLC side, set the port's ASCII receive delimiter to LF, the last character the scanner sends. A port waiting for LF while the scanner sends only CR never completes its receive instruction, and the string never lands. If you must strip a prefix or route part of the payload, the pattern in prefix and suffix parsing with capture groups does it without extra PLC logic.

  1. Program the scanner off-line: RS232 host, 9600 8N1, suffix CR LF, and your trigger mode. Scan the settings back to confirm they took.
  2. Bench-test the scanner alone. Through a null-modem adapter into a PC terminal program, every scan must print one clean line ending in CR LF. Silence here means pins 2 and 3, not the PLC.
  3. Wire the crossover to the PLC port and power the scanner from its own supply.
  4. Set the PLC port to ASCII mode with the same five settings and the receive delimiter on LF.
  5. Trigger one scan and watch the port's receive counter or buffer. When it moves, attach the ASCII receive instruction so it copies the delimited line into a string register and sets a new-data flag.
  6. Measure trigger-to-flag time end to end and tune it if it is slow; cutting scan-to-flag latency on a scanner-to-PLC link has the method.
  7. If the PLC triggers the scanner over the same port, send the scanner's exact serial trigger command. A scanner that stays deaf usually has the wrong command string or the wrong line ending — diagnosing silent serial trigger commands works that list.

Worked example: a 20-character code at 9600 baud, 8N1

Inputs: a typical GS1-128 label carrying 20 characters; the suffix adds CR and LF; both ends at 9600 baud, 8 data bits, no parity, 1 stop bit.

bits per character = 1 start + 8 data + 0 parity + 1 stop = 10 characters per second = baud ÷ bits per character line time = characters on the wire × bits per character ÷ baud

The arithmetic:

  • Characters on the wire: 20 payload + 1 CR + 1 LF = 22
  • Bits: 22 × 10 = 220 bits
  • Line time: 220 ÷ 9600 = 0.0229 s ≈ 23 ms
  • Throughput: 9600 ÷ 10 = 960 characters per second
  • Buffer: 22 bytes = 11 words of 16 bits, so allocate 32 bytes (16 words) and longer labels never truncate
  • At 19,200 baud the same scan: 220 ÷ 19,200 = 11.5 ms

Decision: 9600 8N1 is right up to roughly 20 scans per second — at 10 scans/s the line is busy 23 ms of every 100 ms, and decode time dominates the budget. Past 20 scans/s, or with payloads over 40 characters (44 ms at 9600 baud), set both ends to 19200 baud and halve the line time.

Copy the string, then prove it

Receiving is half the job. After the delimiter closes the line, copy the characters into a string register table sized like the buffer above, one-shot the new-data flag, and clear the receive buffer before the next scan so a short code cannot sit behind a long one. PLC string formats differ — length byte first, fixed tables, or byte pairs per word — and storing ASCII barcode strings in PLC memory maps each of them out.

Then treat the read as data, not gospel. Compare each new string against the previous read and accept on agreement; comparing barcode strings in ladder logic with a three-read count is the pattern. Judge a marginal decode before it reaches production logic using how to tell whether a decode is trustworthy. For a complete plant example of this architecture, bottle label verification over a fixed reader and a PLC serial link walks the whole chain, and a CompactLogix serial ASCII read setup for a barcode scanner shows the same wiring on that controller family.

When plain RS232 ASCII is the wrong answer

Three cases push you off the direct wire:

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
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

Choosing from scratch? Scanner input methods to a PLC: serial, USB and Ethernet compares the three paths, planning a reliable reader-to-PLC link is the design pass to make before ordering, and the no-Ethernet case is answered in a handheld scanner to a PLC without Ethernet: RS232 or USB.

Pre-handover checklist

  • Terminal test passed with your worst real labels: angled, glossy, lightly printed.
  • Both ends at 9600 8N1, flow control off, settings written on the panel drawing.
  • Crossover proven after the pins 2 and 3 check; grounds common at one point only.
  • Receive delimiter on LF, suffix CR LF programmed and scanned back to confirm.
  • String buffer sized for the longest label with margin (32 bytes for a 20-character code).
  • New-data flag one-shots, and the receive buffer clears after every copy.
  • No-read path: a timeout flags the miss and alarms instead of forwarding the last good code.
  • Cable under 15 m, shield grounded at one end, separated from drive wiring.

When the checklist is green, the station is done. For the next station, start at the system configurator or send us the port list and we will match a reader and cable to it; more integration patterns live on the code reading topic page.

Questions

Do I need a null modem adapter between the scanner and the PLC?

Usually yes on a molded cable, and here is the rule: a null modem supplies the crossover, so you need it when both ends are wired DTE (pin 3 TX, pin 2 RX on DE-9) or when you buy a straight-through cable. When one side is wired DCE, straight-through already crosses the lines. The 30-second test never changes: if the link is silent, swap pins 2 and 3 at one end.

Why does the scanner print into a PC terminal but not into the PLC?

In order of likelihood: the PLC port's baud or parity differs, so put both ends back to 9600 8N1; the port still sits in a protocol mode such as Modbus or printer mode instead of ASCII user mode; or the receive delimiter does not match the suffix, so a port waiting for LF with a CR-only scanner never completes its read. Watch the port's receive counter: if it climbs, the wiring is good and the settings are at fault.

How long can the RS232 cable be to the PLC cabinet?

Fifteen meters is the design limit the RS-232 standard set, and 9600 baud holds it with margin. Longer runs do work at low baud in quiet installations, but plan on shielded cable, the shield grounded at one end, and routing away from drive and servo cables. Past 15 m, use an Ethernet reader and carry the string over TCP, or mount a serial-to-Ethernet converter next to the scanner.

Can the PLC serial port power the scanner?

No. RS232 signal lines carry data, not power. The scanner needs the supply its manual specifies, and that supply's 0 V should tie to PLC signal ground at a single point; without that tie, ground offset corrupts characters on longer runs. Handheld scanners draw power through their own interface cable from the same kind of external supply, so budget the supply in the panel from day one.

Should the suffix be CR alone, LF alone, or both?

Program CR and LF together and set the PLC delimiter to LF, the last character on the wire. The pair costs about 2 ms per scan at 9600 baud, two characters at 10 bits each, so there is no speed reason to trim it. Keyboard-wedge and USB-keyboard hosts are the exception: they need the Enter key, because that host consumes keystrokes rather than a serial byte stream.

How do I read two scanners into one PLC serial port?

You cannot share one port: two scanners transmitting onto one RX line collide and both strings arrive corrupted. Give each scanner its own port or communication module, or convert to RS485, where several scanners share a bus and the PLC polls each by address; converter pairs also present multiple scanners as Modbus registers or TCP sockets. On new installations, Ethernet readers scale simplest, since each holds its own address and the PLC polls them one by one.