Hi all, I'm streaming GCODE directly to my Blackbox X32 via serial in a small Python script. The serial port is opened, GCODE commands are streamed to it, and the serial port is closed on exit. Works fine on the first try, but if the script is restarted, it hangs on the first instance of ser.readline(). If the firmware is restarted via the reset button on the X32, it runs fine again on the first try. Any ideas on how to configure it such that no button-reset is required each time? Cheers, Miks Sample code below: ------ class ControlBase(Node): [..] self.rail_interface = '/dev/ttyUSB0' self.rail_baudrate = 115200 self.ser = None self.ser = serial.Serial(self.rail_interface, self.rail_baudrate) def send_wake_up(ser): # Wake up ser.write(str.encode("\r\n\r\n")) time.sleep(2) # Wait for Printrbot to initialize ser.flushInput() # Flush startup text in serial input send_wake_up(self.ser) time.sleep(1) command = b'$X\n' self.ser.write(command) grbl_out = self.ser.readline() # Hangs here after script restart print(f"{command} : " , grbl_out.strip().decode('utf-8')) time.sleep(1) command = b'G91\n' self.ser.write(command) grbl_out = self.ser.readline() print(f"{command} : " , grbl_out.strip().decode('utf-8')) time.sleep(1) command = b'G21\n' self.ser.write(command) grbl_out = self.ser.readline() print(f"{command} : " , grbl_out.strip().decode('utf-8')) time.sleep(1) print("Rail initialized") [..] self.ser.write(command) # GCODE written here asynchronously [..] # Cleanup self.ser.flushInput() self.ser.flushOutput() self.ser.close()
Might have to do with the opening/closing of the port. Maybe your code is not doing the DTR/RTS/CTS handshakes correctly: Play around with DTR disabled first, but for some configs and OS's we do add it back in too: OpenBuilds-CONTROL/index.js at deff1fad029c04ac0a7733f536f37ec1e3e3ba70 · OpenBuilds/OpenBuilds-CONTROL and OpenBuilds-CONTROL/index.js at deff1fad029c04ac0a7733f536f37ec1e3e3ba70 · OpenBuilds/OpenBuilds-CONTROL so best to build it out to handle different autoreset scenarios on port opening. We do have to cater for grbl and grblHAL, both our boards and 3rd party. USB to Serial chips and native USB - quite a mix so we try every handshake on connection before giving up
Thanks Peter! Played around with the DTR/RTS toggling on port opening, the following solved the issue: self.ser = serial.Serial( self.rail_interface, self.rail_baudrate, ) self.ser.dtr = False # Start with DTR low self.ser.rts = False # Start with RTS low time.sleep(0.5) # Wait a bit self.ser.dtr = True # Then set DTR high self.ser.rts = True # Then set RTS high