Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: zmajmr on April 07, 2016, 09:33:02 AM

Title: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 07, 2016, 09:33:02 AM
Hi folks.

So I want when I activate physical switch to macro be triggered/activated also, I know how to do it for one OEM Trigger Input, but when I use 2 diffrent OEM Trigger Inputs and when each input need to activate its own macro problems start.

So I embedded in existing macros that I used over Screens  this command ----->  from example that I found in manual

Example:
‘ Assume OEMTRIGGER5 is assigned to OEM code 301
‘ Assign the M1025 macro to OEM Code 301
SetTriggerMacro(1025)
‘ Now, when OEMTRIGGER5 is driven to its active level,
M1025.m1s will be executed

Also read on forum for specific requests how to use brains, macro pumps (never used anything of that , but have feeling I will...)

So is there any solution or procedure what I need to activate,write to be able to use different OEMTrigger inputs (I read thate exist 15) to activate diffrent macros, I found posts from 2009 , I do not know is anything new since then...

So picture is worth 1000 words, I want to control over foot control (just for example) opening and closing part catcher, for that I use two inputs and two macros, it only works situation one input one macro (other input do job of first input what is wrong/duplicate, so I concluded that I need to know something more...)

(http://i63.tinypic.com/1zpgrdk.jpg)

Any help appreciated :)
 
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: Cbyrdtopper on April 07, 2016, 04:03:45 PM
I have tried to use the OEMtrigger to Macro Call before with no real success, not sure what it was, anyways, what I was trying to do was change the feedrate depending on which direction I had a switch.  In the macro I started out with an "IF" statement, if input 1 then ---> Code --> end if        if input 2 then ---> Code ---> end if.  From your pictures you may have to add an led to the screen to compare the two options.  But that would be simple enough.  Just a thought.
-Chad
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 07, 2016, 04:49:25 PM
I have tried to use the OEMtrigger to Macro Call before with no real success, not sure what it was, anyways, what I was trying to do was change the feedrate depending on which direction I had a switch.  In the macro I started out with an "IF" statement, if input 1 then ---> Code --> end if        if input 2 then ---> Code ---> end if.  From your pictures you may have to add an led to the screen to compare the two options.  But that would be simple enough.  Just a thought.
-Chad
Hi

Picture is just so I can easier explain what I did and what I want to do.

So when I press/activate mechanical switch which is connected to OEMTrig#1 I want for example to execute m301.m1s macro and when I press other switch that is connected to OEMTrig#2 I want to execute m302.m1s macro. So I do not want to press anything on screen in order to activate macro, because of that I am using OEMTrig#_ _ inputs (1 to 15).

This what you see on picture works only in case: choose one of 15 OEMTrigg# (inputs) and activate only one macro.
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: Hood on April 07, 2016, 05:06:18 PM
Above I see m301.m1s and m302.m1s and all you seem to be doing is activating and deactivating OutPut 5, is that all you want to do?

If there is more to it can you put up examples of the macros?


Hood
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 07, 2016, 05:43:46 PM
Above I see m301.m1s and m302.m1s and all you seem to be doing is activating and deactivating OutPut 5, is that all you want to do?

If there is more to it can you put up examples of the macros?


Hood

Hi Hood, yes I want to learn how to do that over OEMTrig inputs because when I learn how to do that I will apply that knowledge to control power chuck and tail stock over foot control(2 pedals connected on push switches, so with one pedal will need to open and close power chuck and with other pedal move tail stock in or out). I wanted to start with something simple that I can control easy (those macros are little complicated then this example).

Like I said in first post I got feeling that will need to learn what is macropump, and I did, that was easy, thing is that in Mach3 Turn I have only 4 inputs so need to save them so because of that I want to use OEM Trigger for those things where I do not need to press anything on screen.

I manage to put macro for power chuck in macropump so for tailstock I can use OEMTrig#1 that calls one macro, but it would be better If I know how to control power chuck also over another OEMTrig input.

