You have one inspection running on a smart camera and a second routine that must run only when an operator or a PLC asks for it. The cleanest way to make that choice is a physical input: a push button or relay contact on an optically isolated digital line, mapped to a routine-select bit in the device logic. A serial command does the same job when the button sits far away or the routine count outgrows your free lines. This guide wires the input, maps it to the routine, sets the debounce, puts a latency number on both paths in milliseconds, and ends with the decision for each case.
Should you switch routines with GPIO or a serial command?
Use GPIO when a free isolated input exists and you are choosing between two and eight routines: the switch lands after one debounce filter plus one logic scan, 25 ms worst case in the worked example below, with no protocol, baud rate or parser involved. Serial earns its keep when the routine count exceeds your lines, the command has to travel, or each switch carries a batch of parameters.
The trade is states against determinism. A digital input is one bit that the on-device logic reads directly, every scan, forever. A serial command is bytes that a receive buffer must collect, checksum and dispatch, so its latency includes software you did not write. Both paths land in milliseconds; what separates them is failure behavior. A broken wire on an input reads open, a defined state your logic can alarm on. A dropped serial link can leave the last received command latched, and nothing on the camera reports it.
The same lines that feed triggers can be read and written while acquisition runs; read camera GPIO input and output pins at the same time shows how the two directions coexist on one connector. Before counting free lines, check which of them acquisition already owns: industrial camera trigger modes compared lists what each mode, from free run to scheduled, ties up.
What hardware do you need for the push-button input?
A 24 V DC push button or relay contact, a twisted pair back to the device's optically isolated input, and the shared input common: typical 24 V inputs accept 10-30 V DC and draw 3-10 mA, so budget a quarter of a watt per input at the top of that range. That budget is 24 V × 10 mA = 0.24 W. A PLC relay output drives this input exactly like a button, which is how the cell controller makes the same selection without an operator.
If the device is not bought yet, decide where the routines live before deciding how to switch them. Smart cameras hold the logic on board and expose a few I/O lines on one connector; vision controllers hold more logic, more lines and built-in light channels. Two devices show how the interface choice shapes the control path:
| Specification | MV-SC3050XC-16M-ATN-H | MV-SC5060XM-08M-WBN |
|---|---|---|
| Communication protocol | RS-232, TCP, UDP, FTP, PROFINET, Modbus, EtherNet/IP, MELSEC/SLMP, FINS, Keyence KV | TCP, UDP, Modbus, Serial Port, PROFINET, EtherNet/IP, Fins, MC, FTP, etc. |
| Sensor type | CMOS, global shutter | CMOS, rolling shutter |
| Pixel size | 3.45 μm × 3.45 μm | 2 μm × 2 μm |
| Sensor size | 1/1.45" | 1/2.4" |
| Resolution | 2432 × 2048 | 3200 × 1920 |
| Max. frame rate | 40 fps | 15 fps |
| Gain | 0 dB ~ 15 dB | 0 dB to 34 dB |
| Exposure time | 6 μs ~ 1 sec | 72 μs to 150 ms |
| Pixel format | RGB 8, Mono 8 | Mono 8 |
| Mono/color | Color | Mono |
| Data interface | Fast Ethernet (100 Mbit/s) | Gigabit Ethernet (1000 Mbit/s) |
| Digital I/O | 12-pin M12 connector for power and I/O: 3 opto-isolated inputs (LINE0/1/2 input), 3 opto-isolated outputs (LINE3/4/5 output), 1× RS-232 interface; Device trigger via top button supported | 12-pin M12 connector provides power and I/O, including opto-isolated input × 3 (Line 0/1/2), opto-isolated output × 3 (Line 3/4/5), RS-232 × 1 |
| Price | $1,809.00 | $1,629.00 |
All 2 share: Power supply 24 VDC; Humidity 20% RH to 95% RH (no condensation); Certification CE, KC. Values as printed in each product's data sheet; open a part for its drawing and full specifications.
The MV-SC3050XC-16M-ATN-H is a 5 MP color vision sensor on Fast Ethernet; the MV-SC5060XM-08M-WBN is a 6 MP mono smart camera on GigE. Both take routine-select commands over their Ethernet link, so for this task the deciding spec is how many free input lines the family offers on its connector — filter the camera finder by interface and series to compare. When the routines outgrow the camera, move them to a controller: the MV-SVC2506-16G60-128G separates 4 camera GigE ports, 1 configuration GigE port and 1 communication GigE port, so routine control never shares a link with image traffic. If your device brings I/O out on a dedicated connector rather than the Ethernet jack, whether you need a camera GPIO cable settles the wiring question.
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 2 USB 3 ports
- Light outputs
- 4 built-in channels
- Memory
- 16 GB
How do you map the input line to a routine?
Wire the contact between +24 V and the input, then select that line in the device's I/O configuration — on a GenICam camera the LineSelector parameter picks it — and assign it as the routine- or job-select source on the logic configuration page. That page is where most smart cameras and vision controllers keep the mapping between physical lines and on-board jobs.
- With the input circuit dead, land the button between +24 V and the input terminal, and the input common on 0 V.
- Power up and confirm the line reads closed when pressed; if it reads inverted, flip the polarity setting for that line instead of rewiring.
- In the I/O configuration, select the input line (the LineSelector parameter on a GenICam camera) and set its filter to 20 ms.
- In the logic configuration, map the line to the job- or routine-select input; most devices put this on the I/O or communication page of their configuration tool.
- Map one user-settable output line to the active routine number, so the press is confirmed back to the PLC or panel lamp.
- Save to the device's permanent job storage and cycle power once; repeat the press test after the reboot.
N select bits address 2^N routines. One input line is two routines, two lines give four, three give eight — the practical ceiling for physical selection, because on a small connector one line is usually already the trigger.
The output echo in step 5 is not decoration. A start or switch that nobody acknowledges is the classic half-configured cell, and vision project start-stop handshake troubleshooting covers the failure patterns that follow.
How much debounce and latency should you plan for?
Set the debounce filter to 20 ms — twice the worst bounce of a snap-action contact — and expect a worst-case switch 65 ms after the press in a 5 ms scan, 40 ms inspection-cycle system, computed below.
Worked example — these are example inputs; your scan and cycle replace them, the arithmetic does not change:
- Bounce: a snap-action contact settles inside 10 ms, so the filter takes 20 ms, a 2× margin.
- Detection: 20 ms filter + 5 ms logic scan = 25 ms worst case.
- Application: the select bit latches at the next inspection start, adding up to 40 ms: 25 + 40 = 65 ms worst case, about 45 ms typical.
- Throughput check: a 40 ms cycle is 1 / 0.040 s = 25 inspections per second, so the new routine is live by the second inspection after the press.
The serial path on the same inputs: an 8-byte select frame at 115200 baud in 8N1 carries 80 bits, and 80 / 115200 = 0.69 ms on the wire. At 9600 baud the same frame takes 80 / 9600 = 8.3 ms. The wire is never the bottleneck; a host polling results every 100 ms adds up to 100 ms before your command is even written. The GPIO path is the deterministic one because its numbers are fixed by your filter and scan, not by software queues.
How do you do the same switch over serial?
Send a short framed command — address, opcode, routine number, checksum — at 115200 baud 8N1, and treat the reply as part of the command: the 8-byte frame spends 0.69 ms on the wire, so distance and host software set the real delay, not the cable speed.
Keep the frame fixed-length, give each routine its own opcode, and always answer — a NAK on a bad checksum, never silence. ASCII hex frames are slower but readable on any bus sniffer, which pays for itself on commissioning day. Distance sets the physical layer: RS-232 is comfortable to about 15 m, while the differential pair of RS-485 reaches about 1200 m and lets several devices share one bus. On a GigE device, skip serial and send the same opcode over TCP; for the camera-side half of a real serial port — routing a UART through an opto-isolated GPIO block — configuring a camera serial UART on opto-isolated GPIO covers the pin mapping.
When commands land and nothing answers, the causes are almost always the station address, the parity or the line ending. Barcode scanner serial trigger diagnostics runs that checklist for host-to-reader commands, and fixed barcode reader trigger modes shows where a hardware trigger line replaces the command entirely.
How do you verify the switch works?
Force the input closed with a jumper at the terminal block and confirm three things: the line status changes, the active routine number changes exactly once per press, and the results stream reports the new routine's counts.
- Bounce: press the button 20 times quickly; the routine must change 20 times, never 21. A 21st change means the filter is short for that contact — raise it before production.
- Wiring loss: unplug the pair. The logic should alarm on an open line instead of silently holding the last routine.
- Power: cycle the device. A mapping that lives only in the configuration session is the most common commissioning surprise.
- Serial: flip one bit in a frame's checksum and send it. The device must reject the frame and say so; a device that acts on a corrupt frame will one day act on noise.
- Results: watch the per-routine counts wherever the cell logs them; reading smart camera results over OPC UA is the usual path back to the PLC.
What usually goes wrong with a second routine?
Three failures cover most of them: the second routine inherits the first one's exposure settings, the lighting does not change with the routine, and the select bit is read mid-inspection so a press swaps the routine under a running part.
Exposure first: give each routine its own exposure, gain and threshold set. A routine that borrows another's exposure produces marginal images of the same part, and the defect looks like lighting when it is configuration.
Lighting next, because the second routine usually needs different light. A controller with built-in channels switches them with the job: the MV-VC3301H-128G66 drives 4 built-in light channels alongside its inspection logic. On a smart camera without light outputs, put a separate unit between a camera output and the lights: the LS-CTL-0322 offers 4 channels with 8 A total output on a 16-24 V bus, enough for the light sets of both routines. Browse light controllers for the full range, and see triggering strobe lighting from robot IO for driving the switching output from a cell controller.
- Output
- Constant voltage 24 V
- Channels
- 4 channels
- Control
- Digital
The line conflict is the last of the three: if every input is taken, the trigger line is not automatically a spare. Using camera trigger lines as digital outputs when space is short explains when a line can double up and when it cannot.
When is GPIO the wrong choice?
Choose serial or TCP when any of these hold: more than eight routines (three select lines is the practical ceiling), switches that carry dozens of parameters, cable runs past 15 m, or an audit trail that needs an acknowledged command.
The decision by case:
- Two to eight routines, a button or relay within a few metres, one free input line: GPIO with a 20 ms filter. Wire it, map it, test it in an afternoon.
- The switch changes exposure, thresholds and lighting together: send a recipe command over TCP or serial. One bit cannot carry a recipe.
- The button lives on another panel or far from the device: RS-485, or land the button on the PLC and let the PLC command the camera.
- A host program already starts your inspections: fold the routine choice into that program — starting an inspection automatically from a custom program is the pattern, and smart camera LabVIEW integration shows the results side of the same setup.
To assemble the whole cell — camera, controller, lights and the I/O that ties them — start at the configurator:
The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.
For wiring questions on a specific device, use the contact page.
Questions
Can a single input line select more than two routines?
Not directly: one line is one bit, so it holds two states. Two ways past it: add lines (two inputs give four routines, three give eight) or encode states in time — a press under 500 ms selects routine 2, a press held past 1 s selects routine 3, both timed with the same 20 ms debounce. Time encoding costs you the instant-read simplicity, so add a line before you encode.
Is it safe to wire the button while the line is running?
The 24 V DC input circuit is low energy — a few mA through an optocoupler — so the hazard is not shock but your screwdriver shorting 24 V into a signal common. Power the input down before changing wiring for that reason alone, and keep AC line voltage off that terminal block entirely: an isolated DC input is field wiring, not mains wiring.
Why does the new routine start one part late?
Because the select bit latches when an inspection starts, a press mid-cycle waits for the next cycle boundary — up to one full inspection period on top of the debounce. To switch inside one part pitch, latch the bit on the frame-trigger edge instead of a free-running scan, or have the PLC issue the switch during the inter-part gap where no exposure is open.
Can the same link carry results and routine commands?
Yes, when the link is full duplex — TCP over GigE, or RS-232 with separate TX and RX. At 115200 baud an 8-byte command occupies the wire for 0.69 ms, so a 100 ms result poll and an occasional select command do not collide. Keep them in separate handlers, though: a loop that blocks waiting for result packets will delay your command write by up to one poll period.
My button sits 30 m from the camera — GPIO or serial?
Serial, over RS-485. RS-232 is comfortable to about 15 m, and a 30 m run of single-ended 24 V signaling picks up induced noise from drives and contactors that a 20 ms filter hides but cannot remove. RS-485's differential pair runs to about 1200 m, and several devices can share the bus. The alternative is mounting the button at the controller and letting its I/O relay the selection.

