Ok the macropump is basically a macro that is constantly running in the background and can be used for things like this.
First thing to do is go to Config Menu then General Config and choose Run Macro Pump.
Next go to Operator menu and Choose Edit VB Scripts, open the macropump.m1s.
Enter your code and save, making sure it is in the correct folder, it has to be in the profile folder that you are using which is in the macro folder., for example C:\Mach3\macros\Mach3Turn
For your examples above the code in the macropump would be
If IsActive(OemTrig1) Then
ActivateSignal(OutPut5)
End If
If IsActive(OemTrig2) Then
DeActivateSignal(OutPut5)
End If
Now the important thing.
EVERY time you alter code in the MacroPump you MUST restart Mach as it loads only when Mach starts, so if you do not restart your previous code will still be loaded and thus you won't see any difference.
Hood
Hi again, thx for you answer, I learned all that few hours before you wrote it but it is good to have that information in one place for future readers.
Need to add that I discovered today that best place to put SetTriggerMacro(*********) command is in macropump, I wrote that my example works as it is but that is not 100% true , it works sometimes and sometimes not, when I cut and paste SetTriggerMacro(*********) to macro pump it works every time (but only in case one OEMTrigger#(input) triggers one macro), I experiment with already made macros that I activated over buttons on screen so because of that it sometimes worked and sometimes not.
Just wanted to document that if you want to use SetTriggerMacro, do what it say in manual and put SetTriggerMacro in macropump, so for my example:
in macro m301.ms
it needs to be only this content:
'part catcher
ActivateSignal(Output5)
and
in macropump (which is macro like Hood described) need to be
SetTriggerMacro(301)
it is coincidence that my macro have number 301 same as code that need to be set for OEMTrig#1 in System Hotkeys Setup.
Hood, your code is OK and new thing that I learned from it is how to write IsActive(OemTrig2) , I tired lot of combinations so at the end I did not know is my syntax bad or I just can not check is OemTrig2 active in same way as I check is some Input active for example
IsActive(Input1)
So I did not tested your example but will .
Anyway I am trying to find out how to with OEM Trig1 and OEMTrig2 activate 2 different macros (I know it can all be in one macro but I want 2 macros because I have different macros that want to execute with different OEMTrig(Inputs 1 to 15).
So as I learned how to use macropump, I copy pasted code for operating power chuck in macropump so one problem solved and second macro for operating tailstock can be used with OEMTrig1 to activate macro that contains logic for operating tailstock.
So in conclusion, I solved problem (controlling power chuck and tail stock over physical buttons but not as I planed , 2 OEMTriggerInputs and 2 different macros), but it would be good to know is it possible to do that as I described , so maybe someone who see this have some idea or know how how to execute that , but if not OK, I will use it as I did.
New problem that I have is connected with problem of activation pump for lubrication bedways, in manual it say activate pump after 20 m of travel on period of 8 second.
I successfully made macro to do that, originally on z axis is mounted inductive sensor that sense every rotation of timing pulley and when I take in count that ballscrew have pitch 5 mm it is easy to calculate that need to active pump after 4000 pulses.
I made macro and connected it with button in mach3 screen (I named button Auto Lube) and in macro impulses are counted and saved in file named oilpump.txt, when 4000 impulses is counted output activates for 8 seconds and counter of impulses resets on zero , that is basically what macro does , in reality it have little more stuffs but pretty much that is idea.
Now problem is when I press RESET from some reason in Mach3, or some trigger is activated (soft limits or something third) my macro is rest also, so I need manually to press button on screen that activates macro , probably more experience users will say that is textbook example to use macropump,
. Well thing is that I tried to use it inside macropump but from some reason when code that works perfectly fine when it is activated over screen button, in macropump does not count existing pulses or in other word it counts too slow , I do not know how is that possible but it is (I was experimenting all day and it simply does not work good).
My friend told me that it is probably possible to set Mach3 to count step signals (good idea), I surfed on net but did not managed to find something that will help me.
So I wonder is it possible to use some function that will return step numbers or something similar or if somebody have some idea how to make my macro for controlling oil pump to work automatically after reset is acknowledge , macropump according to my test will not work, will copy past macro for oil pump which works good when it is activated ove button on Mach3 screen.
I removed while loop , sub main part when it is used in macropump, even tried to eliminate other parts but it simply does not want to count correct.
In case of no ideas I can use it as it works and will delete initialization part that sets initial set when file is opened for first time to zero and will activate it every time manually after RESET is triggered.
Hope you can follow what I write
Sub main ()
Dim oldp,newp,n,error_m As Integer
Dim Msg
oldp=0 ' when I press Autolube button on Mach3 screen counter will be set on 0
Open "C:\Mach3\oilpump.txt" For Output As #1
Print #1,oldp
Close #1
While 1
If Not IsActive(Index) Then
n=0
Else
n=1
End If
Sleep 10 ' sample input f = 100Hz
If IsActive(Index) And n=0 Then ' before 10 ms Index was zero , count only rising edges
Open "C:\Mach3\oilpump.txt" For Input As #2
Line Input #2, oldp
newp=oldp+1
Close #2
If newp=10 Then ' for testing purposes newp is 10 in reality it needs to be 4000 for 20 m of travel with 5 mm pitch ballscrew
ActivateSignal(Output8) 'oil pump is on output 8
error_m=1
Sleep 1000 'turn on pump for period of 8 seconds , 8 x 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
Sleep 1000
If IsActive (Timing) Then
error_m=0
End If
DeActivateSignal(Output8)
newp=0
If error_m=1 Then
Msg = "Oil pump error --> check oil level "
MsgBox Msg
Else
Msg = "Lubrication was sucessful after 20 m of travel "
MsgBox Msg
End If
End If
Open "C:\Mach3\oilpump.txt" For Output As #1
Print #1,newp
Close #1
End If
Wend
End Sub
P.S:
I am using Index and Timing inputs (Index is input that counts pulses from z axis and Timing is input on which is connected pressure switch from oil pump, I do not use parallel port , I am using CSMIO/IP-S motion controller so it works like this, I do not know is it bad idea or not, but what can you do when you have only 4 Inputs)