10-15-2009 03:17 PM
Hello, first of all let me say that I am new to Labview, but have been working with it for a little while now and am starting to get the hang of it. The project I am working on is a VA for a test system for a bunch of cables, each one serialized. The idea is that the user selects a directory, and then for each test enters a serial number while the VI grabs the data (from a network analyzer) and writes it to a text file in the selected directory with the name being the serial number with the .txt extension.
I have this working pretty well, but we would like to integrate a barcode scanner. We have a bunch of scanners which emulate USB keyboards, so it is simple to have the user just click in the text control for serial number, and scan the cable. However, we would also like to be able to have it so that the user does not need to do anything other than connect the cable and scan it. The scanners have are set up to append a carriage return to the end of the number it has just scanned, basically simulating hitting the Enter key. I set the button I use to trigger the test to toggle on Enter, so just scanning a bar code will start the test and save the data. However, it will not clear the text control; rather, the previous serial number sits in there while the new one is appended to the end. How can I clear this field programmatically?
Solved! Go to Solution.
10-15-2009 03:31 PM
10-15-2009 03:33 PM
10-15-2009 03:34 PM
You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:
10-15-2009 04:33 PM
smercurio_fc wrote:You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:
I would recommend using GovBob's approach of using the invoke node to reinitialize the control rather than using property nodes or local variables.
10-15-2009 04:49 PM
Mark Yedinak wrote:
smercurio_fc wrote:You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:
I would recommend using GovBob's approach of using the invoke node to reinitialize the control rather than using property nodes or local variables.
Why? Why go though the VI Server when a simple local variable is just as effective, and probably way faster. The only issue would be to eliminate a race condition, which is solved trivially. Local variables are not EVIL.
10-15-2009 05:34 PM
10-15-2009 05:53 PM
smercurio_fc wrote:
Mark Yedinak wrote:
smercurio_fc wrote:You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:
I would recommend using GovBob's approach of using the invoke node to reinitialize the control rather than using property nodes or local variables.
Why? Why go though the VI Server when a simple local variable is just as effective, and probably way faster. The only issue would be to eliminate a race condition, which is solved trivially. Local variables are not EVIL.
One reason that comes to mind is if you end up reinitializing the control in multiple places. If you use a constant then you will need to update all the places you initialize the control to it's default value. Whereas using the Invoke node allows you to assign the default value as an attribute of the control itself and should that value change you have one place to update it.
As a general rule of thumb I try to avoid the use of local variables and property nodes and stick with pure data flow programming. Granted this is not always possible. By not using them I tend to think more about my design and architecture of my application and develop something that is more robust and flexible. Over time you build your bag of tricks and find you only need to use them on rare occasions.
And for the record I never said they were evil. I said the invoke node was my prefered method.