Explainer
Why Snap7 reads of S7-1200 inputs give no change callback
Short answer
Nothing on the PC-to-S7-1200 link can call back when the robot changes an input: a Snap7 read returns a snapshot of the process image and ends, and the S7 protocol defines no unsolicited message from CPU to client in that role. Poll and compare, or move change detection into the PLC program. At a 5 ms transaction for a sub-222-byte read, a 50 ms poll detects a change within 30 ms on average and 55 ms at worst.
On this page
Nothing on the link between a PC and an S7-1200 can notify your application when the robot writes new input data. A Snap7 read returns a snapshot of the CPU's process image, and the transaction ends there: the protocol defines no unsolicited message from the CPU to a client in that role, so no event exists for a callback to attach to. The robot's PROFINET updates reach the process image whether you read them or not, which means the notification your DeviceNet layout gave you does not survive the move and must be rebuilt. Rebuild it one of two ways: poll the input area and compare every answer against the last good one, or move change detection into the PLC program and deliver the event to the PC by another route. This article gives the permission the CPU needs first, the arithmetic that sizes the loop, and the decision for each robot behavior.
What a Snap7 read actually delivers #
Trace the data to see where the notification disappears. The robot controller writes its status data to its PROFINET outputs; the cyclic PROFINET exchange carries those bytes to the CPU, and the CPU holds them in its process image of inputs. Your read transaction copies out whatever that image holds at the instant the CPU serves the request, and the transaction is finished. Nothing in that exchange registers interest: no subscription is created, nothing is queued, and no message leaves the CPU that you did not ask for.
A callback is a function in your own application that the client library invokes when an event arrives. In the client role Snap7 plays here, every message on the wire starts at the PC, so the library has nothing to invoke a callback with. The GSDML import, the module configuration and the link lights establish the robot-to-CPU relationship; none of them installs an event listener in the PC. Two consequences follow. The CPU can hold newer input data than your application has seen, bounded only by the CPU's own update cycle, and your application learns of a change no earlier than its next read.
The permission a read needs on the CPU #
Before the first read succeeds, the CPU's hardware configuration has to allow unsolicited access. In TIA Portal, open the CPU's Device configuration, Properties tab, Protection & Security, and enable the checkbox that permits access with PUT/GET communication from remote partner; on newer versions it sits under Connection mechanisms. The setting takes effect when the hardware configuration is downloaded to the CPU. Without it, the CPU refuses reads that arrive unsolicited from a remote client, no matter how healthy the link lights look.
That checkbox is the same class of decision every unsolicited client meets: a Modbus TCP server carries its own version of the gate, spelled out in what you must configure on the PLC side for Modbus TCP. Enable it deliberately. It admits reads and writes from any partner that can reach the CPU, so the network around the CPU decides who gets to use it.
Sizing the poll-and-compare loop #
Poll and compare is three steps: send the read, check the result, and compare each successful answer byte for byte against the previous successful answer. A failed read updates nothing and triggers no comparison. Keep one persistent connection for the life of the application instead of reconnecting per poll, because the setup costs more than the read itself.
The transaction sets the scale. This CPU negotiates a 240-byte protocol data unit, and after the protocol headers that leaves 222 bytes of data per read request, so the roughly 100-byte input area a robot gateway like this maps travels in a single request. Plan on about 5 ms for one sub-222-byte read transaction on a lightly loaded link. Treat that as a planning figure, not a guaranteed response: it moves with network load, CPU load and any reconnect per read, so time ten consecutive reads on your hardware and size the loop around the middle of your own distribution.
Worked example, with the input area at 100 bytes and a 50 ms poll interval:
- Polls per second: 1000 ms / 50 ms = 20.
- Link occupancy: 20 × 5 ms = 100 ms of transaction time per 1000 ms, so the loop keeps the link 10% busy.
- Detection latency: on average half an interval plus one transaction, (50 ms / 2) + 5 ms = 30 ms; worst case a full interval plus one transaction, 50 ms + 5 ms = 55 ms.
- Tighter loop at a 20 ms interval: 1000 ms / 20 ms = 50 polls per second, 50 × 5 ms = 250 ms per 1000 ms = 25% occupancy, worst-case detection 20 ms + 5 ms = 25 ms.
The poll interval is the floor on detection latency: the robot and the PROFINET update can both be faster than your loop, and nothing on the CPU side lowers that floor. The loop itself runs unattended for the life of the machine on a computer in the cabinet next to the CPU, and for gateway duty like this the usual host is an industrial mini PC rather than an office desktop.
Pulses, latches and the change counter #
Comparison sees state, not history. A status bit that switches on and off between two consecutive reads produces two identical snapshots, and no comparison flags a change it never observed. Set the poll interval to no more than half the shortest pulse your logic must catch; when a pulse can be shorter than that, retention in the PLC program is the only fix.
The retention pattern is a few rungs of logic: keep a copy of the input bytes, compare it with the fresh image every scan, and on any difference latch the affected bit into a retained area or increment a change counter. The PC then polls the retained word instead of the whole area, a few bytes per poll, and reads the full input area once, when the counter moves. Detection resolution moves from the poll interval to the PLC scan, which runs in milliseconds on this class of CPU, and the counter doubles as a miss detector: if it has advanced further than the changes you processed, you lost one.
Pushing the change instead of polling it #
When several applications need the change, or the requirement is written as a subscription, put an event-delivering protocol between the CPU and its clients. Where the CPU's firmware provides an OPC UA server, a subscription delivers every input change to the client as it happens, which is the subscribe-don't-poll behavior described in why OPC UA clients should subscribe instead of polling batched reads.
The older OPC DA equivalent pushed changes too, but every subscription rode on DCOM callbacks, which is why OPC DA subscribe failures caused by DCOM callback configuration tend to fail silently rather than with a clear error.
A middle path stays inside the S7 protocol: let the PLC do the detecting with the latch or counter from the previous section and treat the retained word as the event source. You then poll a few bytes at a high rate instead of the whole area, and the PLC guarantees that nothing between polls is invisible.
One owner for the command bytes #
The write direction has its own trap. The PC sets command bits in the CPU's output area and PROFINET copies them to the robot; if the PLC program also writes those bytes every scan, the scan wins and the PC's command vanishes within one scan. Give every output byte exactly one owner. Where the PLC logic must keep writing the area, the PC writes a separate command buffer and the PLC copies it under its own control; where the PC owns the area, the PLC treats it as read-only. It is the same ownership rule that keeps writes to PLC output registers from SCADA safe.
The decision for each case #
Nothing in this architecture can be made to call back, so decide case by case how each change gets detected:
- Whole-cycle robot: the program runs a cycle and reports a done flag. Poll and compare at the slower interval from the example; the flag persists until your application consumes it, and the loop leaves the link 90% idle.
- Interactive robot: handshakes run stage by stage, each stage 100 ms or longer. Tighten to the 20 ms interval from the example, which is 25% occupancy and worst-case detection 25 ms. Time your own transactions first, and if a measured transaction runs past a quarter of the interval, reduce the load before shrinking the interval further.
- Short pulses possible: any status pulse shorter than twice the poll interval can vanish between two reads. Poll-and-compare cannot see it, so move detection into the PLC scan with the latch or change counter and poll the retained word.
- Several consumers, or a requirement written as a subscription: serve the inputs over OPC UA and let clients subscribe instead of any client polling.
And if the requirement document says callback, rewrite it as detection latency: the numbers above are the requirement that actually matters.
Questions asked
Does the same snapshot behavior apply when the PC reads a data block instead of the input area?
Yes. Any read this CPU serves over the S7 protocol returns the bytes you asked for at the instant the transaction completes, whether the area is a data block or the process image of inputs. The gap is a property of the client-initiated read, not of the address range, so a different area changes the payload and never the delivery model.
Does permitting PUT/GET access leave the CPU open to any device that can reach it?
Yes, for both reads and writes, so pair the checkbox with segmentation: keep the CPU on a network where only the engineering station and this gateway PC can reach it, and use the CPU's protection levels to restrict who can change the program. The checkbox opens the protocol gate; the network decides who reaches it.
Can the PC write the command bits inside the same transaction as the read?
No. Reads and writes are separate transactions in this protocol, so a write adds its own transaction time to the loop. Put the command write on its own schedule instead of riding along with every poll: commands rarely change while the read loop runs at its fixed interval, and keeping them apart leaves the measured poll time honest.
Can a second PC run its own read loop against the same CPU?
Yes. Each client needs its own connection, and each connection takes one of the CPU's connection resources, so keep one persistent connection per client rather than reconnecting per poll. Run the same compare logic independently in each client: each compares against its own previous answer, so one slow client never delays another's detection.