BT San Technology

26 February 2026

Jetson talking to a PLC: designing request, result, acknowledge and timeout

26 min read · Machine vision

Illustration: a camera over a part, an AI box, an Ethernet switch, a PLC and a stack light
AI-generated illustration

The problem we see most often when connecting AI inspection to a PLC is not that the model is not accurate enough. It is timing: the result arrives so late that the part has already passed the reject point, the result of the previous part is still sitting in a register and the PLC applies it to the next part, or the vision machine restarts mid-cycle and neither side knows which step the other is on. This article shows how to design a handshake between a PLC and a vision machine (for example a Jetson) so that each of these cases has an answer decided in advance, with an example program that actually runs on standard Python alone.

The example program is a simulation on a single machine (127.0.0.1) to show the idea and the order of events. It is not production code and is not connected to a real PLC. All timing numbers in the article are values we set ourselves or actual results from running this example, not figures from anyone's production line. The factory scenarios used as examples are hypothetical.

The real problem: results that arrive late or for the wrong part

Picture a line where the PLC tells the camera to photograph a part and then waits for an OK or NG result. The simplest approach is a single bit called OK: if it is 1, let the part through; if it is 0, reject it. This breaks in at least three ways.

  • Stale result: the OK bit from the previous part is still 1 while this part has not been inspected yet. The PLC reads 1 and lets the part through, although nobody has inspected it.
  • Late result: the model takes longer than usual, and the result arrives after the part has passed the reject point. The PLC cannot tell which part this result belongs to.
  • Nobody knows whether the other side is still alive: the vision machine hangs or restarts and the PLC waits forever, or the reverse, the PLC stops while the vision machine keeps processing with nobody to receive the result.

The fix is to send not just the result but the result with its context (a sequence number issued by the PLC), and to have both sides confirm each step to each other in turn (a handshake). Every step has a timeout that defines who does what when time runs out. There are three key principles.

  1. The PLC owns the sequence of operations. The vision machine only works on request.
  2. Every result carries a sequence number issued by the PLC, which the vision side echoes back. The PLC uses a result only when the number matches the current cycle.
  3. Every wait has a timeout, and what happens on timeout must be a policy written into the spec, not something the programmer guesses at while writing code.

Designing the handshake: register map and step order

This example uses Modbus TCP because many PLCs support it, and its structure is simple enough that the whole protocol can be read in 80 lines. The PLC side is the provider (server) and holds the holding registers. The vision side is the client that reads and writes those registers. The space is split in two: the part only the PLC writes and the part only the vision side writes, so that the two sides never overwrite the same register.

RegisterNameWriterMeaning
0CTRLPLCbit0 = REQ (request inspection), bit1 = ACK (result received)
1PART_IDPLCPart number (or recipe code)
2SEQPLCCycle number, incremented by 1 on every request
3PLC_HBPLCPLC heartbeat, keeps incrementing
10STATUSVisionbit0 = BUSY (inspecting), bit1 = DONE (result ready)
11RESULTVision0 = none yet, 1 = OK, 2 = NG, 100 and above = vision-side error code
12SEQ_ECHOVisionEchoes the cycle number this result belongs to
13VIS_HBVisionVision heartbeat
Register map for the example (made up for explanation, not a standard). On a real system, agree with the PLC team which data block or device each register maps to.
regs.py · lines 1–9
"""Register map shared by both sides. Holding registers live in the PLC (Modbus server)."""
# PLC -> vision (written by PLC)
CTRL, PART_ID, SEQ, PLC_HB = 0, 1, 2, 3
REQ, ACK = 0x1, 0x2          # bits in CTRL
# vision -> PLC (written by vision PC)
STATUS, RESULT, SEQ_ECHO, VIS_HB = 10, 11, 12, 13
BUSY, DONE = 0x1, 0x2        # bits in STATUS
R_NONE, R_OK, R_NG = 0, 1, 2  # RESULT; >= 100 means vision-side error code
SIZE = 16
regs.py: the register map constants, shared by both sides

