# # To send gcode file to Arduino Gcode interpreter: python nc2serial.py < mygcode.nc # Have "%" as the first line of .nc file # # This script reads the lines from stdin and writes them to port_id using Pyserial module # After each line it waits for one of the predefined responses from the port (or until timeout) # # port_id examlpes: "COM1" on Windows, "/dev/ttyUSB0" on Linux # import serial,sys port_id = "/dev/ttyUSB0" ser = serial.Serial(port=port_id, baudrate=19200, timeout=20) for line in sys.stdin.readlines(): ser.write(line) print line.strip('\n') while True: response = ser.readline() print response.strip('\n') if response.strip() in ['ok','start']: break print '' ser.close()