IMDHMIControls LibraryShop main store

How-to

Write HMI device data into an S7-400 DB with an external tag

PLC programming Published 6 min read By IMDHMI controls team

Short answer

An internal HMI tag has no path into the controller, so device data collected by the panel stops at the panel. Bind an external tag to the S7-400 connection and a matching DB element, copy the source value with a SetValue function on a scheduled task or tag-change event, and confirm the DB follows in a watch table within the trigger period.

On this page
  1. Why the value stops at the panel
  2. Steps to carry the device value into the S7-400 DB
  3. Example: a device Real into DB1.DBD 0 on a 1 s task
  4. Choosing the trigger
  5. One safety note
  6. Decision
  7. Questions asked

An internal HMI tag never reaches the S7-400: it has no address in the controller and no connection to travel over. The fix is to bind an external tag to the configured S7-400 connection and a DB element whose data type matches the source, then copy the source value into that tag with a SetValue function fired from a scheduled task or a tag-change event, so the copy runs on any screen. Verify online that the DB member follows the source within the trigger period. There is no function that copies a tag into Step 7; only runtime values move, and only over a connection.

Why the value stops at the panel #

In TIA Portal, every HMI tag is either internal or external. An internal tag is stored in the memory of the HMI device and has no connection to a PLC, so data received into it goes nowhere else. An external tag is bound through a configured connection to a PLC tag or DB address, and the panel reads and writes it over that connection during runtime.

The quick check: in the HMI tag table, look at the Connection column of the tag that receives the device data. If it reads Internal tag, the value is panel-local and no PLC write can happen until an external tag enters the path. This matches the case where you trace an HMI command that never reaches the PLC output: the write loop never closes because no bound tag carries the value.

Steps to carry the device value into the S7-400 DB #

  1. Create or confirm the connection. In the HMI device's connection editor, add the S7-400 as the partner over the interface the hardware actually has, typically Ethernet through the integrated PN interface or a CP. Both stations need addresses in the same subnet for Ethernet, or a configured MPI/PROFIBUS path.

  2. Compile and download both sides. Compile the PLC hardware and the HMI project without errors, download the hardware configuration to the CPU and the project to the panel, and confirm online that the connection reports established with no communication-failure message.

  3. Create the DB element. In the S7-400 program, make a global DB with a member whose type matches the device value: Real for a float, Int or DInt for an integer. S7-400 blocks use standard access, so symbolic and absolute addressing both work for HMI access.

  4. Create the external HMI tag. In the HMI tag table, add a tag whose connection is the S7-400 connection and whose address is the DB member from step 3. When configuring the tag you can simply select the existing PLC tag or DB element to connect to. Check that the tag's Address column shows the DB and offset you intended, and that compilation reports no tag-type warnings.

  5. Copy the source into the target. The device data lives in one HMI tag (the source) and the PLC-bound tag from step 4 is the target. In the function list, use the system function that assigns a tag value, entered as SetValue with the target tag and the source value, for example SetValue("DB1_DeviceValue", "Src_DeviceValue"). Place it on a tag-value-change event on the source or in a scheduled task; a value-change event on a PLC-bound tag also works when the PLC should request the data.

  6. Verify online. Go online with the CPU, open the DB in a watch table, change the device value, and read the DB member. It must equal the source value with correct scaling and no byte swap, and it holds the last written value when the source stops, because the HMI writes only on its trigger.

If a value arrives in the DB but reads wrong rather than absent, the address is right and the type is not; the same failure family is covered by our article on a SCADA write to a PLC REAL address failing silently.

Example: a device Real into DB1.DBD 0 on a 1 s task #

Inputs and where each comes from: the source tag Src_DeviceValue holds a temperature as Real, updated by the device driver every 1 s (your acquisition setting); the target tag DB1_DeviceValue is bound to DB1.DBD 0 as Real; the copy is a cyclic scheduled task set to 1 s (the panel task period you choose); the S7-400 cycle time is a few milliseconds, treated here as negligible.

Rule in words: worst-case staleness in the DB equals the task period plus the source update interval that elapses before a fresh value exists, plus one write cycle.

Arithmetic: 1 s (task period) + 1 s (source update) + about 0.01 s (one PLC cycle) ≈ 2.01 s worst case. Typical case, when the task fires just after a fresh source update: 1 s + about 0.01 s ≈ 1.01 s.

Result: DB1.DBD 0 lags the device by between roughly 1 s and 2 s.