Have question, is it possible to use OEMTRig in macros like this If IsActive(OEMTrig1)Then or is IsActive reserved for Inputs (1 to 4), I got script error , I am not sure is it possible to use or I do not write OEMTrig1 good (OEMTrigger1, OEMTRIGGER#1.... or how else?)
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: Hood on April 07, 2016, 06:24:17 PM
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
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 08, 2016, 12:04:18 PM
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)  :)
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: Hood on April 08, 2016, 01:01:06 PM
If you are using the CSMIO then you would be a lot better off using the built in modbus for its I/O.
It can be used via Macropump or Brains and doesn't require messing with OEMTriggers or setting up port and pin numbers in Mach, it also means you are not limited by the amount of Inputs in Mach.

I think CS-Lab have a macro for an oiler on their website.
Hood
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 08, 2016, 01:21:32 PM
If you are using the CSMIO then you would be a lot better off using the built in modbus for its I/O.
It can be used via Macropump or Brains and doesn't require messing with OEMTriggers or setting up port and pin numbers in Mach, it also means you are not limited by the amount of Inputs in Mach.

I think CS-Lab have a macro for an oiler on their website.
Hood

Well that is new information for me, I thought I have only 4 inputs (not sure what that means but I can tell that I needed to set which pin and port is used in input setup).

Yes they have macro for oil pump but it is based on time, it activates output every x minutes (you choose x by yourself) , I want to make lubrication according to manual of my machine and it say every 20 meters of travel.

I am messing with OEMTrigger(inputs) because I do not know how to trigger macros with out touching screen buttons in Mach3.

I was wondering all the time why I have so much inputs on CSMIO and I have only 4 inputs in mach3 turn.

So biggest problem for now is oil pump macro, like I said in macropump it just does not counts impulse correct (it manage to count every 10 impulses) and over macro triggered buy button it counts correct but RESET is party breaker :).
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: Hood on April 08, 2016, 01:25:49 PM
Here is info on using CSMIO I/O
http://www.cs-lab.eu/en/upload/fotki/Elementy,%20banery/CSMIO-IP-A%20artykuł.jpg

I think there are also examples in the I/O modules manual.

There is stored info in Mach for axis distances but I am not sure if you can get that info from VB or not, you can view it from Operator Menu then Maintenance Hours.
Best bet would be to email Mach Support and see if there are any OEM codes for these DROs.
Hood
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: Hood on April 08, 2016, 01:27:51 PM
Sorry that link was for the CSMIO/IP-A and I am not sure which one you have, I presume IP-S or IP-M as you mention steps.
You will find the info for all here
http://www.cs-lab.eu/en/artykul-128-Digital_and_analog_IOs__configuration__its_easy.html

Hood
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 08, 2016, 01:37:54 PM
Sorry that link was for the CSMIO/IP-A and I am not sure which one you have, I presume IP-S or IP-M as you mention steps.
You will find the info for all here
http://www.cs-lab.eu/en/artykul-128-Digital_and_analog_IOs__configuration__its_easy.html

Hood

No problems, I have CSMIO/IP-S, need to read that , probably did not paid much attention.

Thx for help.
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on April 10, 2016, 07:22:52 AM
Here is update, manage to solve problem of oilpump to work automatically , by myself (that is important, just kidding).

Here is in video what I did

https://youtu.be/G*********qxjDDw?t=2s

So to recapitulate what all I tried before I came to this solution.

First I made macro that controls oil pump and it is activated/triggered over button that I add in mach3 screen by program machscreen editor (it is free), and in my case I connected input that counts impulses on input Index and pressure switch from oil pump (that serves for detection is there any oil and is pump in working condition ) on Timing input, as I  use CSMIO/IP-S as I concluded I can treat those inputs(Index and Timing ) as regular inputs (Input 1 to 4) and I used them because I I thought I have only those 4 inputs.

So macro for for controlling oil pump works correct when is executed over button (I named it Auto lube) and everything work OK until E-stop is activated , I made macro for oil pump to save how many impulses is counted in file named oilpump.txt so I can have exact number of counted impulses even if I close Mach3 and open it again (for that I need to delete from code part that initializes counter of impulses on zero every time I press Auto Lube button).

