LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to send different characters by one button

Solved!
Go to solution

Hello!

 

I want to send  two hex string (0x02 and 0x03) to bluetooth device by pressing  and releasing button with "switch when pressed" behavior. 

 

I've done with sending 02 string  when i pressed button, and now i'm confused about how to send 03 string  when i release button. Most important it need to be just single sendings every time.

 

In code - two loops, with real device connection and with led for test.  Thank you.

 

blink.png

 

 

 

 

 

0 Kudos
Message 1 of 9
(3,362 Views)

Try an event structure set to Value Change for the button.

 

Lynn

Message 2 of 9
(3,358 Views)

Thank you! it works, but how to change string to 03 when i release button?

0 Kudos
Message 3 of 9
(3,342 Views)

Got it!

 

blink_solved.png

0 Kudos
Message 4 of 9
(3,334 Views)
Solution
Accepted by topic author timbak

You should move the boolean terminal into the event structure and get rid of the local variable. The way you have shown will have a race condition. The value of the local will be the value when the iteration of the loop starts, not the value when the change event occurs.

 

Add a new event case for the Stop Button Value Changed event and move the terminal for that button into that case. Then it will stop as soon as the stop button is pressed. Your coed will not stop until the Stop Button is pressed followed by a press of the ON/OFF button.

 

Lynn

0 Kudos
Message 5 of 9
(3,313 Views)

Could also do this with separate events -- mouse up and mouse down.  Overkill in this case but it would allow the button release code to be different than the button press code. 

 

Using "value change" carries the (probably minor) risk of sending the wrong string if the boolean is not latching.  "Mouse down" does not assume the boolean is in a particualr state.

0 Kudos
Message 6 of 9
(3,299 Views)

Zwired1,

 

I think you have it backwards. Value change is exactly what the OP wants for non-latching booleans. For latch action different behaviors for on and off really does not make much sense. The transition back to the false state occurs as soon as the terminal is read, so in effect only the false to true transition can be generated by user action on a latched boolean.

 

Lynn

0 Kudos
Message 7 of 9
(3,250 Views)

Thanks guys!  

0 Kudos
Message 8 of 9
(3,241 Views)

@johnsold wrote:

You should move the boolean terminal into the event structure and get rid of the local variable. The way you have shown will have a race condition. The value of the local will be the value when the iteration of the loop starts, not the value when the change event occurs.

 


THIS!  Why in the world would you create a local variable and then leave the boolean dangling alone?  If a control isn't wired to something, you shouldn't have it.  If you have it, you shouldn't be leaving it dangling.

0 Kudos
Message 9 of 9
(3,213 Views)