Hello Guest it is April 23, 2021, 05:32:50 AM

Author Topic: Macro pauses my program  (Read 556 times)

0 Members and 1 Guest are viewing this topic.

Macro pauses my program
« on: November 29, 2020, 01:21:42 PM »
So i made a macro that will turn on an air solenoid for blowing the part off as I machine aluminum on my cnc mill powered by mach 3. The macro (when called) simply turns on the electric solenoid , "sleeps for 1 sec " then deactivated. It works great.

If I'm cutting a pocket and after a pass or two I insert the m code to clear the part of chips, my machine will pause while it reads the m code causing the cutter to dwell for that time. Is it possible to read the m code and and continue on with the program while the macro does it's thing in the background?

Offline TPS

*
  •  2,113 2,113
    • View Profile
Re: Macro pauses my program
« Reply #1 on: November 30, 2020, 02:17:20 AM »
simple answer: no

every macro call will Interrupt continious movement. so only Chance is to to call the teh macro
when your bit it not cutting material.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Macro pauses my program
« Reply #2 on: November 30, 2020, 07:19:43 PM »
Is there a way to loop a macro?
If possible I'll have the macro activate the output, sleep for a second then deactivate the output, sleep for like 10 seconds then repeat . Is something like that possible? This way I'll activate it prior to the first cut and it will blast air at the part periotically until the end of the program when I can simply call another macro to deactivate it.

Offline TPS

*
  •  2,113 2,113
    • View Profile
Re: Macro pauses my program
« Reply #3 on: December 01, 2020, 02:03:28 AM »
you can use macropump macro to do this.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Macro pauses my program
« Reply #4 on: December 02, 2020, 09:04:14 AM »
Thank you! I got the code to read alot quicker by inserting a g0 or g1 on the next line instead of just the next axis move.

I still want to use the macro pump to control the air every so many seconds but only for certain programs. If I'm cutting a large circle groove using a g3 code then I can only use my macro before or after the groove and not periotically during.

Is this possible? Can I make a macro pump that looks for an active signal on an output and only of it sees it will turn on another output (which would be the relay for air) sleep for a second then deactivate and repeat like the macro pump should. This what I'll create another macro code that will simply turn on the output that themacropump is waiting to go active.

Is that doable or am I really overthinking this

Offline TPS

*
  •  2,113 2,113
    • View Profile
Re: Macro pauses my program
« Reply #5 on: December 02, 2020, 09:34:08 AM »
code for macropump would be something like this:
Code: [Select]

'------------------------------------------------------------------------------------------------------------
Private Declare Function GetTickCount Lib "kernel32" () As Long
'------------------------------------------------------------------------------------------------------------

Const LastMsDRO = 1300 'DRO for data
Dim CurrentMs As Long
Dim LastMs As Long
'------------------------------------------------------------------------------------------------------------

Const BlowTime = 1000  'Blowing Time


Sub Main

'Read data
'-------------------------------------------------------
CurrentMs = GetTickCount()
LastMs = GetUserDRO(LastMsDRO)

If(CurrentMs < LastMs) Then
LastMs = CurrentMs
End If

'check OEMLED to activate
If GetUserLed(1300) = True Then
SetUserLed(1300,0)
ActivateSignal(OUTPUT2)
LastMs = CurrentMs
End If

If(CurrentMs > (LastMs + BlowTime)) Then
DeactivateSignal(OUTPUT2)
End If

'save Data
'-------------------------------------------------------
SetUserDRO(LastMsDRO, LastMs)

End Sub

code for activation macro would be this:
Code: [Select]
SetUserLed(1300,1)
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Macro pauses my program
« Reply #6 on: December 02, 2020, 06:13:20 PM »
Thank you for making that macro. No matter how much I study the tutorial on macros I just can't grasp it .  I copied your code exactly and made it the macropump file. The only thing I changed was the output is 14 . I also copied your other code and made it m115 macro.

Use macro pump is checked and I tried calling up m115 in mdi but nothing happens. What am I missing?

I know the output is working fine because the macro I used to turn it on temporarily still works.

Any suggestions? Thank you in advance

Offline TPS

*
  •  2,113 2,113
    • View Profile
Re: Macro pauses my program
« Reply #7 on: December 03, 2020, 02:09:35 AM »
sorry there was a small mistake in the code.

Code: [Select]

'------------------------------------------------------------------------------------------------------------
Private Declare Function GetTickCount Lib "kernel32" () As Long
'------------------------------------------------------------------------------------------------------------

Const LastMsDRO = 1300 'DRO for data
Dim CurrentMs As Long
Dim LastMs As Long
'------------------------------------------------------------------------------------------------------------

Const BlowTime = 1000  'Blowing Time


Sub Main

'Read data
'-------------------------------------------------------
CurrentMs = GetTickCount()
LastMs = GetUserDRO(LastMsDRO)

If(CurrentMs < LastMs) Then
LastMs = CurrentMs
End If

'check OEMLED to activate
If GetUserLed(1300) = 1 Then
SetUserLed(1300,0)
ActivateSignal(OUTPUT2)
LastMs = CurrentMs
End If

If(CurrentMs > (LastMs + BlowTime)) Then
DeactivateSignal(OUTPUT2)
End If

'save Data
'-------------------------------------------------------
SetUserDRO(LastMsDRO, LastMs)

End Sub


anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Macro pauses my program
« Reply #8 on: December 04, 2020, 06:08:56 AM »
Thank You! It's getting much closer. Now when I turn on mach 3 I can type in my m115 macro and it will trigger the macro pump causing the air valve to open for a second then closing however it doesn't repeat after that. Did I install something incorrect? If I can getit to kick on for a second then deactivate for about 5 seconds then repeat it would absolutely perfect ! Thank you in advance for your help

Offline TPS

*
  •  2,113 2,113
    • View Profile
Re: Macro pauses my program
« Reply #9 on: December 05, 2020, 04:08:52 AM »
code for macropump:
Code: [Select]

'------------------------------------------------------------------------------------------------------------
Private Declare Function GetTickCount Lib "kernel32" () As Long
'------------------------------------------------------------------------------------------------------------

Const LastMsDRO = 1300 'DRO for data
Const StateDro = 1301 'DRO for data
Dim CurrentMs As Long
Dim LastMs As Long
Dim State As Long
'------------------------------------------------------------------------------------------------------------

Const BlowTime = 1000  'Blowing Time
Const PauseTime = 5000  'Pausing Time

Sub Main


'Read data
'-------------------------------------------------------
CurrentMs = GetTickCount()
LastMs = GetUserDRO(LastMsDRO)
State = GetUserDRO(StateDRO)

If(CurrentMs < LastMs) Then
LastMs = CurrentMs
End If

If ((State < 0) Or (State > 2)) Then
State = 0
End If

'check OEMLED to activate
If ((GetUserLed(1300) = 1) And (State = 0)) Then
ActivateSignal(OUTPUT2)
LastMs = CurrentMs
State = 1
End If

If ((CurrentMs > (LastMs + BlowTime)) And (State = 1)) Then
DeactivateSignal(OUTPUT2)
LastMs = CurrentMs
State = 2
End If

If ((CurrentMs > (LastMs + PauseTime)) And (State = 2)) Then
State = 0
End If

'save Data
'-------------------------------------------------------
SetUserDRO(LastMsDRO, LastMs)
SetUserDRO(StateDRO, State)


End Sub

code to activate:
Code: [Select]
  SetUserLed(1300,1)

code to deactivate:
Code: [Select]
  SetUserLed(1300,0)

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