IMDHMIControls LibraryShop main store

Troubleshooting

Why Citect strings read empty from an S7-1500 in Ignition

SCADA and data logging Published 7 min read

Short answer

Citect PSDirect writes only the character bytes of an S7 STRING and never sets the current-length byte, so the PLC, its OPC UA server and Ignition's S7 driver all return an empty string. Write 30 into byte 1 once per string, read the tag at offset 0 with length 32, trim nulls with replace(tag("tagpath"), char(0), ""), and pad Ignition writes to 30 characters.

On this page
  1. Why does the string read empty when the characters are in the DB?
  2. What does the S7 STRING header actually contain?
  3. Why does switching from the S7 driver to OPC UA not fix it?
  4. What address should the Ignition S7 driver use for the string?
  5. How do you set the current-length byte without touching the PLC or Citect?
  6. How do you trim the nulls Ignition returns after the fix?
  7. How should writes from Ignition to these strings be padded?
  8. What if the header cannot be initialized at all?
  9. Questions asked

An S7 STRING carries a two-byte header in front of the characters: byte 0 holds the declared maximum length, byte 1 the number of characters in use. Citect's PSDirect driver writes only the 30 character bytes at offset 2 and never updates byte 1, so every reader that follows the Siemens format — the PLC watch table, the S7-1500's embedded OPC UA server, Ignition's native S7 driver — reports an empty string while the text sits in memory. The repair writes data values only: put 30 into byte 1 once per string, address the Ignition tag at offset 0 with length 32, trim the null padding with an expression, and pad Ignition writes to 30 characters. Nothing in the PLC program or the Citect project changes.

Why does the string read empty when the characters are in the DB? #

Because byte 1 of the header — the current-length byte at DB1000 offset 1 — holds 0, and every compliant reader returns exactly that many characters, which is none, no matter what the character bytes contain.

The characters are present; the length metadata is not. Read the symptoms together before touching any addressing, because each one points at a different part of the header:

What you see What it means Decision
Watch table shows '' for the String[32] at offset 0 Byte 1 holds 0, so the PLC displays zero characters Header fault, not a communications fault
The same bytes viewed as an Array of Char show the text The char view skips the header and dumps bytes 2..31 Data is present; only the length metadata is missing
An OPC UA client to the PLC returns an empty string The PLC's OPC UA server serializes from byte 1 Same fix; changing protocol does not help
The S7 driver at offset 0, length 32 returns empty The driver read the header and honored a current length of 0 Address is correct; initialize byte 1
The S7 driver at offset 2, length 30 returns empty or garbage The driver read your first two characters as a header Wrong address; read S7 strings at the header start
Strings appear after Ignition has written them once Ignition's write set byte 1 Confirms the diagnosis
After the fix, values end in a run of \u0000 A current length of 30 returns Citect's null padding Trim on an expression tag

What does the S7 STRING header actually contain? #

Two length bytes followed by up to 254 character bytes: byte 0 stores the declared maximum, byte 1 the count of characters actually in use, for at most 256 bytes total — the layout Siemens documents for the STRING type.

Byte Content Value for the String[32] Who sets it
0 Declared maximum length 32 The PLC, at DB initialization
1 Current length in characters 0 as found Every compliant writer, on every write
2..33 Characters, one byte each Citect text, null-padded Citect writes bytes 2..31

In a DB with optimized block access disabled, a STRING starts at a word boundary, so header offsets land on even bytes. The S7 order is maximum first, current second; if a document describes the opposite order, trust the DB — byte 0 of a freshly initialized string holds the declared maximum, 32 here. A header whose current length exceeds its maximum is invalid, and the PLC's string instructions handle it unpredictably, so never write the text length into byte 0.

Why does switching from the S7 driver to OPC UA not fix it? #

Because the S7-1500's embedded OPC UA server serializes the string from byte 1 as well, so the empty value follows the data into whichever protocol you pick — the header interpretation simply moves inside the PLC.

PSDirect treats the tag as a fixed 30-byte character block at offset 2: it writes the text plus null padding, and reads 30 bytes back stopping at the first null. It never reads or writes the header, so Citect behaves the same whatever byte 1 holds — which is why the plant runs on while every other consumer sees nothing. The OPC UA route itself is sound, and connecting an S7-1500 to SCADA over OPC UA from TIA Portal covers the server-side setup. The same symptom comes from any package that writes strings as raw character blocks, and from PLC code that fills a string with block moves instead of string instructions.

What address should the Ignition S7 driver use for the string? #

Offset 0 with a string length of 32, never offset 2: the driver reads the two header bytes itself, so an address at offset 2 makes it treat your first two characters as a header and return empty or garbage.

The driver's string address takes the documented form STRING{OFFSET}.{LENGTH}, so this tag is offset 0, length 32. Absolute-offset addressing works only on a DB with optimized block access disabled, which this DB already satisfies because Citect reads it by offset. Your own test proved the point: offset 0 with length 32 returned empty because the address was right and the header was not.

How do you set the current-length byte without touching the PLC or Citect? #

Write 30 — the Citect span — into byte 1 of each string as a one-time data write through the same C-character addresses the per-character scripts already use, DB1000,C1 for this string, and leave byte 0 at 32.

  1. List every Citect string tag and convert each address: header offset = Citect offset - 2.
  2. Cross-check every result against the offset column in the DB editor instead of assuming the strings are packed contiguously.
  3. Read bytes 0 and 1 of each string. Expect 32 and 0 wherever only Citect has written.
  4. Write the Citect span, 30, to header offset + 1 for every string, in one bulk write.
  5. Point the Ignition tags at offset 0 with length 32 on the native S7 driver, or browse the string node through the PLC's OPC UA server.
  6. Add the null-trimming expression tags below, and record the byte 1 write as a commissioning step.

