CASP Python Libraries
This documentation primarily focuses on the usage of functions from 'casp', 'casp_be', 'casp_gpio' and 'casp_udio' namespaces.
Loading...
Searching...
No Matches
casp Namespace Reference

This module defines all necessary functions to. More...

Functions

 Init (bool make_visible=False, str casp_file="CASP-Eval")
 Initializes CASP subprocess.
 Close ()
 Terminates CASP subprocess and releases the resources.
 BlockViewer ()
 Invokes BlockViewer process for user to browse CASP blocks, view block parameters, block documentation etc.
 SerialPorts ()
 Displays available serial ports on the host.
 Refresh ()
 Refreshes CASP project.
 SerialTerminal ()
 Invokes CASP Serial Terminal window.
 Rtv ()
 Opens CASP Remote Terminal Viewer (RTV) process.
 BleClient ()
 Opens CASP Bluetooth Low Energy (BLE) process.
 Help ()
 Opens CASP main documentation.
 HelpBsp ()
 Opens CASP board support package (BSP) documentation.
 HelpPython ()
 Opens CASP Python Libraries documentation.
 FolderUserData ()
 Opens 'CASP User Data' directory from user's Documents folder.
 FolderTargetSupport ()
 Opens current CASP target support folder.
 FolderProject ()
 Opens current CASP project directory.
 FolderTutorials ()
 Opens CASP tutorials directory.
 FolderExamples ()
 Opens CASP examples directory.
str ProjectCreate (str proj_name=None)
 Creates new CASP project and returns the project path.
str ProjectOpen (str proj_full_path=None)
 Opens existing CASP project.
str ProjectOpenDefault ()
 This function does a couple of things.
 WspClear ()
 Clears default project workspace i.e.
 ProjectHelp ()
 Opens project's documentation.
 ProjectSave ()
 Saves current project.
 ProjectClose ()
 Closes current project.
 TargetSet (str target_name)
 Set target hardware on which the current model has to execute.
 TargetIdSet (str target_id)
 Set target ID.
 ProgrammerSet (int programmer=defs.PROGRAMMER0)
 Set programmer port.
 ProgrammerPortSet (str serial_port)
 Set serial port to which the device or development board to be programmed is connected.
 RemoteBuildIPSet (str ip)
 Set IP address of remote device supporting CASP Remote Build protocol.
 RemoteBuildRtvEnable (bool enable=True)
 Set enable or disable Remote Terminal Viewer feature on remote build device.
 GenPyCode (bool skip_disabled_blocks=True)
 Generates Python code for the current project model.
 SimPanelWindowAdd (str grp_name, str wnd_name, int wnd_type)
 Adds new sub-window to an existing group.
 SimSetupFiniteTime (bool set=True)
 Sets simulation execution to finite time.
 SimSetupEndTime (int time_msec=1000)
 Sets simulation end time in milli seconds.
 SimSetupTimeStep (int time_usec=1000)
 Sets simulation time step in micro seconds.
 SimSetupPlotStep (int plot_step=1)
 Sets simulation plot step.
 SimSetupPlotSamples (int plot_samples=10000)
 Sets simulation plot samples.
 SimSetupSpeedFactor (float sf=1)
 Sets simulation speed factor.
 SimSetupPrecision (int precision=defs.PRECISION_32)
 Sets simulation integer and floating point precision to 32-bit, 48-bit (applicable to FPGA) and 64-bit.
 SimSetupOptLevel (int opt_level=1)
 set compiler optimization level (0 to 5: 4-opt for size, 5-opt for speed)
 SimSetupMaximumModelThreads (int max_threads=1)
 Sets maximum threads limit that can run in parallel during execution.
 SimSetupMaximumBlockThreads (int max_threads=1)
 Sets maximum block threads limit that can run in parallel within a block during execution.
 SimSetupTargetPythonSupport (bool enable_disable=True)
 Enables or disables python support for the current target.
 SimSetupOpenMpThreads (int max_threads=1)
 Sets maximum OpenMP threads that can be created for the current target (if this feature is supported by the target).
 SimSetupOpenClSupport (int platform_index=-1, int device_index=-1)
 Configures OpenCL support for current target.
 SimSetupCudaSupport (int device_index=-1)
 Configures CUDA support for current target.
 ModelValidate ()
 Quickly validates current model for any errors and displays the result of validation in brief.
 Build ()
 Builds current model and displays the result of the build process.
 BuildFresh ()
 Generally, casp.Build() function skips un-modified code files during build to speed up the build process.
 BuildCancel ()
 Cancels current build process.
 BuildClear ()
 Clears previous build data including all the intermediate build files.
 SimStart ()
 Starts simulation if the target supports simulation panel.
 SimStartPrev ()
 Starts simulation (or target programming) with previous build data.
 SimStop ()
 Stops current simulation (or target programming) process.
