overview
The SimWB test script is an executable program created by the user. It provides the ability to manipulate the RTDB every model execution cycle.
It may be used to peek or poke RTDB variables, control simulation execution, create signal generators, etc. An example use of a test script
would be to simulate a hardware failure by replacing values read from I/O devices after the read stage, but before the models have run.
SimWB provides APIs for C, SWs
(a custom real-time scripting language) and Python.
Content
Prerequisites
We will continue using the autotrans_demo model (see more information about this demo in here). In this example, we are going to write a script with C to manipulate the RTDB item SWthrottle. In the C script program, we will attach a square wave to the RTDB item SWthrottle. The idea is that, during the running of the test, SWthrottle is going to get its value for each simulation cycle from the square wave we pre-defined in the test script.
Note: Since the RTDB autotrans_demo is created under the <default> project folder, make sure the <default> project folder is selected in the SimWB Control Center.
Create a Script for a SimWB Test
- Click Scripts button (
) in the toolbar and land on the Scripts page.
- Select C Script, enter the name of script autotrans_demo_script, and click add script button
to the script.
- A folder with name autotrans_demo_script is added to the list if folders under Script Files tab.
- In the folder, three files are automatically added -- Makefile, autotrans_demo_script.c, description
- Edit autotrans_demo_script.c, locate the ccurCScript_init routine, and under this routine, attach a square wave signal generator to RTDB item SWthrottle using ccurGen_addGenerator method. For more information about the C API, click here.
- Compile the C script programming by clicking the Make button (
). If make successfully, autotrans_demo_script execuatble will appear in the folder and also in the Script Executables list.
![Image -- new created script folder](../../img/create_script_ori.png)
![Image -- snippet of added code](../../img/script_add_siggen.png)
![Image -- Make successful](../../img/script_make_success_ori.png)
![Image -- list of executables;](../../img/script_exec_list_ori.png)
Create New Test with Script
Note: remember a SimWB test configuration can NOT be modified after it is created (such as changing RTDB, adding script, adding new models to the test), so we have to create a new test to run the autotrans_demo with the script.
Please refer to Create Test under SimWB Control Center to review how to create a test. Only in this cases, we select autotrans_demo_script in Test Script when creating the test.
![Image -- create test](../../img/test_with_script_ori.png)
Run the Test and View RTDB Items Behavior in Real-Time Viewer
Please refer to Run Test and Real-time Viewer for more detail on how to start a test and use Real-time Viewer.
View SWthrottle in a chart and verify it's indeed a square wave.
![Image -- rtviewer, script](../../img/script_test_rtviewer_full.jpg)