Automated Test Scripting in SIMIT: Reading External Scenario Files and Variable Management

Automated Test Scripting in SIMIT: Reading External Scenario Files and Variable Management

In the SIMIT Simulation Platform, native simulation scripts and Component Type Editor (CTE) components operate in high-performance cyclic loops that do not support arbitrary OS file I/O operations (such as opening and reading .txt or .csv files at runtime). To execute automated test scenarios driven by external data files, use one of three supported methods: (1) Import external test curves or lookup data prior to simulation using the SIMIT Import Wizard and Standard Table components; (2) Utilize the SIMIT Automatic Control Interface or SIMIT API via an external Python or C# test runner that reads the external scenario file and writes values directly to SIMIT signals; or (3) Exchange dynamic test vectors via Shared Memory Couplings.

Table of Contents

Executive Summary

As virtual commissioning and automated testing become standard engineering practices for SIMATIC PCS 7 systems, test engineers increasingly utilize the SIMIT Simulation Platform to validate complex technological control schemes prior to plant delivery. A frequent engineering objective is developing automated, repeatable test harnesses—such as simulating pneumatic cylinder stroke travel, valve interlock timings, and motor trip sequences—driven by external test scenario files (.txt or .csv). However, test engineers discover that SIMIT's native scripting engine and Component Type Editor (CTE) do not provide standard file-reading APIs or general-purpose runtime variable instantiation. This article provides architectural clarity on SIMIT's execution boundaries and establishes supported methods for file-driven automated testing.

Architecture and Fundamental Mechanics

The execution architecture of SIMIT enforces strict separation between real-time simulation cycles and general-purpose scripting:

  1. Native Scripting Execution Engine: SIMIT provides a built-in Scripting environment designed for sequence automation. The scripting syntax supports operational commands such as SET (assigning signal values), WAIT (pausing simulation time), CHECK (evaluating boolean or analog feedback assertions), and _printlog() (writing execution results to an output log). However, the engine intentionally lacks low-level file stream readers (fread, open, readline) to prevent script execution from stalling real-time simulation cycles.

  2. Component Type Editor (CTE) Constraints: Custom components built with the Component Type Editor (.simcmp) execute within the core SIMIT calculation loop (typically running at fixed cycle intervals such as 10 ms or 100 ms). Because blocking OS file I/O calls would violate deterministic calculation deadlines, CTE behavior descriptions prohibit direct filesystem interactions. All model parameters must be declared as static component properties or bound via input connectors.

  3. Variable Management in SIMIT: Native SIMIT scripts do not support arbitrary variable declarations (e.g., declaring float x or string buffer). Instead, data storage in SIMIT is signal-based. If an automated script requires intermediate state retention, engineers must instantiate internal simulation variables (User Signals) in the SIMIT Task Navigator, which scripts can read and write using standard signal names.

  4. External Test Automation Architecture: To dynamically ingest external text or CSV test matrices, the industry standard architecture uses an external test controller (written in Python or C#). The external runner parses the scenario file and drives the simulation using the SIMIT Automation API (COM interface or REST API) or through a high-speed Shared Memory Coupling.

Step-by-Step Implementation Procedure

Implement file-driven automated scenario testing using the following engineering approaches:

Approach 1: Pre-Importing Test Matrices via SIMIT Table Components

  1. Format test sequences into a standard CSV spreadsheet with columns for Time, Signal_Name, and Target_Value.
  2. In SIMIT, navigate to the Component Library -> Standard components -> Math / Sources.
  3. Drag a Table or Curve component onto a SIMIT diagram chart.
  4. Open the component properties and click Import. Select the CSV file to load the data matrix into memory.
  5. Wire the table output to the physical input signals of the controller coupling (e.g., SIMIT Virtual Controller).

Approach 2: Driving SIMIT via External Python Test Script (SIMIT API)

  1. Ensure SIMIT is licensed with the Automation Interface / API option.
  2. Create an external test script (e.g., run_tests.py) using Python.
  3. Use the Python csv or pandas module to open and parse the external test matrix (test_scenarios.csv).
  4. Connect to SIMIT via the COM object (win32com.client.Dispatch('SIMIT.Application')) or SIMIT REST API.
  5. In the script loop:
    - Read scenario input rows.
    - Write input states to SIMIT tags: simit.SetSignalValue('Valve_Open_Cmd', True).
    - Wait for simulated transit time using simit.Step(100).
    - Read back feedback sensor states: actual = simit.GetSignalValue('Sensor_Opened').
    - Assert test pass/fail results and write out the verification report to disk.

Approach 3: Intermediate Variable Handling via User Signals

  1. In the SIMIT project navigator, open Signals -> User Signals.
  2. Click New Signal to declare variables (e.g., Test_Counter of type Integer, Temp_Float of type Real).
  3. In native SIMIT scripts, assign and evaluate these signals: SET Test_Counter = Test_Counter + 1.

Verification

Verify automated test scenario execution:

  1. API Handshake Verification: Run the external Python test runner against a running SIMIT project. Verify that the console confirms connection to the SIMIT runtime process and correctly enumerates project signals.

  2. Signal Drive Inspection: Observe SIMIT chart diagrams online. Confirm that inputs update synchronously in response to external test file rows, triggering realistic sensor feedback responses.

  3. Automated Test Report Generation: Verify that the external runner records all signal transitions, evaluates test tolerances, and exports a structured pass/fail test report upon simulation completion.

Limitations and Operational Precautions

Native SIMIT scripts are strictly designed for sequential stimulus and verification within the SIMIT application window; do not attempt to embed arbitrary OS scripting or file handles into native SIMIT script blocks. Furthermore, high-frequency external API polling can degrade simulation performance if called faster than the underlying simulation cycle rate. For microsecond hardware-in-the-loop testing, utilize dedicated Shared Memory Couplings rather than REST APIs.

Engineer FAQ

Can SIMIT native scripts declare local variables like char or float?

No. SIMIT scripting does not support language-level variable declarations. To store intermediate values, create 'User Signals' in SIMIT's signal list, which can then be manipulated like any process tag.

Is there an open file command in native SIMIT scripts?

No. The native scripting language provides _printlog() to write entries into log files, but has no command to open or read files.

What interface allows Python or C# to control SIMIT?

SIMIT provides the Automatic Control Interface (ACI) and the SIMIT Automation API, allowing external programs to control simulation runs and manipulate signals.

Can CTE components perform file I/O?

No. CTE components execute inside real-time cyclic calculation loops. Performing blocking disk I/O would cause deterministic calculation overruns and is prohibited.

Can I load a sequence of setpoints from an Excel file into SIMIT?

Yes. You can import Excel or CSV data tables into SIMIT using the Table or Curve components, or import signal lists via the SIMIT Import Wizard.

Technical References

Related Articles

Related Tags

  • SIMIT
  • Scripting
  • Test Automation
  • CTE
  • Virtual Commissioning
  • Simulation
20 respuestas