API question
Hello,
I am using the websockets API to control my printer via Python.
I am trying to synchronize an action from the python script with the arrival of the print head at a particular location. My problem is that commands through the server are non-blocking, which means that I have no way of knowing when the head actually reaches its destination.
Running a stateList command on the ws API tells where the print is going to be, not where it is currently, so it does not work to poll this for the information.
Is there a way via the API of telling whether the printer is completely idle (i.e. not moving) so I can know that the last command completed, and the head is where I want it to be?
Second question: If I execute a GCODE via the websockets API such as M114, the printer returns the location of the extruder to the server. How do I get that message back to my python script?
Thank you for your help!
I am using the websockets API to control my printer via Python.
I am trying to synchronize an action from the python script with the arrival of the print head at a particular location. My problem is that commands through the server are non-blocking, which means that I have no way of knowing when the head actually reaches its destination.
Running a stateList command on the ws API tells where the print is going to be, not where it is currently, so it does not work to poll this for the information.
Is there a way via the API of telling whether the printer is completely idle (i.e. not moving) so I can know that the last command completed, and the head is where I want it to be?
Second question: If I execute a GCODE via the websockets API such as M114, the printer returns the location of the extruder to the server. How do I get that message back to my python script?
Thank you for your help!
Comments
Firmware does not allow assigning responses to send commands. There is virtually no hint which line comes from which command. That is why you also get no response on send gcodes. You have 2 choices to get noticed on special responses. In printer-setup->gcode->advanced you can define a regular expression that sends an event when the condition is matched and also includes the first matched group as well as the complete line. That is the easy way - you just listen for that event and do not need anything. The other solution is to enable sending all log responses (there is a filter to limit what gets send) and filter your self for position answers. But that solution is more cpu intensive as you get more then you want, so solution 1 is easier.
I apologize because I am new to websockets, but when I do a send of an M400, then do a recv(), I always get back a response immediately of the form: {"callback_id":10586,"data":{},"session":"4D9beRKSgZDItCq&S02i4LKztI!Ufk^v"}. I have tried this with up to 10000 M400s
If I look at the server gcode window, just like you said, I see the M400 commands actually taking much longer. So, it seems like the server is also buffering them?