Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Denford Miracle on December 18, 2015, 10:13:17 AM

Title: Macro Help
Post by: Denford Miracle 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
Title: Re: Macro Help
Post by: BR549 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
Title: Re: Macro Help
Post by: Denford Miracle 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!!!!

Title: Re: Macro Help
Post by: Denford Miracle 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.

:)
Title: Re: Macro Help
Post by: Denford Miracle 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!   

Title: Re: Macro Help
Post by: BR549 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
Title: Re: Macro Help
Post by: Denford Miracle 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".


Title: Re: Macro Help
Post by: Denford Miracle 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.

Title: Re: Macro Help
Post by: BR549 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
                                                           
Title: Re: Macro Help
Post by: Denford Miracle 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! :)

Title: Re: Macro Help
Post by: Denford Miracle on December 22, 2015, 12:45:03 PM
ok, im back.  lol

I have tried your program idea and I keep getting a syntax error.   when I click ok it doesn't show me where the error is.  I just see the cursor next to "Lcnt1".   so im not sure if this is the problem or not.

how do you declare varibles in Cypress Enable?
Title: Re: Macro Help
Post by: BR549 on December 22, 2015, 02:28:45 PM
The only thing I see wrong is MessageBox  should be MsgBox  (;-)

(;-) TP
Title: Re: Macro Help
Post by: BR549 on December 22, 2015, 02:50:39 PM
OOPS there is another error

  IF Lcnt >= 10000 then                                    ' Check the status of the Lcnt1 value IF it timed out then do stop function

SHould read as

  IF Lcnt1 >= 10000 then                                    ' Check the status of the Lcnt1 value IF it timed out then do stop function
Title: Re: Macro Help
Post by: Denford Miracle on December 22, 2015, 05:07:33 PM
Now im having trouble with my turret motor controller.   can seem to make the motor work.

going to take motor out and see if theres a mechanical problem.
Title: Re: Macro Help
Post by: Denford Miracle on December 23, 2015, 05:37:32 PM
Well, took the turret apart and found a screw was the problem, it was mechanically binding the rotating part of the turret. once I removed the screw everything went back to working.

Thank you for your help.  the macro program is working beautifully!!!   :)

the while loop is working good too.  I added msgbox(Lcnt1), and it would show me the count.  which was 173,000 or something close to that.  so I raised the count to 250,000 before the message would appear and its working fine.

Title: Re: Macro Help
Post by: BR549 on December 23, 2015, 05:40:14 PM
Good Job (;-) TP