Hello Guest it is June 18, 2019, 01:54:37 AM

Author Topic: Can macro scrip run parallel with execution of G code ???  (Read 1327 times)

0 Members and 1 Guest are viewing this topic.

Can macro scrip run parallel with execution of G code ???
« on: June 07, 2016, 07:16:10 AM »
Hi folks, I was thinking how to ask this question,  as English is not my mother language , maybe like in subject of topic.

I made macro that is being triggered after RESET button is presses and it runs all the time , have while 1 (loop) and it serves me to count how many impulses z axis balscrew manage to make in order to know when to activate oil pump (every 20 meters need to be turned on for 8 seconds).
So while I am in manual mode macro runs pretty good, it counts impulses, but before few days I discovered while I spent quite amount of time in auto mode running g code, I went to check how many pulses macro/scrip did count, and after some time I realized that number of pulses did not changed from time when I was in manual mode.

So I concluded when I came in auto mode and pressed Cycle start, macro is being stopped, I did not know that will happen, I thought that macro will continue to work . So my observations that when you enter in auto mode all macros are being stopped and you are prepared for execution of g code. Got idea to try to activate macro when  spindle starts, so I went and rearrange brain that controls triggering of macro to be triggered when spindle is started and after when RESET is  pressed. My machine started to move and when it came to part of g code where spindle is turned on movement stops and time is running on in auto mode.

So I came to conclusion that I can not have situation that Mach3 executes g code parallel while my macro for controlling oil pump works also.

Maybe it looks like I confirmed how Mach3 works but I would love to confirm did I conclude good or I am not aware of all possibilities.

Before I made macro, I had plan to use Siemens LOGO PLC for counting impulses but discovered inputs are to slow, so instead to  buy PLC with fast inputs I decide to make it over Mach3 but now as it seams I will need to buy PLC with fast inputs .

Hope someone can clarify me am I concluded good how Mach3 works.

Here is macro for oil pump, I had topic where I described how I all made but if that macro can not work parallel while g code is running then all was for nothing  ;D

Sub main ()  ' logic for auto oil pump

Dim oldp,newp,n,error_m As Integer
Dim Msg

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=4000 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                        
    
Re: Can macro scrip run parallel with execution of G code ???
« Reply #1 on: June 07, 2016, 10:37:43 AM »
here is video about my testing
https://www.youtube.com/watch?v=qiXE-lEhwfE

if someone have something to say about this please let me know