int BlockAdd (str blk_path, str blk_name=" ")
 Adds new block to the current model.
 BlockHelp (int blk_id)
 Displays block documentation of specified block Id.
 BlockNameSet (int blk_id, str blk_name)
 Sets block name of the specified block instance Id.
 BlockEnable (int blk_id, bool enable=True)
 Enable or disable a block in the current model.
 BlockRelocate (int blk_id)
 Auto relocates the block instance in the workspace.
 BlockParaSet (int blk_id, str grp_para_name, str para_val)
 Sets block parameter value of the specified block instance Id.
 BlockInitConditionSet (int blk_id, str grp_para_name, str para_val)
 Sets block initial condition value of the specified block instance Id.
 BlockPortsConnect (int blk_id1, str port_name1, int blk_id2, str port_name2, bool auto_update_input_port_para=True)
 Connects two block ports.
bool BlockDelete (int blk_id)
 Deletes specified block Id instance from the model.

Detailed Description

This module defines all necessary functions to.

  • start CASP process
  • create a new project or open an existing project
  • set target on which the created model is executed
  • create a model with blocks as per desired logic
    • add blocks to the model
    • adjust each block parameters as required
    • connect the blocks
  • build and compile the model
  • run the model on the target hardware
  • and finally when every thing is done, close the CASP process

All functions in this module uses global object _casp_process.casp_proc from _casp_process.py module.

Function Documentation

◆ Init()

casp.Init ( bool make_visible = False,
str casp_file = "CASP-Eval" )

Initializes CASP subprocess.

This is the first function to be called before using any other functions in this module.

Arguments:

visible: Set True to make CASP window visible.

casp_file: Set CASP executable file to be invoked. Set this argument only if the executable file version is different from 'CASP-Eval'.

Definition at line 31 of file casp.py.

◆ Close()

casp.Close ( )

Terminates CASP subprocess and releases the resources.

Definition at line 42 of file casp.py.

◆ BlockViewer()

casp.BlockViewer ( )

Invokes BlockViewer process for user to browse CASP blocks, view block parameters, block documentation etc.

Definition at line 47 of file casp.py.

◆ SerialPorts()

casp.SerialPorts ( )

Displays available serial ports on the host.

User can use this function before using the ProgrammerPortSet() function.

Definition at line 54 of file casp.py.

◆ Refresh()

casp.Refresh ( )

Refreshes CASP project.

For further details about refreshing CASP project, please refer CASP main documentation Help().

Definition at line 60 of file casp.py.

◆ SerialTerminal()

casp.SerialTerminal ( )

Invokes CASP Serial Terminal window.

Definition at line 65 of file casp.py.

◆ Rtv()

casp.Rtv ( )

Opens CASP Remote Terminal Viewer (RTV) process.

For further details please refer to CASP main documentation Help().

Definition at line 70 of file casp.py.

◆ BleClient()

casp.BleClient ( )

Opens CASP Bluetooth Low Energy (BLE) process.

For further details please refer to CASP main documentation Help().

Definition at line 75 of file casp.py.

◆ Help()

casp.Help ( )

