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
Hi,
I'm not sure how much help I can be on this one as I've not personally used SystemWaitFor().
1) I had to go look it up in the mach Programmer manual - while doing that, I noticed it said:
"This function it is used to tell Mach that a macro script is ending, and that "any further
GCode execution should wait for the Signal to go active. If used, this function should
always be the last line in a macro and it should never be used within a loop. "
I'd guess that mach does not like the way you are attempting to use the call in a subroutine instead of the call being the last line of the script.
2) If running this code with MSM, you'll also want to change the DRO range to get out of the 1800's - MSM uses 1700-1899 internally so you could be experiencing DRO conflicts. (See MSM user manual section 14 for MSM resource list).
3) I also suggest that you don't want to be using GetOEMDRO for those DRO numbers and that you want to use GetUserDRO instead. Get OEM DRO says it should only be used for OEM DRO numbers.
According to the mach programmer manual, User DROs range from 1000-2254 and OEM DROs are < 1000.
I know it may be working with mismatched calls vs DRO # ranges, but it's probably better to adhere to the programmer manual - one less possible source of surprises when the script runs.
I'm in the process of needing to make some changes to my M6ATC macro. the changes that are needed are when the G-code program calls for a new tool my automatic tool changer once in a while skips the tool change and the tool no longer matches the programmed tool. I need the macro to trigger the reset to keep the tool change from completing or the machine from continuing with the wrong tool.
Below are some of my attempted edits. It works but Mach's reset button is always triggered even when the tool changer changed tools correctly
**********I make no clime to have any knowledge about VB scripting or syntax so please accept my apologies before reading on.**********
Option Explicit
'********DO NOT remove or change the expand line or the included file contents******************
' MachStdMIll license terms REQUIRE that the copyright and License terms remain a part of this source file
#expand <Masters\Headers\CopyRightAndLicenseNotice>
'**************************************************************************************
#expand <Masters\Headers\MachConstants>
' this is a template script for M6ATC.m1s
' This template is installed by MSM into <mach install dir>\MachStdMill\Profile Macro Masters\Templates
'
' the Auto Tool Changer implementer should flesh this template out with the appropriate code.
' this script is called from MSMM6start for AutoTC mode
' the script will be looked for by M6Start in the macro dir for the current profile
' i.e. in "<mach install dir>\Macros\<GetActiveProfileName() >\" and the name of the script in that dir must be "M6ATC"
'
' this script is responsible for physically putting GetSelectedTool() into the spindle
' this script should returns when the tool mount is complete
'
' the routine should do all TC operations in G53 coordinates
' Routine is entered with G90 G00 G40
' entry point into the script
Sub main()
Const maxtoolnum = 4
Dim newtoolNumber As Integer
Dim oldtoolNumber As Integer
Dim NewtoolDro As Integer
Dim TurretTool As Integer
Dim XTCpos As Double
Dim ZTCpos As Double
Dim BTCpos As Double
Dim Input4 As Integer
If newtoolNumber > maxtoolnum Then
MsgBox "Tool number Range is 1-4 Check tool number "
Exit Sub
main
End If
If newtoolNumber = TurretTool Then
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
Sleep 5000
If newtoolNumber <> TurretTool Then
DoOEMButton( MachResetOEMBtn )
Exit Sub
Main
'MsgBox ("newtool = " & GetSelectedTool)
'MsgBox ("oldtool = " & oldtool )
'MsgBox ("dro 2000 = " & getoemdro (2000) )
'End If
End Sub
Main