1"""! This module defines classes that provide interfaces to perform low level read/write operations with CASP executables. Each class defined in this module creates a subprocess for a particular executable and provides interfaces to talk to that subprocess based on funtionality and need.
2In most cases interfaces defined in this module are not required to be used directly by the user. It is recommended to use the wrapper functions provided in \ref casp.py and \ref casp_gpio.py modules instead.
3Typical interfaces that this module provides:
4 - Interface to create an executable as a subprocess
5 - Interface to write data to the subprocess and read the returned response from the subprocess
6 - Interface to terminate the subprocess
8This module also provides global objects for all classes defined in this module. These global objects are used directly by upper level interfaces to provide required functionalities.
17if sys.version_info[:3] < (3,9):
18 from typing
import List
as list
21 """! CaspProcess class provides interfaces to create, read/write and terminate 'CASP' executable as a subprocess.
22 A global object of this class \ref casp_proc is also created in this module. It is used by upper level interfaces from \ref casp.py module.
25 def init(self, make_visible: bool=
False, casp_file: str=
"CASP-Eval"):
26 """! Starts a python subprocess for 'CASP or CASP-Eval' executable with command line interface (CLI) enabled.
30 make_visible: allows the GUI window to be visible or hidden. Default is to hide the window.
32 casp_file: allows user to specify different version of CASP executable other than the evaluation version. In most cases this argument is not required to be specified by the user.
34 casp_fpath = os.path.join(casp_paths.casp_exe_path, casp_file)
37 if make_visible ==
True:
40 arguments = [
"#cli",
"#hide"]
42 command = [casp_fpath] + arguments
46 stdin=subprocess.PIPE,
47 stdout=subprocess.PIPE,
48 stderr=subprocess.PIPE,
53 print(f
"Initializing CASP...")
54 response = self.
__process.stdout.readline()
55 print(f
"CASP: {response.strip()}")
57 def write(self, cmd: str, arguments: list[str]=
None) -> str:
58 """! In general, data exchange betweem the python side interfaces and the executable is in the form of 'command' and a list of corresponding 'arguments'.
59 This interface writes the command along with its argument list to the subprocess. Waits for the response and returns the response received from the subprocess.
63 cmd: command string to write to the subprocess
65 arguments: argument list to write to the subprocess
69 Response string received from the subprocess
73 arg_len = len(arguments)
76 arg = arg +
'$' +
'$'.join(arguments)
78 arg = arg +
'$' + arguments[0]
81 response = self.
__process.stdout.readline()
83 return response.strip()
86 """! Closes or terminates the subprocess and waits till subprocess is terminated before returning."""
87 print(f
"Terminating CASP process...")
95 """! CaspBlockEditorProcess class provides interfaces to create, read/write and terminate 'BlockEditor' executable as a subprocess.
96 A global object of this class \ref casp_be_proc is also created in this module. It is used by upper level interfaces from \ref casp_be.py module.
99 def init(self, casp_file: str=
"BlockEditor"):
100 """! Starts a python subprocess for 'BlockEditor' executable with command line interface (CLI) enabled.
104 casp_file: allows user to specify different version of 'BlockEditor' executable when required. In most cases this argument is not required to be specified by the user.
106 casp_fpath = os.path.join(casp_paths.casp_exe_path, casp_file)
107 command = [casp_fpath,
"#cli_on"]
111 stdin=subprocess.PIPE,
112 stdout=subprocess.PIPE,
113 stderr=subprocess.PIPE,
118 print(f
"Initializing CASP Block Editor...")
119 response = self.
__process.stdout.readline()
120 print(f
"CASP: {response.strip()}")
122 def write(self, cmd: str, arguments: list[str]=
None) -> str:
123 """! In general, data exchange betweem the python side interfaces and the executable is in the form of 'command' and a list of corresponding 'arguments'.
124 This interface writes the command along with its argument list to the subprocess. Waits for the response and returns the response received from the subprocess.
128 cmd: command string to write to the subprocess
130 arguments: argument list to write to the subprocess
134 Response string received from the subprocess
138 arg_len = len(arguments)
141 arg = arg +
'$' +
'$'.join(arguments)
143 arg = arg +
'$' + arguments[0]
146 response = self.
__process.stdout.readline()
148 return response.strip()
151 """! Closes or terminates the subprocess and waits till subprocess is terminated before returning."""
152 print(f
"Terminating CASP Block Editor process...")
160 """! CaspBlockViewerProcess class provides interfaces to start and terminate 'BlockViewer' executable as a subprocess. The 'BlockViewer' executable is used to browse CASP blocks.
161 A global object of this class \ref casp_bv_proc is also created in this module. It is used by upper level interfaces from \ref casp.py module to invoke the block viewer executable.
164 def init(self, casp_file: str=
"BlockViewer"):
165 """! Starts a subprocess for 'BlockViewer' executable with command line interface (CLI) enabled.
169 casp_file: allows user to specify different version of 'BlockViewer' executable when required. In most cases this argument is not required to be specified by the user.
171 casp_fpath = os.path.join(casp_paths.casp_exe_path, casp_file)
175 stdin=subprocess.PIPE,
176 stdout=subprocess.PIPE,
177 stderr=subprocess.PIPE,
183 """! Closes or terminates the subprocess and waits till subprocess is terminated before returning."""
189 """! CaspGpioProcess class provides interfaces to create, read/write and terminate 'casp_gpio_bridge' executable as a subprocess.
190 A global object of this class \ref casp_gpio_proc is also created in this module. It is used by upper level interfaces from \ref casp_gpio.py module.
193 def init(self, casp_file: str=
"casp_gpio_bridge"):
194 """! Starts a subprocess for 'casp_gpio_bridge' executable with command line interface (CLI) enabled.
197 casp_file: allows user to specify different version of the executable when required. In most cases this argument is not required to be specified by the user.
199 casp_fpath = os.path.join(casp_paths.casp_exe_path, casp_file)
200 command = [casp_fpath,
"#cli"]
204 stdin=subprocess.PIPE,
205 stdout=subprocess.PIPE,
206 stderr=subprocess.PIPE,
211 print(f
"Initializing...")
212 response = self.
__process.stdout.readline()
213 print(f
"CASP: {response.strip()}")
215 def write(self, cmd: str, arguments: list[str]=
None) -> str:
216 """! Data exchange betweem the python side interfaces and the executable is in the form of 'command' and a list of corresponding 'arguments'.
217 This interface writes the command along with its argument list to the subprocess.
218 Waits for the response and returns the response received from the subprocess.
222 cmd: command string to write to the subprocess
224 arguments: argument list to write to the subprocess
228 Response string received from the subprocess
232 arg_len = len(arguments)
235 arg = arg +
'$' +
'$'.join(arguments)
237 arg = arg +
'$' + arguments[0]
240 response = self.
__process.stdout.readline()
242 return response.strip()
245 """! Closes or terminates the subprocess and waits till subprocess is terminated before returning."""
246 print(f
"Terminating process...")
CaspBlockEditorProcess class provides interfaces to create, read/write and terminate 'BlockEditor' ex...
init(self, str casp_file="BlockEditor")
Starts a python subprocess for 'BlockEditor' executable with command line interface (CLI) enabled.
str write(self, str cmd, list[str] arguments=None)
In general, data exchange betweem the python side interfaces and the executable is in the form of 'co...
close(self)
Closes or terminates the subprocess and waits till subprocess is terminated before returning.
CaspBlockViewerProcess class provides interfaces to start and terminate 'BlockViewer' executable as a...
init(self, str casp_file="BlockViewer")
Starts a subprocess for 'BlockViewer' executable with command line interface (CLI) enabled.
close(self)
Closes or terminates the subprocess and waits till subprocess is terminated before returning.
CaspGpioProcess class provides interfaces to create, read/write and terminate 'casp_gpio_bridge' exec...
init(self, str casp_file="casp_gpio_bridge")
Starts a subprocess for 'casp_gpio_bridge' executable with command line interface (CLI) enabled.
close(self)
Closes or terminates the subprocess and waits till subprocess is terminated before returning.
str write(self, str cmd, list[str] arguments=None)
Data exchange betweem the python side interfaces and the executable is in the form of 'command' and a...
CaspProcess class provides interfaces to create, read/write and terminate 'CASP' executable as a subp...
str write(self, str cmd, list[str] arguments=None)
In general, data exchange betweem the python side interfaces and the executable is in the form of 'co...
close(self)
Closes or terminates the subprocess and waits till subprocess is terminated before returning.
init(self, bool make_visible=False, str casp_file="CASP-Eval")
Starts a python subprocess for 'CASP or CASP-Eval' executable with command line interface (CLI) enabl...