Hello Guest it is July 14, 2020, 07:54:03 PM

Author Topic: Run a macro from a button press??  (Read 9289 times)

0 Members and 1 Guest are viewing this topic.

Offline Davek0974

*
  •  2,597 2,597
    • View Profile
    • DD Metal Products Ltd
Re: Run a macro from a button press??
« Reply #30 on: September 29, 2016, 07:31:45 AM »
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.
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Run a macro from a button press??
« Reply #31 on: September 29, 2016, 08:04:45 AM »
up to you - but I'd use a trigger - made for the job.

Offline Davek0974

*
  •  2,597 2,597
    • View Profile
    • DD Metal Products Ltd
Re: Run a macro from a button press??
« Reply #32 on: September 29, 2016, 09:39:32 AM »
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 ;)
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline ger21

*
  • *
  •  6,282 6,282
    • View Profile
    • The CNC Woodworker
Re: Run a macro from a button press??
« Reply #33 on: September 29, 2016, 10:31:24 AM »
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).
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline Davek0974

*
  •  2,597 2,597
    • View Profile
    • DD Metal Products Ltd
Re: Run a macro from a button press??
« Reply #34 on: September 29, 2016, 10:39:44 AM »
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?
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline ger21

*
  • *
  •  6,282 6,282
    • View Profile
    • The CNC Woodworker
Re: Run a macro from a button press??
« Reply #35 on: September 29, 2016, 10:53:37 AM »
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.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Run a macro from a button press??
« Reply #36 on: September 29, 2016, 11:09:04 AM »
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

Offline Davek0974

*
  •  2,597 2,597
    • View Profile
    • DD Metal Products Ltd
Re: Run a macro from a button press??
« Reply #37 on: September 29, 2016, 01:52:59 PM »
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.
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.
Re: Run a macro from a button press??
« Reply #38 on: August 25, 2018, 04:02:56 PM »
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.

Offline TPS

*
  •  1,615 1,615
    • View Profile
Re: Run a macro from a button press??
« Reply #39 on: August 26, 2018, 04:08:54 AM »
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.

anything is possible, just try it.
if you find some mistakes, in my bad bavarian english,they are yours.