Code readingHow-to

Smart camera OCR string output over TCP: how to send it

Set a smart camera OCR string output to a TCP port, connect your host as a TCP client, and read the text at every inspection, with a sizing example.

LumaSpec Vision10 min read Share on LinkedIn

On this page 9 sections
  1. 01What port does a smart camera send its TCP string on?
  2. 02How do I map the OCR read text to the TCP string output?
  3. 03How does the host receive the OCR string?
  4. 04How many pixels does OCR need per character?
  5. 05What lens and working distance read a 3 mm date code?
  6. 06Which smart cameras can serve OCR strings over TCP?
  7. 07When is TCP string output the wrong choice?
  8. 08What should you check before the line runs?
  9. 09Questions

Your smart camera reads the date code on its own screen, but the text has to reach the machine that uses it: a PLC, a line PC, a SCADA tag. The clean path is the camera's string output over TCP — one port, one connection, the OCR text delivered on every inspection. This guide shows where the port number comes from, how to map the OCR read text onto that port, how the host connects and parses the string, and how to size the camera and lens so the string is worth sending. The menu names here — "Inspection Outputs", "String output port", "TCP1 (49211)" — are the ones printed in documented smart-camera setups; where your software words them differently, the jobs they do are the same.

What port does a smart camera send its TCP string on?

The camera listens on the port printed next to the string-output selector — 49211 wherever the selector reads TCP1 (49211) — and your host connects to the camera's IP address on exactly that number.

The camera is the TCP server. Once the job runs, it holds the port open and waits for a client; your host — PLC, PC, gateway — is the client that connects. The number in brackets is the port: TCP1 (49211) means port 49211, and a second entry such as TCP2 is an independent second port. Record the number at configuration time, because the host must match the number, not the name.

Give the camera a static IP before anything else. A DHCP lease renewal changes the address under your host's settings, and the string simply stops arriving with no other symptom. If the client-versus-listener question is live on your network, the guide to TCP client or listener roles for a network reader settles who connects to whom.

How do I map the OCR read text to the TCP string output?

Open Inspection Outputs, set the String output port to TCP1, then point the first value field at the OCR tool's read text — from that moment every inspection pushes the read characters to the port.

  1. Tune the OCR tool first: region, character set, tolerance. The string can only be as good as the read, and an unusual font is fixed by training a custom OCR font, not by output settings.
  2. In the camera's setup software, open Inspection Outputs and its TCP/IP and Serial Out page.
  3. Set String output port to TCP1. Read the number in brackets — 49211 in the documented setup — and record it for the host side.
  4. Click the Value 1 field and select the OCR tool's Read Text output. Further value fields can carry the pass/fail flag or a part counter.
  5. Save the job to the camera and set it running. The string port is now live and waiting.

How does the host receive the OCR string?

The host opens a TCP client connection to the camera's IP on the printed port — 49211 where the selector reads TCP1 — and every completed inspection delivers the OCR string over that open connection.

  1. On a PC, use any terminal program with a TCP/IP mode as the first client: connection type TCP/IP, host address the camera's IP, port the number you recorded. Connect.
  2. Trigger one inspection — a part in front of the lens, the camera's trigger input, or a software trigger. The read string appears exactly as your production host will see it.
  3. Parse on the line terminator, not on message length: the text changes length with every read.
  4. Close the terminal before production. Most platforms serve a single client per string port, and a forgotten test terminal is why the real host's connection gets refused.

A PLC host runs the same client logic with its Ethernet instructions. Sending a reader's results to a PLC over raw TCP sockets shows the socket pattern, and a worked PLC-to-smart-camera TCP setup walks the controller side end to end.

How many pixels does OCR need per character?

Give the smallest character at least 15 pixels of height — 10 pixels is the floor where decode rates fall apart — and 2 to 3 pixels across the narrowest stroke.

px/mm = sensor pixels across ÷ field of view (mm) character height (px) = character height (mm) × px/mm stroke width (px) = stroke width (mm) × px/mm

