Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: Davek0974 on September 11, 2016, 10:08:32 AM
-
Is there a correct or preferred way to execute a macro from a button press via an input on the CSMIO controller?
I have input 9 wired to a panel button that i want to execute auto-z reference for my mini-mill, the button needs to call M881.m1s which holds all the custom code (2010 screen-set) to do the height measuring etc.
Can't seem to find a method here?
-
I asked the same question last month and used this thread as a way forward, it pertains to useing a xbox 360 controller, I hope it helps
http://www.machsupport.com/forum/index.php/topic,32445.0.html
regards
-
Ok, that might do it, use a screen editor to assign a hotkey then configure an OEM trigger to use that hotkey?
Will try it tomorrow night.
Thanks
-
Have the code in your macropump and have it activated when it sees the input from the button.
Hood
-
All the code - it's a pretty lengthy macro routine on this screen-set??
Or just use a "RunScript.." command, if that even works, just guessing here ;)
-
Any reason this is not working???
I have a button input - input 9
In screen4 I edited a screen button and gave it a short-cut of shift-1 which it showed as code 1073
In ports and pins I have assigned OEMTrigger9 to pin 9 port 10 (csmio default port)
In System system hotkeys I have assigned OEMTrigger 9 the value of 1073
Now,
on the keyboard if i press shift-1 the screen button is activated as expected but if i press the physical button nothing happens.
Have i missed a step?
-
Hi Dave
You're confusing OEM codes with hot key codes.
-
Ah bum, so is this route a dead-end?
-
yep - 'fraid so.
AFAIK there's no "elegant" way to do what you're after.
But you have clues earlier. i.e. the macropump and runscript. (note: runscript isn't present in earlier versions of Mach3 - I can't use it for example because I use 3.42.20)
Here's one way:
put your macro code in a file.
Monitor your input in the macropump and use runscript to run your macro (as opposed to putting the code itself in the macropump). If you do this be aware of the difference between an input BEING active and an input GOING active. Otherwise you'll end up in a world of pain.
Then also put a runscript call in your button.
Then at least you have just one copy of code run from two places as opposed to two copies - one in the pump and the other in the button.
FWIW - you *should* have been able to use a trigger macro but they're flawed. I raised it with Brian a thousand years ago but he couldn't see the problem so wouldn't fix it.
-
Thanks
I did try the triggermacro thing but all it ended in doing was completely hanging Mach3, had to fall back on a backup - didn't try again.
The button has no code in it luckily - it just has the "run macro...." attribute set - i guess thats the same as an internal "runscript..."
I'll play with the macropump - seems the only way.
-
The button has no code in it luckily - it just has the "run macro...." attribute set - i guess thats the same as an internal "runscript..."
I have no idea what that means but I doubt it's what you think it means.
-
If you look at the button in screen4 etc there are 3 action options - vb button editable in mach3, run macro, oem function
It just has the macro file set and nothing else
-
Not in my version of Screen 4 - there are 4 options (which is correct because ALL editors should provide the 4 capabilities of the screen "driver" itself).
1) System Function
2) OEM Code Function
3) GCode Function
4) VB Script function edited in Mach3
If you set button option 4 and do what I said in #8 you're good to go.
-
Oops, my bad, I was not at home earlier and tried to go by memory - D'oh!
Its the "Gcode Function" set to M889
I will change to VB script and add the unscript command.
Thanks
-
It's possible to run 1 macro from a button press:
https://www.machsupport.com/forum/index.php/topic,10387.msg64292.html#msg64292
I wrote a step by step once on the Mechmate forum, but couldn't find it.
I've heard that the MachMad plugin will allow you to do more...
-
Thanks, i did try that before, all it seemed to do was to stop Mach loading - had to fall back to a backup xml, maybe only works on certain versions?
I'll try the macro pump version and see how that goes.
-
OK - I might have mis-understood what you're wanting to do.
I read it as you wanted to run a macro BOTH from an external (real) button AND from a screen button.
I'm now thinking the use of a screen button was just your way of trying it and that all you really want is to run a macro from an external button. Is that correct?
If so then forget about the screen button completely.
Just use the macropump and if you don't want to put all the code IN the macropump then call it using runScript.
A word about trigger macros.
In this post http://www.machsupport.com/forum/index.php/topic,15120.msg101160.html#msg101160 I describe a way to fire multiple macros using OEMTriggers.
However, after I wrote that I discovered an annoying bug so I would use the macropump now instead.
The bug, if you're interested, is that whilst an OEM code trigger fires immediately, the trigger macro doesn't fire if there's anything in the gcode buffer. i.e. it will fire at some time later when the buffer becomes empty. If that's ok for your usage then fine but often you want the macro to run immediately regardless and that won't work. Like I said earlier I asked Brian to fix this ages ago when Mach3 was still supported but he chose not to for whatever reason.
-
Yes thats what i need, i think the macropump idea will work perfectly, will try tonight.
-
(note: runscript isn't present in earlier versions of Mach3 - I can't use it for example because I use 3.42.20)
Would it be in this version - "Mach3Version3.043.062.exe" - is that version 043 or 062 ???
It does not run so i am guessing either i typed something wrong or this version does not support it ??
-
See bottom of page 67 in Mach3_V3.x_Macro_Prog_Ref.pdf
Your version should be fine. Time to post your code.
-
Ok, thanks
looks like the line should be RunScript("M889") but i had RunScript(M889)
will try again tonight ;)
-
Well, tried several styles of issuing a runscript command from within the macro pump and none of them worked.
The pump is running as the last attempt was...
Dim Response
If IsActive(INPUT1) Then
Response = RunScript("M889")
end if
Message "Result = " & Response
That little lot returned a value of 1, trouble is I have no idea what a result of 1 means, but it proved the pump and script is running :)
Nothing happens, no errors or any activity, if i MDI M889 it functions as expected so the target macro is fine.
Looks like runscript does not function in this version?
-
I remember trying this a long time ago and never got any joy but likely it was in the older versions that don't work.
See though that you are using a Mach Input, is there a reason for that? Personally I would use GetInBit(90,1) or whatever.
Hood
-
Thats a thought, thanks.
I'll try that way tomorrow, BUT as i said - the macro-pump does seem to be triggering its just that runscript does nothing or is not recognised?
-
As said I could never get it to work back in time but whether it was a broken version I tried with I am not sure as it was a long time ago.
I used MachMad from Scott Schaefer on the Beaver Mill and it worked well, might be worth a go for all it costs.
Hood
-
Gonna have a poke of fun with you here Dave - but it's all done in the best possible taste ;D
When you built your magnificent traction engines - did you have to follow any instructions? or did you just make it up as you went along?
runScript (as clearly stated in the manual) requires a fully qualified filename which is relative to the Mach install directory.
so... cutting to the chase - try this: (it works just fine here with your version of Mach3)
Const script As String = "M889"
'note: script does NOT have to be an M code
If isActive(INPUT1) Then
If runScript("macros\" & GetActiveProfileName() & "\" & script) < 0 Then
message "runScript failed"
End If
End If
Note that I'm assuming you put your M889 in the macros directory for your current profile. But note that a script is NOT a macro (M code) so you can put it wherever you like.
-
Poke fun all you like, most of the time i ask for it ;)
Got it, it was the qualified name bit i didn't grasp, there are no examples of it in the manual at all :(
I will insert your code tonight and have a go, no doubt it will run.
Thanks
BTW, the tractions engines - all you get is a set of dimensioned drawings, no instructions, no tips, how you make it is entirely up to you :)
-
Just one potential gotcha. You haven't said (or I missed it) what your M889 macro actually does.
How long does it take to execute?
-
It runs a z-height sense routine using G31, the usual style - fast then slow, using a touch-plate.
Probably takes 10-15s to run.
It will certainly take longer than the button-down time so multiple runs should be avoided there if that was the gotcha?
I also need to add in some code to prevent it running if the stop LED is off i.e. in run or feed-hold modes.
-
OK - for that length of time and given that you only run it when no other gcode is happening, a trigger macro would be better. The problem is that you're going to be blocking the macropump. Does it matter? well - depends if you have anything else in it and how Mach will like having it blocked.
-
No free lunch is there ;)
There is nothing else in the pump so thats one thing, whether Mach will like it well i'll just have to see i guess :)
Definitely one of the weaker points of Mach3 though I think.
-
up to you - but I'd use a trigger - made for the job.
-
Is the thing with adding a macro to the INIT line, the macro has SetTriggerMacro(*********x) in it etc?
I did try that once before but it hung Mach so i thought it best not to pursue it ;)
-
OK, I dug this info up:
In Config >Hotkeys, set OEM Trigger #1 to 301
Create a macro named M1919.m1s and save it in MAch3\macros\yourprofile\
The contents of M1919 should be:
SetTriggerMacro(889)
In General Config, add M1919 to the Initialization String.
Setup up your button in ports and pins, Input pins, assigned to OEMTrigger #1.
Simple, huh?
Here's how this works.
The initialization string calls M1919, which tells Mach3 to assign M889 as the Trigger Macro. The 301 in Config Hotkeys tells Mach3 to run the macro assigned with SetTriggerMacro when the OEMTrigger is activated (your button).
-
Thanks Gerry, Stirling,
Yes that was what i tried before but after adding the macro to the INIT line, mach would not start again, I had to revert to a backup to get going again then aborted trying to get this working that way, I will try again tonight.
Another oddity, after messing with editing the macropump macro, Mach seems to get a bit pissed and does odd things like starting up code with no M3 so no spindle, MDI and M3 and you get the script compiler error message, restart Mach and its happy again. Done this a few times now - is it a bad idea to edit the macro pump file while Mach is running?
-
You must have had an error in your macro that you called from the init string.
When I wrote the above info two years ago, it worked.
-
If you suspect issues with the init string macro, then the simple way to TRY it is just to set your ports and pins for trigger1 and then set 301 as the OEM code in hotkeys. Then just do the setOEMTrigger 889 in the CB editor. At that point you can test your trigger.
The only reason for putting the trigger config macro in the init string is so that it's set each time you start Mach.
If that works THEN do the init string macro.
re: editing the macropump macro: There should be no issue because the macropump macro is compiled (as opposed to "regular" macros/scripts which are interpreted). The compilation is done when you start Mach so the edited version means nothing until you re-start Mach. i.e. there's no issue with you over writing it as it's running if that's what you're wondering.
You must have had an error in your macro that you called from the init string.
When I wrote the above info two years ago, it worked.
Absolutely agree. It works here now and it worked when I wrote this 6 years ago. :P
http://www.machsupport.com/forum/index.php/topic,15120.msg101160.html#msg101160
-
All sorted, and it works :)
Must have been an error last time, i've turned off the macropump as there was nothing else in the macro, trigger works nicely.
Thanks all for the assistance.
-
Hey guys, im sorta after the same thing here, i have a pnumatic clamp that i lock with m20 and unlock with m21, i need to activated this with a hardware momentary button that does the opposite to the current state, so if m20 is active pressing the button will toggle it to m21 and visa versa, any help would be appreciated.
-
you have to create a "Memory" to know the Output is on or off.
for example:
add to M20:
SetUserLed(1800,1)
add to M21:
SetUserLed(1800,0)
and the button script:
If GetUserLed(1800)=1 Then
SetUserLed(1800,0)
DeActivateSignal(your clamp Output)
Else
SetUserLed(1800,1)
ActivateSignal(your clamp Output)
End If
not tested, just written down.
-
thanks mate, ll give this a try tomorrow and report back.
-
OK, I dug this info up:
In Config >Hotkeys, set OEM Trigger #1 to 301
Create a macro named M1919.m1s and save it in MAch3\macros\yourprofile\
The contents of M1919 should be:
SetTriggerMacro(889)
In General Config, add M1919 to the Initialization String.
Setup up your button in ports and pins, Input pins, assigned to OEMTrigger #1.
Simple, huh?
Here's how this works.
The initialization string calls M1919, which tells Mach3 to assign M889 as the Trigger Macro. The 301 in Config Hotkeys tells Mach3 to run the macro assigned with SetTriggerMacro when the OEMTrigger is activated (your button).
Big thanks to you! This is very important information, I have been looking for it for a long time.