Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: Cncman2nv 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
-
What about a simple :
While IsActive() = True/False
Pause 250
Wend
So using the IsActive() in a loop, instead of SystemWaitFor()
-
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
-
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.