Opens CASP main documentation.

Definition at line 80 of file casp.py.

◆ HelpBsp()

casp.HelpBsp ( )

Opens CASP board support package (BSP) documentation.

Definition at line 85 of file casp.py.

◆ HelpPython()

casp.HelpPython ( )

Opens CASP Python Libraries documentation.

Definition at line 90 of file casp.py.

◆ FolderUserData()

casp.FolderUserData ( )

Opens 'CASP User Data' directory from user's Documents folder.

Definition at line 95 of file casp.py.

◆ FolderTargetSupport()

casp.FolderTargetSupport ( )

Opens current CASP target support folder.

Definition at line 101 of file casp.py.

◆ FolderProject()

casp.FolderProject ( )

Opens current CASP project directory.

Definition at line 107 of file casp.py.

◆ FolderTutorials()

casp.FolderTutorials ( )

Opens CASP tutorials directory.

Definition at line 113 of file casp.py.

◆ FolderExamples()

casp.FolderExamples ( )

Opens CASP examples directory.

Definition at line 119 of file casp.py.

◆ ProjectCreate()

str casp.ProjectCreate ( str proj_name = None)

Creates new CASP project and returns the project path.

Arguments:

proj_name: Project name to be created.

Return Value:

Returns project path where the project is created.

Definition at line 125 of file casp.py.

◆ ProjectOpen()

str casp.ProjectOpen ( str proj_full_path = None)

Opens existing CASP project.

Arguments:

proj_full_path: Project full path (along with project file extension .prj) should be provided as argument. If no argument is provided, CASP opens most recent project created or closed.

Return Value:

Returns project path that was opened.

Definition at line 147 of file casp.py.

◆ ProjectOpenDefault()

str casp.ProjectOpenDefault ( )

This function does a couple of things.

  • It creates a temporary project along with a default workspace (.wsp) file.
  • Loads/open the temporary project.
  • Creates two simulation panel windows of type '2D Plotter' and 'Controls/Meters'

Please note that the temporary project files created using this function and further modified using other functions will be available till next CASP process start. Once CASP restarts these files will be deleted.

User is recommended to use this function (in place of above two functions) to quickly create a project and start working on it.

Return Value:

Returns project path that was opened.

Definition at line 169 of file casp.py.

◆ WspClear()

casp.WspClear ( )

Clears default project workspace i.e.

deletes all blocks that were created in the workspace. This function is rarely required to be used by the user.

Definition at line 195 of file casp.py.

◆ ProjectHelp()

casp.ProjectHelp ( )

Opens project's documentation.

Definition at line 201 of file casp.py.

◆ ProjectSave()

casp.ProjectSave ( )

Saves current project.

Definition at line 206 of file casp.py.

◆ ProjectClose()

casp.ProjectClose ( )

Closes current project.

Definition at line 212 of file casp.py.

◆ TargetSet()

casp.TargetSet ( str target_name)

Set target hardware on which the current model has to execute.

It also updates casp_pins.py with the selected target pin variables for later use, and reloads it.

Arguments:

target_name: Target name string from \ref casp_targets.py file.

Definition at line 218 of file casp.py.

◆ TargetIdSet()

casp.TargetIdSet ( str target_id)

Set target ID.

Arguments:

target_id: Target ID string to be set.

Definition at line 229 of file casp.py.

◆ ProgrammerSet()

casp.ProgrammerSet ( int programmer = defs.PROGRAMMER0)

Set programmer port.

In most cases leave it to default.

Arguments:

programmer: Use either \ref casp_defs.PROGRAMMER0 or \ref casp_defs.PROGRAMMER1.

Definition at line 239 of file casp.py.

◆ ProgrammerPortSet()

casp.ProgrammerPortSet ( str serial_port)

Set serial port to which the device or development board to be programmed is connected.

Use function SerialPorts() to display available serial ports on the host.

Arguments:

serial_port: Set serial port to which the device to be programmed is connected.

Definition at line 249 of file casp.py.