Decision: this path is fine for logging and setpoint transfer where a 2 s lag is acceptable. For anything the PLC acts on faster than that, or where a stale value could cause damage, connect the device to the S7-400 directly and let the panel display the PLC data instead. This example calculation uses the periods above, so a 100 ms task with a 100 ms source shrinks the worst case to roughly 0.2 s, and a screen-level trigger has no period guarantee at all.

Choosing the trigger #

Trigger Where configured Use when
Source tag value change Event on the source tag, in the tag's events Every device update must reach the PLC
Cyclic or timed scheduled task Scheduled tasks editor A fixed refresh period is acceptable
PLC tag change Event on a PLC-bound tag The PLC requests the data as a handshake

A scheduled task or a tag event runs regardless of the open screen; an event on a screen object runs only while that screen is open. Put the copy outside the screen when the flow must not depend on which screen the operator is on. Our article on PLC screen changes by tag event or job mailbox in WinCC shows the same event mechanics applied to screen navigation.

One safety note #

An HMI is not a deterministic data path: a panel restart, a lost connection or a closed runtime leaves the DB holding a stale value that still looks valid. If the copied value feeds control or a safety-related decision, add a heartbeat or timestamp the panel writes on each copy and have the PLC monitor it, and never route an E-stop or protective function through this path.

Decision #

Internal tag as the target: the value never leaves the panel; change the target to an external tag on the S7-400 connection. Type mismatch: the compiler warns or the DB reads nonsense; match Real to Real, Int to Int. Screen-level trigger: the copy stops when the screen closes; move it to a scheduled task or tag event. Device value used for control: connect the device to the PLC directly and reserve the HMI relay for logging and setpoints.

Questions asked

What happens if the receiving HMI tag stays internal?

The value lives only in the panel runtime memory and no communication cycle ever carries it to the S7-400. Open the tag's properties, set its connection to the configured S7-400 connection, and give it the DB element as its address. An internal tag can still feed a screen or an event, so you can leave the device-side tag internal and copy it into the external one.

What happens if the HMI tag type differs from the DB member type?

The compiler either raises a tag warning or the DB receives a wrong number, for example a Real bit pattern read as an integer produces a huge or nonsensical value. Match Real to Real and Int to Int. Our article on an HMI writing the wrong PLC value above 9 shows how a type and format mismatch corrupts small numbers in exactly this way.

What happens to the DB value when the HMI runtime stops?

The DB keeps the last written value and the PLC cannot tell it is stale, because the write only happens when the copy triggers. If the CPU uses the value for control, add a heartbeat word or timestamp the panel writes on each copy and have the PLC monitor it, so a stopped panel or lost connection is detected in the program.

Does the copy script run when its screen is not open?

An event placed on a screen object runs only while that screen is open. A scheduled task and a tag-value-change event on the tag itself run regardless of the active screen, so put the copy in one of those when the data must flow on every screen.

Why does my copy work on the bench but not after download?

On the bench, runtime often talks to the project in the panel while the CPU still runs the matching test project. After download, check that the connection's interface and subnet match the real hardware, that the compiled project went to the panel, and that the DB exists in the downloaded CPU program. A silent write failure with a matching-looking address is usually an offline project or a non-downloaded DB, not a bad copy function.

Keep reading

  • How-to

    What an S7-1200 upload recovers and what the IO devices need

    The documented upload of an S7-1200 recovers the CPU program and the controller-stored PROFINET configuration, including device names, IP addresses and module arrangements. It recovers nothing stored in the ten third-party IO devices: install each vendor's GSDML description separately and back up each device's own settings with its vendor tool, then verify byte counts and addresses online before building on the project.

    PLC programming

  • Explainer

    Why a Linux C++ app must not share KBUS with CODESYS on a PFC200

    On a PFC200, CODESYS and a Linux C++ program cannot both open the KBUS that runs the local I/O modules — one bus, one owner. Keep I/O acquisition and interlocks in CODESYS and hand values across the boundary with shared memory or a C-compatible library built from the BSP example, so the cyclic task's execution time stays bounded and the C++ process sends its JSON to the server on its own schedule.

    PLC programming

  • Troubleshooting

    PLC-5/80E loses scan list on remote I/O after power cycle

    Auto-negotiate selected on Ethernet Channel 2 of a Series F Revision A PLC-5 clears the chassis scan list on the remote I/O scanner channels whenever the processor power cycles. Disable auto-negotiate and hard-set 100 Mbps full duplex, or flash Revision A.1 or newer; Auto-Config only rebuilds the list after each event.

    PLC programming