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: 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. 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: 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.
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
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.
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)
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).
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. Running this file repeatedly, the controller remembers its coordinates