Hello Guest it is April 23, 2024, 11:17:56 PM

Author Topic: M6ATC Macro Help  (Read 3253 times)

0 Members and 1 Guest are viewing this topic.

M6ATC Macro Help
« on: November 18, 2015, 11:16:05 PM »
Here is the script for a tool change macro on a lathe with a rear mounted spindle "B axis"  and the actual ATC unit is controlled from a PLC communicating through modbus Serial plugin and brains logic.
The trouble I'm having is that Mach3 needs to wait for the PLC to send that the tool change is complete and the input/bit is true. I have seen where other people have used SystemWaitFor() but I don't know how to get the syntax right.
I was using G4 P4 but when the rapids were slowed down the tool changer would start before it was at the tool change location.





Sub main()        
              
        Const maxtoolnum = 4
     Dim newtoolNumber As Integer
     Dim oldtoolNumber As Integer
     Dim NewtoolDro As Integer
     Dim XTCpos As Double
   Dim ZTCpos As Double
     Dim BTCpos As Double
        Dim Input3 As Integer
  
     XTCpos = GetoemDRO (1817)
   ZTCpos = GetOemDRO (1819)
   BTCpos = GetOemDRO (2017)
   newtoolnumber = (getselectedtool)
   setOemdro(2000,newtoolnumber)
 
  
  
  If newtoolNumber > maxtoolnum Then
     MsgBox  "Tool number Range is 1-4 Check tool number "
    
     Exit Sub
     main
   End If     
       Code "G53 G90 G40 G00 B" & BTCpos
       Code "g53 g90 G40 G00 X" & XTCpos  
       Code "G53 G90 G40 G00 Z" & ZTCpos
      
      
       While ISmoving()
       Sleep 50
      
      
       Wend
      
      
      
      
      
      
        SystemWaitFor(input3)
      
      End Sub        
        
        
        
  'MsgBox ("newtool = " & GetSelectedTool)
 'MsgBox ("oldtool = " & oldtool )
  'MsgBox ("dro 2000 = " & getoemdro (2000) )
  
  
  Exit Sub

                              
Adam
Re: M6ATC Macro Help
« Reply #1 on: November 24, 2015, 03:37:24 PM »
What about a simple :
While IsActive() = True/False
Pause 250
Wend

So using the IsActive() in a loop, instead of SystemWaitFor()

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: M6ATC Macro Help
« Reply #2 on: November 24, 2015, 07:05:13 PM »
How exactly is the PLC notify Mach3 ?  Is it activating Input3 ?? DO you see the LED activate on the diagnostic page ??  You will also need an escape plan for IF the loop gets stuck in an endless loop. I use a timed loop that will end at a specifc point to allow you to escape the loop and stop the program CLEANLY.

(;-) TP
Re: M6ATC Macro Help
« Reply #3 on: December 07, 2015, 08:55:31 PM »
How exactly is the PLC notify Mach3 ?  Is it activating Input3 ?? DO you see the LED activate on the diagnostic page ??  You will also need an escape plan for IF the loop gets stuck in an endless loop. I use a timed loop that will end at a specifc point to allow you to escape the loop and stop the program CLEANLY.

(;-) TP
Right now the PLC is communicating through modbus and Brains but there is no reason why I cant use a physical input. I'm using smooth stepper with the third port expiation card
so the IsActive(4) will wait for the the input signal 9 to go true then continue running the script.
   
Adam