IMD SolutionComputing LibraryShop main store

Troubleshooting

Write PI bad quality as a system digital state in UFL

Edge computing and IIoT Published 7 min read

Short answer

A quality label such as Bad or NaN cannot enter a Float32 PI tag through the value argument. Map it to the status argument of StoreInPI instead: 0 writes the value as good, -290 writes the system digital state Bad Data on a non-digital tag. Declare STATUS as a string, parse every field above the IF branch, and keep the StoreInPI call outside it so each record writes its own value and timestamp.

On this page
  1. Why a quality label fails in a numeric value field
  2. Map quality to the status argument of StoreInPI
  3. Declare STATUS as a string, not a number
  4. Writing three extracted records for the Float32 tag Tag1
  5. Keep the parse lines and the write call outside the branch
  6. Decisions by case
  7. Questions asked

A quality label such as Bad, Bad Tag, Unavail or NaN cannot be coaxed into a Float32 PI tag through the value argument: the UFL numeric cast fails before anything reaches the archive, and the interface never turns a failed conversion into a bad-quality event on its own. Send quality through the status argument of StoreInPI instead — 0 writes a value as good, and the Bad Data state number writes the system digital state on a non-digital tag — declare STATUS as a string, parse every field of the current record above the IF branch, and keep the write call outside it. With that in place, three extracted records produce three archive events, each at its own timestamp.

Why a quality label fails in a numeric value field #

StoreInPI converts the value argument to the destination point's type before it writes anything. The text Bad cannot become a Float32 number, so the cast throws a conversion error and no event is archived: the interface does not read a failed conversion as a request to store a bad-quality state. Substituting quality text for bad values in the extraction SQL therefore moves the failure into UFL rather than removing it.

The substitution also destroys a distinction the migration needs. In the IP21 source, one record can hold 0 with Good quality and another 0 with Bad quality; an extract that keeps only TagName, Timestamp and Value makes those two events indistinguishable on the file. Export the quality column and map it in UFL instead, so a valid zero stays a valid zero. An event with bad quality is supposed to carry no usable reading — that is what the quality flag means, as covered in Why a bad quality update hides Historian values.

Check these symptoms first:

  • Good numbers import but the label Bad fails with a conversion error — the label reached the value cast.
  • A good zero and a bad zero look identical in the file — the extract dropped the quality column.
  • NaN fails the same way — the cast cannot parse it, so it needs the same explicit mapping as Bad.
  • A bad record shows the previous timestamp's value — a parse line or the write sits inside the IF branch.
  • The archive shows No Data where Bad Data was expected — something overwrote the status after the branch assigned it, typically a stray extraction expression filling Status from the file.

Map quality to the status argument of StoreInPI #

The write call takes the state separately from the value: StoreInPI(Tag, InstrumentTag, Timestamp, Value, Status). The UFL documentation defines Status as a number that corresponds to an entry in the PI system digital set — 0 for a valid value, a positive number for a digital tag, a negative number for every other data type. The Bad Data entry this migration writes is the state number -290.

For one good record and one bad record on a Float32 tag:

StoreInPI(Tag1, , 04/12/2024 08:00:00, 100.5, 0)
StoreInPI(Tag1, , 04/12/2024 08:01:00, 0, -290)

The second call archives the system digital state Bad Data at 08:01:00 — not a good zero, and not a measurement of -290. Placing the state number in the value argument with a good status would instead store a valid reading of minus 290, a different event entirely.

The same rule holds whenever you write timestamped history back into a SCADA server: every event must carry its own timestamp and its own quality, never the previous record's.

OPEN, RUN and CLOSED are a different case: they are process states of a digital point, not quality. The documented convention puts them on the positive side — for a destination digital tag, the status number indexes that tag's digital state set — so map each label to its own state number and keep the negative quality states for non-digital types. UFL cannot recover an underlying DCS boolean from exported state text: the file contains only what the extraction wrote, so a needed raw value must be added to the extraction on the source side.

Declare STATUS as a string, not a number #

On the reported installation, declaring STATUS as a number threw a conversion error at the assignment inside the IF and stopped the record; declaring STATUS as a string and assigning the state number as text let every record reach the archive, because the write path accepts numeric text in that argument. That string declaration is reported behavior on one interface build, not a documented rule — the documented part is the status argument and its sign convention — so test it against your own build with one good record and one bad record before the full migration. Match the declarations to the data: Value_Temp as string for the raw field text, Value as number for the converted reading, Status as string for the state number.

Writing three extracted records for the Float32 tag Tag1 #

Inputs: an example extract in the TagName, Timestamp, Value layout the migration produces, with quality labels substituted for the bad values. Parse the timestamps with the format and time zone the file actually uses, because a mismatch shifts every migrated event, as covered in Historian shows a real value hours off: check the UTC offset.

Tag1,04/12/2024 08:00:00,100.5
Tag1,04/12/2024 08:01:00,BAD
Tag1,04/12/2024 08:02:00,97.2

Declarations: Value_Temp as string, Value as number, Status as string.

The rule in words: read the whole record first; compare the raw value text against the quality labels; on the bad branch assign the Bad Data state number to Status and a placeholder zero to Value; on the good branch assign a good status and convert the raw text to a number; write once, after the branch, using this record's fields.

Value_Temp=["*,*,*,(*)"]
Value=["*,*,(*),*"]
IF (Value_Temp == "BAD" OR Value_Temp == "BAD TAG" OR Value_Temp == "UNAVAIL") THEN
  Status = "-290"
  Value = 0
