Hello Guest it is April 19, 2024, 05:25:23 AM

Author Topic: Would like Mach3 to find the next tool number during tool change  (Read 8055 times)

0 Members and 1 Guest are viewing this topic.

What I mean is that I would like to place a custom userDRO on the screen that would display what tool number is next in line to run after the current tool finishes.  This way while tool A is running, I can look on the screen and find which tool to get ready for the next manual tool change.  I figure when the tool change macro is ran,  I'll use some script to scan ahead and find which tool is next.

So far, I have been able to get the macro to find the line the next tool change is on and post the entire line of code to the message bar, but I'm not sure how to post just the T number (word) to a DRO.  I want it posted to the DRO because any messages are immediately replaced in the history file.


Dim currentfile As String
Dim filesys, filetxt, lastline, oldline As String
Dim currentLine As String
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
currentLine = GetOEMDRO(816)
Found = False
currentfile = FileName
Set filetxt = filesys.OpenTextFile(currentfile, ForReading, True)
Dim i As Integer
i = 0
Do While filetxt.AtEndOfStream <> true
linestring = UCase(filetxt.ReadLine()) & " "
If linestring <> " " Then
i = i+1
If i > currentLine Then
If ((InStr(linestring,"M6" ) >0 Or InStr(linestring,"M06" )>0)) Then  
Message "()" & linestring 'post the entire line of code to the history folder
Found = True
MsgBox " Your next toolchange position is at line "& i
Exit Do
End If
End If
End If
Loop
If Found = False Then
MsgBox "No M6/M06 Found after LINE:"& currentLine
End If
filetxt.Close
Set filesys = Nothing
Set filetxt = Nothing

My question is, how can I get the tool number (T word) set to a user dro.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Would like Mach3 to find the next tool number during tool change
« Reply #1 on: July 12, 2010, 09:31:24 PM »
YOu may want to send the String to a USER Label They act just like the message bar but the message stays put until you change it.

