11-01-2014 06:42 PM
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.
Solved! Go to Solution.
11-01-2014 06:50 PM
Try an event structure set to Value Change for the button.
Lynn
11-01-2014 07:06 PM
Thank you! it works, but how to change string to 03 when i release button?
11-01-2014 07:19 PM - edited 11-01-2014 07:19 PM
Got it!
11-01-2014 07:46 PM
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
11-01-2014 08:22 PM
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.
11-02-2014 03:15 PM
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
11-02-2014 03:21 PM
Thanks guys!
11-02-2014 10:30 PM
@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.