Hello;
I'm setting up Mach3 to run a lathe with a 4 position toolpost on it. I've generated a pass at the VB script with the help of a friend (I'm no programmer) and I wanted to see if someone could proof it and see if it would work. I just downloaded & configured Mach3, so it would be used on the most current version. Here are the specs on the toolchanger and what I am attempting to do.
-4 position changer, air actuated so it only spins in one direction (CW, in case it matters). Added complexity is the changer can hold multiple tools on a single face. The changer only moves 1 step at a time, and requries another input to progress another step - always in the same direction. i.e. it has 4 faces, to get from face 2 back to face 1, it has to progress 3 steps.
It recieves a 24V momentary (pushbutton type) signal which tells it to start actuating, and it finishes 1 step with no other input, automatically seats. It also has a 24V feedback signal that changes state between seated, or turning. (I'm not sure of the exact state between the two, still have to check).
What I thought to do with the code was build a table that would equate a tool to a face, numbering the tools around the holder sequentially 3 times (giving option for 3 tools on a face) and equating that tool number to a face 1 through 4. This way the code could get the current tool and find out what face that equated too, get the requsted tool - what face that equated too, then run the loop to step the toolchanger around until the values were equal.
Here is the script:
Sub Main
Dim currentLocation As Integer
Dim targetLocation As Integer
Dim currentToolID As Integer
Dim targetToolID As Integer
Dim tool (13) As Integer
tool (0) = 0
tool (1) = 1
tool (2) = 2
tool (3) = 3
tool (4) = 4
tool (5) = 1
tool (6) = 2
tool (7) = 3
tool (

= 4
tool (9) = 1
tool (10) = 2
tool (11) = 3
tool (12) = 4
currentTool = GetCurrentTool()
targetTool = GetSelectedTool()
currentLocation = tool(currentTool)
targetLocation = tool(targetTool)
While currentLocation <> targetLocation
If Not IsActive(InputX) Then
ActivateSignal(OutputX)
Sleep (250) 'Signal index pin for 0..25sec
DeActivateSignal(OutputX)
While IsActive(InputX) Then
Sleep (50) 'Allow toolchanger to seat
Wend
currentLocation = currentLocation + 1
If currentLocation > 4 Then
currentLocation = 1 'resets current location back to 1 since completed 1 revolution
End If
End If
Wend
End Sub
One question we had that is important is will Mach3 return an integer when presented with the GetCurrentTool? If not I need to know what it sends so I can decode it!
Thanks, feedback appreciated!