The handshake step by step

StepWhoWhat it doesIf it does not happen as described
1PLCWrites PART_ID and SEQ first, then sets REQ=1None (the order "data before the request bit" means the vision side never reads a half-written state)
2VisionSees REQ and a new SEQ, sets BUSY=1PLC waits for the result timeout
3VisionInspects (simulated), then checks again that the PLC is still waiting for this cycleIf the PLC has stopped waiting, the vision side discards the result and does not write it
4VisionWrites RESULT and SEQ_ECHO (a single FC16 write), then sets DONE=1 lastThe PLC sees DONE only when the result is ready
5PLCSees DONE and SEQ_ECHO equal to SEQ, reads the result, decides, then sets ACK=1If the echo does not match, it is a stale result: do not use it, keep waiting
6VisionSees ACK, clears DONE and BUSYIf it does not see ACK within the done timeout, it clears them itself and logs the event
7PLCSees DONE go low, clears REQ and ACK, ending the cycleIf DONE does not go low, resend ACK once, then raise a fault
Every step is a state change that the other side can see, so you can trace afterwards where it got stuck.

Two subtle points make this sturdier than a single OK bit. The first is writing DONE last, after the result and the echo are in the registers, because a PLC that sees DONE reads the result immediately. The second is reading CTRL, PART_ID, SEQ and PLC_HB with a single FC03 command over four consecutive registers. The vision side then gets a consistent snapshot and never sees a new REQ mixed with an old SEQ.

Timeouts at every step and the policy when time runs out

Timeouts must be set from the machine's cycle time, not as numbers that merely look reasonable. This example uses values we set ourselves so the simulation runs fast. On a real line you need to measure the actual inspection time and add a margin, which should be an item in commissioning.

TimeoutValue in the example (self-set)Who waitsOn timeout
result timeout300 msPLC waits for DONEPer policy: reject (treat as NG) or stop the line, then clear REQ
ack timeout150 msPLC waits for DONE to go lowResend ACK once; if DONE still does not go low, raise an ACK fault
done timeout250 msVision waits for ACKVision clears DONE/BUSY itself and logs the event
vision heartbeat150 ms with no changePLCSet vision-lost status, used for the next cycle's decision and for alerts
PLC heartbeat200 ms with no changeVisionDo not start new work until the heartbeat returns
All values are set only to make the example run fast and are not recommended values. See the Timeline in the run output.

The most important line in the table is the first one: when the vision side does not answer, what must the PLC do? The example makes this a parameter, on_timeout, with two values.

  • reject: treat the part as failed. It is rejected and the line keeps running. This suits cases where a defect reaching the customer costs more than rejecting one good part.
  • stop: stop the line and raise an alarm. This suits cases where repeated timeouts mean the inspection system is really broken, not that a single part was slow. Rejecting continuously would hide the problem.

A common approach is a mix: reject the part that timed out and count it, and if more than N timeouts occur in a row, stop the line. The example code does not implement this counter, so it is something to agree on and write when building the real system.

The example code, part by part

Minimal Modbus TCP with struct and asyncio

Modbus TCP wraps the command (PDU) in a seven-byte MBAP header: a two-byte transaction id, a two-byte protocol id (always 0), a two-byte length (counting the one-byte unit id plus the PDU), and a one-byte unit id. The details are in the Modbus Messaging Implementation Guide, referenced at the end of the article. The adu function below builds this header, and handle_pdu answers FC03 (read holding registers), FC06 (write a single register) and FC16 (write multiple registers), with exception 1 for an unsupported function and exception 2 for an address out of range.

modbus.py · lines 8–34
def adu(tid: int, pdu: bytes) -> bytes:
    # MBAP: transaction id, protocol id (0), length = unit byte + PDU, unit id
    return struct.pack(">HHHB", tid, 0, len(pdu) + 1, UNIT) + pdu


