qmi.utils.adbasic_compiler
Driver for the adbasic command line script.
It is recommended to use this script instead of directly invoking /opt/adwin/bin/adbasic. It provides much nicer formatting of compiler errors, a working exit code, and help.
Functions
|
Check that the compiler run was successful. |
|
|
|
Compile an ADbasic program. |
|
|
|
|
|
Run the ADbasic compiler. |
Classes
|
Information from one error message from the ADbasic compiler. |
|
Information from a run of the ADbasic compiler. |
Exceptions
|
Raised when an error occurs while compiling ADbasic code. |
- class qmi.utils.adbasic_compiler.AdbasicError(error_number: int, error_description: str, error_line: str, filename: str, line_number: int)
Information from one error message from the ADbasic compiler.
- error_number: int
Alias for field number 0
- error_description: str
Alias for field number 1
- error_line: str
Alias for field number 2
- filename: str
Alias for field number 3
- line_number: int
Alias for field number 4
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- class qmi.utils.adbasic_compiler.AdbasicResult(command_line: str, duration: float, returncode: int, success: bool, errors: list[AdbasicError], warnings: list[AdbasicError])
Information from a run of the ADbasic compiler.
- command_line: str
Alias for field number 0
- duration: float
Alias for field number 1
- returncode: int
Alias for field number 2
- success: bool
Alias for field number 3
- errors: list[AdbasicError]
Alias for field number 4
- warnings: list[AdbasicError]
Alias for field number 5
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- exception qmi.utils.adbasic_compiler.AdbasicCompilerException(message: str, errors: list[AdbasicError])
Raised when an error occurs while compiling ADbasic code.
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- qmi.utils.adbasic_compiler.run_adbasic_compiler(adwin_dir: str, processor_type: str, adbasic_arguments: list[str], working_dir: str | None = None, parse_stderr: bool = True, remove_c_directory: bool = False, pretty_print: bool = False) AdbasicResult
Run the ADbasic compiler.
- Parameters:
adwin_dir – Base directory of ADwin software installation (e.g. /opt/adwin).
processor_type – The type of processor the command is run for.
adbasic_arguments – List of command-line options for the ADbasic compiler.
working_dir – Working directory when running the compiler.
parse_stderr – True to parse error messages from the ADbasic compiler and return them. False to ignore error messages from the compiler.
remove_c_directory – True to remove the directory with intermediate C files from the compiler.
pretty_print – True to print compiler messages in pretty colors. False to log messages via the Python log system.
- Returns:
- Tuple containing results from the compilation process.
If parse_stderr is True, this result will contain parsed compiler error messages.
- Return type:
- Raises:
AdbasicCompilerException – If an unexpected error occurs while interacting with the ADbasic compiler.
- qmi.utils.adbasic_compiler.compile_program(basic_filename: str, trigger: str, process_number: int, processor_type: str, hardware_type: str, priority: int = 1000, working_dir: str | None = None, keep_c_files: bool = False, adwin_dir: str = '/opt/adwin', pretty_print: bool = False) AdbasicResult
Compile an ADbasic program.
The ADbasic compiler expects that include files can be found relative to the current working directory.
If compilation is successful, an executable file will be created in the same directory as the source file. The name of this file is based on the name of the source file, with the “.bas” extension replaced by “.TCn” depending on the process number.
- Parameters:
basic_filename – File name of the ADbasic .bas file to compile.
trigger – Select event trigger mechanism, either “external” or “timer”.
process_number – Select process number, range 1 to 10.
processor_type – Select processor type “T<x>”, where <x> is 11, 12 or 12.1.
hardware_type – The hardware that is used for compilation. Possible choices P, PII, G, GII (P=pro, G=Gold)
priority – Process priority, integer in range -10 to 10 for low priority, or PRIO_HIGH for high priority.
working_dir – Working directory when running the compiler. This determines the base directory for searching include files. Pass None to keep the current working directory of the process.
keep_c_files – Keep ‘c’ directory containing intermediate C files from ADbasic compiler. This only works under Linux.
adwin_dir – Base directory of ADwin software installation.
pretty_print – True to print compiler messages in pretty colors. False to log messages via the Python log system.
- Returns:
- Tuple containing results and error messages (if any) from the compilation process.
If compilation is successful, the success field of this tuple will be True. If compilation fails, the success field will be False and the errors field will contain a list of error messages from the compiler.
- Return type:
- Raises:
AdbasicCompilerException – If an unexpected error occurs while interacting with the ADbasic compiler.
- qmi.utils.adbasic_compiler.check_compiler_result(basic_filename: str, result: AdbasicResult) None
Check that the compiler run was successful.
- Parameters:
basic_filename – File name of the ADbasic .bas file.
result – Result from running the compiler.
- Raises:
AdbasicCompilerException – If the compiler was not successful.