LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Buggy LabVIEW Templates & Courses?

Hi!

 

I am refering to the project templates supplied with the latest LabVIEW (e.g. Continuous Measurement and Logging Sample Project) and I am also refering to the LabVIEW Core 3 courses. All of these templates / best-practice courses use the Event-Driven Producer/Consumer Pattern. Unfortunately, they all look buggy to me, as controls are being disabled in the consumer loop and not in the event cases of the producer loop. To me this is simply buggy programming style as it allows the user to click multiple times on a button (because the button does not get disabled immediately) and this causes the event to fire multiple times which in turn means that the same command is enqueued multiple times instead of only once. This definitely leads to incorrect program behavior!

 

Well, I am neither a CLAD, nor a CLD, nor a CLA, nor a LabVIEW god but I just can't imagine how it is possible to put such buggy code in courses and put it in templates which are created by "experts" and are given as best-practice solutions. Please correct me if I'm wrong...

 

Regards,

Anguel

0 Kudos
Message 1 of 16
(4,192 Views)

You are not wrong. I am a CLA (and some other stuff as well) and it has been a personal issue for me over many years that the quality of the examples is poor. For the most, reading NI code is not a good way to learn about LV programming. Though there are exceptions, it is usually poorly documented, devoid of any sort of meaningful error handling and buggy. Very often examples will have significant memory leaks because they don't close references.

 

IMO, the style of the Continuous Measurement and Logging Sample Project is overly complex and difficult to read or understand.

 

Another problem is that sometimes examples are written in one version of LV and never updated to take advantage of new capabilities as new versions are released.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 16
(4,164 Views)

Mike, thanks for the confirmation. Unfortunately, here I am not talking about some examples but about recommended (!) project starting points advertised by NI as best-practice and being written by absolute experts. Such projects are automatically created when you open the latest LabVIEW versions and they make you build your app on top of them. They are used by so many people, also in critical applications and developers trust them.

 

The same programming style is also used in teaching and in exam preparations as far as I understand. This is really incredible! The complete application can be brought down by a simple double-click on a control. In my small business I would immediately fire a programmer who delivers such buggy code that can be brought to crash if the user clicks a bit "too fast" on the interface. Just can't believe it...This makes you think that LabVIEW is just some fun project not to be taken very seriously. But you pay a lot for that fun and people rely on it...

0 Kudos
Message 3 of 16
(4,156 Views)

Basically I agree with you, but in terms of the double-click problem, the code should first be written such that it doesn't matter if the button is clicked twice. One of the issues to remember is that sometimes double-clicking is a valid event that you can trap, but LV can't know ahead of time if a double click is coming so it always registers and fires a selection event (a single-click) before it fires the double click event.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 16
(4,150 Views)

@mikeporter wrote:

Basically I agree with you, but in terms of the double-click problem, the code should first be written such that it doesn't matter if the button is clicked twice. One of the issues to remember is that sometimes double-clicking is a valid event that you can trap, but LV can't know ahead of time if a double click is coming so it always registers and fires a selection event (a single-click) before it fires the double click event.

 

Mike...


What I meant by double-click is that the user accidentaly clicks twice with the mouse instead of once. In this case he fires the value change event twice if the consumer loop does not manage to disable the button immediately. E.g. for a start button - the button should be pressed only once and then it gets disabled until you click on stop. But if the disable property node is not in the event handler but in the consumer loop as in the NI templates, the user could fire the event twice and this will make the program do unexpected things.

0 Kudos
Message 5 of 16
(4,131 Views)

@AStankov wrote:

@mikeporter wrote:

Basically I agree with you, but in terms of the double-click problem, the code should first be written such that it doesn't matter if the button is clicked twice. One of the issues to remember is that sometimes double-clicking is a valid event that you can trap, but LV can't know ahead of time if a double click is coming so it always registers and fires a selection event (a single-click) before it fires the double click event.

 

Mike...


What I meant by double-click is that the user accidentaly clicks twice with the mouse instead of once. In this case he fires the value change event twice if the consumer loop does not manage to disable the button immediately. E.g. for a start button - the button should be pressed only once and then it gets disabled until you click on stop. But if the disable property node is not in the event handler but in the consumer loop as in the NI templates, the user could fire the event twice and this will make the program do unexpected things.


You could also include some logic in the event structure to effectively filter out repeated events for a control if they occur within some specific amount of time. There are valid instances when the consumer should have teh control over when things are enabled or disabled. l agree that there are some extremely poor examples and templates. There is an effort to cleanup the examples (some of which have not been touched in over 10 years). At the same time you can't simply state that due to a potential for a bug one should never allow the consumer to control the state of controls/indicators.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 16
(4,117 Views)

Anguel,

 

Are you running into problems where multiple button clicks are being registered before the control disables? I'm unable to click twice anywhere near fast enough to beat the queue/dequeue operation. The infinitely quick double click may still register twice and relying on speed is not a good practice so from a conceptual standpoint you bring up a valid point and one we were aware of. As with any decision in programming there are trade-offs. We decided to disable controls in the consumer for one main reason.

 

The consumer loop is the keeper of state. If someone were to expand our templates or sample projects and wanted to handle events differently depending on the state then this logic would be in the consumer loop. The event structure's job is to catch that the event happened and delegate immediately. It's up to the consumer loop to decide what to do with that information.

 

