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
- Architecture and Fundamental Mechanics
- Step-by-Step Implementation Procedure
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
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:
-
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. -
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. -
Variable Management in SIMIT: Native SIMIT scripts do not support arbitrary variable declarations (e.g., declaring
float xorstring 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. -
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
- Format test sequences into a standard CSV spreadsheet with columns for
Time,Signal_Name, andTarget_Value. - In SIMIT, navigate to the Component Library ->
Standard components -> Math / Sources. - Drag a
TableorCurvecomponent onto a SIMIT diagram chart. - Open the component properties and click
Import. Select the CSV file to load the data matrix into memory. - 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)
- Ensure SIMIT is licensed with the Automation Interface / API option.
- Create an external test script (e.g.,
run_tests.py) using Python. - Use the Python
csvorpandasmodule to open and parse the external test matrix (test_scenarios.csv). - Connect to SIMIT via the COM object (
win32com.client.Dispatch('SIMIT.Application')) or SIMIT REST API. - 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 usingsimit.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
- In the SIMIT project navigator, open
Signals -> User Signals. - Click
New Signalto declare variables (e.g.,Test_Counterof type Integer,Temp_Floatof type Real). - In native SIMIT scripts, assign and evaluate these signals:
SET Test_Counter = Test_Counter + 1.
Verification
Verify automated test scenario execution:
-
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.
-
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.
-
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
- SIMIT Simulation Platform Operating Manual V10.2
- SIMIT Component Type Editor (CTE) Modeling Guide
- Test Automation with SIMIT Automation Interface Application Example
Related Articles
- SIMIT Virtual Controller Licensing Architecture and Controller Stacking Rules
- Architectural Boundaries and Controller Limits in SIMIT Demo Mode
- Testing and Replacing Instantiated SIMIT Simulation Macros
Related Tags
- SIMIT
- Scripting
- Test Automation
- CTE
- Virtual Commissioning
- Simulation