API

Serial Manager

This module manages the communication between the frontend and the ATmega that speaks only serial.

An instance of the SerialManager is istanciated by the main module logic. Its primary functions are those of sending GCODE commands to te microcontroller and read back status information about the just executed operation and the various subsystems and sensors.

The main stuff is in SerialManager.queue_gcode which is the entry point from the frontend logic that enqueues new commands to be sent.

The other interesting code is in SerialManager.send_queue_as_ready method which polls the serial line for statuses and send new commands if there are any waiting in the send queue.

The protocol employed uses two special control characters (ASCII‘s DC2 and DC4, used as READY_CHAR and REQUEST_READY_CHAR in the code) to control the flow on the wire. REQUEST_READY_CHAR is sent by the tx part of SerialManager.send_queue_as_ready and then the next chunk of data (as much as SerialManager.TX_CHUNK_SIZE) is sent as soon as a READY_CHAR is read from the rx part of the same method. It’s a bit like half an XON/XOFF flow control with the logic reversed.

THE GCODE commands are sent as-is or an error detection byte or a so-called error correction line is added to the bytes to be sent.

backend.serial_manager.FEC_TYPES = FecTypes(NONE=0, ERROR_DETECTION=1, ERROR_CORRECTION=2)

Types of Forward Error Correction.

NONE
No error correction is applied or detected.
ERROR_DETECTION
A checksum is added to the sent lines so that the other endpoint can detect RX errors.
ERROR_CORRECTION
Every sent line is doubled enabling some kind of error correction.
class backend.serial_manager.SerialManager[source]

Manages the serial communication with the ATmega

LASAURGRBL_FIRST_STRING = b'LasaurGrbl'

String to find at connection initialization time, sent by the ATmega.

READY_CHAR = b'\x12'

Character sent by the ATmega in response to the reception of a REQUEST_READY_CHAR, it’s like a pong in a ping-pong protocol.

REQUEST_READY_CHAR = b'\x14'

Character sent by this code to the ATmega to be sure that the other other side is still functional, it like a ping in a ping-pong protocol.

RX_CHUNK_SIZE = 16

Number of bytes read from the device in one go.

TX_CHUNK_SIZE = 16

This is the number of bytes to be written to the device in one go. It needs to match the firmware.

cancel_queue()[source]

Removes all the instructions from the queue

fec_redundancy = None

Forward Error Detection.

By default enable error correction. See FEC_TYPES

process_status_line(line)[source]

Process a line read from the serial interface and transform single byte status reports into flags inside the status mapping.

queue_gcode(gcode)[source]

Processes a group of GCODE instructions, add redundancy for error detection and correction and queue them.

send_queue_as_ready()[source]

This is the communication workhorse, it reads and sends return-terminated lines via the serial interface. It gets polled from the main app code.

status = None

Dictionary member containing status information decoded by parsing the line sent by the ATmega, see process_status_line.