The 15-pixel figure is the working rule of thumb for printed OCR. Embossed, dot-peened or low-contrast characters want 20 pixels and up, because their edges are soft. The transport never rescues an under-resolved image: a flawless TCP delivery of a blurry read is still a bad read. If the print quality itself is the question, date code print quality inspection covers grading what you are about to transmit.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

What lens and working distance read a 3 mm date code?

An 8 mm focal length at about 300 mm working distance covers a 222 mm field of view and puts a 3.0 mm character at roughly 42 pixels tall — comfortable margin over the 15-pixel rule on a 6 MP class camera.

m = sensor width ÷ field of view WD = f × (1 + m) ÷ m blur (px) = part speed × exposure × px/mm DOF ≈ 2 × f-number × c × (1 + m) ÷ m²

Work the numbers on a real case: an inkjet date code on a pouch, characters 3.0 mm tall, pouch 200 mm wide, position wandering ±15 mm, belt at 250 mm/s. Assume a 6 MP class sensor — 3072 x 2048 pixels on a 6.1 mm x 4.1 mm image area, 2.0 µm pixels.

  • Field of view: 220 mm — the 200 mm pouch plus sway margin.
  • Magnification: m = 6.1 mm ÷ 220 mm = 0.0277.
  • Working distance on an 8 mm lens: WD = 8 × 1.0277 ÷ 0.0277 = 297 mm, so 300 mm.
  • Resolution on the part: 3072 px ÷ 222 mm = 13.8 px/mm.
  • Character height: 3.0 mm × 13.8 px/mm = 41.5 px, call it 42 px — well past 15.
  • Stroke: an inkjet stroke near 0.5 mm gives 0.5 × 13.8 ≈ 7 px — past the 2 to 3 px minimum.

Motion next. One pixel on the part is 1 ÷ 13.8 = 0.072 mm, so at 250 mm/s the exposure must stay under 0.072 mm ÷ 250 mm/s = 0.29 ms to hold blur under one pixel. Set 200 µs on the integrated light: blur = 250 mm/s × 0.0002 s = 0.05 mm, which is 0.7 pixel.

Depth of field must swallow the ±15 mm sway, so 30 mm total. With the circle of confusion at two pixels (c = 0.004 mm), the estimate gives 2 × 0.004 × 1.0277 ÷ 0.0277² = 10.7 mm per unit of f-number. f/2.8 lands exactly at 30 mm with no margin; f/4 gives about 43 mm. Choose f/4, and treat the estimate as ±30 %.

The decision from the arithmetic: 8 mm lens, 300 mm working distance, f/4, 200 µs strobed exposure — and a 3 mm character arrives at 42 pixels. Read first, transmit second.

Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

Which smart cameras can serve OCR strings over TCP?

Any smart camera with an Ethernet port and an OCR tool can do it, which in practice means the GigE and Fast Ethernet models — a USB-only camera has no TCP port to serve.

Three Ethernet models that suit this job:

Smart cameras & vision sensors1.6 MP smart camera, 60 fps, 16 mm lens, white light (polarized, transparent light) (LS-SMC-0063)LS-SMC-0063
Interface
GigE
Resolution
Up to 3 MP
$1,110.00View part
Smart cameras & vision sensorsHikrobot MV-SC5060XM-08M-WBN SC5000X series Smart Camera, 6 MP, Mono, 8 mm focal length, M12-mountMV-SC5060XM-08M-WBN
Interface
GigE
Resolution
6-10 MP
$1,629.00View part
Smart cameras & vision sensorsHikrobot MV-SC6050C-08M-XBN SC6000 Series Smart Camera, 5 MP, Color, 8 mm focal length, M12-mount, Multi-color light sourceMV-SC6050C-08M-XBN
Interface
GigE
Resolution
5 MP
$3,449.00 · quotedView and quote

The LS-SMC-0063 is a 1.6 MP smart camera with a 16 mm lens and GigE — the close-up, small-field end of the range. The MV-SC5060XM-08M-WBN is a 6 MP model with an 8 mm focal length on an M12 mount and GigE, the class the worked example assumed; its rolling shutter is happiest with indexed or slow-moving parts. The MV-SC6050C-08M-XBN is a 5 MP smart camera with a global shutter on GigE for parts that keep moving.

