Skip to content

Grbl Api

GRBL API for controlling CNC machines using the GRBL firmware. Refer to https://github.com/gnea/grbl/tree/master/doc/markdown for more information on the GRBL firmware.

ATTRIBUTE DESCRIPTION
LOOP_INTERVAL

loop interval for device

TYPE: float

MOVEMENT_TIMEOUT

timeout for movement

TYPE: int

READ_FORMAT

read format for device

TYPE: str

WRITE_FORMAT

write format for device

TYPE: str

Data

data for device

TYPE: NamedTuple

CLASS DESCRIPTION
GRBL

GRBL class for controlling CNC machines using the GRBL firmware.

Documentation last updated: 2025-02-22

GRBL

GRBL(
    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

GRBL class for controlling CNC machines using the GRBL firmware.
Refer to https://github.com/gnea/grbl/tree/master/doc/markdown for more information on the GRBL 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:
    getAlarms: check for alarms in the response
    getErrors: check for errors in the response
    getInfo: query device information
    getParameters: query device parameters
    getSettings: query device settings
    getState: query device state
    getStatus: query device status
    clearAlarms: clear alarms in the response
    halt: halt the device
    home: home the device
    resume: resume activity on the device
    setSpeedFactor: set the speed factor in the device
    clear: clear the input and output buffers
    connect: connect to the device
    disconnect: disconnect from the device
    query: query the device (i.e. write and read data)
    read: read data from the device
    write: write data to the device
    Initialize GRBL 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.

clearAlarms

clearAlarms()

Clear alarms in the device

connect

connect()

Connect to the device

getAlarms

getAlarms(response: str) -> bool

Checks for alarms in the response

PARAMETER DESCRIPTION
response

response

TYPE: str

RETURNS DESCRIPTION
bool

whether an alarm was found

TYPE: bool

getErrors

getErrors(response: str) -> bool

Checks for errors in the response

PARAMETER DESCRIPTION
response

response

TYPE: str

RETURNS DESCRIPTION
bool

whether an error was found

TYPE: bool

getInfo

getInfo() -> list[str]

Query device information

RETURNS DESCRIPTION
list[str]

list[str]: information in the response

getParameters

getParameters() -> dict[str, list[float]]

Query device parameters

RETURNS DESCRIPTION
dict[str, list[float]]

dict[str, list[float]]: parameters 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

getState

getState() -> dict[str, str]

Query device state

RETURNS DESCRIPTION
dict[str, str]

dict[str, str]: state 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

home

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

Home the device

PARAMETER DESCRIPTION
axis

axis to home. Defaults to None.

TYPE: str | None DEFAULT: None

timeout

timeout for homing

TYPE: int | 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,
    jog: bool = False,
    wait: bool = False,
    **kwargs,
) -> list[str] | None

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

PARAMETER DESCRIPTION
data

data to query

TYPE: Any

multi_out

whether to read lines

TYPE: bool DEFAULT: True

timeout

timeout for query

TYPE: int | None DEFAULT: 1

jog

whether to perform jog movements

TYPE: bool DEFAULT: False

wait

whether to wait for the device to reach the status

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
list[str] | None

list[str]|None: response from the device

resume

resume()

Resume activity on 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