|
CASP Python Libraries
This documentation primarily focuses on the usage of functions from 'casp', 'casp_be', 'casp_gpio' and 'casp_udio' namespaces.
|
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. | |
This module defines all necessary functions to.
All functions in this module uses global object _casp_process.casp_proc from _casp_process.py module.
| 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'.
| casp.Close | ( | ) |
| casp.BlockViewer | ( | ) |
| casp.SerialPorts | ( | ) |
Displays available serial ports on the host.
User can use this function before using the ProgrammerPortSet() function.
| casp.Refresh | ( | ) |
| casp.Rtv | ( | ) |
| casp.BleClient | ( | ) |
| casp.HelpBsp | ( | ) |
| casp.HelpPython | ( | ) |
| casp.FolderUserData | ( | ) |
| casp.FolderTargetSupport | ( | ) |
| casp.FolderProject | ( | ) |
| str casp.ProjectCreate | ( | str | proj_name = None | ) |
| 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.
| str casp.ProjectOpenDefault | ( | ) |
This function does a couple of things.
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.
| casp.WspClear | ( | ) |
| 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.
| casp.TargetIdSet | ( | str | target_id | ) |
| casp.ProgrammerSet | ( | int | programmer = defs.PROGRAMMER0 | ) |
| 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.
| casp.RemoteBuildIPSet | ( | str | ip | ) |
| casp.RemoteBuildRtvEnable | ( | bool | enable = True | ) |
| casp.GenPyCode | ( | bool | skip_disabled_blocks = True | ) |
| 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.
| casp.SimSetupFiniteTime | ( | bool | set = True | ) |
| casp.SimSetupEndTime | ( | int | time_msec = 1000 | ) |
| casp.SimSetupTimeStep | ( | int | time_usec = 1000 | ) |
| casp.SimSetupPlotStep | ( | int | plot_step = 1 | ) |
| 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).
| casp.SimSetupSpeedFactor | ( | float | sf = 1 | ) |
Sets simulation speed factor.
This value should be non negative.
In case 3 and 4 above the simulation speed is with respective to real time.
Arguments:
sf: Set simulation speed factor.
| 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.
| 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.
Arguments:
opt_level: Set compiler optimization level from above values.
| 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.
| 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.
| 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.
| 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.
| casp.SimSetupOpenClSupport | ( | int | platform_index = -1, |
| int | device_index = -1 ) |
| casp.SimSetupCudaSupport | ( | int | device_index = -1 | ) |
| casp.ModelValidate | ( | ) |
| casp.Build | ( | ) |
| 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.
| casp.BuildClear | ( | ) |
| casp.SimStart | ( | ) |
| casp.SimStartPrev | ( | ) |
| casp.SimStop | ( | ) |
| 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.
| 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.
| casp.BlockNameSet | ( | int | blk_id, |
| str | blk_name ) |
| casp.BlockEnable | ( | int | blk_id, |
| bool | enable = True ) |
| casp.BlockRelocate | ( | int | blk_id | ) |
| 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.
| 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.
| casp.BlockPortsConnect | ( | int | blk_id1, |
| str | port_name1, | ||
| int | blk_id2, | ||
| str | port_name2, | ||
| bool | auto_update_input_port_para = True ) |