CASP supports building and running CASP models using Python scripts. This feature allows developing models programmatically in Python and deploying them on the target with highly efficient and production ready code. This test project runs a simple Python script from CASP Python examples to validate whether CASP Python libraries are correctly installed and functional and whether the CASP Python libraries installed path is correctly added to the PYTHONPATH environment variable.
Pre-Requisites
- CASP software is properly installed and functional.
- Native compiler tool chain is installed.
- CASP Python Libraries are installed.
Model Details
The Python script models a sine wave generator connected to a plotter and configures to run on native target.
Procedure
- Start CASP program, click Start button on top left corner and select ‘Open Folders > CASP User Data Folder’.

- It opens ‘casp_user_data’ folder in the explorer. Navigate to ‘casp_user_data/pycasp/examples’ folder.
- Open operating system terminal (also called command prompt in Windows) from within the folder and run the Python script ‘ex01_native_sine_wave.py’ from the terminal by typing command: >python ex01_native_sine_wave.py.
- CASP should start and run the model from the Python script. Below is the output of the model in Windows OS, similar output is expected on other supported platforms.

Python Source
Python source code for this example is given below
import sys
# Import CASP Python module
import casp
# Initialize CASP
casp.Init(False)
# Show Block Viewer window for browsing and selecting blocks. This is usefull in interative mode where user can browse for required blocks. Right click on the choosen block and select 'Show Python Script' to show Python script of the block.
#casp.BlockViewer()
# Import required CASP block Python modules.
from blks import SignalGenerator664599731 as SignalGenerator
from blks import TimePlotter166251707 as TimePlotter
# Create and open default project
casp.ProjectOpenDefault()
# Add a group and plotter sub-window to the simulation panel to display the sine plot.
casp.SimPanelWindowAdd("MyGrp0", "MyWnd0", casp.wtypes.PLOT_DISPLAY)
# Add signal generator block with block name 'sig0'. Save the block id returned by the function for later use.
sig0_id = casp.BlockAdd(SignalGenerator.path, "sig0")
#no need to set any block parameters. we will use the defaults.
# Similarly add a plotter block with suitable block name. Save the block id returned by the function for later use.
plot0_id = casp.BlockAdd(TimePlotter.path, "plot0")
# Assign plotter block to the simulation panel group and sub-window (created above)
casp.BlockParaSet(plot0_id, "_Simulation Panel$Group", "MyGrp0")
casp.BlockParaSet(plot0_id, "_Simulation Panel$Group SubWindow", "MyWnd0")
# Connect signal block's output port to plotter block input port.
casp.BlockPortsConnect(sig0_id, "o1", plot0_id, "i1")
# Set simulation to real time (by setting simulation speed factor to 1).
casp.SimSetupSpeedFactor(1)
# Run simulation.
casp.SimStart()
# Open project folder. Go through the log files (log_build_wnd.txt and log_msg_wnd.txt) in the project folder for any error/warning messages.
casp.FolderProject()
# Promptly close CASP model editor program. Simulation panel program will still be running.
casp.Close()