def handle_pdu(regs: list[int], pdu: bytes) -> bytes:
    fc = pdu[0]
    try:
        if fc == 3:
            addr, n = struct.unpack(">HH", pdu[1:5])
            if not (1 <= n <= 125 and addr + n <= len(regs)):
                raise IndexError
            return bytes([3, 2 * n]) + struct.pack(f">{n}H", *regs[addr:addr + n])
        if fc == 6:
            addr, val = struct.unpack(">HH", pdu[1:5])
            regs[addr] = val
            return pdu[:5]
        if fc == 16:
            addr, n, nbytes = struct.unpack(">HHB", pdu[1:6])
            if not (1 <= n <= 123 and nbytes == 2 * n and addr + n <= len(regs)):
                raise IndexError
            regs[addr:addr + n] = struct.unpack(f">{n}H", pdu[6:6 + nbytes])
            return pdu[:5]
    except (IndexError, struct.error):
        return bytes([fc | 0x80, 2])  # illegal data address
    return bytes([fc | 0x80, 1])  # illegal function
modbus.py: framing and the server-side command handler (the simulated PLC side)

The client sends one request at a time per connection and checks that the transaction id in the reply matches the one it sent. It uses asyncio.Lock so that two jobs (reading registers and sending the heartbeat) never send over the same socket at the same time. This is a bug you can really hit when several tasks share a single stream.

modbus.py · lines 62–83
    async def _call(self, pdu: bytes) -> bytes:
        async with self.lock:
            self.tid = (self.tid + 1) & 0xFFFF
            self.w.write(adu(self.tid, pdu))
            tid, _, length, _ = struct.unpack(">HHHB", await self.r.readexactly(7))
            resp = await self.r.readexactly(length - 1)
        if tid != self.tid:
            raise IOError("transaction id mismatch")
        if resp[0] & 0x80:
            raise IOError(f"modbus exception {resp[1]}")
        return resp

    async def read(self, addr: int, n: int) -> list[int]:  # FC03
        resp = await self._call(struct.pack(">BHH", 3, addr, n))
        return list(struct.unpack(f">{n}H", resp[2:2 + resp[1]]))

    async def write(self, addr: int, value: int):  # FC06
        await self._call(struct.pack(">BHH", 6, addr, value))

    async def write_many(self, addr: int, values: list[int]):  # FC16
        n = len(values)
        await self._call(struct.pack(f">BHHB{n}H", 16, addr, n, 2 * n, *values))
modbus.py: the vision-side client. read = FC03, write = FC06, write_many = FC16

PLC side: owns the sequence, decides on timeout

The inspect method simulates a PLC program block that runs one inspection cycle. It increments SEQ, writes the data first and then sets REQ, then waits for a DONE whose echo matches the cycle. If it sees a DONE with a non-matching echo, it logs it as a stale result and does not use it. If time runs out, it decides according to the on_timeout policy and clears REQ. At the ACK step, it resends once if the vision side does not release DONE.

