The CBEAM CNC machine can be controlled via serial communication using the provided Python class.
Please install the PySerial package by running the following command:
pip install pyserial
The Openbuilds Blackbox motor controller is used to drive the NEMA motors in the CNC stages.
Below, we provide an example showing you how to communicate with your CBEAM CNC machine. The API issues serial commands to communicate with the instrument.
import time
from cbeam import CBEAM
def main():
address = "/dev/ttyUSB0" # Replace with the appropriate serial port for your CBEAM CNC machine
cbeam = CBEAM("CBEAM", address)
# Connect to the CBEAM CNC machine
if cbeam.connect():
print("Connected to CBEAM CNC machine")
# Unlock the CNC machine
cbeam.set_unlock()
# Set the home position
cbeam.set_home()
# Set the X, Y, and Z positions
cbeam.set_position_X(100)
cbeam.set_position_Y(50)
cbeam.set_position_Z(0)
# Wait for the move to complete
cbeam.wait_for_move_complete()
# Run G-code from a file
# gcode_filename = "example.gcode"
# cbeam.run_gcode(gcode_filename)
# Disconnect from the CBEAM CNC machine
cbeam.disconnect()
if __name__ == "__main__":
main()
This example code does the following:
Imports the necessary modules and the CBEAM class from the cbeam.py file provided.
Defines a main function that:
Make sure to replace the address variable with the appropriate serial port for your CBEAM CNC machine. Please visit the 'Tutorials' section to find the appropriate serial port.