The arithmetic for this string, end to end: the Citect tag sits at offset 2, so its header offset is 2 - 2 = 0. The String[32] occupies 2 + 32 = 34 bytes, addresses 0 through 33. Byte 1 is therefore DB1000,C1, and the value it needs is 30. Citect's String[30] covers bytes 2 through 31, leaving bytes 32 and 33 outside its view; they stay null, which is harmless.

# One-time header write. plc is your connection name (illustrative);
# the server name, C-address form and calls are documented forms.
plc = "S7-1500"                    # str: your S7 driver connection
server = "Ignition OPC UA Server"  # internal OPC server in the gateway
item = "[" + plc + "]DB1000,C1"    # byte 1 of the string at offset 0
system.opc.writeValues(server, [item], [30])
print(system.opc.readValues(server, [item])[0].value)  # expect 30

The write touches data values only, so it changes no PLC code and no Citect configuration, and because Citect never writes byte 1, the value stays until something else overwrites it. Test on one string and check the returned quality codes before the bulk run: a wrong offset lands silently in a neighboring string's characters rather than raising an error.

How do you trim the nulls Ignition returns after the fix? #

With byte 1 held at 30, Ignition returns all 30 characters including Citect's null padding, so a value shows as its text followed by a run of \u0000 — strip them on an expression tag that references the raw tag: replace(tag("tagpath"), char(0), "").

Point HMI bindings, history, and downstream OPC UA consumers at the expression tag, not the raw tag. The expression removes every null, not only the trailing ones, which is harmless for text data.

How should writes from Ignition to these strings be padded? #

Pad every Ignition write to exactly 30 characters with trailing nulls, because a compliant short write sets byte 1 to the shorter count — "ABC" leaves byte 1 at 3 — and the fixed 30-character scheme then drifts.

Citect is unaffected either way: PSDirect reads its fixed 30 bytes from offset 2 and stops at the first null, so it shows the text plus padding whatever byte 1 says. Ignition readers return byte 1 characters, though, so once a short write has collapsed it, re-run the header write to restore 30.

What if the header cannot be initialized at all? #

Fall back to per-character assembly — one C address per character, ignoring the header entirely — which works today but costs 30 OPC items per string and cannot expose a native string tag to OPC UA clients.

A per-character script reads each byte, assembles the text, and strips trailing nulls from the right; reading PLC tag arrays in one block request keeps its traffic down. Keep that route only for strings whose header you cannot write. For everything else, byte 1 is the fix — and after any DB reinitialization it is the fix again, because a reinitialized string comes back with byte 1 at 0.

Questions asked

Does the header write survive a PLC download?

No. A download that reinitializes DB1000 rewrites byte 0 to the declared maximum and byte 1 to 0, and the empty-string symptom returns everywhere at once. Record the byte 1 write as a commissioning step and repeat it after any download or DB reinitialization. Citect writes never restore it, because PSDirect never touches the header.

Can both header bytes be set to 30 instead of leaving byte 0 at 32?

Yes. Writing 30 into byte 0 as well leaves a consistent header whose maximum equals its current length, and compliant readers return the same characters. Leave byte 0 at 32 if you want the PLC's declared String[32] untouched. The one invalid choice is a current length above the maximum, which the PLC's string instructions handle unpredictably.

Do other SCADA packages cause the same empty S7 string?

Yes. Any writer that copies characters into the string without updating byte 1 produces it: HMI and SCADA packages that treat the string as a raw character block, and PLC logic that fills it with move instructions instead of string instructions. The test is always the same: read byte 1. Zero with characters present means the writer skipped the header.

Why did the strings appear after Ignition wrote them once?

Because Ignition's S7 driver is a compliant writer: every string write sets byte 1 to the number of characters it stored. The first Ignition write repaired the header as a side effect, which is also the quickest confirmation of the diagnosis on a live machine. Strings written only by Citect stay empty until byte 1 is set.

Is the per-character script a good long-term fix?

It works, but it does not scale. Each string costs 30 OPC items read individually, the result is not available as a native string tag to OPC UA clients, and every consumer must repeat the assembly and null stripping. Initialize byte 1 instead, and keep the script only for strings whose header you cannot write.

Keep reading

  • Troubleshooting

    Troubleshooting a SCADA PC station that reaches only one S7-1500

    When every S7-1500 answers ping but SCADA updates only one PLC, ping has proven nothing about the S7 link. Work the checks in order: four distinct MAC addresses on the PLC subnet, the S7ONLINE access point bound to the connected network card, one HMI connection per CPU, and every tag's Connection pointing at its own CPU's connection.

    SCADA and data logging

  • Troubleshooting

    Fix ControlLogix tags missing from Ignition OPC UA browse

    Restart the OPC-UA module, delete the stored /data/drivers/.tags file on the Ignition server, then refresh the browse from the device page — not the OPC Browser. The Logix driver resolves only addresses present in its browse results, so a hand-typed tag for a missing address stays Stale until the stored browse data is rebuilt.

    SCADA and data logging

  • Troubleshooting

    Fix SIMATIC NET OPC DA to an S7-1500 after a PLC swap

    Yes, SIMATIC NET v16 keeps serving OPC DA to the CPU 1511-1 PN; nothing new is bought on the PC side. The fix is PLC-side: enable PUT/GET in the CPU, clear optimized block access on the DBs you address absolutely, and load an XDB compiled from a TIA Portal PC station. OPC UA only needs the CPU's own server enabled and certificates trusted from firmware V2.9.

    SCADA and data logging