plc.py · lines 38–69
    async def inspect(self, part_id: int) -> str:
        r, self.seq = self.regs, (self.seq + 1) & 0xFFFF or 1
        seq = self.seq
        r[PART_ID], r[SEQ] = part_id, seq          # data first ...
        r[CTRL] = REQ                               # ... then the request bit
        self.tl.add("PLC", f"part {part_id} seq {seq}: REQ=1")
        stale = []
        def done():
            if r[STATUS] & DONE and r[SEQ_ECHO] != seq and not stale:
                stale.append(1)
                self.tl.add("PLC", f"ignore stale DONE (echo {r[SEQ_ECHO]} != seq {seq})")
            return bool(r[STATUS] & DONE and r[SEQ_ECHO] == seq)
        if not await self._wait(done, self.result_timeout):
            r[CTRL] = 0
            d = "REJECT(timeout)" if self.on_timeout == "reject" else "STOP_LINE(timeout)"
            self.tl.add("PLC", f"no result in {self.result_timeout*1000:.0f} ms -> {d}, REQ=0")
            return d
        res = r[RESULT]
        d = {R_OK: "OK", R_NG: "NG"}.get(res, f"REJECT(error {res})")
        self.tl.add("PLC", f"result {res} for seq {seq} -> {d}; ACK=1")
        r[CTRL] = REQ | ACK
        if not await self._wait(lambda: not r[STATUS] & DONE, self.ack_timeout):
            self.tl.add("PLC", "vision still DONE -> pulse ACK again")
            r[CTRL] = REQ
            await asyncio.sleep(0.02)
            r[CTRL] = REQ | ACK
            if not await self._wait(lambda: not r[STATUS] & DONE, self.ack_timeout):
                self.tl.add("PLC", "ACK FAULT: vision never released DONE")
                d += "+ACK_FAULT"
        r[CTRL] = 0
        self.tl.add("PLC", "REQ=0 ACK=0, cycle closed")
        return d
plc.py: one PLC-side inspection cycle with timeout, stale guard and ACK retry

Vision side: answer on request, and never write a result nobody is waiting for

The vision side watches for the rising edge of ACK, because ACK is the single confirmation for that cycle. After inspecting, it reads CTRL again before writing the result. If the PLC has already cleared REQ or moved on to a new cycle, nobody is waiting for this result, so it discards it. This step is the first line of defense against stale results. The second is the SEQ_ECHO check on the PLC side.

vision.py · lines 51–80
    async def handle(self, part, seq):
        c = self.c
        await c.write(STATUS, BUSY)
        self.tl.add("VISION", f"REQ seen part {part} seq {seq}: BUSY=1")
        await asyncio.sleep(self.delay(part))               # the real model would run here
        ctrl, _, now_seq, _ = await c.read(CTRL, 4)
        if not ctrl & REQ or now_seq != seq:                 # PLC gave up: do not answer
            self.tl.add("VISION", f"too late for seq {seq} (PLC moved on): discard")
            await c.write(STATUS, 0)
            self.last_seq = seq
            return
        await c.write_many(RESULT, [simulated_inspect(part), seq])  # FC16: result + echo
        await c.write(STATUS, BUSY | DONE)                   # DONE last
        self.tl.add("VISION", f"result written, echo seq {seq}: DONE=1")
        end, was_ack = asyncio.get_running_loop().time() + self.done_timeout, False
        while asyncio.get_running_loop().time() < end:
            ack = (await c.read(CTRL, 1))[0] & ACK
            if ack and not was_ack:                          # act on the rising edge
                if self.drop_acks:
                    self.drop_acks -= 1
                    self.tl.add("VISION", "(ACK pulse lost on the link)")
                else:
                    self.tl.add("VISION", "ACK seen: DONE=0 BUSY=0")
                    break
            was_ack = bool(ack)
            await asyncio.sleep(0.005)
        else:
            self.tl.add("VISION", "no ACK in time: release DONE/BUSY on my own")
        await c.write(STATUS, 0)
        self.last_seq = seq
vision.py: handle() processes one request: set BUSY, inspect, write result and echo, set DONE, wait for ACK

The vision heartbeat is a separate task. While building this example, the author found a real mistake: at first the heartbeat was written in the main loop, so while the model was inspecting for a long time the heartbeat stopped and the PLC declared the vision side dead, when it was only busy. The fix was to split it into its own task and lock this behavior in with a self-check. In a real system where the model runs in a separate process or thread, the heartbeat should come from whatever confirms that the image-inspection process is still working, not just that the main program has not died.

vision.py · lines 28–33
    async def heartbeat(self):
        while True:
            self.hb = (self.hb + 1) & 0xFFFF
            await self.c.write(VIS_HB, self.hb)
            await asyncio.sleep(0.05)