◆ RemoteBuildIPSet()

casp.RemoteBuildIPSet ( str ip)

Set IP address of remote device supporting CASP Remote Build protocol.

Please refer CASP main documentation for details on CASP Remote Build feature.

Arguments:

ip: Set remote device IP.

Definition at line 259 of file casp.py.

◆ RemoteBuildRtvEnable()

casp.RemoteBuildRtvEnable ( bool enable = True)

Set enable or disable Remote Terminal Viewer feature on remote build device.

Please refer CASP main documentation for details on Remote Terminal Viewer.

Arguments:

enable: Set True to enable and False to disable.

Definition at line 269 of file casp.py.

◆ GenPyCode()

casp.GenPyCode ( bool skip_disabled_blocks = True)

Generates Python code for the current project model.

The generated file (.py) will be located in projects directory.

Arguments:

skip_disabled_blocks: Skips disabled blocks in the generated code.

Definition at line 279 of file casp.py.

◆ SimPanelWindowAdd()

casp.SimPanelWindowAdd ( str grp_name,
str wnd_name,
int wnd_type )

Adds new sub-window to an existing group.

Creates new group if group name is not found.

Arguments:

grp_name: Existing group name to which new sub-window is added.

wnd_name: New sub-window name to be added. It should be unique to existing sub-window names in the group.

wnd_type: Sub-window type. It shall be one of the constants defined in \ref casp_wtypes.py module.

Definition at line 289 of file casp.py.

◆ SimSetupFiniteTime()

casp.SimSetupFiniteTime ( bool set = True)

Sets simulation execution to finite time.

Arguments:

set: Set True to set simulation execution to finite time or False to set simulation execution time to infinite.

Definition at line 303 of file casp.py.

◆ SimSetupEndTime()

casp.SimSetupEndTime ( int time_msec = 1000)

Sets simulation end time in milli seconds.

Arguments:

time_msec: Set end time in milli seconds.

Definition at line 313 of file casp.py.

◆ SimSetupTimeStep()

casp.SimSetupTimeStep ( int time_usec = 1000)

Sets simulation time step in micro seconds.

Arguments:

time_usec: Set time step in micro seconds.

Definition at line 323 of file casp.py.

◆ SimSetupPlotStep()

casp.SimSetupPlotStep ( int plot_step = 1)

Sets simulation plot step.

Arguments:

plot_step: Set plot step in multiples of simulation time step.

Definition at line 333 of file casp.py.

◆ SimSetupPlotSamples()

casp.SimSetupPlotSamples ( int plot_samples = 10000)

Sets simulation plot samples.

It sets specified fixed plot samples buffer (FIFO buffer) during simulation. Plot samples are pushed into the buffer at each simulation plot step. If the buffer is full the first in sample will be discarded. Higher buffer values demand more memory and CPU resources.

Arguments:

plot_samples: Set number of plot samples.

Example:

For a simulation time step=1msec with plot step=1 and plot samples set to 10000, the FIFO buffer size can hold samples for 10 secs (0.001*1*10000).

Definition at line 343 of file casp.py.

◆ SimSetupSpeedFactor()

casp.SimSetupSpeedFactor ( float sf = 1)

Sets simulation speed factor.

This value should be non negative.

  • Speed factor 0 will run the simulation at full speed.
  • Speed factor 1 will run the simulation in real time.
  • Speed factor between 0 and 1 will run the simulation slower than real time.
  • Speed factor >1 will run the simulation faster than real time.

In case 3 and 4 above the simulation speed is with respective to real time.

Arguments:

sf: Set simulation speed factor.

Definition at line 357 of file casp.py.

◆ SimSetupPrecision()

casp.SimSetupPrecision ( int precision = defs.PRECISION_32)

Sets simulation integer and floating point precision to 32-bit, 48-bit (applicable to FPGA) and 64-bit.

Arguments:

precision: Set simulation precision constants as define in module \ref casp_defs.py. Typical values are \ref casp_defs.PRECISION_32, \ref casp_defs.PRECISION_48, \ref casp_defs.PRECISION_64.

