Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: Ironic on March 08, 2013, 06:29:02 AM

Title: Associate script to button while running code
Post by: Ironic on March 08, 2013, 06:29:02 AM
Hi guys.
Been reading this forum for some time now, learned a lot but I need help now that I could not find an answer on my own.

I would like to associate a script to a button. Something similar to E-stop, but that instead would do feedhold, stop spindle and raise the Z axis.
This is to stop program if i think the part is cut all the way trough, but still be able to resume if it is not.

I can do a script that does this, but it will not run if a program is running. I assume you can't run Gcode in a script while the main Gcode is running.

Any thoughts?
Tks
Title: Re: Associate script to button while running code
Post by: BR549 on March 08, 2013, 12:08:57 PM
DoButton(1) 'Pause
While Ismoving()
Wend
DoSpinStop() 'Stop Spindle
DoButton(3) 'Stop
GotoSafeZ()  'Raise Z to SafeZ


(;-) TP
Title: Re: Associate script to button while running code
Post by: Ironic on March 08, 2013, 02:19:32 PM
Tks

Will try on monday.

Rgds
Title: Re: Associate script to button while running code
Post by: Ironic on March 22, 2013, 10:23:20 AM
Hi.

So the thing is can't get this to run.

I have OEM Trig #1 active and associated to a pin.
A macro called M1000 with a single line : SetTriggerMacro(1001)

(M1000 is in the init line of mach3)

And a macro called M1001 with your code.

Anything missing?

Regards



Title: Re: Associate script to button while running code
Post by: BR549 on March 22, 2013, 11:58:21 AM
Mach3 Programmers reference manual

Page 119   " SetTriggerMacro () "

It is IN the manual,

(;-) TP
Title: Re: Associate script to button while running code
Post by: Ironic on April 02, 2013, 09:19:49 AM
Hi

Tks for the help but i am feeling dumb here.

I i think i have done all of that.

(http://s22.postimg.org/8oh9iuiod/Capture1.jpg) (http://postimg.org/image/8oh9iuiod/)

(http://s22.postimg.org/8tl0sipzh/Capture2.jpg) (http://postimg.org/image/8tl0sipzh/)

In C:\Mach3\macros\Mach3Mill i have M1000 that just has:

Code: [Select]
SetTriggerMacro(1001)
Message "Ready" 

And the Ready prints out when mach3 starts up or i press reset.

 M1001 has the code you suggested.

But nothing happens when the pin goes low (running program or not).

To debug i used your code in a button script and that works.
Do not think it is electric issue, since it work for probe and i can see the pin go low in diag screen.

Regards
Title: Re: Associate script to button while running code
Post by: Ironic on April 02, 2013, 09:33:13 AM
Did another debugging test.

If i put your code in a button script it works.

But if i instead in the button script i just put CODE("M1001") nothing happens if it is moving.

It seems i can run button scripts while machine is moving but i cant call macros...
Title: Re: Associate script to button while running code
Post by: BR549 on April 02, 2013, 11:05:07 AM
OK just tested it HERE and it works fine. So lets go over it one more time.

1 Create your macros, M1000, M1001

M1000
SetTriggerMacro(1001)
Message" TriggerMacro#1001"
End

M1001
Message "Action code completed"
END

2. On the Genconfig page place the M1000 in the initialization line , Last entry

3 Setup ports and pins for OEMtrigger#1

4 Config Hotkeys  for OEMtrigger#1  = 301

press reset and then reset again to run init string. You should see the message form the M1000 in the message line

Press your switch and you should see the message from the M1001 macro in the message line.

(;-) TP
Title: Re: Associate script to button while running code
Post by: Ironic on April 02, 2013, 11:37:14 AM
Hi BR549

So i already had the M1000 in init line so with your new code i get TriggerMacro#1001 when mach3 starts or i double press reset.

With your new M1001, with a simple gcode( M3, G01 X100,G01 Y100) i press the probe during the movement but i only see the message when the program ends.

If i instead i assign the code to a button script i does show up in real time.

So trying you original code if i touch the probe it seems to try to run the code on the end of the program but says nothing to feedhold.
If i instead assign it to a button it pauses when i click but then says Terminating script. From the tests i made it seems the DoButton(3) 'Stop also stops the script execution so nothing else after that is runned.

Tricky tricky

Tks
Title: Re: Associate script to button while running code
Post by: stirling on April 02, 2013, 12:03:00 PM
With your new M1001, with a simple gcode( M3, G01 X100,G01 Y100) i press the probe during the movement but i only see the message when the program ends.

If i instead i assign the code to a button script i does show up in real time.

That's cos trigger macros are broken. I raised the problem a while back here (http://www.machsupport.com/forum/index.php/topic,23679.0.html) and here (http://groups.yahoo.com/group/mach1mach2cnc/message/138639) but unfortunately didn't get anywhere - well apart from some grief from Terry for me asking Brian to fix it.  :P

Brian did TRY to fix it but unfortunately his fix didn't work - haven't heard anything since.

Ian
Title: Re: Associate script to button while running code
Post by: Ironic on April 02, 2013, 12:16:29 PM
Tks for the tip Stirling.

At least no more wasting time.

So if i stick to button scripts, how do i get around the issue (or that it seems to be for me) that DoButton(3) stops the script execution so the instructions after that do not run?

Regards


Title: Re: Associate script to button while running code
Post by: BR549 on April 02, 2013, 01:14:10 PM
GUYS it is working fine here ????  I just created a function based on the same thing you needed and used the same Macro code to stop and tested it.

What version are you running ???

(;-) TP
Title: Re: Associate script to button while running code
Post by: BR549 on April 02, 2013, 01:33:44 PM
OK i have run it in Ver.042.022 AND .067 It works fine here.

(;-) TP
Title: Re: Associate script to button while running code
Post by: stirling on April 03, 2013, 05:08:57 AM
@Terry - It depends on what you mean by "it" and "working".

if you go back to your post Reply #7, then....

If there is currently NO movement in progress then...

if you execute your M1001 from a button, from the MDI, from the CB editor or from a trigger then it executes as you would expect i.e. IMMEDIATELY.

HOWEVER - If there IS currently movement in progress then...

if you execute your M1001 from a button, from the MDI, from the CB editor then again it executes as you would expect i.e. IMMEDIATELY.

HOWEVER IT DOES NOT EXECUTE IMMEDIATELY from a trigger - IT WAITS UNTIL MOVEMENT has stopped and THEN EXECUTES.

This is on 43.22 but I've tested it from 43.66 back to 42.18 and it's the same. Well it is here anyway - if a macro executes from a trigger immediately on your system WHILE movement is in progress then you have (AFAIK) the only system out there where triggers work FULLY and PROPERLY.

Ian