@linuxcnc-node/core - v2.0.0
    Preparing search index...

    Class CommandChannel

    Index

    Constructors

    Methods

    • Aborts the currently running task/program Immediately stops all motion and task execution

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Emergency stop of current program
      await commandChannel.abortTask();
    • Destroys the command channel and cleans up resources Call this when done using the command channel

      Returns void

    • Sets program execution direction to forward Used after reversing to resume normal forward execution

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

    • Gets the serial number of the current command Each command sent has a unique serial number for tracking

      Returns number

      The current command serial number

      // Get current command serial number
      const serial = commandChannel.getSerial();
      console.log(`Current command serial: ${serial}`);
    • Homes a specific joint by moving it to its home position

      Parameters

      • jointIndex: number

        Zero-based index of the joint to home, -1 to home all joints

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Home joint 0 (typically X-axis)
      await commandChannel.homeJoint(0);

      // Home joint 2 (typically Z-axis)
      await commandChannel.homeJoint(2);

      // Home all joints
      await commandChannel.homeJoint(-1);
    • Starts continuous jogging motion for a specific axis or joint

      Parameters

      • axisOrJointIndex: number

        Index of the axis (0=X,1=Y,2=Z...) or joint to jog

      • isJointJog: boolean

        true for joint jogging, false for axis jogging

      • speed: number

        Jogging speed in machine units per second

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Jog X axis continuously at 10 units/sec
      await commandChannel.jogContinuous(0, false, 10);

      // Jog joint 2 continuously at -5 units/sec (negative direction)
      await commandChannel.jogContinuous(2, true, -5);
    • Jogs a specific distance at a given speed for an axis or joint

      Parameters

      • axisOrJointIndex: number

        Index of the axis (0=X,1=Y,2=Z...) or joint to jog

      • isJointJog: boolean

        true for joint jogging, false for axis jogging

      • speed: number

        Jogging speed in machine units per second

      • increment: number

        Distance to jog in machine units

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Jog Y axis 1.0 unit at 5 units/sec
      await commandChannel.jogIncrement(1, false, 5, 1.0);

      // Jog joint 0 back 0.1 units at 2 units/sec
      await commandChannel.jogIncrement(0, true, 2, -0.1);
    • Stops jogging motion for a specific axis or joint

      Parameters

      • axisOrJointIndex: number

        Index of the axis (0=X,1=Y,2=Z...) or joint to stop

      • isJointJog: boolean

        true for joint jogging, false for axis jogging

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Stop axis X jogging
      await commandChannel.jogStop(0, false);

      // Stop joint 1 jogging
      await commandChannel.jogStop(1, true);
    • Reloads the tool table from disk Updates the in-memory tool table with changes made to the tool table file

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Reload tool table after editing the .tbl file
      await commandChannel.loadToolTable();
    • Executes a Manual Data Input (MDI) command Allows direct execution of G-code commands without a program file

      Parameters

      • command: string

        G-code command string to execute

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Move to position
      await commandChannel.mdi('G0 X10 Y20 Z5');

      // Set spindle speed
      await commandChannel.mdi('S1000 M3');
    • Overrides axis limits to allow motion beyond normal soft limits

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Override limits for recovery from limit switch activation
      await commandChannel.overrideLimits();
    • Pauses the currently running G-code program Program can be resumed with resumeProgram()

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Pause the running program
      await commandChannel.pauseProgram();
    • Opens a G-code program file for execution

      Parameters

      • filePath: string

        Absolute path to the G-code file to open

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Open a G-code program
      await commandChannel.programOpen('/home/user/programs/part.ngc');
    • Resets the G-code interpreter

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

    • Resumes a paused G-code program

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Resume the paused program
      await commandChannel.resumeProgram();
    • Reverses program execution direction Used for backing up through a program

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

    • Runs the currently loaded G-code program

      Parameters

      • startLine: number = 0

        Line number to start execution from (default: 0 for beginning)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Run program from the beginning
      await commandChannel.runProgram();

      // Run program starting from line 100
      await commandChannel.runProgram(100);
    • Sends a display message to the operator

      Parameters

      • message: string

        Display message (max 254 characters)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Send display message
      await commandChannel.sendOperatorDisplay('Insert tool T1 M6');
    • Sends an error message to the operator display

      Parameters

      • message: string

        Error message to display (max 254 characters)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Send error message
      await commandChannel.sendOperatorError('Tool change required');
    • Sends a text message to the operator display

      Parameters

      • message: string

        Text message to display (max 254 characters)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Send informational message
      await commandChannel.sendOperatorText('Setup complete');
    • Enables or disables adaptive feed functionality Allows external signals to modulate feedrate in real-time

      Parameters

      • enable: boolean

        true to enable adaptive feed, false to disable

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable adaptive feed for force-sensitive machining
      await commandChannel.setAdaptiveFeedEnable(true);
    • Sets the value of an analog output pin

      Parameters

      • index: number

        Index of the analog output pin

      • value: number

        Analog value to set

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set analog output 0 to 13.3
      await commandChannel.setAnalogOutput(0, 13.3);
    • Enables or disables block delete functionality When enabled, lines beginning with "/" are skipped during execution

      Parameters

      • enable: boolean

        true to enable block delete, false to disable

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable block delete - skip lines starting with "/"
      await commandChannel.setBlockDelete(true);

      // Disable block delete - execute all lines
      await commandChannel.setBlockDelete(false);
    • Sets debug flags for LinuxCNC components using OR-ed EmcDebug flags Multiple debug categories can be enabled simultaneously by combining flags

      Parameters

      • level: EmcDebug

        Debug flags from EmcDebug enum, can be OR-ed together

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Disable all debugging
      await commandChannel.setDebugLevel(0);

      // Enable interpreter debugging only
      await commandChannel.setDebugLevel(EmcDebug.INTERP);

      // Enable multiple debug categories
      await commandChannel.setDebugLevel(EmcDebug.INTERP | EmcDebug.MOTION_TIME);

      // Enable task and NML debugging
      await commandChannel.setDebugLevel(EmcDebug.TASK_ISSUE | EmcDebug.NML);

      // Enable Python and remap debugging for custom components
      await commandChannel.setDebugLevel(EmcDebug.PYTHON | EmcDebug.REMAP);
    • Sets the state of a digital output pin

      Parameters

      • index: number

        Index of the digital output pin

      • value: boolean

        true to set high, false to set low

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set digital output 0 high
      await commandChannel.setDigitalOutput(0, true);

      // Set digital output 3 low
      await commandChannel.setDigitalOutput(3, false);
    • Enables or disables feed hold functionality When enabled, allows pausing motion without stopping the program

      Parameters

      • enable: boolean

        true to enable feed hold, false to disable

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable feed hold capability
      await commandChannel.setFeedHoldEnable(true);
    • Enables or disables feedrate override functionality

      Parameters

      • enable: boolean

        true to enable feedrate override, false to disable

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable feedrate override control
      await commandChannel.setFeedOverrideEnable(true);
    • Sets the feedrate override scale factor

      Parameters

      • scale: number

        Feedrate scale factor (1.0 = 100%, 0.5 = 50%, 2.0 = 200%)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set feedrate to 50% of programmed values
      await commandChannel.setFeedRate(0.5);

      // Set feedrate to 120% of programmed values
      await commandChannel.setFeedRate(1.2);
    • Turns flood coolant on or off

      Parameters

      • on: boolean

        true to turn flood on, false to turn off

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Turn on flood coolant
      await commandChannel.setFlood(true);

      // Turn off flood coolant
      await commandChannel.setFlood(false);
    • Sets the maximum position limit for a joint

      Parameters

      • jointIndex: number

        Zero-based index of the joint

      • limit: number

        Maximum position limit in machine units

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set maximum limit for joint 0 to 200 units
      await commandChannel.setMaxPositionLimit(0, 200);
    • Sets the maximum velocity for trajectory planning

      Parameters

      • velocity: number

        Maximum velocity in machine units per second

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set maximum velocity to 200 units/second
      await commandChannel.setMaxVelocity(200);
    • Sets the minimum position limit for a joint

      Parameters

      • jointIndex: number

        Zero-based index of the joint

      • limit: number

        Minimum position limit in machine units

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set minimum limit for joint 0 to -100 units
      await commandChannel.setMinPositionLimit(0, -100);
    • Turns mist coolant on or off

      Parameters

      • on: boolean

        true to turn mist on, false to turn off

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Turn on mist coolant
      await commandChannel.setMist(true);

      // Turn off mist coolant
      await commandChannel.setMist(false);
    • Enables or disables optional stop (M1) functionality When enabled, M1 codes in programs will pause execution

      Parameters

      • enable: boolean

        true to enable optional stops, false to disable

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable optional stops
      await commandChannel.setOptionalStop(true);

      // Disable optional stops
      await commandChannel.setOptionalStop(false);
    • Sets the rapid traverse override scale factor

      Parameters

      • scale: number

        Rapid rate scale factor (1.0 = 100%, 0.25 = 25%)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set rapid rate to 50%
      await commandChannel.setRapidRate(0.5);
    • Sets the spindle speed override scale factor

      Parameters

      • scale: number

        Spindle override scale factor (1.0 = 100%)

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set spindle speed to 80% of programmed values
      await commandChannel.setSpindleOverride(0.8);

      // Set spindle 1 speed to 110%
      await commandChannel.setSpindleOverride(1.1, 1);
    • Enables or disables spindle speed override functionality

      Parameters

      • enable: boolean

        true to enable spindle override, false to disable

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable spindle override control
      await commandChannel.setSpindleOverrideEnable(true);
    • Sets the task state for LinuxCNC

      Parameters

      • state: TaskState

        The task state to set (ESTOP, ESTOP_RESET, OFF, or ON)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable E-stop
      await commandChannel.setState(TaskState.ESTOP);

      // Reset E-stop
      await commandChannel.setState(TaskState.ESTOP_RESET);

      // Turn machine on
      await commandChannel.setState(TaskState.ON);
    • Sets the task execution mode for LinuxCNC

      Parameters

      • mode: TaskMode

        The task mode to set (MDI, MANUAL, or AUTO)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Switch to MDI mode for manual data input
      await commandChannel.setTaskMode(TaskMode.MDI);

      // Switch to manual mode for jogging
      await commandChannel.setTaskMode(TaskMode.MANUAL);

      // Switch to auto mode for program execution
      await commandChannel.setTaskMode(TaskMode.AUTO);
    • Sets tool data for a specific tool number Updates tool geometry and parameters in the tool table

      Parameters

      • toolEntry: RecursivePartial<ToolEntry> & { toolNo: number }

        Tool entry containing tool number and optional geometry data

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set basic tool data
      await commandChannel.setTool({
      toolNo: 3,
      pocketNo: 3
      });

      // Set tool with geometry data
      await commandChannel.setTool({
      toolNo: 1,
      pocketNo: 1,
      diameter: 6.35,
      offset: {
      x: 0,
      y: 0,
      z: 25.4
      }
      });
    • Sets the trajectory mode for coordinated motion

      Parameters

      • mode: TrajMode

        The trajectory mode (FREE, COORD, or TELEOP)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Set to coordinated mode for normal G-code execution
      await commandChannel.setTrajMode(TrajMode.COORD);

      // Set to free mode for individual joint control
      await commandChannel.setTrajMode(TrajMode.FREE);
    • Engages or releases the spindle brake

      Parameters

      • engage: boolean

        true to engage brake, false to release brake

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Engage spindle brake
      await commandChannel.spindleBrake(true);

      // Release brake on spindle 1
      await commandChannel.spindleBrake(false, 1);
    • Decreases spindle speed by a predefined increment Spindle must already be running

      Parameters

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Decrease speed of main spindle
      await commandChannel.spindleDecrease();

      // Decrease speed of spindle 1
      await commandChannel.spindleDecrease(1);
    • Increases spindle speed by a predefined increment Spindle must already be running

      Parameters

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Increase speed of main spindle
      await commandChannel.spindleIncrease();

      // Increase speed of spindle 1
      await commandChannel.spindleIncrease(1);
    • Turns off the spindle

      Parameters

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Turn off main spindle
      await commandChannel.spindleOff();

      // Turn off spindle 1
      await commandChannel.spindleOff(1);
    • Turns on the spindle at a specified speed

      Parameters

      • speed: number

        Spindle speed in RPM (positive = clockwise, negative = counterclockwise)

      • spindleIndex: number = 0

        Index of the spindle to control (default: 0)

      • waitForSpeed: boolean = true

        Whether to wait for spindle to reach speed before continuing (default: true)

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Turn on spindle at 1000 RPM clockwise
      await commandChannel.spindleOn(1000);

      // Turn on spindle 1 at 500 RPM counterclockwise
      await commandChannel.spindleOn(-500, 1);

      // Start spindle without waiting for speed
      await commandChannel.spindleOn(800, 0, false);
    • Executes a single step of the G-code program Advances program execution by one line/block

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Step through program one line at a time
      await commandChannel.stepProgram();
    • On completion of this call, the VAR file on disk is updated with live values from the interpreter.

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

    • Enables or disables teleop mode

      Parameters

      • enable: boolean

        true to enable teleop mode, false for joint mode

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Enable teleop mode for Cartesian jogging
      await commandChannel.teleopEnable(true);

      // Disable teleop mode for joint jogging
      await commandChannel.teleopEnable(false);
    • Unhomes a specific joint, clearing its homed status

      Parameters

      • jointIndex: number

        Zero-based index of the joint to unhome, -1 to unhome all joints

      Returns Promise<RcsStatus>

      Promise resolving to RcsStatus indicating command completion

      // Unhome joint 1 (typically Y-axis)
      await commandChannel.unhomeJoint(1);

      // Unhome all joints
      await commandChannel.unhomeJoint(-1);
    • Synchronously waits for the last command to complete This does the same as await but provides a synchronous way to wait for command completion

      Parameters

      • Optionaltimeout: number

        Maximum time to wait in seconds (default: 5 seconds)

      Returns RcsStatus

      RcsStatus indicating completion status (RCS_DONE, RCS_ERROR, or -1 for timeout)

      // These two approaches are equivalent:

      // Approach 1: Using await (asynchronous)
      await commandChannel.runProgram();
      console.log('Program completed');

      // Approach 2: Using waitComplete (synchronous)
      commandChannel.runProgram(); // Fire and forget - don't await
      const status = commandChannel.waitComplete(); // Synchronously wait for completion
      if (status === RcsStatus.DONE) {
      console.log('Program completed');
      }