12-16-2012 06:37 PM
hi,
i am trying to scan a barcode with a usb HID barcode scanner. i am using an event structure to detect the value change of a string control. when i scan the barcode, the string control updates on the front panel but the event does not trigger until i left click my mouse on the front panel. can any one help? see vi attached
Solved! Go to Solution.
12-16-2012 07:01 PM
I can't look at your code right now (no LV 12 handy), but you should know that the VALUE CHANGED event happens in two and only two circumstances:
1... The USER changes the value from the front panel, by typing or Inc/Dec, or paste.
2... Somebody feeds a value to the VALUE(SIGNALING) property node. In this case, the event will fire whether the value actually changes or not.
The event will NOT happen if:
A... You set a LOCAL VARIABLE
B... It's an indicator and you set a value via the TERMINAL.
C... You set a value via a VALUE property node.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
12-16-2012 07:21 PM
hi CoastalMaineBird thanks for the reply......
i am trying to trigger a "VALUE CHANGE" event of the control labeled "String" (see jpeg).
the barcode scanner is a HID device and my PC sees it as a keyboard.
so i woiuld have thought this would be consistant with the first point of your post.
also on a side note, when i type a string from the keyboard the event only triggers when i press enter. this is ok for entering a barcode from the keyboard, but can be annoying when trying to scan the barcode in.
12-16-2012 07:24 PM
This is because the string control doesn't trigger the value changed event until the control loses focus. The reason for this is there's, no way for the control itself to know when the value has actually changed to the final value that the user actually wants. For this case, however, there is an option on the string control to "update value while typing." If you select that, you should get the functionality you want.
12-16-2012 07:34 PM
i did try that..... the only problem is that the event will be triggered for every character of the barcode i.e. if i have a 10 character barcode the event will be triggered 10 times.
this just means i will have to program around this......i was hoping to avoid this......
12-16-2012 07:37 PM
the barcode scanner is a HID device and my PC sees it as a keyboard.
--- Perhaps LabVIEW does not. I don't have an answer for that, but I'm sure of the rules I posted.
As a workaround, go back to the pre-event method and do polling: every 100 mSec (for example), read the control, and compare it to the previous value (held in a shift register). If the value is different, do something with the new value.
when i type a string from the keyboard the event only triggers when i press enter.
--- Most of the time, that's what you would want. For a numerical control, if I enter "1234" I don't want the event firing for "1" and then again for "12" and then again for "123" and then again for "1234" - that tells me the thing changed four times, when the user just wants to go to 1234. And what if I make a mistake and enter 1,2,3,5,backspace,4, then I get SIX events instead of one.
You can change that behavior, though - there's a boolean property called "Update Value While Typing", default FALSE.
Set that property TRUE (usually via right-click on the control) and you get the other behavior.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
12-16-2012 07:39 PM
the only problem is that the event will be triggered for every character of the barcode i.e. if i have a 10 character barcode the event will be triggered 10 times.
I don't understand what you want- here you DON'T want 10 separate events, but earlier it was "annoying" that you got only one.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
12-16-2012 08:04 PM
when i type a string from the keyboard the event only triggers when i press enter. this is ok for entering a barcode from the keyboard
so if the user does need to enter the barcode from the keyboard for some reason (eg. not enough room for hand held scanner) he/she can press the enter key when the entire barcode has been entered.
however if the user needs to press the enter key or click on the front panel after ever scan of a barcode scanner that would be annoying.
i was going to use the barcode in the event
so if i had a barcode eg. 123456789, entering the event after 1 was entered then again when 2 was entered etc wouldn't make sense.
but if the only way is to set the "update while typing" property to high then i will have to work around that.
12-16-2012 08:10 PM
Your barcodes are probably fixed length. When you get an event, check the length. If it matches the length of the barcode, then process the data, otherwise wait for more characters. This can be handled very fast in the event case.
Lynn
12-16-2012 08:12 PM
i think thats what i will have to do......