Hello Guest it is March 28, 2024, 06:44:36 PM

Author Topic: Macro Help  (Read 4920 times)

0 Members and 1 Guest are viewing this topic.

Macro Help
« on: December 18, 2015, 10:13:17 AM »
Need help with the below program, can someone tell me what's wrong?

oldtool = GetCurrentTool()         'Get the current tool postion
newtool = GetSelectedTool()         'Get the new tool position

if newtool < 1 or newtool > 8 Then      'make sure new tool isnt a number
   DoOemButton(1003)         'below 1 or above 8
   MsgBox("Tool Number Not Valid")
   End
End if

if oldtool = newtool Then            'if new tool is same as current tool
   End               'quit and do nothing
End if

if newtool = 1 Then            'if tool number 1 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#1)      'oem trig #1 is tool position 1
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 2 Then            'if tool number 2 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#2)      'oem trig #2 is tool position 2
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 3 Then            'if tool number 3 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#3)      'oem trig #3 is tool position 3
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 4 Then            'if tool number 4 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#4)      'oem trig #4 is tool position 4
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 5 Then            'if tool number 5 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#5)      'oem trig #5 is tool position 5
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 6 Then            'if tool number 6 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#6)      'oem trig #6 is tool position 6
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 7 Then            'if tool number 7 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#7)      'oem trig #7 is tool position 7
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

if newtool = 8 Then            'if tool number 8 selected
   ActivateSignal(Output2)         'output2 is turret foward
   While IsActive(OEMtrig#8)      'oem trig #8 is tool position 8
   Wend
   Deactivate(Output2)         'turn off output 2
   ActiveSignal(Output3)         'output 3 is turret reverse
   While IsActive(Input1)         'input 1 is turret clamped
   Wend
   Code ("G4 P1")            'wait 1 sec to ensure turret clamped
   Deactivate(Output3)         'turn off output 3
End if

SetCurrentTool(newtool)
End

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Macro Help
« Reply #1 on: December 18, 2015, 08:08:22 PM »
(;-) You may want to explain what the sequences of events are that take place for 1 tool change. As is I would guess that no one else knows exactly what you are trying to make happen. I can guess but it would only be a guess.

I see what may be the problem but i need to know what you are expecting to happen.

(;-) TP
Re: Macro Help
« Reply #2 on: December 21, 2015, 10:14:03 AM »
BR549,

I guess that would help if I explained what im trying to do.  lol     but all I was asking was why it wont compile.   ALOT has changed since I have asked this question. I found something called VB editor in Mach3.  If I press the "run script" button it tells me where the error is. If I only new about this earlier I would have been doing fine.

my program has changed dramatically since finding this helpful software. my 8 tool turret now changes and does exactly what I want it to do.

so thank you for the help.  :)   im on my way to turning some parts!!!  WOOHOO!!!!

Re: Macro Help
« Reply #3 on: December 21, 2015, 10:20:01 AM »
this is what I have right now:

If GetSelectedTool() = GetCurrentTool() Then
   End
End If

If GetSelectedTool = 1 Then
   ActivateSignal(Output2)         'output2 is turret foward
   While Not IsActive(oemtrig1)      'oem trig #1 is tool position 1
   Wend                                                'wait in while statement till input is on
   DeactivateSignal(Output2)              'turn off output 2
   ActivateSignal(Output3)         'output 3 is turret reverse
   While Not IsActive(Input1)              'input 1 is turret clamped
   Wend                       'wait in while statement till clamped
   Sleep 1000                                         'wait 1 second
   DeactivateSignal(Output3)              'turn off output 3
End If
End


this is what I was playing with in the VB editor.  now I have to copy and past it for 7 more tools and im done.  I was worried about "what if same tool number is called?" answer:  change to that tool again!  lol  I did handle if same tool called then end program.

:)
Re: Macro Help
« Reply #4 on: December 21, 2015, 10:23:11 AM »
"this is what I was playing with in the VB editor.  now I have to copy and past it for 7 more tools and im done.  I was worried about "what if same tool number is called?" answer:  change to that tool again!  lol  I did handle if same tool called then end program."

I think im hung over.   not sure what I meant by saying the same thing twice!   

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Macro Help
« Reply #5 on: December 21, 2015, 10:41:02 AM »
You need to build in an escape mechanism to your While Loops otherwise you COULD get stuck there forever (;-)

(;-) TP
Re: Macro Help
« Reply #6 on: December 21, 2015, 11:55:56 AM »
yeah, I have done that a few times already!    mach really doesn't like it when that happens.  I have to reboot the whole computer to fix it.

do you have any suggestion's to how I should go about doing that?     

I would love to have it wait for 10 seconds and then display a message saying something like "tool change error".


Re: Macro Help
« Reply #7 on: December 21, 2015, 11:57:33 AM »
also,  it would be nice to actually stop all G code from happening after the macro finishes.   not sure how to do that either.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Macro Help
« Reply #8 on: December 21, 2015, 01:01:45 PM »
Here is an example of a simple loop and counter function   each time the loop runs it looks at teh OemTrigger and the Lcnt1 value Then increases the loop count by 1. adjust the timeout value to get the time you want.


Lcnt1 = 0                                                            'Set Loop Counter to 0
While Not IsActive(oemtrig1)  OR Lcnt1 < 10000    'oem trig #1 is tool position 1 OR Loop Count < 10000
Lcnt1 = (Lcnt1 +1)                                             ' Increase count by 1 on each loop
Wend                                                                  'wait in while statement till one or the other  input conditions is met

    IF Lcnt >= 10000 then                                    ' Check the status of the Lcnt1 value IF it timed out then do stop function
    MessageBox("Atc time out ERROR")
    DoButton(3)                                                   'Stop program run
    END                                                              'END macro script
    End if
                                                           
Re: Macro Help
« Reply #9 on: December 21, 2015, 01:25:31 PM »
VERY COOL!    I like the way you did the loop count. that's a good idea.  I will definitely do that.

I had/have no idea that DoButton(3) would stop the running of the g&m codes program. I will definitely do this too.

thank you very much for all your help! :)