Skip to content

FluidNC API reference¤

A subclass should be created from the parent fluidpy.FluidNC and can implement one or more of the handle_* methods to receive callbacks when certain messages are received.

FluidNC Usage Example¤

Each platform will have a different mechanism for communicating with the controller, and will each require a different BufferInterface implementation, defining read, write and readline methods. See examples directory for CircuitPython and Python implementations.

Subclass fluidpy.FluidNC and implement handle_version method which is called when the controller has started.

Once the I/O interface is defined, instantiate subclass of fluidpy.FluidNC and call the listen method.

from fluidpy import FluidNC

class MyFluidExpander(FluidNC):
    """
    Implement one or more 'handle_*' methods to receive incoming messages
    """

    def __init__(self, io: BufferInterface) -> None:
        super().__init__(io)

    def handle_version(self, message: str) -> None:
        print(f"Version: {message}")

io = MyBufferInterface()
fluid = MyFluidExpander(io)
fluid.listen()

API¤

FluidNC ¤

FluidNC(io: BufferInterface)

handle_accessory_state ¤

handle_accessory_state(state: str)

Parameters:

  • state ¤

    (str) –

    accessor state information

handle_alarm ¤

handle_alarm(alarm: str)

Parameters:

  • alarm ¤

    (str) –

    alarm message or code

handle_buffer_size ¤

handle_buffer_size(size: int)

Parameters:

  • size ¤

    (int) –

    current buffer size

handle_echo ¤

handle_echo(message: str)

Parameters:

  • message ¤

    (str) –

    echo'ed message

handle_error ¤

handle_error(error: str) -> None

Parameters:

  • error ¤

    (str) –

    error message or code

handle_exp_io ¤

handle_exp_io(io_name: str, io_mode: str) -> None

Handle the initialization of an expander pin. Needs to acknowledge the pin initialization (0xB2) or failure (0xB3).

Parameters:

  • io_name ¤

    (str) –

    io.1, io.2, etc

  • io_mode ¤

    (str) –

    comma seperated list of [in|out|low|high|pu|pd]

Returns:

  • None

    None

handle_feed ¤

handle_feed(feed_rate: DecimalNumber) -> None

Parameters:

  • feed_rate ¤

    (DecimalNumber) –

    in mm/min or inches/min

handle_help ¤

handle_help(message: str) -> None

Parameters:

  • message ¤

    (str) –

    help message

handle_line_number ¤

handle_line_number(line_number: int) -> None

Parameters:

  • line_number ¤

    (int) –

    current line number

handle_log ¤

handle_log(level: str, message: str) -> None

Parameters level: one of DBG, INFO, WARN, ERROR message: log message

handle_machine_state ¤

handle_machine_state(state: str) -> None

Parameters:

  • state ¤

    (str) –

    one of one of ['Idle', 'Run', 'Hold', 'Jog', 'Alarm', 'Door', 'Check', 'Home', 'Sleep']

handle_mode ¤

handle_mode(mode: Mode) -> None

Parameters:

  • mode ¤

    (Mode) –

    Mode object with attributes for rapid, wco_index, plane, is_inches, is_absolute, feed_rate_mode, coolant, tool_number, feed_rate, spindle_speed

handle_mode_command ¤

handle_mode_command(mode_cmd: str, status: str = 'None') -> None

Parameters:

  • mode_cmd ¤

    (str) –

    one of G54, G55, G56, G57, G58, G59, G28, G30, G92

handle_ok ¤

handle_ok(ok: str)

Parameters:

  • ok ¤

    (str) –

    'ok'

handle_overrides ¤

handle_overrides(feed: DecimalNumber, rapid: DecimalNumber, spindle: DecimalNumber) -> None

Parameters:

  • feed ¤

    (DecimalNumber) –

    override percentage

  • rapid ¤

    (DecimalNumber) –

    override percentage

  • spindle ¤

    (DecimalNumber) –

    override percentage

handle_position ¤

handle_position(kind: str, position: Position) -> None

Parameters:

  • kind ¤

    (str) –

    MPos (machine position) or WCO (work coordinate offset)

  • position ¤

    (Position) –

    Position object with x, y, z, a, b, c attributes

handle_prb ¤

handle_prb(message: str) -> None

Parameters:

  • message ¤

    (str) –

    probe message

handle_spindle ¤

handle_spindle(spindle_speed: DecimalNumber) -> None

Parameters:

  • spindle_speed ¤

    (DecimalNumber) –

    in RPM

handle_tlo ¤

handle_tlo(message: str) -> None

Parameters:

  • message ¤

    (str) –

    tool length offset message

handle_triggers ¤

handle_triggers(triggers: str) -> None

Parameters:

  • triggers ¤

    (str) –
    • X Y Z A B C XYZABC limit pins, respectively
    • P > the probe pin. -T > the tool setter pin
    • D H R S > the door, hold, soft-reset, and cycle-start pins, respectively

handle_variable ¤

handle_variable(variable: str, value: str) -> None

Parameters:

  • variable ¤

    (str) –

    name of the variable

  • value ¤

    (str) –

    value of the variable

handle_version ¤

handle_version(version: str) -> None

Parameters version: X.Y.Z or X.Y.Z-abc

send_bytes ¤

send_bytes(command: bytes) -> None

Send a bytes message to the controller.

send_message ¤

send_message(message: str) -> None

Send a string message to the controller.

Position ¤

Attributes:

  • a (DecimalNumber) –

    a value of the position

  • b (DecimalNumber) –

    b value of the position

  • c (DecimalNumber) –

    c value of the position

  • x (DecimalNumber) –

    x value of the position

  • y (DecimalNumber) –

    y value of the position

  • z (DecimalNumber) –

    z value of the position

Mode ¤

Attributes:

  • coolant

    'MIST' (M7), 'FLOOD' (M8), 'OFF' (M9)

  • feed_rate

    feed rate

  • feed_rate_mode

    'INVERSE' (G93), 'UNITS/MIN' (G94), 'UNITS/REV' (G95)

  • is_absolute

    absolute (G90), relative (G91)

  • is_inches

    inches (G20), mm (G21)

  • is_rapid

    rapid mode (G0), feed rate mode (G1)

  • plane

    'XY' (G17), 'XZ' (G18), 'YZ' (G19)

  • spindle_speed

    spindle speed

  • spindle_state

    'CW' (M3), 'CCW' (M4), 'STOP' (M5)

  • tool_number

    tool number 0-9

  • wco_index

    work coordinate offset of 0 (G53), 1 (G54), 2 (G55), etc

BufferInterface ¤

read ¤

read(n: int) -> bytes

Read up to n bytes from the buffer.

readline ¤

readline() -> bytes

Read a line from the buffer.

write ¤

write(data: bytes) -> int

Write data to the buffer. Return the number of bytes written.