OR you can create a UserDro on the screen and format the String "Number" and place in the Dro by SetUserDro(####)    #### is the dro#
Re: Would like Mach3 to find the next tool number during tool change
« Reply #2 on: July 13, 2010, 02:19:26 AM »
How would I send the string to a user label.  I don't think it's possible.

Thanks
Re: Would like Mach3 to find the next tool number during tool change
« Reply #3 on: July 13, 2010, 05:02:07 PM »
I think your misunderstanding what I'm trying to ask.  I know how to set DRO's, what I can't figure out is how to extract the T number from the line string.  The VB script I have so far will find the next line of code with the M6, and stores it as a string of text "linestring".  So an example would be that linestring = N1000 T3 M6 G43 H3.  I would like to be able to grab the number after the T word (3) and store it as "NextTool" so that it can then be set setuserDRO (1152,NextTool).  I've been able to do it with some very crude impractical methods that use the run from here button and require preparation moves.  One method that I would like to use looks something like this;

1000
n=n + 1
If n>256 Then
Code "(no tool found)"
setuserDRO (1152,0)
end if
exit sub
Else
If ((InStr(linestring,"T" & n )   Then
setuserDRO (1152,n)
end if
exit sub
Else
goto  1000


Where n is an integer from 0 to max. tool number ( I think it is 256)
linestring is the string of text that appears in the Gcode.
I would like to run this script in the M6 macro, and I want to avoid preparation moves.
This code works if the line says:  If ((InStr(linestring,"T3" )    but it does when I use If ((InStr(linestring,"T" & n )  even if I insert
n=3 into the script

Any help would be appreciated.

Thanks

Re: Would like Mach3 to find the next tool number during tool change
« Reply #4 on: July 13, 2010, 08:27:38 PM »
Dim position As Integer
Dim ToolNo As Integer

linestring = "N1000 T3 M6 G43 H3"
position=InStr(linestring, "T" )
ToolNo=Mid(linestring,position+1,2) 'as long there is a space after the tool number

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Would like Mach3 to find the next tool number during tool change
« Reply #5 on: July 13, 2010, 08:37:11 PM »
Userlabels  work just fine you should be able to send your string staright to a userlabel.

As to the DRO route you will have to work that out. Isolate what you need and format as a double and it should work fine.

NOW IF you were to rethink your Gcode you could do it the way we did with look ahead toolchangers.

State the T# in advance such as

T10
*

*
*
*
*
*
M6
G43 H10
T9

This way the Tool# is loaded into the hold que in advance of its use AND that number can be directly displayed in a DRO on screen. Then when needed for tool change the M6 transfers the tool into the current tool and then you state the next TOOL in advance. The look ahead tool changers used this to have the next tool standing by and ready to swap. Saved a lot of time in tool changes waiting for the tool to get ready.

AND there is not a need for a VB scheme to do what you want.

Just a thought,(;-)


Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Would like Mach3 to find the next tool number during tool change
« Reply #6 on: July 13, 2010, 08:47:21 PM »
If you want to get the next tool with that code I would count back from 3 characters out from T and check to see if it is numeric.

Code: [Select]
Dim filesys As String
Dim currentLine As String
Set filesys = CreateObject("Scripting.FileSystemObject")
Dim i As Integer
i = 0

currentLine = GetOEMDRO(816)+1

Set filetxt = filesys.OpenTextFile(FileName , 1, True)


Do While filetxt.AtEndOfStream <> true
linestring = UCase(filetxt.ReadLine()) & " "

If linestring <> " " Then

i = i+1

If i > currentLine Then

If ((InStr(linestring,"M6" ) >0 Or InStr(linestring,"M06" )>0)) Then

ToolIndex = InStr(linestring,"T")

For d = 3 To 0 Step -1

ToolNum = Mid(linestring,ToolIndex+1,d)

'Msgbox ToolNum

If IsNumeric(ToolNum) Then

N = GetToolDesc(ToolNum)
D = GetToolParam(ToolNum,1)
L = GetToolParam(ToolNum,2)

SetUserLabel(1, ToolNum & " " & N)
SetUserDRO(2000,ToolNum)

Exit For

End If

 Next d   



Exit Do

End If

End If
End If

Loop

'MsgBox GetUserDRo(2000)
'MsgBox GetUserLabel(1)

filetxt.Close
Set filesys = Nothing
Set filetxt = Nothing
Re: Would like Mach3 to find the next tool number during tool change
« Reply #7 on: July 13, 2010, 09:49:25 PM »

most times I do what BR549 mentioned, just put it on a line by itself well before calling the m6 toolchange
then you don't have to worry about stripping out any additional characters.
« Last Edit: July 13, 2010, 09:55:16 PM by Ya-Nvr-No »
Re: Would like Mach3 to find the next tool number during tool change
« Reply #8 on: July 13, 2010, 10:22:05 PM »
or

Dim linestring ,shortlinestring As String
Dim lenstring, position ,spaceposition, nextpos, ToolNo As Integer

linestring = "N1000 T344 M6 G43 H3"
position=InStr(linestring, "T" )
lenstring=Len(linestring)
shortlinestring= Right(linestring,lenstring-position)
spaceposition=InStr(shortlinestring, " " )

ToolNo=Mid(linestring,position+1,spaceposition) 'as long there is a space after the tool number

you could do a value compare to make sure it is a number and not a character if no spaces are used.
just a small little for x=1 to 3 next loop
Re: Would like Mach3 to find the next tool number during tool change
« Reply #9 on: July 14, 2010, 02:03:32 PM »
Thanks for the help, this is exactly what I needed.  The idea of stating the T# in advanced is a good idea but the CAM program I use does not all it and I don't want to have to manually edit the programs.   I'm still interested in learning how to post to user labels.  I didn't think this was possible because in Screen4 when you add a user label to the screen, the  label has no specific number to identify it from other labels,  unlike the DROs.  If I could post to a user label and use it as another message bar that would be great.

Thanks