vision.py: the heartbeat as a separate task

Actual run results for every scenario

Run with python3 demo.py on the author's machine on 2026-11-21. Each scenario starts a new server on a random port of 127.0.0.1. The numbers in the left column are milliseconds counted from the start of the scenario. The output was saved to output.txt without manual editing.

output.txt · lines 1–56

=== 1. normal cycles (parts 101, 102, 104) ===
  +   0 ms  VISION up, status cleared
  + 100 ms  PLC    part 101 seq 1: REQ=1
  + 103 ms  VISION REQ seen part 101 seq 1: BUSY=1
  + 225 ms  VISION result written, echo seq 1: DONE=1
  + 228 ms  PLC    result 1 for seq 1 -> OK; ACK=1
  + 230 ms  VISION ACK seen: DONE=0 BUSY=0
  + 233 ms  PLC    REQ=0 ACK=0, cycle closed
  + 233 ms  PLC    part 102 seq 2: REQ=1
  + 235 ms  VISION REQ seen part 102 seq 2: BUSY=1
  + 356 ms  VISION result written, echo seq 2: DONE=1
  + 361 ms  PLC    result 1 for seq 2 -> OK; ACK=1
  + 361 ms  VISION ACK seen: DONE=0 BUSY=0
  + 366 ms  PLC    REQ=0 ACK=0, cycle closed
  + 366 ms  PLC    part 104 seq 3: REQ=1
  + 366 ms  VISION REQ seen part 104 seq 3: BUSY=1
  + 487 ms  VISION result written, echo seq 3: DONE=1
  + 488 ms  PLC    result 2 for seq 3 -> NG; ACK=1
  + 492 ms  VISION ACK seen: DONE=0 BUSY=0
  + 493 ms  PLC    REQ=0 ACK=0, cycle closed
  PLC decisions: ['OK', 'OK', 'NG']

=== 2. vision too slow on part 201 (PLC timeout 300 ms, policy reject) ===
  +   0 ms  VISION up, status cleared
  + 100 ms  PLC    part 201 seq 1: REQ=1
  + 104 ms  VISION REQ seen part 201 seq 1: BUSY=1
  + 400 ms  PLC    no result in 300 ms -> REJECT(timeout), REQ=0
  + 604 ms  VISION too late for seq 1 (PLC moved on): discard
  + 802 ms  PLC    part 202 seq 2: REQ=1
  + 806 ms  VISION REQ seen part 202 seq 2: BUSY=1
  + 926 ms  VISION result written, echo seq 2: DONE=1
  + 929 ms  PLC    result 1 for seq 2 -> OK; ACK=1
  + 931 ms  VISION ACK seen: DONE=0 BUSY=0
  + 935 ms  PLC    REQ=0 ACK=0, cycle closed
  PLC decisions: ['REJECT(timeout)', 'OK']

=== 2b. same, policy stop_line ===
  +   0 ms  VISION up, status cleared
  + 100 ms  PLC    part 201 seq 1: REQ=1
  + 103 ms  VISION REQ seen part 201 seq 1: BUSY=1
  + 401 ms  PLC    no result in 300 ms -> STOP_LINE(timeout), REQ=0
  PLC decisions: ['STOP_LINE(timeout)']

=== 3. first ACK pulse lost ===
  +   0 ms  VISION up, status cleared
  + 100 ms  PLC    part 301 seq 1: REQ=1
  + 104 ms  VISION REQ seen part 301 seq 1: BUSY=1
  + 224 ms  VISION result written, echo seq 1: DONE=1
  + 228 ms  PLC    result 1 for seq 1 -> OK; ACK=1
  + 229 ms  VISION (ACK pulse lost on the link)
  + 379 ms  PLC    vision still DONE -> pulse ACK again
  + 401 ms  VISION ACK seen: DONE=0 BUSY=0
  + 405 ms  PLC    REQ=0 ACK=0, cycle closed
  PLC decisions: ['OK']
