Skip to content

Marlin Api

This module provides a class to interact with the Marlin firmware.

ATTRIBUTE DESCRIPTION
LOOP_INTERVAL

loop interval for checking status

TYPE: float

MOVEMENT_TIMEOUT

timeout for movement

TYPE: int

READ_FORMAT

read format for serial communication

TYPE: str

WRITE_FORMAT

write format for serial communication

TYPE: str

Data

data structure for serial communication

TYPE: NamedTuple

CLASS DESCRIPTION
Marlin

Marlin class provides methods to interact with the Marlin firmware.

Marlin

Marlin(
    port: str | None = None,
    baudrate: int = 115200,
    timeout: int = 1,
    init_timeout: int = 2,
    message_end: str = "\n",
    *args,
    simulation: bool = False,
    **kwargs,
)

Bases: SerialDevice

Marlin class provides methods to interact with the Marlin firmware.
Refer to https://marlinfw.org/meta/gcode/ for more information on the Marlin firmware.

Attributes:
    port (str): device serial port
    baudrate (int): device baudrate
    timeout (int): device timeout
    connection_details (dict): connection details for the device
    serial (serial.Serial): serial object for the device
    init_timeout (int): timeout for initialization
    message_end (str): message end character
    flags (SimpleNamespace[str, bool]): flags for the device
    is_connected (bool): whether the device is connected
    verbose (bool): verbosity of class

Methods:
    getInfo: Query device information
    getSettings: Query device settings
    getStatus: Query device status
    halt: Halt the device
    home: Home the device
    setSpeedFactor: Set the speed factor in the device
    connect: Connect to the device
    query: Query the device (i.e. write and read data)
    clear: clear the input and output buffers
    connect: connect to the device
    disconnect: disconnect from the device
    read: read data from the device
    write: write data to the device
    Initialize Marlin class

    Args:
        port (str|None): Serial port to connect to. Defaults to None.
        baudrate (int): baudrate for serial communication. Defaults to 115200.
        timeout (int): timeout for serial communication. Defaults to 1.
        init_timeout (int): timeout for initialization of serial communication. Defaults to 2.
        message_end (str): message end character for serial communication. Defaults to '

'. simulation (bool): simulation mode for testing. Defaults to False.

connect

connect()

Connect to the device

getInfo

getInfo() -> dict[str, str]

Query device information

RETURNS DESCRIPTION
dict[str, str]

dict[str, str]: information in the response

getSettings

getSettings() -> dict[str, int | float | str]

Query device settings

RETURNS DESCRIPTION
dict[str, int | float | str]

dict[str, int|float|str]: settings in the response

getStatus

getStatus() -> tuple[str, ndarray[float], ndarray[float]]

Query device status

RETURNS DESCRIPTION
tuple[str, ndarray[float], ndarray[float]]

tuple[str, np.ndarray[float], np.ndarray[float]]: status, current position, home offset

halt

halt() -> Position

Halt the device

RETURNS DESCRIPTION
Position

current position of the device

TYPE: Position

home

home(axis: str | None = None, **kwargs) -> bool

Home the device

PARAMETER DESCRIPTION
axis

axis to home. Defaults to None.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
bool

whether the device was homed

TYPE: bool

query

query(
    data: Any,
    multi_out: bool = True,
    *,
    timeout: int | float = 1,
    wait: bool = False,
    **kwargs,
) -> list[str] | None

Query the device (i.e. write and read data)

PARAMETER DESCRIPTION
data

data to write to the device

TYPE: Any

multi_out

whether to read multiple lines of data. Defaults to True.

TYPE: bool DEFAULT: True

timeout

timeout for reading data. Defaults to 1.

TYPE: int | float DEFAULT: 1

wait

whether to wait for the device to be idle. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
list[str] | None

list[str]|None: response from the device

setSpeedFactor

setSpeedFactor(
    speed_factor: float, *, speed_max: int, **kwargs
)

Set the speed factor in the device

PARAMETER DESCRIPTION
speed_factor

speed factor

TYPE: float

speed_max

maximum speed

TYPE: int