Definition at line 374 of file casp.py.

◆ SimSetupOptLevel()

casp.SimSetupOptLevel ( int opt_level = 1)

set compiler optimization level (0 to 5: 4-opt for size, 5-opt for speed)

Sets compiler optimization level. Typical values are from 0 to 5. Default value is 1.

  • 0: No optimization
  • 1 to 3: Increasing optimization level from 1 to 3
  • 4: Optimize for size
  • 5: Optimize for speed

Arguments:

opt_level: Set compiler optimization level from above values.

Definition at line 385 of file casp.py.

◆ SimSetupMaximumModelThreads()

casp.SimSetupMaximumModelThreads ( int max_threads = 1)

Sets maximum threads limit that can run in parallel during execution.

Arguments:

max_threads: Set maximum threads limit value. 0 value indicate that the maximum threads are set based on the available CPU cores on the target. The set value will be limited to available CPU cores on the target.

Definition at line 400 of file casp.py.

◆ SimSetupMaximumBlockThreads()

casp.SimSetupMaximumBlockThreads ( int max_threads = 1)

Sets maximum block threads limit that can run in parallel within a block during execution.

Arguments:

max_threads: Set maximum block threads limit value. 0 value indicate that the maximum threads are set based on the available CPU cores on the target. The set value will be limited to available CPU cores on the target.

Definition at line 410 of file casp.py.

◆ SimSetupTargetPythonSupport()

casp.SimSetupTargetPythonSupport ( bool enable_disable = True)

Enables or disables python support for the current target.

Here, python supprt means blocks having embedded python code will be executed during simulation if this feature is enabled otherwise compilation will generate and error. User can enable it only if the target supports embedded python.

Arguments:

enable_disable: Set True to enable or False to disable this feature.

Definition at line 420 of file casp.py.

◆ SimSetupOpenMpThreads()

casp.SimSetupOpenMpThreads ( int max_threads = 1)

Sets maximum OpenMP threads that can be created for the current target (if this feature is supported by the target).

Arguments:

max_threads: Set maximum threads (1,2,3...). Value 1 means this feature is disabled. 0 means the maximum value is decided based on number of CPU cores available on the target.

Definition at line 430 of file casp.py.

◆ SimSetupOpenClSupport()

casp.SimSetupOpenClSupport ( int platform_index = -1,
int device_index = -1 )

Configures OpenCL support for current target.

Arguments:

platform_index: Set OpenCL platform index (-1,0,1,2...)

device_index: Set OpenCL device index (-1,0,1,2...)

If both 'platform_index' and 'device_index' arguments are -1 then this feature is disabled.

Definition at line 440 of file casp.py.

◆ SimSetupCudaSupport()

casp.SimSetupCudaSupport ( int device_index = -1)

Configures CUDA support for current target.

Arguments:

device_index: Set CUDA device index (-1,0,1,2...). -1 disables CUDA support.

Definition at line 455 of file casp.py.

◆ ModelValidate()

casp.ModelValidate ( )

Quickly validates current model for any errors and displays the result of validation in brief.

If the validation fails, user can check the log files in project directory for details.

Definition at line 465 of file casp.py.

◆ Build()

casp.Build ( )

Builds current model and displays the result of the build process.

User should check the log files in the project directory for details if the build fails.

Definition at line 472 of file casp.py.

◆ BuildFresh()

casp.BuildFresh ( )

Generally, casp.Build() function skips un-modified code files during build to speed up the build process.

However, the BuildFresh() function deletes all the intermediate build files from previous build and freshly rebuilds the model. After the build process is completed, it displays the result of the build process in brief. User should check the log files in the project directory for details if the build process fails.

Definition at line 479 of file casp.py.

◆ BuildCancel()

casp.BuildCancel ( )

Cancels current build process.

Definition at line 486 of file casp.py.

◆ BuildClear()

casp.BuildClear ( )

