Core
Global settings
Logger settings and project constants
Configuration
Load configuration file, check and set default values
- libreprinter.config_parser.debug_config_file(config: ConfigParser)[source]
Display sections, keys and values of config file
- Parameters:
config (configparser.ConfigParser) – Opened ConfigParser object
- libreprinter.config_parser.load_config(config_file='./libreprinter.conf')[source]
Load configuration file and set default settings
- Parameters:
config_file (Path) – Path of the configuration file to load. Default: CONFIG_FILE from commons module.
- Returns:
Configuration updated object.
- Return type:
configparser.ConfigParser
- libreprinter.config_parser.parse_config(config: ConfigParser)[source]
Read config file, check and set default values
Note
All values are of type string; they must be casted (with dedicated methods) if necessary.
The syntax if not xxx: handles None and ‘’ data retrieved from file.
- Parameters:
config (configparser.ConfigParser) – Opened ConfigParser object
- Returns:
Processed ConfigParser object
- Return type:
configparser.ConfigParser
File handler
Gestion of files (creation and processing) and directories used by the project
- libreprinter.file_handler.cleanup_directories(output_path)[source]
Delete all directories initialised by this project in the given path
Deletes also /dev/shm/ shared memory.
- Parameters:
output_path (str) – Path were directories will be created.
- libreprinter.file_handler.convert_data_line_ending(in_data, line_ending)[source]
Replace line endings of in_data and return the result
unix => windows: \n => \r\n
windows => unix: \r\n => \n
- Parameters:
in_data (bytes) – Data to be processed
line_ending (bytes) – Destination line ending.
- Returns:
Processed data
- Return type:
bytes
- libreprinter.file_handler.convert_file_line_ending(in_file, out_file, line_ending)[source]
Replace line endings of in_file and put data in out_file
See also
- Parameters:
in_file – Path of processed but not modified file.
out_file – Path of result file.
line_ending (str) – Destination line ending
- libreprinter.file_handler.get_job_number(output_path)[source]
Return the number of the current job based on files found in output directories
Get only non empty files
Get only expected extensions (txt, raw, eps)
Search highest file number in all folders
TODO: handle properly pdf dir data: page1-1.pdf, page1-2.pdf, page2-1.pdf, … :return: Current job number :rtype: int
Interface communication
Group of functions that communicate with the interface via the serial port
initialisation
configuration
data receiving
- libreprinter.interface.apply_msb_control(databyte, msbsetting)[source]
Apply MSB control command to the given byte
Note
This kind of control codes is deprecated according to the Epson datasheet. Not many printers should use them…
- Parameters:
databyte (bytes) – Supposed modified byte
msbsetting (int) – Expects value in (0: No modification, 1: MSB (bit 7) is set to 0, 2: MSB (bit 7) is set to 1).
- Returns:
Modified value; value derived from unsigned int (c_uint8)
- Return type:
int
- libreprinter.interface.build_interface_config_settings(config)[source]
Build configuration strings ready to be sent to the interface
About enabled param of serial_printer config section:
- no: Only parallel printer will be working
=> send only parallel config
- yes: Only serial printer will be working
=> send only serial config
- Parameters:
config (configparser.ConfigParser) – ConfigParser object
- Returns:
List of settings (form: <param>=<value>n).
- Return type:
list[str]
- libreprinter.interface.configure_interface(serial_handler, config)[source]
Send settings of the session to the interface via the serial port
Configuration process description:
sequenceDiagram Host->>+Printer: param=value Printer->>Host: param: value Host->>Printer: ... Printer->>Host: ... Host->>Printer: end_config Printer->>Host: Serial/Parallel printer configured! Printer->>-Host: end_config- Parameters:
serial_handler (serial.Serial) – Serial port handler.
config (configparser.ConfigParser) – ConfigParser object
- libreprinter.interface.get_buffer(serial_handler, end_page_timeout)[source]
Try to read and return bytes from interface
Serial read timeout = end_page_timeout defined in config.
- Parameters:
serial_handler (serial.Serial) – Serial port handler.
end_page_timeout (int) – Timeout in seconds used to define the number of retries in case of empty buffer. Serial read is in blocking mode (1sec per try).
- Returns:
None in case of no response or timeout, a bytearray otherwise.
- libreprinter.interface.is_bit_set(byte, bit_number)[source]
Test if nth bit is set in the given byte
- Parameters:
byte (bytes) – databyte to test
bit_number (int) – nth bit number to test in databyte
- Returns:
Result of test
- Return type:
boolean
- libreprinter.interface.parse_buffer(serial_handler, job_number, config)[source]
- TODO: penser à coroutine:
générateur emettant des databytes + un flag de fin de page (tant que pas envoyé, écriture dans le même fichier) + flag emulation
- STREAM_PLAIN_TEXT || STREAM_STRIP_ESCP2
just put data in the same file during receiving and sync converter for STREAM_STRIP_ESCP2
NO_PLAIN_TEXT || JOBS_TO_PLAIN_TEXT => parent loop JOBS_STRIP_ESCP2: handled by converter
- usbpassthrough:
enabled: store a raw file and then put it in the given peripheral
disabled: store a raw file and alert converters of the job status
- Parameters:
serial_handler (serial.Serial) – Serial port handler.
job_number
config
Serial handler
Low level functions to interact with the serial port
Basically get a serial handler used in the libreprinter.interface() module.