Commands not appending

The place to discuss your hardware and software/firmware modifications...
Post Reply
Pillbug
Posts: 2
Joined: Thu Apr 09, 2015 7:12 pm

Commands not appending

Post by Pillbug » Thu Apr 09, 2015 7:19 pm

I am trying to run the makergear m2 printer with my own python code and using printcore for commands. So I connect to the printer and send code like this:

string = "G1 X%s Y%s F2000" % (nx, ny)
p.send(string)
string = "G1 Z%s F100" % height
p.send(string)

Pretty sloppy, but it gets the job done most of the time. I'm running into an issue though. I have a separate thread that runs through the above code, and I would expect that the commands get appended to the 'mainqueue' because I'm using the 'send' command and the printer is printing when the thread runs through my block of code. However; the printer makes it through about 3/4 of the commands I tell it to and then stops. When I debugged the program, it never appended the commands because it never thought the printer was in the process of printing, but the program goes through every step (presumably because I'm working through it more slowly?).

I have the code like I showed above running in a loop for a specified amount of points I want it to go to. If I put a time.sleep command in between the loops to let the printer 'catch up' to the code, things work well. So my question is how do I make the commands append to the queue?

Hope this wasn't too confusing!

User avatar
insta
Posts: 2007
Joined: Tue Sep 16, 2014 3:59 am

Re: Commands not appending

Post by insta » Thu Apr 09, 2015 7:53 pm

How are you opening the connection to the printer with printcore?

When the main thread exits, are you waiting for your subthread to exit before closing the connection / disposing of the resources?

Is printcore even threadsafe? You may need to add synchronization around it...
Custom 3D printing for you or your business -- quote [at] pingring.org

Pillbug
Posts: 2
Joined: Thu Apr 09, 2015 7:12 pm

Re: Commands not appending

Post by Pillbug » Thu Apr 09, 2015 9:41 pm

I don't know what you mean exactly by 'opening the connection to the printer with printcore', but I have a separate python file that my main program calls to scan the ports for the printer and set the connection. I took it from printcore I believe (this was a year ago). It declares the 'p' variable to be global so I can work with it in my main program. Also a bit sloppy, but it worked well until now.

My main program is a GUI, so I separately threaded the code handling all the movements to keep the GUI responsive. I had initially thought that I might use some time.sleep arguments in it. But the thread handles the movements, going through the loop and sending commands to the queue, then exits. I figured this was OK if all the commands went to the queue, which apparently isn't happening...

Could you explain more about synchronization? I'm not sure how it would be an issue if only one thread is using the printcore commands. I'm also a bit of a threading novice, so I could easily be overlooking something.

Post Reply