LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mechanical Latch Action plus Event Handling

Solved!
Go to solution

I have a weird sort of a problem currently. Well, not exactly a problem but a question on how to implement it. 

I have a need to keep a button pressed till the mouse button is pressed on it - mechanical action - Switch until released. 

However, I have a choice of events here : Value Change - which can occur on every press of the button but that doesn't exactly play nicely with the mechanical action I have in mind. Suggestions to get the outcome welcome 🙂 

 

Requirement: Stepper motor movement through a NI 6501 whose port is connected to a stepper motor driver. 

 

0 Kudos
Message 1 of 12
(3,611 Views)

I believe you want switch when released.  It will stay pressed until you click on it again.  (I like "switched when released" instead of "switched when pressed" because it is gives the user a chance to move off the already-clicked button without generating an event.)

 

I think I misunderstood your intent.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 12
(3,598 Views)

The control will generate TWO events, one when you click and one when you let go.  You can use the control value (or "New Value") to determine what happens with each event.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 12
(3,590 Views)

Your description isn't exactly clear.  I assume you want to activate the stepper motor as long as the button is pressed down.  Upon releasing the button, the motor should stop.  Is this correct?

 

If so, Switch until released is the proper action and a value change will work fine.  But you'll need to store the value of the button change, either in a shift register or maybe a functional global.  If you are using a state machine (hint: use a state machine), at some point in your code (i.e. in a state called "Move Motor"), you'll need to check the value in the SR or FGV repeatedly and activate/deactivate the stepper motor based on the value.  Just make sure you aren't using a while loop in that Move Motor state, otherwise your event structure will never see the button release, (unless your event structure is decoupled from your state machine). 

aputman
0 Kudos
Message 4 of 12
(3,582 Views)
Solution
Accepted by newbieprogrammer

See attached...uses the JKI State Machine. 

aputman
Message 5 of 12
(3,572 Views)

Hi Aputman, yes, that's exactly what I want. Let me check out the code snippet you've attached :).

0 Kudos
Message 6 of 12
(3,543 Views)

Hi billko, I assume you mean the old value and new value. But the event would still be value changed isn't it? Initially, I wanted to have a sort of a loop to poll whether the mouse button is still being held and then fire off the DIO as in, Check the value change event, check if the mouse button is still down, if yes, then drive the motor. If there are work arounds, I could give them a shot too. 

0 Kudos
Message 7 of 12
(3,541 Views)
Solution
Accepted by newbieprogrammer

I was just thinking that the event would fire and you'd send somebody a queued message with a state change depending on what the value of the button was.  I was hoping that my post would lead you to fill in the blanks by yourself.  Any message handling design pattern would work.  I suppose the one by JKI works just fine.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 12
(3,531 Views)

It's just that im pretty new to labview. Hence the number of questions. 🙂 Thanks for the help Bill. I'll try and learn more.

0 Kudos
Message 9 of 12
(3,529 Views)

Keep asking questions!  I would even recommend reading topics that seem interesting but don't have much relevance to what you are doing.  I've picked up SO MANY invaluable little tidbits of information that way.  Still am.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 12
(3,521 Views)