So next I thought that problem that I have by stopping macro by Estop can be easily solved by inserting code in macropump (like Hood said it is macro but it executes cyclic after you turn on mach3, you do not need to press any buttons or switches , you just need to adjust in general config that you want to use it, just check box where it say macropump and that is it, escape mach3 and come back and it should work, and inside of macropump you can put what ever you want that need  checks to be executed cyclic (from my experience, I put inside logic that checks do I want to open or close power chuck, and now will need to put same logic for tailstock, and most important thing that I discovered you need to put inside of macropump SetOEMTrigger(*********) function).

So as I wanted to cyclic run code that will count impulses in order to control oil pump I put code inside of macropump, and I thought, OK it will work same as in macro triggered by button (Auto lube), but it does not work , why, probably because of code that is necessary for macro for counting impulses, it needs to detect is it rising edge present (otherwise if sensor is active , macro will count presence  of sensor same as timing pulley made one revolution which is not good , because of that it needs to count changes not presence  , and other thing is that data is saved in file (and file needs to be open and closed), anyway probably that goes from some reason slow in macropump and because of that it misses to count impulses (it counts but not accurate).

And only solution till now that I can use is to use code over macro triggered by Auto lube button, but in that way macro counts correct but it is stopped when Estop is activated, I have nothing against   stopping because I will not get wrong data but I need to manually press activate pump and I can easily forget to press button, so after reading forums I discovered that there exist brains in mach3, only problem I never used them and have no clue what that should be, it sounds complicated "brain" haha. It is similar to ladder diagram for programing PLC, so you can activate output by input and you can between insert some logic and as I read they are faster then macros.

So I had simple idea, when Estop is acknowledged (I need to press RESET) if I want to start macro for oilpump (I named it m555.m1s) , so if Estop is triggered I must press RESET if I want to continue to work, I can not forget to press it.

And after experimenting with bits that I tested before (some OEM cods) I gradually came to solution to choose brain and make some logic, I guess.

So when Estop (LED with code 800) is not turned on , it needs to activate OEMTrigger1 which triggers macro (m555.m1s), Estop and OEMTrigger1 are connected over (no operation inverted), and as I described in macropump needs to be SetOEMTrigger(555) .

How that works, macropump is cyclic running and inside of it is SetOEMTrigger(555) and it waits for OEMTrigger1 to be activated (in  System HotKeys Setup under Triggerer#1 is selected code 301, and that means when OEM Trigger#1 input is activated it will trigger my macro m555.m1s , and that will happen when I press on button RESET (for that need to be no operation inverted).

Hope you can follow idea and what I did, in that way I do not need to worry about oil pump at all because it will automatically be under control of macro555 (it is script because I do not made button for it, script/macro all the same to me) and information about how many impulses is counted is in file oilpump.txt, I just need to worry is there enough oil in reservoir :)

I do not know why link for video is wrongly showed *******, I did not wrote those symbols

If you are interested in video try to copy paste this in youtube search :

Macropump Macro Mach3 Brain OEMTrigger
Title: Re: How to activate more then one macro with diffrent OEM Trigger Inputs ????
Post by: zmajmr on May 06, 2016, 01:13:43 PM
Here is info on using CSMIO I/O
http://www.cs-lab.eu/en/upload/fotki/Elementy,%20banery/CSMIO-IP-A%20artykuł.jpg

I think there are also examples in the I/O modules manual.

There is stored info in Mach for axis distances but I am not sure if you can get that info from VB or not, you can view it from Operator Menu then Maintenance Hours.
Best bet would be to email Mach Support and see if there are any OEM codes for these DROs.
Hood

Funny update, got this from support before day ago :), I guess this what I did is best that can be done , I do not know...

"Hello Marko, take a look at this thread in our support forum, this user was able to achive what you are look to do and has posted their work there, best regards Jim.

https://www.machsupport.com/forum/index.php/topic,32293.msg224740.html#msg224740


James Dingus Jr.
Tech support staff
To learn the answers to our most Frequently Asked Questions please visit our FAQs page at http://www.machsupport.com/help-learning/f-a-q/