Welcome to Our Community

Some features disabled for guests. Register Today.

Blackbox reset after streaming GCODE via serial

Discussion in 'Control Software' started by skimslozo, Aug 14, 2024.

  1. skimslozo

    skimslozo New
    Builder

    Joined:
    Jul 11, 2024
    Messages:
    2
    Likes Received:
    1
    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()
     
  2. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    14,868
    Likes Received:
    4,283
    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
     
  3. skimslozo

    skimslozo New
    Builder

    Joined:
    Jul 11, 2024
    Messages:
    2
    Likes Received:
    1
    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
     
    Peter Van Der Walt likes this.
  4. David the swarfer

    David the swarfer OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Aug 6, 2013
    Messages:
    3,430
    Likes Received:
    1,907
    arduino based GRBL resets on connect, grblHAL 'might' reset on connect.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice