Overview
When a tool or machine mode in an S7-1500 program changes, the controller must be able to enable or disable specific Ethernet ports on a downstream SCALANCE managed switch without operator intervention. The PLC cannot reach the SCALANCE Web Based Management (WBM) page, and it cannot call the STEP 7 topology editor at runtime, so the only viable field-level path is SNMP. This reference explains how to send an SNMP SET to the ifAdminStatus object in the standard IF-MIB (RFC 2863) from an S7-1500 using the freely available Siemens S7-1500 SNMP library.
It covers the supported SCALANCE families, the exact OIDs and values, library installation in TIA Portal, SCL code for SET operations, verification procedures, and the typical error matrix you will see during commissioning. The same procedure applies to SCALANCE S615 security modules and SCALANCE M-800 industrial routers where a switch port must be brought down or up based on the PLC's program state.
Architecture and Prerequisites
The PLC sits in the same IP subnet as the SCALANCE management interface (or reaches it through a router). The PLC issues an SNMP SET request using UDP port 161 directed at the SCALANCE. The SCALANCE processes the request against the local MIB tree and either brings the port administratively up or administratively down. The change is persistent on the integrated switch, the S615, and the M-800 family, and survives a power cycle on every SCALANCE model that supports it.
Hardware and software prerequisites
- S7-1500 CPU (CPU 1511-1 PN or higher recommended). Firmware V2.0 or later; the SNMP library entry supports TIA Portal V15.1 through V20. CPUs older than firmware V2.0 may not have sufficient work memory or a sufficient number of Open User Communication (OUC) resources.
- TIA Portal V16, V17, V18, V19, or V20 for the corresponding project and library version. The library is delivered as
.al16through.al20; pick the one matching your installed TIA Portal. - SCALANCE managed switch with SNMP enabled. Unmanaged variants (SCALANCE XB-100, XC-100, XF-100, X-100) do not have an SNMP agent and cannot be controlled programmatically.
- Ethernet connectivity between the S7-1500 PROFINET interface and the SCALANCE management VLAN/interface. SNMP traffic can ride on the same PROFINET network if you keep it inside a separate VLAN or use a dedicated management IP, but in PROFINET IRT networks the SNMP SET may be delayed by the reserved cycle window; for deterministic control use a separate, non-IRT connection for the SNMP path.
- Read/write credentials on the SCALANCE: SNMPv2c community string or SNMPv3 user with auth/priv keys.
Functional topology
Compatible SCALANCE Devices
Only SCALANCE devices with a built-in SNMP agent and full management firmware support ifAdminStatus SET operations. The table below summarizes device family support and notes any caveats. Always confirm the device's firmware release against the SCALANCE firmware release notes for the SNMP service before relying on the SET in production.
| SCALANCE family | Examples (MLFB) | SNMP write on ifAdminStatus | Notes |
|---|---|---|---|
| SCALANCE XC-200 | 6GK5 208-0BA10-2AA3, 6GK5 208-0BA00-2AB2 | Yes | Port count depends on variant (6, 8, 16, 24) |
| SCALANCE XC-300 | 6GK5 324-0BA00-3AA3, 6GK5 328-0AA00-3AA3 | Yes | Layer 2 managed; supports SNMPv3 with SHA/AES |
| SCALANCE XC-400 | 6GK5 408-0AA00-4AA3, 6GK5 424-0AA00-4AA3 | Yes | Layer 2/3; full MIB-II support |
| SCALANCE XR-300 | 6GK5 324-0BA00-3AR3, 6GK5 328-0AA00-3AR3 | Yes | 19-inch rack, 24 ports typical |
| SCALANCE XR-500 | 6GK5 524-0BA00-5AR3, 6GK5 528-0AA00-5AR3 | Yes | Layer 3 functions included |
| SCALANCE XM-400 | 6GK5 408-0AA00-4AM2 | Yes | Modular, 8-port basic; expand with MM900 media modules |
| SCALANCE X-200 (legacy) | 6GK5 204-0BA00-2AA3, 6GK5 208-0BA10-2AA3 | Yes (FW V4+) | Update to latest firmware before relying on SNMP SET |
| SCALANCE X-300 (legacy) | 6GK5 304-1BD00-2AA3 | Yes | Full MIB-II support |
| SCALANCE X-400 (legacy) | 6GK5 408-0AA00-4AA2 | Yes | Layer 3 static |
| SCALANCE X-500 | 6GK5 508-0BA00-2AC2 | Yes | Layer 3 full |
| SCALANCE M-800 | M812-6 (6GK5 812-1AA00-2AA2), M816-1, M826-2, M874-2, M874-3, M876-3, M876-4 | Yes (switch ports) | Switch ports appear as ifIndex after the WAN interface |
| SCALANCE S615 | 6GK5 615-3AA00-2AA2, 6GK5 615-3AM00-2AA2 | Yes (LAN ports) | Treat the 4 LAN ports as ifIndex 1..4 on the integrated switch |
| SCALANCE SC-600 | 6GK5 606-1AS00 (SC622), 6GK5 606-1AT00 (SC626) | Yes | Nano/compact security module |
| SCALANCE XB-100 | 6GK5 104-0BA00-2AA2 | No | Unmanaged; no SNMP agent |
| SCALANCE XC-100 | 6GK5 101-0BA00-2AA2 | No | Unmanaged; no SNMP agent |
| SCALANCE XF-100 | 6GK5 100-0BA00-2AA2 | No | Flat unmanaged |
ifIndex mapping before writing. Although most SCALANCE switches number ifIndex 1..N to match physical ports 1..N, some models interleave internal VLAN or loopback interfaces. Use SnmpGetNextRequest on ifDescr (1.3.6.1.2.1.2.2.1.2) and walk the table once during commissioning to confirm that ifIndex 2 is port 2 and so on. Save the mapping into a data block so the runtime program uses the correct ifIndex.SNMP MIB Reference and OID Encoding
The relevant MIB is IF-MIB, defined in RFC 2863 (The Interfaces Group MIB). IF-MIB is a standard Internet MIB implemented by every conformant SCALANCE agent, so the OID for port enable/disable is identical across families. Operations on top of IF-MIB follow RFC 3416 for SNMPv2 PDUs, and security for v3 follows RFC 3414 (USM).
Object OIDs
| Object | OID (full) | Syntax | Access | Use |
|---|---|---|---|---|
| ifNumber | 1.3.6.1.2.1.2.1 | Integer32 | read-only | Total interfaces on the device |
| ifIndex | 1.3.6.1.2.1.2.2.1.1.<ifIndex> | InterfaceIndex | read-only | Used as the row index |
| ifDescr | 1.3.6.1.2.1.2.2.1.2.<ifIndex> | DisplayString | read-only | Human readable port name; use to confirm port-to-index mapping |
| ifAdminStatus | 1.3.6.1.2.1.2.2.1.7.<ifIndex> | INTEGER {up(1), down(2), testing(3), unknown(4), dormant(5), notPresent(6), lowerLayerDown(7)} | read-write | The target of the SET to enable/disable a port |
| ifOperStatus | 1.3.6.1.2.1.2.2.1.8.<ifIndex> | INTEGER (same SYNTAX as ifAdminStatus) | read-only | Reflects the actual operational state after the SET |
| ifAlias | 1.3.6.1.2.1.31.1.1.1.18.<ifIndex> | DisplayString (0..255 chars) | read-write | Optional port description; persists across reboots |
Value encoding for ifAdminStatus
RFC 2863 lists the full enumeration, but only the values up(1) and down(2) are valid for SET. Writing testing(3) is permitted by the SYNTAX but places the port in a test mode intended for diagnostics; do not use testing(3) in a production control loop. The other values (unknown(4) through lowerLayerDown(7)) are reserved for agent-internal use and must not be SET.
| Action | ASN.1 value | Integer to write |
|---|---|---|
| Enable port | up | 1 |
| Disable port | down | 2 |
Full OID walk for a 24-port SCALANCE XC-200
For a SCALANCE XC-200 with 24 ports, the SET to disable port 5 uses the OID 1.3.6.1.2.1.2.2.1.7.5 with the INTEGER value 2. Enable the same port by writing 1 to the same OID. The same OID format is used on the S615 (4 LAN ports have ifIndex 1..4) and on the M-800 family, although the WAN interface takes ifIndex 1 and the LAN switch ports start at the next available index; always run the discovery walk before the first commissioning.
Installing the S7-1500 SNMP Library
The SNMP client blocks are provided as a license-free global library in the Siemens Industry Online Support: S7-1500 SNMP library, entry 57249109. The library contains SCL function blocks, user data types, an OID helper, and a small example project. It is delivered without runtime licensing; the blocks count only against your CPU's work memory and OUC resources.
Library contents
| Block | Type | Function |
|---|---|---|
| SnmpGetRequest | FB | Issues a single GET |
| SnmpGetNextRequest | FB | Issues a GET-NEXT (used for MIB walk) |
| SnmpGetBulkRequest | FB | Issues a GET-BULK (SNMPv2c/v3 only) |
| SnmpSetRequest | FB | Issues a SET — this is the block you call to enable/disable a port |
| SnmpUser | UDT | User/security parameters: version, community, v3 user name, auth protocol/key, priv protocol/key |
| SnmpAgent | UDT | Target address (IP, port) |
| SnmpVarBind | UDT | Single OID/value pair for SET or response |
| SnmpReceiver | FB | Helper that demultiplexes incoming response UDP datagrams |
Installation steps
- Download the ZIP from entry 57249109. Pick the variant matching your TIA Portal:
.al16for V16,.al17for V17,.al18for V18,.al19for V19,.al20for V20. - Extract the ZIP to a project-readable folder. The archive contains one global library per TIA Portal version and a documentation PDF.
- Open TIA Portal. Choose Options > Global libraries > Open library and navigate to the extracted
.alXXfile. - Open the library in the project tree, expand Types > master copies, and drag the FBs and UDTs you need into your project's Program blocks.
- Compile. Resolve any name conflicts. The library blocks do not require a runtime license, but they do consume one Open User Communication (OUC) connection resource per active SNMP session; for a single SCALANCE in a star topology, one connection is enough.
SnmpSetRequest opens a transient UDP send/receive socket. The CPU has a limited number of OUC connections (1500-series CPUs: typically 64 to 118, depending on order number). Plan for at least one OUC connection per concurrent SCALANCE target. If you also need GET/GET-NEXT for verification, plan for a second.SCALANCE SNMP Configuration
Before the PLC can SET ifAdminStatus, the SCALANCE must accept SNMP write requests from the PLC's IP. Enable the agent and either configure an SNMPv2c community string or, preferably, an SNMPv3 user with SHA authentication and AES-128 privacy.
WBM configuration path
- Open WBM with the SCALANCE management IP.
- Navigate to System > SNMP > General and enable SNMP.
- For SNMPv3, navigate to System > SNMP > Users and create a user with Authentication = SHA and Privacy = AES-128. Note the user name, auth key, and priv key; the same values go into
SnmpUseron the S7-1500. - For SNMPv2c, configure a community string under System > SNMP > Communities and limit the rights of that community to Read/Write if you intend to SET. Use a strong community string; the default
publicis read-only and must not be used for write operations. - Under Information > Log Table, ensure SNMP events are logged if you need an audit trail.
TIA Portal configuration
If the SCALANCE is already a PROFINET device in your TIA project, you can configure SNMP in the device properties under Properties > System > SNMP. The same Status > Enabled/Disabled setting under SCALANCE X / W / M > Configuring interfaces > Ethernet > Configuration is what the WBM and the SNMP SET both end up writing; using the TIA path documents the value as the project default and is useful for the initial commissioning state.
Confirming the agent is reachable
From the engineering station or from a separate diagnostic laptop, run an SNMP GET against 1.3.6.1.2.1.1.1.0 (sysDescr) to confirm that the agent responds and that your community / v3 credentials work. Only proceed to the SET step once the GET round-trip is verified.
S7-1500 Program Implementation
The program consists of a single instance DB for the SET FB, a configuration DB that holds the target IP, port, credentials, and the per-tool port table, and a small cyclic routine that evaluates the tool state and triggers a SET when it changes.
Data block layout (DB_SnmpPortControl)
| Tag | Type | Initial value | Comment |
|---|---|---|---|
| scSwitchIp | STRING[15] | '192.168.1.10' | SCALANCE management IP |
| iSwitchPort | INT | 161 | UDP port for SNMP |
| iSnmpVersion | INT | 3 | 1 = v1, 2 = v2c, 3 = v3 |
| sSnmpUser | STRING[32] | 'plcUser' | v3 user name |
| sAuthKey | STRING[32] | 'AuthKey123!' | v3 auth key (min 8 chars) |
| sPrivKey | STRING[32] | 'PrivKey456!' | v3 priv key (min 8 chars) |
| iAuthProto | INT | 2 | 1 = MD5, 2 = SHA, 3 = SHA-224, 4 = SHA-256, 5 = SHA-384, 6 = SHA-512 |
| iPrivProto | INT | 2 | 1 = DES, 2 = AES-128, 3 = AES-192, 4 = AES-256 |
| iToolCount | INT | 4 | Number of tools to track |
| aPortTable[1..4] | ARRAY[1..4] OF STRUCT | -- | Records with: iIfIndex, bToolActive, bLastState, iLastStatus, bError, wErrorStatus |
| bBusy / bDone / bError | BOOL | FALSE | FB status flags |
| wErrorStatus | WORD | 16#0 | FB status word |
SCL routine: cyclic port control
// Block: OB1 (or OB30 cyclic) - Port control dispatcher
// Purpose: For each tool, if active state changes issue a SET
// Library : S7-1500 SNMP library, entry 57249109
"DB_SnmpPortControl".bBusy := "DB_SnmpSet".Busy;
"DB_SnmpPortControl".bDone := "DB_SnmpSet".Done;
"DB_SnmpPortControl".bError := "DB_SnmpSet".Error;
"DB_SnmpPortControl".wErrorStatus := "DB_SnmpSet".Status;
FOR #i := 1 TO "DB_SnmpPortControl".iToolCount DO
IF ("DB_SnmpPortControl".aPortTable[#i].bToolActive <>
"DB_SnmpPortControl".aPortTable[#i].bLastState)
AND NOT "DB_SnmpSet".Busy THEN
"DB_SnmpSet".Execute := TRUE;
"DB_SnmpSet".Server.IpAddress := "DB_SnmpPortControl".scSwitchIp;
"DB_SnmpSet".Server.Port := 161;
"DB_SnmpSet".User.Version := 3;
"DB_SnmpSet".User.UserName := "DB_SnmpPortControl".sSnmpUser;
"DB_SnmpSet".User.AuthProtocol:= "DB_SnmpPortControl".iAuthProto;
"DB_SnmpSet".User.AuthKey := "DB_SnmpPortControl".sAuthKey;
"DB_SnmpSet".User.PrivProtocol:= "DB_SnmpPortControl".iPrivProto;
"DB_SnmpSet".User.PrivKey := "DB_SnmpPortControl".sPrivKey;
// OID = 1.3.6.1.2.1.2.2.1.7.<ifIndex>
"DB_SnmpSet".Oid[0] := 1; // iso
"DB_SnmpSet".Oid[1] := 3; // org
"DB_SnmpSet".Oid[2] := 6; // dod
"DB_SnmpSet".Oid[3] := 1; // internet
"DB_SnmpSet".Oid[4] := 2; // mgmt
"DB_SnmpSet".Oid[5] := 1; // mib-2
"DB_SnmpSet".Oid[6] := 2; // interfaces
"DB_SnmpSet".Oid[7] := 2; // ifTable
"DB_SnmpSet".Oid[8] := 1; // ifEntry
"DB_SnmpSet".Oid[9] := 7; // ifAdminStatus
"DB_SnmpSet".Oid[10] := "DB_SnmpPortControl".aPortTable[#i].iIfIndex;
"DB_SnmpSet".OidLength := 11;
// Value: 1 = up, 2 = down
IF "DB_SnmpPortControl".aPortTable[#i].bToolActive THEN
"DB_SnmpSet".Value := 1;
ELSE
"DB_SnmpSet".Value := 2;
END_IF;
"DB_SnmpSet".Timeout := T#2s;
"DB_SnmpSet".RequestId := "DB_SnmpPortControl".dwReqId;
"DB_SnmpPortControl".dwReqId := "DB_SnmpPortControl".dwReqId + 1;
END_IF;
END_FOR;
IF "DB_SnmpSet".Done THEN
IF "DB_SnmpSet".Status = 16#0 THEN
"DB_SnmpPortControl".aPortTable[#i].bLastState :=
"DB_SnmpPortControl".aPortTable[#i].bToolActive;
"DB_SnmpPortControl".aPortTable[#i].bError := FALSE;
ELSE
"DB_SnmpPortControl".aPortTable[#i].bError := TRUE;
"DB_SnmpPortControl".aPortTable[#i].wErrorStatus := "DB_SnmpSet".Status;
END_IF;
"DB_SnmpSet".Execute := FALSE;
END_IF;
Reading the result back
After each SET, issue a SnmpGetRequest on the same OID to confirm that the agent actually applied the change. Some agents may return a successful SET PDU but reject the value internally and revert; the GET-back is the only safe verification. The verification GET should be issued in a different OB cycle (for example OB1 with a 2-second slow timer) to avoid blocking the SET dispatcher.
Verification and Commissioning Checks
-
Agent reachable: Run a GET on
1.3.6.1.2.1.1.1.0(sysDescr) from the sameSnmpGetRequestblock. Expect a string starting withSiemens, SCALANCEfor SCALANCE devices. -
Port table walk: Run a
SnmpGetNextRequestloop on1.3.6.1.2.1.2.2.1.2(ifDescr) untilendOfMibViewis returned. Save theifIndex-to-port-name mapping to a data block. Confirm the ifIndex numbers match the physical ports of the SCALANCE variant in your cabinet. -
Test SET in safe state: Pick a port with no active device, write
ifAdminStatus = 2(down) and confirm the port LED extinguishes. Read back with a GET and confirm the integer is 2. -
Test SET in active state: Plug a known device into the same port, write
ifAdminStatus = 1(up), and confirm that the link comes up within 3-5 seconds. The device's own network stack will perform a re-negotiation; this is normal. -
Persist across reboot: Power-cycle the SCALANCE (or reload the configuration) and confirm that the last SET value is retained. SCALANCE switches persist
ifAdminStatusthrough reboots because the value is stored in the start-up configuration; the SET is therefore safe to use as a one-time boot action. -
Inspect
ifOperStatus: Read1.3.6.1.2.1.2.2.1.8.<ifIndex>after the SET to confirm that the operational status matches the administrative status. A mismatch (for example adminStatus=up but operStatus=down) typically indicates a physical-layer fault or that the connected device is not autonegotiating.
Troubleshooting Matrix
| Symptom | Library status word | SNMP PDU error-status | Root cause | Fix |
|---|---|---|---|---|
| FB never reports Done; Busy stays TRUE for > 2 s | 16#8001 | -- | SNMP agent unreachable; no response to UDP/161 | Check IP, VLAN, firewall, ACL on the SCALANCE; verify the OUC connection resource is open in Online & Diagnostics > Connections |
| Done with Error, status = 16#0005 | 16#0005 | genErr(5) | SCALANCE rejected the request | Check agent logs under Information > Log Table; usually a write access right issue |
| Done with Error, status = 16#0006 | 16#0006 | noAccess(6) | Community string is read-only, or v3 user has read-only rights | Configure the SCALANCE community or v3 user with Read/Write permission |
| Done with Error, status = 16#0007 | 16#0007 | wrongValue(7) | Value not in the allowed enumeration | Only 1 (up) and 2 (down) are valid for SET; reject all other integers |
| Done with Error, status = 16#0010 | 16#0010 | authorizationError(16) | SNMPv3 auth/priv key mismatch | Re-enter auth/priv keys; check for whitespace and key-length minimums (SHA: 8+ chars, AES: 8+ chars) |
| Done with Error, status = 16#0011 | 16#0011 | notWritable(17) | OID is read-only | Confirm you are targeting ifAdminStatus (1.3.6.1.2.1.2.2.1.7) and not ifOperStatus
|
| Done with Error, status = 16#0012 | 16#0012 | inconsistentValue(12) | Value conflicts with current port configuration (for example port locked by 802.1X) | Check Security > 802.1X in WBM; release the port or remove the 802.1X hold |
| Done with success, but port LED does not change | 16#0000 | noError(0) | Wrong ifIndex; wrote to a different port or to an internal interface |
Re-run the MIB walk on ifDescr; correct the iIfIndex in the port table |
| Port toggles up/down repeatedly every few seconds | 16#0000 | noError(0) | Program toggles the trigger; edge detection not debounced | Add a hysteresis time; only call SET if the new state is held for at least N seconds |
| SET succeeds in TIA test mode but fails at runtime | various | various | Different user credentials between online test and runtime; the TIA test uses a different user | Use the same DB_SnmpPortControl values in both online test and runtime; verify the loaded CPU DB matches the project |
Security Considerations
SNMP write access on a managed switch is a powerful control surface. The following hardening rules apply to every deployment that uses this technique.
- Use SNMPv3 with SHA + AES-128 (or stronger). SNMPv1 and v2c send the community string in clear text and are vulnerable to replay and spoofing. The S7-1500 SNMP library supports SHA-256, SHA-384, SHA-512 and AES-192/256 if your SCALANCE firmware supports them; check the SCALANCE firmware release notes for the supported auth/priv list before selecting the algorithm.
-
Do not use the default community
publicfor write. The default is read-only on SCALANCE; any custom write community must be a non-guessable string of at least 12 characters. - Restrict SNMP source IPs. In WBM under System > SNMP > General, configure an SNMP filter that allows only the S7-1500 CPU's IP. Combine with a management VLAN for the SNMP path.
- Do not store keys in plain text inside the project. Use the TIA Portal password protection on the project, and store the keys in a separate access-protected DB if you must keep them in the CPU. Consider deriving the keys from a one-time provisioning step instead of embedding them in the source.
- Audit trail. Enable the SCALANCE log for SNMP writes. The log records the source IP, community/user, OID, and value. Forward the log to a SIEM if the site has one.
- Operator visibility. Do not let the PLC silently re-enable a port that an operator has manually disabled in the WBM. Add a one-way latch: if the WBM disables a port, treat the PLC state as advisory, not authoritative. This is a defence-in-depth pattern, not a protocol-level guarantee.
FAQ
Can I use this procedure to enable/disable ports on a SCALANCE S615?
Yes. The S615 exposes its four LAN ports as standard ifTable entries. Run a SnmpGetNextRequest walk on 1.3.6.1.2.1.2.2.1.2 to enumerate the interface table once during commissioning; the LAN port ifIndex values are typically 1 through 4 on the integrated switch, with the WAN interface taking the next index. SET 1.3.6.1.2.1.2.2.1.7.<ifIndex> with INTEGER 1 or 2 to enable or disable.
How do I find the ifIndex for a specific SCALANCE port?
Run an SNMP walk on ifDescr (1.3.6.1.2.1.2.2.1.2) using SnmpGetNextRequest in a commissioning step. Each returned value is the human-readable port name (for example port 1, port 2). The ifIndex is the index in the OID of the response. Persist the mapping in a data block so the runtime program uses the correct index.
Can I use SNMPv2c instead of SNMPv3?
Yes, the library supports SNMPv2c. Set User.Version := 2 and supply a non-empty community string in User.Community. SNMPv2c is acceptable on isolated, dedicated management networks but is not recommended for production cells or any network exposed to plant traffic because the community string travels in clear text and there is no authentication of the source IP.
What other port parameters can I change via SNMP besides enable/disable?
Common writeable objects include ifAlias (1.3.6.1.2.1.31.1.1.1.18, port description), and in the SCALANCE-specific MIB objects for port speed/duplex lock, PoE enable, and broadcast limiter threshold. The IF-MIB standard only defines enable/disable cleanly; advanced port features require loading the SCALANCE MIB file into an MIB browser and using the OIDs documented there.
Does this work on PROFINET networks with IRT?
Yes, but with caveats. SNMP traffic is non-real-time and rides on the best-effort phase of the PROFINET cycle. Under heavy IRT load, an SNMP SET can be delayed by tens of milliseconds. For deterministic runtime control of ports, route the SNMP traffic on a separate VLAN or a separate physical interface on the S7-1500. The SET is reliable; only its latency varies.