Hello Guest it is April 24, 2024, 03:14:22 PM

Author Topic: The basics of making a switch run a script?  (Read 16217 times)

0 Members and 1 Guest are viewing this topic.

Re: The basics of making a switch run a script?
« Reply #10 on: July 04, 2006, 03:04:10 PM »
Ok, i tried what I posted on my previous post and it doesnt work, so I tried Brians way and it works!
3 Questions though.

1. The M450 macro does not run unless you run the M451 first, how can you make the running of M451 automatic at startup or some other time as for the user no to do it each time Mach3 is loaded.
2. What happens if you want to use more than one external button, what OEM codes (like the 301) and what macro numbers like the (M450 and M451) should be used for each OEM trigger?
3. I noticed that if you press the button the script starts to run, and if you press it again while the code is running, as soon as the first code is finished a second code starts to run. How can this be avoided?

Best Regards
Fernando
Re: The basics of making a switch run a script?
« Reply #11 on: July 04, 2006, 05:42:15 PM »
The best way to get the macro number loaded on startup is to add the M450 to the init string (under Config/State)

that should do it...
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: The basics of making a switch run a script?
« Reply #12 on: July 04, 2006, 06:06:58 PM »
Thanks a lot Brian,
Any thoughts on the other two questions?
Regards
Fernando
Re: The basics of making a switch run a script?
« Reply #13 on: July 04, 2006, 06:33:25 PM »
you can use any macro that you like :) The problem is that you can only have one button the is doing everything. Art and I have talked about changing this but it is going to be after the G100 is done...

There will be a bug fix for the buffered commands..
Thanks
Brian
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: The basics of making a switch run a script?
« Reply #14 on: July 04, 2006, 06:42:46 PM »
Thanks a lot Brian,
I guess meanwhile a keyboard emulator would have to do the trick along with a scripted button.
And maybe a set of one shot relays to avoid the buffered commands.
Thanks again
Fernando
Re: The basics of making a switch run a script?
« Reply #15 on: July 04, 2006, 07:14:16 PM »
Afer talking to Art we think it is best that you put code in your macro to see IF the macro should be run. It is very easy to add code that looks at the state of an LED and figure out if the macro should run. so lets say that your macro loads a Gcode file and runs it SO at the start of tha mcaro you should look and see if there is a job running. Here is an example:

Sub Main()

if (GetLED(4)) Then'This is where the Macro is told not to run if there is a job running
MsgBox("Could Not load there is a Job running")
Exit Sub
End if

'TODO add Macro code here

Main

This is more work but gives you more power in the end...
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: The basics of making a switch run a script?
« Reply #16 on: July 05, 2006, 12:41:14 PM »
I dont know if this would be possible, practical or even reasonable or easy enough to implement...

If when an input or an oemtrig is activated via a switch (button, limit switch or whatever) The keystroke or hotkey related to that input can be emulated, then a button on the screen which is related to that hotkey would be run.
For instance:
If I have OemTrig #1 set to port 1 and pin 10 and assign the hotkey Q (81) to that trigger, then every time the pin 10 is grounded Mach will know when that trigger has been activated, then mach can emulate that keystroke. If that is done, a user button that has a script within can be assigned to hotkey Q(81) and the script would run everytime pin 10 is grounded.

Regards
Fernando
Re: The basics of making a switch run a script?
« Reply #17 on: July 05, 2006, 01:58:35 PM »
Afer talking to Art we think it is best that you put code in your macro to see IF the macro should be run. It is very easy to add code that looks at the state of an LED and figure out if the macro should run. so lets say that your macro loads a Gcode file and runs it SO at the start of tha mcaro you should look and see if there is a job running. Here is an example:

Sub Main()

if (GetLED(4)) Then'This is where the Macro is told not to run if there is a job running
MsgBox("Could Not load there is a Job running")
Exit Sub
End if

'TODO add Macro code here

Main

This is more work but gives you more power in the end...

Ok I tried this and it said compile error syntax error. So I tried some other way, like this:

If IsMoving() then
MsgBox ("Cant do it, its moving")
else
Code "F100"
Code "G01 x10"
Code "G01 x0"
Code "G01 x10"
Code "G01 x0"
End If

And while debugging in the VB editor, it works, if the machine is moving, the cycle displays the message and ends, but when I do the actual test, it doesnt work, it sometimes displays the message, and still move, and sometimes it just moves without displaying the message.
Dont know whats going on
Regards
Fernando
Re: The basics of making a switch run a script?
« Reply #18 on: July 05, 2006, 03:05:18 PM »
I just found out another thing,

If I press the button for the oemtrig 3 times, i find that it runs the script 2 times, and when the first script finishes the message box pops up, and does not run the script the third time... Same thing happens if you press the button 5 times, it runs 2 times and 3 message boxes pop up.
So the If then else script works fine, except for the second time, more than two times and it works fine.
Regards
Fernando
Re: The basics of making a switch run a script?
« Reply #19 on: July 05, 2006, 09:23:27 PM »
Sorry i missed the End sub... It is hard to go from C++ to VB :(  I know this is not as simple as you would like but this gives you the most power...

Sub Main()

if (GetLED(4)) Then'This is where the Macro is told not to run if there is a job running
MsgBox("Could Not load there is a Job running")
Exit Sub
End if

'TODO add Macro code here
End Sub
Main
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com