A code reader hands your PLC a short string of digits, and the PLC has to decide, inside one bottle pitch, which of four coder jobs that string earns. The logic is simple; the trap is not obvious until it costs a misprint. Converting the whole ten-digit code into a plain 32-bit integer overflows, because ten digits reach 9,999,999,999 while a signed 32-bit value stops at 2,147,483,647. This guide walks the chain for a line running 60 to 80 bottles per minute: capture the string, convert only the leading digits your ranges use, band-compare them, pulse the right 24 VDC output, and default everything unmatched. You finish with a ladder pattern, a bench test list and a reader sized for the rate.
What you need
- A fixed code reader with an Ethernet or serial port and a discrete good-read output
- A PLC whose CPU handles 32-bit signed integers and string instructions
- Four spare discrete outputs at 24 VDC, one per coder job input; the I/O boxes and modules in the code reader accessories range keep that wiring short
- The band table from your product list: the leading-digit ranges behind brand jobs 1 to 3, plus the private-label default
- A photo-eye, or the reader's trigger input, to start each capture as a bottle enters focus
From scan to coder output, step by step
- Capture the string. Trigger the reader from the photo-eye or let it free-run and take the latest good read. Receive the ASCII over Ethernet TCP or serial into a string buffer. If you open the socket yourself, the barcode reader as TCP server guide covers the PLC end of the link, and the barcode scanner input methods article compares serial, USB and Ethernet.
- Validate before converting. Confirm the buffer holds digits only, at the length you expect. A five- or eleven-digit stray goes straight to the default branch, exactly as the product list predicts. If the code bundles more than the number itself, split the string into fields first and keep the numeric part.
- Cut the digits your bands use. Five-digit prefixes are the common case, so take the first five characters and leave the rest in the buffer. The arithmetic that forces the cut:
Five digits cap at 99,999, and the ceiling is about 21,475 times higher. Ten digits cap at 9,999,999,999, roughly 4.7 times over the limit. The encyclopedia entry on 2,147,483,647 explains where the limit comes from: 31 value bits plus one sign bit.
- Convert the prefix. Run the platform's string-to-integer instruction on the trimmed buffer. The result, at most 99,999, fits any 32-bit CPU with room to spare.
- Band-compare. Each range is one AND rung: prefix greater than or equal to the lower bound, and prefix less than or equal to the upper bound. Stack the three brand ranges in order and wire each true result to its job bit.
- Pulse the matching output. Fire 24 VDC at the coder input for 50 to 200 ms: long enough to register one job, short enough to select exactly one. Scope the first pulse and trim the length to the input's response.
- Default the rest. A valid read that matched no band gets output 4, the private-label job. That branch keeps an unknown brand from printing nothing, or worse, the previous bottle's layout.
- Alarm on no-read. A missed decode is not a private-label bottle; it is a bottle you know nothing about. Drive a separate no-read output or a reject, and never let job 4 fire on silence.
Worked example: routing a ten-digit code to one of four coder outputs at 80 bottles per minute
Inputs, and where each comes from:
- Code format: ten numeric digits, with five- and eleven-digit strays that must fall to the default (the product list)
- Stand-in code: 7294011037
- Bands on the leading five digits: 72940-72949 to job 1, 72950-72999 to job 2, 73000-73099 to job 3, everything else to job 4 (the line's range scheme)
- Integer ceiling: 2,147,483,647 for a signed 32-bit value
- Rate: 60 to 80 bottles per minute, coder inputs switching at 24 VDC
Rule in words: convert at most the leading five digits, compare the prefix against each band, pulse the matching output, default everything else.
Arithmetic:
- The whole code as one integer is 7,294,011,037. The ceiling is 2,147,483,647, so the value overshoots by 7,294,011,037 - 2,147,483,647 = 5,146,527,390, about 3.4 times the limit. The conversion is invalid before any comparison runs.
- The prefix alone is the string 72940, or 72,940 as an integer. The largest possible prefix is 99,999, which leaves 2,147,483,647 - 99,999 = 2,147,383,648 of headroom.
- Band test for job 1: 72,940 is at least 72,940 and at most 72,949, so both comparisons hold and job 1 wins.
- Timing: 80 bottles/min divided by 60 s gives 1.33 bottles per second, so each bottle owns 1 / 1.33 = 0.75 s, or 750 ms, of pitch. Keep capture through pulse under half of that, 375 ms, and the trigger lands before the next bottle arrives.
Result: output 1 pulses 24 VDC to coder input 1, once per bottle, and the coder prints the brand layout.
Decision: prefix conversion is safe by a factor of about 21,475, and even a seven-digit band tops out at 9,999,999 with the ceiling about 215 times higher. Commit to five-digit compares on any 32-bit CPU, and up to nine digits if a scheme ever needs them. If a future decision really needs all ten digits, compare digit strings — the approach in this PLC ASCII string compare for barcode scanner matching walkthrough — or move to 64-bit integers. Never convert the full code into a 32-bit integer.
How to verify it worked
Run this bench sequence before the first production bottle:
- Feed the boundary codes 72939, 72940, 72949, 72950, 72999, 73000, 73099 and 73100. Each must land on the job bit the band table predicts.
- Read the five-digit and eleven-digit strays. Both must reach output 4 and nothing else.
- Cover the lens. No job output may move; the no-read alarm must.
- If inherited logic converts the full ten digits, feed it 7294011037 and watch which output fires — that is the overflow making your decisions for you.
- Scope all four outputs for a full minute at 80 bottles per minute: one clean pulse per bottle, no double-fire, no stuck level.
- At a batch change, require three agreeing reads before the first coder trigger. The PLC ladder logic to compare barcode strings and count three reads guide shows the counting rungs.
Read every bottle rather than sampling the first of each batch: a swapped case mid-run stays invisible to sampling, and continuous decoding costs nothing extra at this rate.
Common mistakes
- Converting all ten digits and hoping. The rung runs, no fault is raised, and band 1 can select a brand job for a private-label bottle. Cut first, then convert.
- Letting a no-read fall into the default branch. Job 4 then prints a private-label layout onto a bottle whose real code nobody saw. Give no-read its own output.
- Leaving stale characters in the buffer. Clear the length register on the transfer-done bit, or bottle two decodes as bottle one.
- Hardcoding the bands as ladder constants. Keep them in retentive registers so the HMI edits them; when the list outgrows the PLC, the barcode part number parameter lookup guide covers the database split.
- Triggering the coder from the reader's good-read discrete. Good-read says a decode happened, not that job 4 is the answer. Pulse from the decision rung.
Choose the reader for the line rate
Work the demand backwards from the conveyor. At 80 bottles per minute the reader owes you 80 / 60 = 1.33 reads per second, so rate is rarely the binding spec. The deciding specs sit elsewhere: an Ethernet or serial port that talks to your PLC, a focus distance that holds the label sharp at your stand-off, and clean trigger wiring to the coder. Plan the link itself with the barcode reader to PLC communication plan before you order cable.
The LS-CRD-0028 reads up to 60 codes per second and resolves 2560 x 2048 at 30 fps over Fast Ethernet. Against 1.33 reads per second of demand that is a 45-fold margin.
- Interface
- Fast Ethernet
- Resolution
- 5 MP
- Sensor format
- 1/1.7"
- Shutter
- Global
If the labels sit closer to the reader, or the plant runs a GigE backbone, these cover the other common set-ups:
- Interface
- Fast Ethernet
- Resolution
- Up to 3 MP
- Resolution
- Up to 3 MP
- Shutter
- Global
- Interface
- GigE
- Resolution
- 12 MP
Next step
Cut your code list into bands, set the prefix width to the deepest digit any band uses, and one reader covers every SKU you add. Pick hardware in the fixed code reader finder, size the rest in the configurator, or talk to the applications team with your code list and bottle pitch. More decode-side patterns sit on the code reading topic page.
Questions
How many digits fit in a 32-bit signed integer?
Nine digits always: 999,999,999 sits below the 2,147,483,647 ceiling. Ten digits fit only up to the ceiling itself, which covers codes starting with 0, 1 or 2 — 1,999,999,999 converts cleanly, 3,000,000,000 does not. Because real-world prefixes start with any digit, treat ten digits as unsafe: compare the leading digits you actually need, or move the decision to 64-bit integers.
Does a leading zero break the numeric range compare?
No. A prefix of 07294 converts to 7,294 and lands in the band holding 7,294, which is exactly what the label means. Slice the first five characters from the string before converting, never digits off the converted number, and mixed-length lists stay predictable. Numeric compare treats 07294 and 7294 as the same value, and that is the behavior you want.
What does the PLC do when the conversion overflows?
Nothing visible. Most platforms raise no fault; some clamp the result at 2,147,483,647, others wrap it negative. The band rungs then evaluate on a value the code never held. Feed a code above the ceiling, such as 7,294,011,037, through the bench test and watch which output fires — that tells you which behavior your CPU has before a bottle tells you.
Can the code reader do the matching instead of the PLC?
Some fixed readers keep match lists on board, which suits exact code sets that rarely change. Band logic over hundreds of products, edited whenever the range table moves, is easier to maintain in PLC registers next to the outputs it drives. It also keeps the decision in the PLC if you later swap the reader.
How big can the band table grow before the PLC struggles?
Memory will not stop you: 300 bands at two integers each is 600 retentive registers, small for any current PLC. Maintenance is the limit. Past a few hundred bands that change often, hand the lookup to a database or MES and keep only the three-way band compare and the default branch in the ladder.