Actual output from 2026-11-21 (scenarios 1 to 3). The millisecond numbers can shift on every run because of scheduler jitter, so do not read them as fixed values.
output.txt · lines 57–87
=== 4. vision restart mid-cycle (result timeout 800 ms) ===
  +   0 ms  VISION up, status cleared
  + 100 ms  PLC    part 401 seq 1: REQ=1
  + 104 ms  VISION REQ seen part 401 seq 1: BUSY=1
  + 201 ms  TEST   vision killed while BUSY
  + 355 ms  PLC    vision heartbeat LOST
  + 452 ms  VISION up, status cleared
  + 452 ms  VISION REQ seen part 401 seq 1: BUSY=1
  + 456 ms  PLC    vision heartbeat back
  + 653 ms  VISION result written, echo seq 1: DONE=1
  + 655 ms  PLC    result 1 for seq 1 -> OK; ACK=1
  + 658 ms  VISION ACK seen: DONE=0 BUSY=0
  + 660 ms  PLC    REQ=0 ACK=0, cycle closed
  PLC decisions: ['OK']

=== 5. stale result from a previous part ===
  +   0 ms  VISION up, status cleared
  + 100 ms  TEST   leftover DONE=1, result NG, echo seq 99 in registers
  + 100 ms  PLC    part 501 seq 1: REQ=1
  + 100 ms  PLC    ignore stale DONE (echo 99 != seq 1)
  + 104 ms  VISION REQ seen part 501 seq 1: BUSY=1
  + 225 ms  VISION result written, echo seq 1: DONE=1
  + 228 ms  PLC    result 1 for seq 1 -> OK; ACK=1
  + 230 ms  VISION ACK seen: DONE=0 BUSY=0
  + 233 ms  PLC    REQ=0 ACK=0, cycle closed
  PLC decisions: ['OK']

=== 6. PLC heartbeat stops ===
  +   0 ms  VISION up, status cleared
  + 256 ms  VISION PLC heartbeat LOST -> will not start new jobs
  PLC decisions: []
Actual output from 2026-11-21 (scenarios 4 to 6). The timing numbers can shift from run to run.

Abnormal situations and what the PLC does

1. Vision too slow (scenarios 2 and 2b)

Part 201 is simulated to take 500 ms to inspect while the result timeout is set to 300 ms. In the run output, the PLC sets REQ at +100 and declares a timeout at +400 (300 ms later, as configured), decides REJECT and clears REQ. When the vision side finishes inspecting at +604, it reads CTRL, sees that REQ is low, discards the result and writes no register. The next cycle (part 202) is inspected normally and gets OK. In 2b the policy is changed to stop, and the PLC answers STOP_LINE as soon as time runs out.

Suppose a conveyor with an air-blast reject head at the end. With the reject policy, the part that timed out is blown off along with the NG parts. The result is that one good part is lost in that cycle, but no uninspected part gets through. This example is hypothetical, for explanation.

Caution: if the next part arrives faster than the vision side can release itself from the slow cycle, the following cycles will time out one after another in a chain. This example leaves a 400 ms gap before the next part on purpose. On a real line you must design whether a vision side that is still stuck on the old cycle should drop the old job as soon as it sees a new SEQ.

2. Lost ACK (scenario 3)

The PLC sets ACK at +228, but the vision side is simulated as not seeing this pulse, so DONE does not go low. The PLC waits for the ack timeout of 150 ms, then briefly drops ACK and sets it again at +379. The vision side sees a new rising edge at +401 and finishes the cycle. The result the PLC had already decided on, OK, is not affected. If the resend also fails, the PLC raises an ACK fault and goes on to clear REQ, which is a signal to check the cabling or the vision-side program.

The vision side also has its own done timeout (250 ms in the example), which clears DONE and BUSY when ACK does not arrive, so it does not stay in the DONE state forever. This value is set larger than the PLC's ack timeout so that the PLC gets to retry first.

3. Vision restarts mid-cycle (scenario 4)

The example kills the vision task at +201 while it is BUSY. The run output shows the vision heartbeat lost at +355 (timeout set to 150 ms). The new vision instance comes up at +452, clears all of STATUS first, then sees the same REQ and SEQ still there and starts inspecting the whole part again. The result arrives at +653, the PLC gets OK, and the heartbeat returns to normal. This works because the result timeout in this scenario is set to 800 ms, wide enough for the restart to finish in time. If it were set to 300 ms like the other scenarios, the PLC would reject this part according to the policy, too.

The recovery principle is "the state lives in the PLC." The vision side does not need to remember anything across a restart. It looks at REQ and SEQ and does that job again. The trade-off is that the same part may be inspected twice, which is acceptable when inspection has no side effects.

4. Stale result from the previous part (scenario 5)

The test leaves DONE=1, RESULT=NG and SEQ_ECHO=99 in the registers before the PLC requests inspection of part 501 (seq 1). The PLC sees DONE immediately, but the echo is 99, which does not match, so it logs ignore stale DONE and keeps waiting, until the vision side writes the real result for seq 1 at +225 and the PLC decides OK. If the PLC did not check the echo, this part would be rejected with the NG result of a part that does not exist. This is the same kind of bug as the leftover results found in real systems that use a single bit.

5. Heartbeat stops (scenario 6)

If the PLC stops incrementing its heartbeat, the vision side declares PLC heartbeat LOST at +256 and accepts no new work until the value changes again. In the real world, this pair of heartbeats warns the operator that the link or the program on one side has a problem, before they find out from parts that have already been lost.

Hypothetical factory examples: where this handshake can be used

The three examples below are hypothetical scenarios to show that the timeout policy changes with the job. They are not any customer's project.

Hypothetical scenarioIf vision times outReason
Sorting parts on a conveyor (reject gate)Reject that part and count it. If more than N parts in a row time out, stop the lineA failed part must not flow on, but repeated timeouts mean the inspection system has a problem
Robot pick after inspection (robot pick)Do not pick. Wait or skip the part, and alert the operatorPicking the wrong part risks the part and the machine more than waiting does
Rotary indexing table (indexing table)Do not index until there is a result or the operator confirmsThe table moves all parts to the next station together; if a result does not match its slot, the whole row is wrong
The policy must be agreed with the process owner, not decided by the software team alone.

For an indexing table, SEQ should also be tied to the slot position (for example, by adding a slot-number register) so that the result for the part in slot 3 is not applied to slot 4. This shows that extending the register map to suit the type of machine is normal.

If not Modbus TCP: other options

The structure of the handshake (REQ, BUSY, DONE, ACK, sequence echo, heartbeat, timeout) is not tied to a protocol. What changes is how values are read and written.

OptionStrengths / things to knowStarting point
Modbus TCPSimple and widely supported, but has no timestamp or type built in, so you must agree on the map yourselfpymodbus (Python), or write it yourself as in this example
Siemens S7python-snap7 works directly with S7-300/400. For S7-1200/1500 you must enable PUT/GET in TIA Portal, and optimized data blocks cannot be accessed, as stated in the READMEpython-snap7
Mitsubishi SLMP/MC protocolMitsubishi's protocol over Ethernet, reading and writing the PLC's devices directlySee the manufacturer's SLMP manual for your model
Omron FINSOmron's protocol over Ethernet/UDP or TCPSee the manufacturer's FINS manual for your model
OPC UAHas types, methods, subscriptions and security built in. Suits cases with several systems. Higher setup costasyncua (Python) or open62541 (C)
Digital I/O (hardwired signals)Response is easy to predict and needs no network, but carries only a few bits, so the result must be encoded onto a few wires and a part number cannot be sentWorks when the PLC ties timing to part position itself, for example through an encoder

