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_be.py
1"""! This module defines all necessary functions to
2
3 - start CASP Block Editor process
4 - create a new block as a project
5 - modify block internal parameters
6 - add block user parameters
7 - add block ports
8 - save the block to the disk
9 - and finally when every thing is done, close the Block Editor process
10
11 All functions in this module uses global object \ref _casp_process.casp_be_proc from \ref _casp_process.py module.
12"""
13
14import importlib
15
16import sys
17if sys.version_info[:3] < (3,9):
18 from typing import List as list
19
20from _casp_process import casp_be_proc
21import casp_utils as utils
22import casp_defs as defs
23
24def Init(casp_file: str="BlockEditor"):
25 """! Initializes CASP Block Editor subprocess. This is the first function to be called before using any other function in this module.
26
27 Arguments:
28
29 casp_file: Set executable file to be invoked. Set this argument only if the executable file version is different from 'BlockEditor'.
30 """
31 casp_be_proc.init(casp_file)
32
34 """! Opens CASP Python Libraries documentation.
35 """
36 response = casp_proc.write("casp.help.python")
37
38def Close():
39 """! Terminates CASP Block Editor subprocess and releases the resources.
40 """
41 casp_be_proc.close()
42
43def Open(blk_name: str, visible_title: str, parent_dir_path: str="", overwrite_existing: bool=True) -> bool:
44 """! Creates new block and opens it for further configuration.
45
46 Arguments:
47
48 blk_name: Block name to be created. The block name should follow standard file naming conventions.
49
50 visible_title: Block visible title text.
51
52 parent_dir_path: Block location/arent directory path. If empty, the new block will be created in 'casp_user_data/blocks' folder.
53
54 overwrite_existing: True to overwrite existing block if path matches.
55
56 Return Value:
57
58 Returns True if successful or else False.
59 """
60 response = casp_be_proc.write("casp.open", [blk_name, visible_title, parent_dir_path, str(int(overwrite_existing))])
61 print(f"CASP: {response.strip()}")
62 if "Error" in response.strip():
63 return False
64 return True
65
66def AddPort(port_name: str, visible_text: str, output_port: bool=False, data_type: str=defs.DATA_TYPE_INT32, data_size :int=1) -> bool:
67 """! Adds new port to the block.
68
69 Arguments:
70
71 port_name: Block port name to be added. The port name should follow standard file naming conventions.
72
73 visible_text: Block port visible text.
74
75 output_port: True for output port or False for input port
76
77 data_type: Port data type. Set one of the data type constants from \ref casp_defs.py module.
78
79 data_size: Port data size. Value should be > 0.
80
81 Return Value:
82
83 Returns True if successful or else False.
84 """
85 response = casp_be_proc.write("casp.add_port", [port_name, visible_text, str(int(output_port)), data_type, str(data_size)])
86 print(f"CASP: {response.strip()}")
87 if "Error" in response.strip():
88 return False
89 return True
90
91def AddPara(para_name: str, var_name: str, data_type: str=defs.DATA_TYPE_INT32, para_values :list[str]=["None"]) -> bool:
92 """! Adds new parameter to the block.
93
94 Arguments:
95
96 para_name: Block parameter name to be added. The parameter name should follow standard file naming conventions.
97
98 var_name: Internal variable name of the block parameter. It should be as per C/C++ variable naming conventions.
99
100 data_type: Parameter value data type. Set one of the data type constants from \ref casp_defs.py module.
101
102 para_values: Set Parameter values as a string list.
103
104 Return Value:
105
106 Returns True if successful or else False.
107 """
108 args = [para_name, var_name, data_type] + para_values
109 response = casp_be_proc.write("casp.add_para", args)
110 print(f"CASP: {response.strip()}")
111 if "Error" in response.strip():
112 return False
113 return True
114
115def SetOtherLangSupport(lang_type: int=defs.LANG_PYTHON) -> bool:
116 """! Set support for other languages such as Python, Fortran and Verilog.
117
118 Arguments:
119
120 lang_type: Set additional languages supported (if any). Set one of the constants from \ref casp_defs.py module.
121
122 Return Value:
123
124 Returns True if successful or else False.
125 """
126 response = casp_be_proc.write("casp.oth_lang_support", [str(lang_type)])
127 print(f"CASP: {response.strip()}")
128 if "Error" in response.strip():
129 return False
130 return True
131
132def Save() -> bool:
133 """! Save block data to disk. This function actually creates the block folder on disk. Should be called only once and at the end of your script.
134
135 Returns True if successful or else False
136 """
137 response = casp_be_proc.write("casp.save")
138 print(f"CASP: {response.strip()}")
139 if "Error" in response.strip():
140 return False
141 return True
142
143def Folder():
144 """! Show block folder.
145 """
146 response = casp_be_proc.write("casp.show_dir")
147 print(f"CASP: {response.strip()}")
148
bool AddPara(str para_name, str var_name, str data_type=defs.DATA_TYPE_INT32, list[str] para_values=["None"])
Adds new parameter to the block.
Definition casp_be.py:91
bool SetOtherLangSupport(int lang_type=defs.LANG_PYTHON)
Set support for other languages such as Python, Fortran and Verilog.
Definition casp_be.py:115
Close()
Terminates CASP Block Editor subprocess and releases the resources.
Definition casp_be.py:38
bool Open(str blk_name, str visible_title, str parent_dir_path="", bool overwrite_existing=True)
Creates new block and opens it for further configuration.
Definition casp_be.py:43
HelpPython()
Opens CASP Python Libraries documentation.
Definition casp_be.py:33
Init(str casp_file="BlockEditor")
Initializes CASP Block Editor subprocess.
Definition casp_be.py:24
bool Save()
Save block data to disk.
Definition casp_be.py:132
bool AddPort(str port_name, str visible_text, bool output_port=False, str data_type=defs.DATA_TYPE_INT32, int data_size=1)
Adds new port to the block.
Definition casp_be.py:66
Folder()
Show block folder.
Definition casp_be.py:143