Welcome to Our Community

Some features disabled for guests. Register Today.

Black Box X32 Remember Machine Coordinates after reopening COM port

Discussion in 'Control Software' started by Isaiah Baker, Jun 22, 2023.

  1. Isaiah Baker

    Builder

    Joined:
    Jun 15, 2023
    Messages:
    3
    Likes Received:
    0
    Hello, I am a new to grblHAL motion control and am attempting to replicate some of the functionality of the openbuilds software in python as part of a python application.

    I am using a serial port monitor to investigate how the software communicates with the controller.

    For example, I noticed that when you disconnect and reconnect the controller in the openbuilds software, the machine coordinates are remembered.

    Here is an example:
    upload_2023-6-22_13-41-16.png

    As you can see, the machine coordinates are approx. -5,-5,-5, the connection is closed and reopened, and the machine coords are still -5,-5,-5.

    However, when I open the com port in python, they always reset to zero.

    Here is an example where I close the port in the openbuilds software and reopen it in python.

    upload_2023-6-22_13-47-38.png

    As you can see, here after connecting and reconnecting and sending the same commands (<LF>, then <CAN>)

    The controller appears to reset somehow and then the machine coordinates are reset to 0,0,0.

    How can I open the controller in python without triggering this reset?
    Is it a difference in my serial settings?

    Here is the python code for I am using to the controller:

    upload_2023-6-22_15-15-46.png

    What is it about this that causes the machine coordinates to be reset? I did not do a power cycle. I did send the cancel character, but so does the openbuilds software.
     
  2. Peter Van Der Walt

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

    Joined:
    Mar 1, 2017
    Messages:
    15,191
    Likes Received:
    4,346
    We do "keep" it around while closed until a new update comes through. But Grbl is correct, it should zero on startup - because you are supposed to HOME on startup to set Machine Coordinates, all other positions are offsets from Home. Rehoming, restores G53, which in turn restores G54 (Work coordinates)

    After homing stored offsets are restored and DRO will match
     
  3. Isaiah Baker

    Builder

    Joined:
    Jun 15, 2023
    Messages:
    3
    Likes Received:
    0
    Thank you for your reply. I appreciate your support and the work you have done with openbuilds.

    If I understand you correctly, you are saying the openbuilds software stores the previous machine coordinates locally on the host computer?

    This makes sense as I can see the software assuming -5 -5 -5 before the ? command is issued.

    I am still confused by my observations with the serial monitor, because in the first example I showed the ? command returns -5,-5,-5 after a reconnect. Is the software somehow reuploading the stored coordinates to the controller upon reconnect?
    If so, wouldn't that be apparent in the serial monitor?

    I understand the benefits of rehoming each time the device is connected, but the ability for the controller to remember its machine coordinates is still desirable for my application, it seems like it is in my first example.

    In any case I am just curious how the openbuilds software achieves this.
     
  4. Peter Van Der Walt

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

    Joined:
    Mar 1, 2017
    Messages:
    15,191
    Likes Received:
    4,346
    No, only if you happened to be at MPOS0,0,0 when you rebooted. Machine can't retain machine position because machine could move while controller is off. Must home, no other way (that is reliable)
     
  5. terjeio

    terjeio Well-Known
    Builder

    Joined:
    Oct 18, 2020
    Messages:
    60
    Likes Received:
    61
    Some controllers are hard reset on connect via USB depending on how the connection is made. E.g. ESP32 dev boards are wired for resetting, IIRC by the toggling the RTS line. The BlackBox is likely wired similarly as your log suggest so, there is a POWERON RESET message in it. If you get this message every time you connect (without a power cycle in between) then it certainly is.
    If you want to keep the controller in its current state you can try to connect without toggling/changing the RTS and/or DTR lines (if the serial implementation in python allows that).
     
    Isaiah Baker likes this.
  6. Isaiah Baker

    Builder

    Joined:
    Jun 15, 2023
    Messages:
    3
    Likes Received:
    0

    After finding my own hack way to do this by modifying the pyserial library itself, I found a github issue from 2016 about this exact quirk of pyserial.

    DTR and RTS control lines toggle unintentionally when opening port · Issue #124 · pyserial/pyserial

    it is still open, but the workaround is instead of using the constructor like this:


    ser = Serial(port='COM4', baudrate=115200, timeout=1)

    Use it like this:

    ser = Serial(port=None, baudrate=115200, timeout=1)
    ser.port = 'COM4'
    ser.baudrate = 115200
    ser.timeout = 1
    ser.dtr = 0
    ser.rts = 0
    ser.open()

    Setting rcscts and dsrdtr to false is not enough, you have to set them to None before the port is opened.

    upload_2023-6-30_17-12-26.png

    Running this file repeatedly, the controller remembers its coordinates

    upload_2023-6-30_17-12-56.png
     

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