The Modbus TCP transaction identifier associates a response with its request. A correct match proves that the messaging layer returned the response to the expected transaction context. It does not prove that the client requested the right register, interpreted the bytes with the right data type, or read a value that is current and safe to use.
This distinction matters when a robot gateway or PLC has several outstanding reads. Transport correlation can be perfect while the application quietly applies pressure data as velocity, treats an unsigned count as signed, or accepts a stale register value.
What the identifier does
The MBAP header carries a 16-bit transaction identifier. The official Modbus TCP implementation guide says the client uses it to associate a future response with the request and that it must be unique among simultaneous transactions on a connection. The server returns the value associated with the original request.
A client may increment a counter or use the value as an index into stored transaction context. That context should include more than a callback address. Preserve server connection, unit identifier, function code, starting address, quantity, issue time, expected response form, and application destination.
On response, first find the pending transaction using the connection and transaction identifier. Then verify the rest of the protocol and application contract.
Check the complete MBAP and PDU
Validate the protocol identifier, length field, unit identifier where routing makes it meaningful, function code, byte count, and exception form. A matching transaction ID with an impossible length or wrong function response is not acceptable.
For a read of multiple registers, confirm that the returned byte count matches the requested quantity. For a write, verify the echoed address and value or quantity required by that function. Release the pending transaction context only after the response is accepted or conclusively failed.
Do not reuse an identifier while its earlier transaction can still return. A late response can otherwise match a new request with the same identifier. Bound the number of simultaneous requests to client, server, gateway, and TCP-window capacity.
Correlation is not data modeling
Modbus defines 16-bit registers and function behavior. The device model defines what a particular address means. The model must state register table, zero-based protocol address versus human-facing reference, access, data type, word order, scaling, units, validity bits, update behavior, and firmware applicability.
If the transaction context says holding registers 120 through 121 contain a signed 32-bit encoder count with a documented word order, the decoder must apply exactly that contract. The transaction ID cannot detect an off-by-one address or a wrong map version.
Treat a syntactically valid value as untrusted until semantic checks pass. Confirm range, units, quality flags, mode, and consistency with related registers.
Gate side effects carefully
A read response should update only the data item named by its original transaction context. Never route by arrival order when several transactions are outstanding.
For writes, a normal protocol response shows that the server processed the Modbus function according to its implementation. It does not prove the robot physically executed a command. Device state, interlocks, local control tasks, and actuator feedback remain separate.
Require application acknowledgement or physical feedback for consequential work. An echoed write value is not a motion-complete receipt.
Design the pending table
Store one immutable record per outstanding request: connection generation, transaction ID, unit ID, function, address range, issued timestamp, deadline, decoder version, and destination signal. Mark completion once.
Use a connection-generation value so responses from an old TCP session cannot be applied after reconnect. Clear or quarantine pending requests when the socket closes. Reissue only according to an explicit idempotency policy.
Log unknown, duplicate, late, and mismatched responses. Do not silently discard them without metrics; they reveal identifier reuse, gateway delay, retry races, or implementation defects.
Test out-of-order responses
Send several independent reads without waiting for each response where the server supports it. Delay and reorder replies in a test proxy. Confirm that each response updates the application item named by its transaction context, not the next item in a queue.
Inject a response with a correct transaction ID but wrong function code, byte count, or unit ID. The client must reject it. Inject a correct protocol response containing a value outside the declared engineering range. The semantic validator must reject or flag it separately from a transport failure.
Test identifier wrap and reconnect. Use a small artificial identifier space to force reuse while ensuring no live context is overwritten. Deliver a delayed response from the previous connection and verify that connection generation prevents acceptance.
Separate error categories
Report correlation failure, protocol-format failure, Modbus exception, timeout, semantic decode failure, stale data, and physical non-execution as different conditions. They lead to different recovery actions.
A correlation failure suggests client/server or gateway messaging trouble. An illegal data address exception suggests map or device-state issues. A semantic range failure can mean the wrong decoder, bad sensor data, or a legitimate extreme. Combining them into communication error destroys evidence.
Protect freshness
The response timestamp shows when data arrived, not necessarily when the device measured it. Some registers update on a scan, latch, snapshot, or event. Use device-defined sequence counters, timestamps, validity flags, or paired reads when available.
Polling the same register faster does not make its underlying measurement newer. Record the source update contract beside the request interval.
Secure the wider path
Classic Modbus TCP does not make transaction IDs authentication or integrity tokens. They are short correlation fields and predictable use is normal. Where the threat model requires protection, use the Modbus Security protocol or another approved secured architecture, network segmentation, identity controls, and authorization.
State the evidence precisely
A defensible record says that a response matched a live transaction on a named connection, passed MBAP and PDU validation, decoded under a versioned register map, met semantic and freshness checks, and—if needed—was confirmed by device or physical feedback.
The transaction identifier solves one essential problem: which request owns this response. It cannot answer whether the request was correct or the returned register value means what the robot software thinks it means.