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,361 Views)

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

 

Lynn

Message 2 of 9
(3,357 Views)

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

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

Got it!

 

blink_solved.png

0 Kudos
Message 4 of 9
(3,333 Views)
Solution
Accepted by 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,312 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,298 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,249 Views)

Thanks guys!  

0 Kudos
Message 8 of 9
(3,240 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,212 Views)