Fixed code readers overlap this ground, and many carry text-reading tools alongside decode — reading several text strings in one image on a fixed code reader covers that side of the fence.

When is TCP string output the wrong choice?

Choose a different path when the host wants typed, structured data, when the link is a legacy serial port, or when the "text" is really a bar code — each case has a cleaner answer.

Path What travels Pick it when Trade-off
TCP string output OCR read text per inspection a PC or SCADA logs text; a PLC parses simple lines one client per port, and you own the framing
OPC UA typed, named results the host already speaks an industrial protocol more set-up than a raw string
RS-232 telegram fixed-position result string the host is a PLC serial port point-to-point wiring and slower
Digital I/O pass/fail only the line just needs the reject decision carries no text

For typed data, reading smart camera results over OPC UA is the structured route. For serial hosts, a fixed-position RS232 telegram from a vision result is the pattern. For pure pass/fail, controlling a smart camera over GPIO or serial does the job with two wires.

And if the mark is a DataMatrix rather than printed characters, skip OCR and put a reader on it: the LS-CRD-0028 decodes up to 60 codes/s from 2560 x 2048 pixels 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

What should you check before the line runs?

Six checks catch nearly every failure of a TCP string link: port match, trigger delivery, the no-read case, the terminator, reconnection, and pixel height on the final optic.

  • Port match. Connect a test terminal to the printed port before writing a line of host code.
  • Trigger delivery. Confirm one string per trigger, not one per poll; trigger modes — sensor, serial or free-run lays out the choices.
  • No-read behavior. Decide what the host does with an empty string before the first one arrives.
  • Terminator. Test the parser with the shortest and the longest string the line can produce.
  • Reconnection. Pull the Ethernet cable once mid-run; the host must re-establish the connection on its own.
  • Static IP and final pixels. Lock the camera's address, then re-measure the smallest character through the installed optic — it must still clear 15 pixels.

While wiring, power the camera from the supply its wiring diagram specifies, keep the connector behind the panel door, and do not stare into the integrated illuminator at close range while it free-runs.

Ready to pick parts? The smart cameras category lists the Ethernet models, the fixed code readers category the readers, and the camera finder filters by interface and resolution once the numbers above are set. The system configurator walks camera, lens, light and controller in one pass, more guides sit on the code reading topic page, and if the host side needs a hand, contact us — free expert support comes with every order.

Questions

Does the camera connect to my host, or does my host connect to the camera?

For the string output described here, the camera listens and the host connects: the camera holds the port open as a TCP server, and your PLC or PC opens the connection to the camera's IP on the printed port. Many platforms also offer an outbound client mode; if your host must be the listener, enable that on the camera side rather than building a bridge.

Why does my terminal show nothing after connecting?

The connection opens silently, and data moves only when an inspection completes. Trigger the camera — present a part, fire the trigger input, or switch the job to free-run for a bench test — and the string should appear at once. If the connection itself was refused, the port you typed does not match the number printed beside the string output selector; reconnect with that number.

What does the camera send when the OCR read fails?

Usually the same output frame with an empty read-text field, often with a pass/fail flag beside it — the link does not go quiet on a failed read. The host must treat an empty string as no-read and act on it, not log it as a value. Put the inspection pass/fail flag into the value fields so the host can tell a blank passing read from a failure.

Can I send more than the OCR text on the same connection?

Yes. Value fields beyond the first can carry the pass/fail flag, a counter or another tool's result in the same string, in the order the fields are listed. Keep the format fixed — same fields, same order, same terminator — so the host stays a simple split. Keep it compact too: a string well under a couple of hundred bytes arrives in a single segment and keeps PLC parsing simple.

Do I need a PC on the line to receive the string?

No. Anything that can open a TCP client connection works: a PLC with an Ethernet port, an HMI runtime, a data logger, a small embedded controller. The PC-and-terminal method in this guide is simply the fastest way to prove the camera side before you write host code. A USB-only smart camera is the one dead end — it has no TCP port to serve.