The Mitsubishi and Omron information in the table is general observation, and the author did not cite a specific link for it. Open the manual for the model you actually use before choosing. Modbus, python-snap7 and OPC UA have verified links in the reference list.

Things to think about when choosing: which PLC brand you use, which protocols are already enabled, whether the electrical team allows the port to be opened, and how much type and data security you need. The safe path is to start from what the existing PLC team can maintain, then change the lower layer while keeping the handshake the same.

Commissioning checklist and common mistakes

  • Agree the register map as a document that both the PLC team and the vision team sign off, including endianness and word order for 32-bit registers.
  • Always write the data first and then set the request bit, and write the result first and then set DONE.
  • Every cycle has a sequence number and the PLC checks the echo before using the result, including when the PLC restarts and starts counting again. Design it so that after a PLC restart, any old REQ is cleared.
  • Measure the real inspection time in both the fastest and the slowest cases, and set the result timeout from the measurement, not from a guess.
  • Decide the timeout policy in writing (reject, stop, or a mix) and have the process owner sign it.
  • Test real faults: unplug the LAN cable, kill the vision process, deliberately slow the model, power-cycle the PLC, and check that the line responds according to the spec.
  • Common mistakes: the heartbeat in the same loop as the inspection work, a single OK bit with no sequence, both sides writing the same register, no timeout at the ACK step, and not clearing the state at program start.

Safety: a vision machine must not be a safety function. Emergency stop (e-stop) and operator protection must go only through a safety PLC, safety relay, or a device certified for safety. The handshake in this article controls part quality. It does not protect people, and the output of a general AI model should not be a condition in a safety circuit.

From example to real system

  • Logging: record every cycle (sequence, part, result, time of each step, outcome of any timeout). The Timeline in this article's example is the format you can use to trace problems on site.
  • Alarm: raise an alarm on heartbeat lost, ACK fault, or consecutive timeouts. Do not let the operator find out from parts that have already escaped.
  • Test with a real PLC: the example code reads and writes at plain numeric addresses of holding registers, and a real system may have an offset of 0 or 1 depending on the brand. Always test with the PLC-side tools first.
  • Timing: the example runs on a single machine and scheduler jitter makes the numbers shift. On a real industrial network you must measure latency and jitter yourself on that network.
  • Jetson side: frame rate and inspection time depend on the model, the power mode and TensorRT, which this article did not measure. Measure on the real board and use the values to set the timeouts (see the NVIDIA Jetson documentation).
  • Self-check: the example folder contains test_handshake.py, which checks the Modbus framing and the behavior of every scenario. Use it to re-test every time you change the step order or the timeouts.

How to run the example: download the jetson-plc-handshake-timeout-result folder and run python3 demo.py to see the Timeline of every scenario, and python3 test_handshake.py to run the self-check, which takes a few seconds. You need Python 3.14 (nearby versions should probably run it). No extra packages need to be installed.

References

  1. Modbus Organization: Modbus specifications (Modbus Application Protocol V1.1b3 และ Modbus Messaging Implementation Guide V1.0b) (accessed 2026-11-21)
  2. pymodbus: Modbus client/server/simulator library for Python (GitHub) (accessed 2026-11-21)
  3. python-snap7: Python library for Siemens S7 PLCs (GitHub) (accessed 2026-11-21)
  4. asyncua (opcua-asyncio): asyncio OPC UA client and server for Python (GitHub) (accessed 2026-11-21)
  5. open62541: open source C implementation of OPC UA (GitHub) (accessed 2026-11-21)
  6. NVIDIA Jetson Software Documentation (JetPack, Jetson Linux) (accessed 2026-11-21)
  7. Python documentation: asyncio Streams (open_connection, start_server) (accessed 2026-11-21)

Add us on LINE

Scan with the LINE app on your phone

QR code to add LINE @Bankoos

LINE ID: @Bankoos

Open LINE on this computer