e..g. the acquire button should be disabled when the acquisition is running, not when the acquisition is requested. If for some reason the application couldn't start (hasn't been configured yet, an error in initialization, the consumer loop has already exited, queue reference is bad) you don't want the UI to have automatically updated based on a hard coded assumption.

 

Another reason for doing it the way we did it is if there are multiple UIs (perhaps physical buttons, a remote control device, or an automated scheduler) that could request that the system start acquiring then we'd need to disable the local controls even though the event didn't fire.

 

We decided that these situations were more likely than someone being able to click fast enough to queue up multiple commands that would cause problems to the application. [On a related note I feel like relying on the disabled state of a control to ensure your program doesn't get into a bad state is not a best practice -- writing the Value (Signaling) property on a disable control will still fire the value changed event.  If recieving the event out of turn is catestrophic you should discard the errant event rather than trying to prevent it.]

 

I'll admit we're often guilty of over-hyping things like the sample projects but they are expert created starting points rather than solutions. For any concrete application there are certain tradeoffs we made that may or not make sense in that situation and it's up to the programmer to change those things. Over time we'll get better at documenting which tradeoffs need to be considered in certain situations.

 

We feel giving everyone a passable starting point for a well designed application is better than making everyone start with a blank VI.

 

I hope we can continue to have conversations like these. Best practices aren't set in stone, they evolve over time and I hope the templates and sample projects we provide will evolve as the state of the LabVIEW art does.

 

 

And to Mike -- I wholeheartedly agree and apologize about the state of examples in Example Finder - we've tried to make inroads with that this year and you should see some progress in that regard come August.

Message 7 of 16
(4,104 Views)

@Mark_Yedinak wrote:

You could also include some logic in the event structure to effectively filter out repeated events for a control if they occur within some specific amount of time. There are valid instances when the consumer should have teh control over when things are enabled or disabled. l agree that there are some extremely poor examples and templates. There is an effort to cleanup the examples (some of which have not been touched in over 10 years). At the same time you can't simply state that due to a potential for a bug one should never allow the consumer to control the state of controls/indicators.

The idea with filtering out repeated events is interesting but sounds complicated to me. Do you have any sample code? So why not just disable controls like "start" or "stop" immediately in the event case? This will prevent enqueuing them twice and breaking the program. Then the consumer loop can still decide what to do with the controls. I never said that it should not touch the controls. I don't speak about old examples, I mean the latest LabVIEW 2012 and the latest courses and exam preparation examples...

0 Kudos
Message 8 of 16
(4,073 Views)

@SimonH wrote:

 

Are you running into problems where multiple button clicks are being registered before the control disables? I'm unable to click twice anywhere near fast enough to beat the queue/dequeue operation. The infinitely quick double click may still register twice and relying on speed is not a good practice so from a conceptual standpoint you bring up a valid point and one we were aware of. As with any decision in programming there are trade-offs. We decided to disable controls in the consumer for one main reason.


 

Let's take the Continuous Measurement and Logging Project Template. Just add some delay to the "Start" case in the consumer loop, this is realistic because it may take some longer to execute a consumer command. Put a simple local var and increment it inside the same case and output it to an indicator. Then click the "Start" button quickly twice. It will enqueue the Start operation twice before the "Start" button is disabled by the consumer (watch your counter). This is the bug! Disabling the "Start" button immediately inside the producer event case solves the problem for me.

 

 


 

 e..g. the acquire button should be disabled when the acquisition is running, not when the acquisition is requested.

 


 

Starting an aquisition twice is much worse. Why not disable at least the "Start" button in the event case and then do with the buttons whatever you like in the consumer?

 

 

 


 

We decided that these situations were more likely than someone being able to click fast enough to queue up multiple commands that would cause problems to the application.

I don't agree  - this happens when the consumer takes a bit longer or has already multiple commands enqueued.
For me the templates / sample solutions are buggy as they are and don't point the user to the expected problems I described above. The courses don't even make the developer aware of these problem. I am a casual LabVIEW developer and expect a more stable starting point than one that can make the application crash because of a faster click.

Regards,
Anguel
0 Kudos
Message 9 of 16
(4,066 Views)

@AStankov wrote:

@Mark_Yedinak wrote:

You could also include some logic in the event structure to effectively filter out repeated events for a control if they occur within some specific amount of time. There are valid instances when the consumer should have teh control over when things are enabled or disabled. l agree that there are some extremely poor examples and templates. There is an effort to cleanup the examples (some of which have not been touched in over 10 years). At the same time you can't simply state that due to a potential for a bug one should never allow the consumer to control the state of controls/indicators.

The idea with filtering out repeated events is interesting but sounds complicated to me. Do you have any sample code? So why not just disable controls like "start" or "stop" immediately in the event case? This will prevent enqueuing them twice and breaking the program. Then the consumer loop can still decide what to do with the controls. I never said that it should not touch the controls. I don't speak about old examples, I mean the latest LabVIEW 2012 and the latest courses and exam preparation examples...


Here is a basic example.

 

Filter events.png

 

Note: The event structure lost track of the ewvent cases when I made this into a snippet. The event above is for the OK Button value change. This code is correct in the development environment.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 16
(4,057 Views)