Hello Guest it is December 06, 2019, 12:44:56 PM

Author Topic: Need a little macro help  (Read 2507 times)

0 Members and 1 Guest are viewing this topic.

Offline derek

*
  •  201 201
    • View Profile
Need a little macro help
« on: October 04, 2012, 07:05:16 AM »
Starting to work out the details on my tool change macro for my ATC.
Ran into a bit of a stumble right away. Here's what I'm trying to accomplish:
ActivateSignal( OUTPUT5 )
Wait for signal from proximity switch on input 1 then
ActivateSignal( OUTPUT6 )

I've searched and tried a few things but a can't seem to get it figured out.

Thanks
Derek

Offline Hood

*
  •  25,856 25,856
  • Carnoustie, Scotland
    • View Profile
Re: Need a little macro help
« Reply #1 on: October 04, 2012, 03:38:06 PM »
This may work for you.
Hood

Do                                       
 ActivateSignal(OutPut5)               
 If IsActive(Input1) Then Exit Do 
 sleep 10         
 Loop
 ActivateSignal(Output6)

Offline derek

*
  •  201 201
    • View Profile
Re: Need a little macro help
« Reply #2 on: October 04, 2012, 06:06:12 PM »
Hi Hood
Thanks for the help.
I kicks an error "Error on line:2-Exit for/do not within for/do loop"

Any ideas?
Thanks
Derek

Offline Hood

*
  •  25,856 25,856
  • Carnoustie, Scotland
    • View Profile
Re: Need a little macro help
« Reply #3 on: October 04, 2012, 06:11:49 PM »
Works perfectly here, just tried. What else do you have in the macro as that is likely the problem.
Hood

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Need a little macro help
« Reply #4 on: October 04, 2012, 06:38:54 PM »
Just another method, The GetUserDRO(2000) is a safety to get OUT of the loop if needed.  For the macro to work you need to first set the UserDro(2000) to 99 with      SetUserDro(2000,99). I have a saftey button on screen with the exit code "SetUserDro(2000,0)" that allows the loop to exit else you may stay in an endless loop.



ActivateSignal(OutPut5)               
 Do While Not IsActive(Input1) And GetUserDro(2000) = 99
 sleep (10)         
 Loop
ActivateSignal(Output6)
 End
 

Just a thought, TP

Offline derek

*
  •  201 201
    • View Profile
Re: Need a little macro help
« Reply #5 on: October 04, 2012, 07:01:16 PM »
Thanks guys
I'll play some more tomorrow as for now I'm home BBQing some pork chops!

Thanks for the help
Derek

Offline derek

*
  •  201 201
    • View Profile
Re: Need a little macro help
« Reply #6 on: October 05, 2012, 06:34:42 AM »
Well I couldn't get hoods to work but a modified BR549 did the trick.

ActivateSignal(OutPut5)               
 Do While Not IsActive(Input1)
 sleep (10)         
 Loop
ActivateSignal(Output6)

I'm confused as to the SetUserDro(2000,99) safety does.

Thanks
Derek

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Need a little macro help
« Reply #7 on: October 05, 2012, 11:14:37 AM »
Just a note , Hoods code worked here as well. (;-) The safety was added to allow you to break OUT of the loop if needed. IF your Input1 relay failed it would stay in the loop as a never ending loop with no way out. With the safety as soon as you pushed the safety button and it changed the value of the safety DRO it would break out of the loop and allow you to continue without having to shut down the computer completely.

(;-) TP
« Last Edit: October 05, 2012, 11:18:35 AM by BR549 »

Offline derek

*
  •  201 201
    • View Profile
Re: Need a little macro help
« Reply #8 on: October 05, 2012, 12:11:19 PM »
Just a note , Hoods code worked here as well. (;-) The safety was added to allow you to break OUT of the loop if needed. IF your Input1 relay failed it would stay in the loop as a never ending loop with no way out. With the safety as soon as you pushed the safety button and it changed the value of the safety DRO it would break out of the loop and allow you to continue without having to shut down the computer completely.

(;-) TP

Thats weird!
I was really careful about typing the correct stuff and tried it a few times. It just kept kicking that error message. Is it possible that something is corrupt or needs updating on the computer?

I'm going to try it on a different machine and see what I get.

Thanks for the explanation on the safety.

Derek