IMDHMIControls LibraryShop main store

Troubleshooting

Control a ClearSCADA scanner InService flag with IEC logic

SCADA and data logging Published 5 min read By IMDHMI controls team

Short answer

ViewX crashes because the script calls itself without end, and mimic scripts run only on the client while the mimic is displayed. Move the control into a ClearSCADA IEC Structured Text program on the server: map the digital input's CurrentValue as a DINT input, the scanner's InService as a BOOL output, and set execution to input processed so each new input value runs the program once. Keep a script only for one-off bulk changes such as a single UPDATE query.

On this page
  1. Why the self-calling script crashes ViewX
  2. The server-side IEC program
  3. Set execution to input processed
  4. Verify the control with no client connected
  5. Keep scripting for one-off bulk changes
  6. The decision
  7. Questions asked

Your ViewX client crashes because the script calls itself without end, and because mimic scripts run on the client, not on the server. The fix is to move the digital-input-to-scanner control into a ClearSCADA IEC Structured Text program on the server, with the execution method set to input processed: the program runs each time the server processes a new value for the input, writes the second scanner's InService flag, and needs no client at all. Here is why the script fails, the program to enter, the execution setting, the test that proves it, and where a script is still the right tool.

Why the self-calling script crashes ViewX #

Three properties of ViewX scripting combine to take the client down:

  • A self-call with no end. Check_point() calls itself from inside its own body, so every execution starts another one and nothing ever returns. Removing the self-call is what stopped the crash on your system, which identifies the recursion as the cause.
  • A client-side lifetime. Mimic VBScript executes in ViewX, only while its mimic is displayed. Close the mimic or disconnect the client and the control stops, so a function that must follow the plant around the clock cannot live there.
  • One script at a time. VBScript is single-threaded per client: launching another script terminates the one already running. A long-running control loop is the first casualty whenever an operator opens anything that also scripts.
  • No pacing. Every pass makes one read through Server.GetOPCValue and one write through Server.SetOPCValue, with no delay between passes, so the loop repeats as fast as client and server allow, hour after hour.

If the symptom were ViewX closing the instant a mimic is clicked, rather than after running a while, that is a different client-side fault; troubleshooting ViewX closing when a mimic is clicked covers that case.

The server-side IEC program #

IEC logic runs on the ClearSCADA server whether or not any client is connected, which is exactly the property the script lacks. A logic program reads and writes database items through direct variables, which are declared in VAR blocks with the documented AT %M(...) mapping. Enter this as a Structured Text program:

PROGRAM CheckPoint
VAR
  Current AT %M(.adam4055.DinStatus.CurrentValue) : DINT;
  ScannerStatus AT %M(.scada_project.adam4055.Din_Scanner.InService) : BOOL;
END_VAR
IF Current = 1 THEN
  ScannerStatus := TRUE;
ELSE
  ScannerStatus := FALSE;
END_IF;
END_PROGRAM;

Current and ScannerStatus are names of your own choosing; the AT %M(...) form is the documented direct-variable mapping. Current is a DINT input mapped to the digital input status point your first scanner polls, and ScannerStatus is a BOOL output mapped to the second scanner's InService property. Because both are direct variables, they take no initial value: the database item itself is the storage. The example paths are the ones from this application, and direct-variable references resolve relative to the program's own location in the database, so fix the VAR block if the program sits elsewhere.

Notice what the program is not: there is no loop. It reads one value, compares it, writes one value and finishes. The repetition comes from the execution method, not from the code.

Set execution to input processed #

In the program's properties, set the execution method to input processed. The Logic Guide defines it plainly: the program executes whenever one of its inputs is processed, meaning whenever the server receives a value for a point the program uses as an input but not as an output.

With the first scanner polling the ADAM module every 2 s, every processed poll result triggers exactly one execution. The timing works out as follows:

  • Worst case: the field contact changes just after a poll, so the next poll reads it 2 s later, and the server processes that value and runs the program in the same step. The InService write lands within 2 s plus one input-processing step, which is milliseconds, not seconds.
  • Average: the change arrives mid-interval, so about 1 s of waiting plus the same processing step.
  • Load: 24 h × 3600 s/h = 86,400 s per day; at one execution per 2 s poll that is 86,400 ÷ 2 = 43,200 executions per day, each a single comparison and a single write on the server, against a client loop with no delay at all.