ELSE
  Status = "0"
  Value = Value_Temp
ENDIF
StoreInPI(TagName,,Timestamp,Value,Status,)

The two extraction expressions adapt to your .ini field layout; the field positions shown match the reported configuration.

Arithmetic, record by record:

  • 08:00:00 — "100.5" matches no label, so the good branch runs and the archive holds a valid reading of 100.5.
  • 08:01:00 — "BAD" matches, so Status takes the Bad Data state number, Value takes the placeholder zero, and the archive holds Bad Data at 08:01:00.
  • 08:02:00 — "97.2" takes the good branch, and the archive holds a valid reading of 97.2.

Result: three records in, three events out, each at its own timestamp; a real zero with good quality would take the good branch and stay a good zero.

Decision: compare the archive event count for the migrated range with the line count in the file. Equal counts mean the mapping works; fewer events, or a bad timestamp carrying an earlier value, means a parse line or the write is inside the branch — apply the three fixes in the next section. Keep the source extracts until that count check and a spot check at known timestamps have passed, because any calculation that ignores status reads the bad event's placeholder zero as a real zero.

Keep the parse lines and the write call outside the branch #

The reported half-working logic passed three values and archived two, with the bad timestamp carrying the previous timestamp's value; changing the archive substitution mode did not change it, because the cause was execution order. Three fixes:

  1. Delete the extraction expression filling Status from the file, reported as Status=["*,*,*,(*)"] — it overwrites the state assigned inside the branch, which is how a Bad Data write came out as No Data.
  2. Move the two value expressions, reported as Value=["*,*,(*),*"] and Value_Temp=["*,*,*,(*)"], above the IF so every record is parsed before classification; a record that skips the branch must not inherit the previous record's text.
  3. Move StoreInPI(TagName,,Timestamp,Value,Status,) below ENDIF: inside the branch it fires only for matching records, so the others are never written at all.

After the reorder, each record parses, classifies and writes its own value and timestamp, and the archive event count matches the file.

Decisions by case #

  • Non-digital destination such as Float32, record labeled Bad, Bad Tag, Unavail, Suspect or NaN: placeholder zero in the value argument, -290 in the status argument; the archive stores Bad Data.
  • Same destination, record with a usable number: the converted number in the value argument with a good status; the archive stores the reading.
  • Digital destination with real process states such as OPEN/CLOSED or RUN/STOP: map each label to its own state number in that tag's digital set; never write a quality state into a process-state tag.
  • A field the extract never carried, such as the underlying DCS boolean: fix it in the extraction SQL on the source; no UFL setting reconstructs it.

Questions asked

Does the state number passed in the status argument end up in the archive as the tag's value?

No. The number selects an entry of the PI system digital set, and the archive stores that state, Bad Data, as the event. The placeholder zero in the value argument exists only to satisfy the write call and never becomes a measurement. Read the migrated event back at its timestamp to confirm: a correct write shows the state name, not a number.

Can UFL recover the DCS boolean behind OPEN, RUN or CLOSED text in the extract?

No. UFL reads only what the extraction file carries, so it sees the state text the source exported and nothing else. To store the underlying boolean or raw code, add it as its own column in the extraction SQL on the source side, then map that column's position in the .ini field layout and write it like any other value. The UFL configuration cannot reconstruct a field the extract never contained.

What status applies when the destination is a genuine digital tag with states such as OPEN and CLOSED?

For a digital tag the documented convention uses the positive side: the status number indexes the entry of that tag's digital state set, while negative state numbers are reserved for non-digital data types. Confirm the destination digital set exists before the run, map each label to its own state number, and keep quality states out of a tag whose states are process positions.

How should a NaN value in the extract be handled?

Treat it like any other invalid label: add it to the same comparison list as the quality labels so it routes to the bad-state status before the numeric cast, never through the value conversion. Also check what NaN meant in the source system. If it marks a distinct condition rather than plain bad quality, give it its own mapping instead of collapsing it into the same state.

Keep reading

  • Selection guide

    Choosing a PI System to Oracle integration route with validation

    With read-only PI access and cleansing owned by the receiving side, pull AF assets and status with the PI OLEDB Enterprise Provider through SSIS into a staging SQL Server, qualify transitions there — reject momentary interruptions and anything older than 2 hours — then write Oracle. Event Frames and the RDBMS interface need PI-side configuration or tag-based mapping that loses AF context.

    Edge computing and IIoT

  • Troubleshooting

    Fix historian silent data gaps with a registry value

    The data is stored; the retrieval view of it is stale. On the Historian server, create the DWORD32 value UseFileCacheForRetrieval set to 0 under HKLM\SOFTWARE\ArchestrA\Historian\Programs\aahStorage, then refresh the trend, with no reboot required. Confirm the fix by loading a previously blank window before running any manual query.

    Edge computing and IIoT

  • Selection guide

    Manual lab data entry into a historian: choosing the write path

    Put every measured variable into its own timestamped PI point and write it from inside PI Vision with a manual-entry symbol; keep specifications, qualifiers, blanks and notes as separate AF fields, not in the value. The load is only 1,800 values per day, so the decision rides on the write path, authentication and per-operator write rights, never on avoiding the 300 points.

    Edge computing and IIoT

Why Wonderware System Platform tags do not reach Historian