How to auto run a program, wait till complete then do something else

More
10 Mar 2021 10:35 #201636 by Willheg
Hello again Everyone.

I'm making progress on my Glade Panel.

My issue I'm having now is I have a button loading some g code and running it using linuxcnc.command.auto(linuxcnc.AUTO_RUN, 0) to touch off a work piece automatically (with safety pauses), which is great.

What I'm having trouble with is I'm wanting to wait until the program has finished in this mode then reload the originally loaded program.

Is anyone able to steer me in the right direction on how to wait until the current program has finished before trying to load the next python command.

Thank All.

William

Please Log in or Create an account to join the conversation.

More
10 Mar 2021 15:15 #201651 by HansU
These HALUI pins you know?:
halui.program.is-paused (bit, out) - status pin telling that a program is paused
halui.program.is-running (bit, out) - status pin telling that a program is running

Please Log in or Create an account to join the conversation.

More
10 Mar 2021 20:53 #201709 by newbynobi
If you use python, you may react on the Hal status signal interpreter idle, as that one is emitted if a program or a MDI command has finished, when running the signal status interpreter run is emitted.

You need to add status widget to your glade panel and connect the signals of that widget to a function in your python code.

Norbert

Please Log in or Create an account to join the conversation.

More
10 Mar 2021 23:45 #201760 by Willheg
Thanks for the responses.

Norbert, I like the sound of your idea as I'm using glade and python, and I kinda get what you mean but I'm struggling to get my head around how to hook up the signals to watch/wait for and then when complete/idle to do the next thing I request.

I will keep hunting to see if I can find some code that may enlighten me on how to achieve this.

Please Log in or Create an account to join the conversation.

More
11 Mar 2021 05:31 #201776 by newbynobi
I use that signals to control running Macros within gmoccapy, so you may take a look at my code.

Norbert

Please Log in or Create an account to join the conversation.

More
11 Mar 2021 08:38 #201784 by Willheg
Hello again,

I have scrolled the code suggested briefly tonight but I'm still in a head spin as how it works, or maybe I was not clear enough with my explanation?

What I'm trying to do is load a .NGC file in linuxcnc with python code from a button, execute the code containing some "M0" pause programs in it, the reload the old program.

Where I am at is I can save the old file name for reload, change to the new program, run the new program. But this is where it comes unstuck, it then just after starting to run the new program tries to carry on with the next line of python instead of waiting until the gcode has finished running before doing something.

I've tried looking for loops, using if statements and tried using linuxcnc.command.wait_complete(), all with no effect, it just loads the new program, starts running, pauses from the M0 coded in the gcode, but carries on without finishing and loads the next line of python.

I'm sure there is an easy way to do this but it just requires me to get my head around what to implement to make it happen.

If required I could post snippets of my code to see if anyone has any ideas

Thanks all

Please Log in or Create an account to join the conversation.

More
11 Mar 2021 10:40 #201793 by Willheg
Upon further testing tonight, if I comment out the M0 commands in the gcode I'm running it almost works as I like apart from a couple of minor error messages about a telop mode and something else, not by my computer anymore.

So still trying to work out how with M0 in the file I've had my python code load and run, to get the python code to wait until the end of the file I'm running is complete before continuing with he next part.

Thanks if you have read this far, I will keep playing and looking at code and see if I can magic something unless someone else has any ideas or can enlighten me.

Still having fun learning and making it my own, just frustrating that it takes a bit to learn.

Please Log in or Create an account to join the conversation.

More
11 Mar 2021 20:59 #201861 by newbynobi
You have to do something like this:
import time
...
...
Start programm
...
...
while self.stat.interp_state != linuxcnc.INTERP_IDLE:
    time.sleep(1)
...
...
continue with code

But that is very ugly!

I would integrate something like signals and if hal_status_interpreter_idle is thrown tell taht part what to do now, so place here some code

Norbert

Please Log in or Create an account to join the conversation.

More
12 Mar 2021 01:03 #201915 by Willheg
Thanks Norbert,

I had starting looking into while loops last night after my last 2 posts, I thought it seams ugly as well, but if it is going to work maybe I give it a shot.

Thanks for your help again, I will see how I get on and if I require anything else I will be back to ask more questions to see if anyone can enlighten me.

Please Log in or Create an account to join the conversation.

More
20 Mar 2021 10:57 #202961 by HansU
Have a look at programtimer_xxxx.py and programtimer_xxxx.glade in forum.linuxcnc.org/gmoccapy/40709-gmocap...lock?start=40#202843
This is a very simple example how to use signals and signal handlers.

Hans

Please Log in or Create an account to join the conversation.

Moderators: mhaberlerHansU
Time to create page: 0.111 seconds
Powered by Kunena Forum