Problem Overview
The Siemens FB126 PNIODiag function block is supplied with STEP 7 V5.x as the official interface for reading diagnostic data from PROFIBUS Diagnostic Repeaters (DR). In several field deployments — particularly those with an S7-300 CPU fronting an Ethernet CP for HMI traffic — the block returns corrupted distance telemetry. The classic symptom: WinCC Flexible displays a faulty station at 32388 dm (3,238.8 m) when the actual physical distance is on the order of 1.5 m. The status word simultaneously reports "The overflow bit is set in the norm diagnostics! The data is incomplete."
This article documents the failure modes of FB126 on a 315-2 DP / CP 343-1 Lean configuration, isolates the architectural reasons the block fails, and presents two proven alternatives: the SFC51 "Read System Status" approach and the lower-level FB99 FB_READ_DR_CTRL from the Siemens diagnostic repeater library.
Affected Hardware and Software Versions
| Component | Variant in this case | Notes |
|---|---|---|
| CPU | S7-315-2 DP (6ES7315-2AG10 / -2AH14) | Single PROFIBUS DP interface, no second PB port |
| Ethernet CP | CP 343-1 Lean (6GK7343-1CX10) | Used for HMI / WinCC Flexible traffic, not for DR comms |
| PROFIBUS segment | Two Diagnostic Repeaters (6GK1500-0AA00 / -0AB10) | Topology table populated correctly in STEP 7 |
| Engineering | STEP 7 V5.5 + SP4 / HSP update | FB126 v6.x included in standard library |
| HMI | WinCC Flexible 2008 SP5 | Reads DB126 instance DB over Ethernet S7 connection |
| FB in use | FB126 PNIODiag, DB126 instance | Overflow bit set; distance values garbage |
Root Cause Analysis
Three independent root causes converge in this configuration:
- Architectural legacy of FB126. FB126 was originally written two decades ago and patched repeatedly as Siemens added features. Internal scratch buffers, pointer arithmetic, and asynchronous OB1 calls share state with the rest of the user's cycle. Under any unusual cycle load — for example when an Ethernet CP is consuming OB1 time slices for HMI keep-alive — the block's internal handshake state can de-synchronize from the actual diagnostic repeater polling cycle. The overflow bit in the normalized diagnostics is FB126's own error flag, not the DR's.
-
Distance telemetry format mismatch. PROFIBUS DR distance frames are returned in decimeters (dm), not meters. A value of
32388in the FB126 distance word corresponds to3238.8 m, which exceeds the maximum PROFIBUS segment length of 1,200 m and is therefore a sentinel for "invalid / not yet measured" or "overflow". When FB126 fails to capture a valid topology entry, it leaks the previous-cycle or default-max value into the output word. WinCC Flexible multiplies by 0.1 m for display but does not clamp; the result is the absurd distance observed on screen. - Multi-segment DR chaining. Two DRs in series require FB126 to merge two topology lists into one consolidated view. The block was not designed for that case in the original 6GK1500-0AA00 generation and shows inconsistent behavior on chained segments. The diagnostic repeater topology table in STEP 7 is correct because that view is read directly from the DR's diagnostic buffer; FB126 is doing its own re-assembly on top and is where the corruption enters.
FB126 PNIODiag Architecture and Interface
FB126 lives in the standard STEP 7 library under PROFIBUS DP / Diagnostic Repeater / FB126 PNIODiag. The default instance data block is DB126. Per the official Siemens documentation (FB126 PNIODiag manual, entry ID 98278878), DB126 holds:
| Offset (bytes) | Name | Type | Meaning |
|---|---|---|---|
| 0.0 | REQ | BOOL | Trigger edge — start a new read cycle |
| 2.0 | MODE | BYTE | 0 = topology read, 1 = statistics read |
| 4.0 | DP_MASTER_SYS | BYTE | Number of DP master system |
| 6.0 | DR_ADDR | BYTE | PROFIBUS address of the DR |
| 8.0 | DONE | BOOL | Read completed without error |
| 8.1 | ERROR | BOOL | Read completed with error |
| 10.0 | STATUS | WORD | DR status word (overflow bit = M7) |
| 12.0 | DIAG[1..n] | STRUCT | Per-station structure: address, distance (dm), fault class, timestamp |
The overflow bit is bit M7 of STATUS (value 16#0080) and is set whenever FB126's internal normalization exceeds the configured segment length. Once set, the entire DIAG array must be considered invalid for that cycle. WinCC Flexible cannot distinguish this case from a valid 32388-dm reading because the tag it polls is just the raw WORD value.
Confirming the Fault in OB1 / VAT
Before replacing FB126, confirm the overflow bit in a VAT table:
- Open the S7 project online with the test bench CPU.
- Insert a VAT and monitor
DB126.STATUS,DB126.ERROR, andDB126.DIAG[1].DISTANCE. - Force a topology refresh:
DB126.REQedge from FALSE to TRUE on a one-shot. - Observe: if
STATUSbit 7 toggles to 1 andDISTANCEjumps to 32388, FB126 is the source. IfSTATUSremains 0 but the value is still wrong, the corruption is downstream in the WinCC tag pointer.
Solution Path A — Replace FB126 with SFC51 "Read System Status"
SFC51 is a standard system function available on every S7-300 / S7-400 CPU. It reads CPU-internal system status lists (SSLs) without the buffer-merge logic that breaks FB126. The SSL IDs relevant to PROFIBUS DR diagnostics are listed below. See the Siemens entry 19951051 — Reading out system status lists with SFC51.
| SSL_ID | INDEX | Returns |
|---|---|---|
| W#16#0092 | 0 | Communication status of all DP slaves |
| W#16#00A0 | DP master ID | Diagnostic buffer of a single DP slave |
| W#16#0121 | Slot 0 | Module diagnostic record (per slot) |
| W#16#00B2 | DP addr | Diagnostic data record for a DP slave |
| W#16#00B3 | DP addr | Diagnostic data record DR-specific (distance, level) |
Sample call in STL
// Call SFC51 to read DR distance for PROFIBUS address 33 (DR #1)
CALL SFC51 // READ_SSL
REQ :=TRUE // trigger
SSL_ID :=W#16#00B3 // DR diagnostic record
INDEX :=33 // DR PROFIBUS address
RET_VAL :=MW100 // return code (0 = OK)
BUSY :=M101 // 1 while read in progress
SSL_RECORD:=P#DB120.DBX0.0 BYTE 32 // target area, 32 bytes
// After RET_VAL = 0, parse bytes 6..7 of SSL_RECORD as distance in dm
L DB120.DBW6 // distance word, big-endian
T MW102 // hand off to WinCC tag
Parameter checklist
- REQ must be a rising edge; SFC51 ignores level-triggered calls.
- SSL_RECORD must be at least 32 bytes (W#16#00B3 returns up to 26 bytes of DR payload plus 6 bytes of header).
- RET_VAL = 0 means success.
80A1means SSL_ID/INDEX combination invalid for this CPU firmware. - Stagger calls — issue one SFC51 call per OB1 scan to a single DR; otherwise BUSY collisions corrupt the buffer.
Solution Path B — Use FB99 FB_READ_DR_CTRL
The Siemens diagnostic repeater library ships a lower-level block, FB99 FB_READ_DR_CTRL, that talks directly to the DR via DPV1 read/write services without FB126's normalization layer. It is the block recommended by Siemens support when FB126 misbehaves on chained DRs or on CPUs with an Ethernet CP front-end. Import the library from Options → Install SIMATIC Bibliothek → Diagnostic Repeater.
FB99 call template
// FB99 instance DB99, called in OB1 with edge-triggered REQ
CALL FB99, DB99
REQ :=M0.0 // rising edge
DR_ADDR :=33 // DR PROFIBUS address
MODE :=1 // 1 = read topology
RET_VAL :=MW110
BUSY :=M111
ERROR :=M112
STATUS :=MW113
TOPO_LEN :=24 // expected topology length
TOPO_PTR :=P#DB99.DBX20.0 BYTE 24 // topology record target
// Distance for station N is at TOPO_PTR + (N*8) + 6, in decimeters
Why FB99 works where FB126 does not
- Direct DPV1 acyclic read against the DR — no intermediate normalization step.
- Single-DR scope: each call addresses one DR explicitly, removing the chained-segment ambiguity.
- Returns native distance in dm; the conversion to meters is the integrator's responsibility, avoiding the silent sentinel leak that FB126 suffers.
Distance Conversion and Sentinel Handling
Both SFC51 and FB99 return distance in decimeters (dm). The PROFIBUS DR reserves the maximum 16-bit value (65535) for "not measured / overflow". Any value above the configured segment length (typically 1200 m = 12000 dm) is a sentinel, not a measurement. Implement this clamp in the WinCC Flexible tag or in a CFC block before display:
// In S7 ST: clamp distance before exposing to WinCC
L MW102 // raw distance in dm
L 12000 // 1200 m segment cap
>I // greater than?
JC OVER // if yes, route to sentinel
T MW104 // else expose valid value
SPA END
OVER: L 0
T MW104 // expose 0 = "no data"
END: NOP 0
On the WinCC Flexible side, use a tag of type UINT and a scaling factor of 0.1. Add a value-range check: any reading > 1200 m or equal to the previous cycle's value for >10 cycles should be flagged as stale in the HMI faceplate.
WinCC Flexible Integration
- Define the WinCC connection to the CP 343-1 Lean via Ethernet S7 (port 102). Use a separate connection from the programming connection to avoid priority conflicts with FB126/FB99 polling.
- Create tags:
DR1_Distance(UINT, address MW104),DR1_Status(WORD, address MW113),DR1_Error(BOOL, address M112.0). - In the visualization, use an IO field with a scaling factor 0.1 and a "unit" field of "m". Add an indicator lamp tied to
DR1_Statusbit 7 (overflow). - Poll the tag with a 500 ms update cycle; longer cycles (1–2 s) reduce CPU load but delay fault display.
Verification Procedure
- Disconnect one PROFIBUS station physically and observe:
DR1_Distancefor the disconnected station should change from a valid value to 0 (sentinel) within 2 s;DR1_Statusbit 7 should pulse. - Reconnect and confirm the value restores within one DR polling cycle (default 2 s for the 6GK1500-0AA00).
- Power-cycle the second DR; topology should rebuild automatically; FB99 should report BUSY briefly, then DONE with STATUS = 0.
- Run STEP 7 online → PLC → PROFIBUS → Diagnose Repeater and cross-check every distance value the HMI shows against the values in the topology table. They must match exactly.
- Force a CPU STOP/RUN transition and verify FB99 restarts cleanly without leaving BUSY latched.
Troubleshooting Matrix
| Symptom in WinCC | Likely cause | Action |
|---|---|---|
| Distance = 32388 dm, STATUS bit 7 set | FB126 overflow; chained DR not merged | Switch to FB99 or SFC51 (W#16#00B3) |
| Distance flickers between 0 and valid value | BUSY collision on shared instance DB | Edge-trigger REQ; one call per cycle |
| Distance = 65535 dm constantly | DP address not in DR topology | Re-check DR configuration in STEP 7 HW Config |
| Distance correct in STEP 7, wrong in WinCC | Tag type mismatch (INT vs UINT) | Re-declare tag as UINT with factor 0.1 |
| STATUS = 80A1 | SSL_ID/INDEX not supported on firmware | Update CPU firmware or use FB99 instead |
| Distance frozen on a single value | SFC51 RET_VAL = 80A0 (busy) | Wait one cycle, do not retrigger REQ |
| DR missing entirely from topology | DR not assigned to DP master system | Open HW Config, drag DR into DP master line, recompile HW |
Performance and Cycle-Time Notes
A single SFC51 call with a 32-byte record takes 8–15 ms on an S7-315-2 DP at default OB1 priority. With two DRs polled every 500 ms, expect ~30 ms/s additional OB1 load, well within budget for a 150 ms minimum cycle time. FB99 is lighter (3–6 ms per call) because it skips the SSL machinery. Avoid polling both DRs in the same OB1 sweep — stagger by 250 ms to keep return-code interleaving clean.
Migration Checklist from FB126 to FB99
- Export the existing DB126 symbol table from the S7 project before deleting FB126.
- Install the Diagnostic Repeater library from the STEP 7 DVD under ...\Siemens\Automation\S7\Lib.
- Drop FB99 into OB1 with a new DB99 instance.
- Re-map every WinCC Flexible tag from DB126 to DB99 offsets. Confirm the new offsets match the FB99 documentation for entry ID 98278878.
- Run a parallel test for at least one full shift: WinCC reads both DB126 (frozen) and DB99 (live) and displays side-by-side distance and overflow status.
- Once parity is confirmed, delete FB126/DB126 and rebuild the WinCC tag list against DB99 only.
FAQ
What does the "overflow bit set in the norm diagnostics" message actually mean?
It is FB126's own internal flag (bit 7 of the STATUS word in DB126) indicating that the block's normalization stage could not fit a topology entry into its output buffer. The PROFIBUS DR itself is not reporting overflow — the DR's own diagnostics show correct 1.5 m. Treat the message as a signal to replace FB126 with FB99 or SFC51.
Why does distance show as 32388 dm in WinCC Flexible?
32388 dm = 3,238.8 m, far above the 1,200 m PROFIBUS segment maximum. The value is a sentinel or a leaked stale buffer entry. It means FB126 failed to capture a valid measurement for that cycle but exposed an uninitialized or previous-cycle value. Switch to SFC51 with SSL_ID W#16#00B3 or to FB99 FB_READ_DR_CTRL.
Can I keep FB126 and just disable the Ethernet CP?
It is a useful bench test but not a production fix. With the CP 343-1 Lean removed, the OB1 cycle stops sharing time with HMI keep-alive traffic and FB126 occasionally behaves correctly — confirming the cycle-load sensitivity. Long-term, replace the block; do not redesign the network around a 20-year-old FB that has known multi-interface limitations.
Which SSL_ID returns the DR distance from SFC51?
Use SSL_ID W#16#00B3 with INDEX = PROFIBUS address of the DR. Bytes 6–7 of the returned record contain the distance in decimeters. Refer to Siemens entry ID 19951051 for the full SSL list and to entry ID 98278878 for the FB126 PNIODiag manual.
Is FB99 FB_READ_DR_CTRL shipped with STEP 7 by default?
No. It is in the optional Diagnostic Repeater library on the STEP 7 installation DVD under the SIMATIC library catalog. You must install it via Options → Install SIMATIC Bibliothek → Diagnostic Repeater before the FB becomes available in the project.
How often should I poll the DR for distance data?
A 500 ms cycle is a good balance between CPU load and fault display latency on an S7-315-2 DP. For fault scenarios that need faster visibility (e.g., cable break detection on a moving line), shorten to 200 ms and verify OB1 cycle time stays below the configured maximum (typically 150–200 ms for 315-2 DP).