Hello Guest it is July 08, 2020, 01:37:05 AM

Author Topic: Pausing a Macro to wait for a signal from an input  (Read 2441 times)

0 Members and 1 Guest are viewing this topic.

Pausing a Macro to wait for a signal from an input
« on: February 11, 2011, 02:40:47 PM »
I'm writing my tool changer macro and I need a little help. I need to make my tool magazine move and stop when it triggers a position switch. This is what I have so far (Note this is to make the mag go CCW):


If IsActive(OUTPUT5) = True Then
    DeactivateSignal(OUTPUT5) 'Mag CW
End If
   
ActivateSignal(OUTPUT6) ' Mag CCW

While IsActive(OEMTRIG12) = False Then
    Sleep 10
Wend

DeactivateSignal(OUTPUT6)


Note:
OUTPUT5 = Mag CW
OUTPUT6 = Mag CCW
OEMTRIG12 = Pocket position switch

When I run this the mag just keeps spinning.

Any help would be great!!

Thanks,

Aero

Offline Hood

*
  •  25,846 25,846
  • Carnoustie, Scotland
    • View Profile
Re: Pausing a Macro to wait for a signal from an input
« Reply #1 on: February 11, 2011, 04:27:08 PM »
I do my toolchange with Do Loops but I am crap at VB so there is likely better ways to do it although they do work great for me so I will stick to them :)
Hood

Offline djc

*
  •  47 47
    • View Profile
Re: Pausing a Macro to wait for a signal from an input
« Reply #2 on: February 11, 2011, 05:52:53 PM »
If IsActive(OUTPUT5) = True Then

Try IsOutputActive instead of IsActive.

Don't ask me how long it's just taken me to realise the difference.

Also, you don't need = True. The function returns a value of 1 if it's true and 0 if it's false. Hence asking if 1 = true is unnecessary.
Re: Pausing a Macro to wait for a signal from an input
« Reply #3 on: February 11, 2011, 09:14:26 PM »
OK I got it working!!!! I attached it below if anyone needs a Tool changer that uses cam driven magazine with position switches. The do loop worked great :)

I will list the inputs and outputs later... I'm beeeeet!!!


Thanks for all the help guys!!!

Aero

Offline djc

*
  •  47 47
    • View Profile
Re: Pausing a Macro to wait for a signal from an input
« Reply #4 on: February 12, 2011, 04:29:16 AM »
OK I got it working!

Have you tested it? Big difference between 'working' and 'working and tested'. My bike engine works really well right up to the point where I realise the kill switch isn't wired up and I drive through the wall at the end of the street.

There are lots of places in your macro where you test IsActive against an OUTPUT signal. This will not work correctly.

See:

http://www.machsupport.com/MachCustomizeWiki/index.php?title=Mach_specific_Subroutines/Functions_grouped_by_purpose#Signals

Try this and you will see the difference.

Code: [Select]
ActivateSignal(OUTPUT5)
 Message "OUTPUT5 is active. The value of IsActive(OUTPUT5) is " & IsActive(OUTPUT5)
 If IsActive(OUTPUT5) Then
  Message "I can only print this if IsActive(OUTPUT5) is true"
 End If
 Sleep 5000
 Message ""
 Sleep 5000
 If IsOutputActive(OUTPUT5) Then
  Message "I can only print this if IsOutputActive(OUTPUT5) is true"
 End If


Re: Pausing a Macro to wait for a signal from an input
« Reply #5 on: February 12, 2011, 09:57:39 AM »
Hmmm.. I tested it a few times and it seemed to work. BUT I'm not sure if when I test if an OUTPUT is on truly works. From what I read I should change the IsActive for outputs to IsOutputActive.

Thanks for the INFO, that would have sucked if I really needed to test against an OUTPUT and it didn't work :P


Thanks again,

Aero