Clears previous build data including all the intermediate build files.

Definition at line 493 of file casp.py.

◆ SimStart()

casp.SimStart ( )

Starts simulation if the target supports simulation panel.

Else it starts to program the target board with generated binary and resets the target board so that the uploaded binary will get executed. This function also builds the model if needed.

Definition at line 500 of file casp.py.

◆ SimStartPrev()

casp.SimStartPrev ( )

Starts simulation (or target programming) with previous build data.

This function does not re-build the model.

Definition at line 507 of file casp.py.

◆ SimStop()

casp.SimStop ( )

Stops current simulation (or target programming) process.

Definition at line 514 of file casp.py.

◆ BlockAdd()

int casp.BlockAdd ( str blk_path,
str blk_name = " " )

Adds new block to the current model.

The module corresponding to the block to be added shall be first imported. These block modules are available in pycasp/blks directory.

Arguments:

blk_path: block path constant from the corresponding block module. Generally, it is in the form of <block module>.path.

blk_name: any meaning full string.

Return Value:

Block Id (of type integer) if the block instance is created and added to the model or else 0. It is better to store the return value as it will be referred in functions related to the block.

Definition at line 521 of file casp.py.

◆ BlockHelp()

casp.BlockHelp ( int blk_id)

Displays block documentation of specified block Id.

The module corresponding to the block Id shall be first imported from pycasp/blks directory.

Argument:

blk_id: It should be the reference block Id (and not the block Id of the created block instance). Generally, it is in the form of <block module>.id.

Definition at line 542 of file casp.py.

◆ BlockNameSet()

casp.BlockNameSet ( int blk_id,
str blk_name )

Sets block name of the specified block instance Id.

Argument:

blk_id: block instance Id for which the block name shall be set.

blk_name: a user friendly name to be set.

Definition at line 552 of file casp.py.

◆ BlockEnable()

casp.BlockEnable ( int blk_id,
bool enable = True )

Enable or disable a block in the current model.

Argument:

blk_id: block instance Id

enable: True to enable the block or False to disable it

Definition at line 564 of file casp.py.

◆ BlockRelocate()

casp.BlockRelocate ( int blk_id)

Auto relocates the block instance in the workspace.

This function is useful only when CASP window is visible and user wants to re-locate the block in the workspace.

Argument:

blk_id: block instance Id to re-locate

Definition at line 576 of file casp.py.

◆ BlockParaSet()

casp.BlockParaSet ( int blk_id,
str grp_para_name,
str para_val )

Sets block parameter value of the specified block instance Id.

Arguments:

blk_id: block instance Id

grp_para_name: parameter name string of the block parameter. Generally, it is in the form of <block_module_name>.Para.<block_group_constant>.<block_parameter_constant>.name.

para_val: new value of the block parameter. Parameter value can be of absolute value or one of the value from the parameter list. Refer block module help for parameter value list.

Definition at line 586 of file casp.py.

◆ BlockInitConditionSet()

casp.BlockInitConditionSet ( int blk_id,
str grp_para_name,
str para_val )

Sets block initial condition value of the specified block instance Id.

The function is similar to casp.BlockParaSet() except it sets block initial condition values instead block parameter values. Refer casp.BlockParaSet() for details.

Definition at line 600 of file casp.py.

◆ BlockPortsConnect()

casp.BlockPortsConnect ( int blk_id1,
str port_name1,
int blk_id2,
str port_name2,
bool auto_update_input_port_para = True )

Connects two block ports.

Arguments:

blk_id1: block1 Id

port_name1: port name of block1

blk_id2: block1 Id

port_name2: port name of block2

auto_update_input_port_para: auto updates input port data type and size based on connected output port parameters.

Definition at line 606 of file casp.py.

◆ BlockDelete()

bool casp.BlockDelete ( int blk_id)

Deletes specified block Id instance from the model.

Argument:

blk_id: block Id to delete

Returns:

True if successful else False

Definition at line 624 of file casp.py.