Verify the control with no client connected #

  1. Drive the field input so the DIN point reads 1 through the normal polled path, not by writing the point directly. Confirm the second scanner's InService property shows TRUE.
  2. Drive the input to 0 and confirm InService shows FALSE.
  3. Close the mimic and disconnect ViewX completely. Change the field input once more and confirm the flag still follows. This third step is the proof that the control lives on the server, the one thing the script could never demonstrate.

Keep scripting for one-off bulk changes #

Scripting is not banned; it is wrong for unattended control and right for a one-off or operator-driven action, for example taking 500 points out of service in one go. Skip the per-point Server.SetOPCValue loop. Per the Scripting Guide, Server.Query accepts SELECT, UPDATE, INSERT and DELETE, so one statement does the whole job:

set rs = server.query("UPDATE CAdvOPCDigital SET InService = FALSE WHERE FullName LIKE 'Test.%'")

Check rs.Error and rs.ErrorMessage after the call. For a change this size you can also run the same SQL directly in querypad.exe from the Program Files folder, with no script at all.

One caution before you run it: the UPDATE takes every point matching the pattern out of service in a single step and there is no undo, so confirm the FullName pattern selects only the group you intend.

The decision #

  • Continuous, unattended control of InService from a live input: the Structured Text program above, with direct variables for the input point and the scanner property and execution on input processed. It runs on the server and tracks the field contact within one poll interval, client or no client.
  • A one-off or operator-driven bulk change: one UPDATE through Server.Query with the error check after it, or the same query typed straight into querypad.exe.
  • Any mimic script you keep: short, no self-calls, and nothing that must keep running once the mimic closes.

Questions asked

The IEC program is set to input processed but never runs. What is wrong?

The ClearSCADA Logic Guide troubleshooting lists this case directly: a program set to execute on input processed that does not contain a valid input will not run. In practice a direct-variable path in the VAR block fails to resolve to a real database item, so the program has nothing to trigger on. Correct the path, relative to the program's own location in the database, and the first processed input value starts it.

Can the same control be built as a function block diagram instead of structured text?

Yes. A function block diagram performs the same read-compare-write graphically, with the same direct-variable input and output and the same input-processed execution setting. When ClearSCADA generates the ST equivalent of a diagram, it attempts to order the program so inputs are processed before outputs, the same sequence the hand-written ST gives you.

A per-point out-of-service script runs but changes nothing. How do I see why?

Remove On Error Resume Next and its matching On Error GoTo 0, then run the script again: the runtime error stays visible and points to the failing line. FALSE, "FALSE", 0 and "0" should all work as the InService value, so the value form is not the problem. Replacing the loop with a single UPDATE query removes most of the places a per-point script can fail.

Does the program's own write to InService trigger another execution?

No. Input-processed execution fires when the server processes a value for a point used as an input but not as an output, and InService is mapped as the output here. That is why the logic cannot chase itself the way the script did: it runs once per new input value, writes the flag, and stops until the next poll result arrives.

Keep reading

  • Troubleshooting

    Why a Modicon M221 bit stays fixed in Kepware over Modbus TCP

    A Modbus TCP tag at 00001 that never changes usually reads the wrong Modbus object, not a broken link. The M221 does not expose its %I inputs to a read request, so match the controller's documented coil mapping, then correct Kepware's zero-based addressing option before blaming the network.

    SCADA and data logging

  • Troubleshooting

    Why AdvancedHMI Modbus TCP floats stop reading a PLC

    A blank float in AdvancedHMI over Modbus TCP is almost never a byte-swap problem: when 16-bit integers work while floats stay blank, append the @F address modifier to the float address, as in 40001@F, so the driver reads two registers and decodes them as a 32-bit float. If every analog control goes blank at once, the PLCAddressValue read properties were cleared; restore them from a backup.

    SCADA and data logging

  • Troubleshooting

    Why Citect sends no Modbus TCP requests to a PLC

    When Wireshark shows the SCADA host emits no Modbus TCP frame at all while an empty project with the same device, port and protocol reaches the same test server, the request-generation path in the original project is dead. Check I/O server startup, device-to-server ownership, variable acquisition and duplicate device definitions before touching the PLC or the network.

    SCADA and data logging