Author Topic: VB script converstion to Mach4  (Read 120 times)

0 Members and 1 Guest are viewing this topic.

Offline nickkinsman

  • Active Member
  • Posts: 14
    • View Profile
VB script converstion to Mach4
« on: January 19, 2019, 12:57:35 PM »
Hello!

I am in process of upgrading my Lathe to Mach4.  Unfortunately I have a non-standard toolchanger that was part of the original commercial machine.  With a lot of forum help I was able to get a VB script that works the toolchanger perfectly, and now I need to make it work in Mach4 if I want to upgrade.  It is a 4-position horizontal rotary tool changer, air activated, which only rotates one direction (counterclockwise as viewed from above). I have a VBscript for Mach3 which was developed with forum help and it works perfectly. I am looking to migrate this to Mach4. Any help with converting this would be great. Following so some background info on how it works to help understand the VB script.

The turret has one each input and output switches. Output 2 is a momentary relay which starts the toolchanger to cycle one 90 degree step. Input 2 is active when air pressure is missing (checked at beginning of script) and also is active while turret is cycling between steps. Tools are assigned by basis of each face (some faces can hold more than one tool, so tool in same face is given next number increment of plus 4). A math function is used to calculate the current face and face requested, (ToolNumber-1) Mod 4, and also to calculate number of steps needed (see below).

'M6Start.m1s

If IsActive(Input2) Then
MachMsg ("Connect Air Pressure to Turret!!","Turret Index Warning",MachMsgTypeOK)
End If

selectedTool = GetSelectedTool()
currentTool = GetCurrentTool()
currentFace = (currentTool - 1) Mod 4
targetFace = (selectedTool - 1) Mod 4

'rotate turret required number of "clicks"
For click = 1 To (targetFace - currentFace + 4) Mod 4 'rotate accounting for rollover

ActivateSignal(Output2) 'activate momentary command to rotate
Sleep (500)
DeActivateSignal(Output2) 'deactivate momentary command and wait for movement signal
Sleep (1500)
While IsActive(Input2) 'wait for turret to stop
Sleep (100)
Wend
Next

'not forgetting to update to the new tool
SetCurrentTool selectedTool

Any help would be appreciated.
Thanks!