dsf python reconnect after eStop
-
So I have written a dsf-python script to control my ODrive based spindle. It is basically a customized version of the custom_m_code.py script:
https://github.com/Duet3D/dsf-python/blob/main/examples/custom_m_codes.py
so far it is working great. Only issue is that when I press the Emergency Stop button the script dies with the following output:
root@Duetoko:~# python3.7 odrivespindle2.py send: {"mode":"Intercept","version":11,"InterceptionMode":"Pre","Channels":["HTTP","Telnet","File","USB","Aux","Trigger","Queue","LCD","SBC","Daemon","Aux2","AutoPause","Unknown"],"Filters":["M3","M4","M5"],"PriorityCodes":false} recv: {"success":true} Closing connection: Traceback (most recent call last): File "odrivespindle2.py", line 70, in start_intercept cde = intercept_connection.receive_code() File "/usr/local/lib/python3.7/dist-packages/dsf_python-3.3.2-py3.7.egg/dsf/connections.py", line 458, in receive_code return self.receive(code.Code) File "/usr/local/lib/python3.7/dist-packages/dsf_python-3.3.2-py3.7.egg/dsf/connections.py", line 122, in receive json_string = self.receive_json() File "/usr/local/lib/python3.7/dist-packages/dsf_python-3.3.2-py3.7.egg/dsf/connections.py", line 162, in receive_json raise TimeoutError TimeoutError
My hacky solution has been to wrap the whole thing in a while loop and add a ten second sleep at the end of the loop so when it throws an exception it sleeps ten seconds and starts the whole process again. I am assuming though there is a better way to handle this using exceptions and the like. Any suggestions would be greatly appreciated.