‎01-17-2018 02:43 AM
nathand wrote:
The Read ADC case constantly enqueues "Read ADC". How do you stop it? Flush the queue, remove all the "Read ADC" elements, and put everything else back in the queue. But what if the consumer loop executed again while flushing the queue? Better flush the queue again (and again, and again) - 10000 times - just to make sure.
Not to mention those property nodes in the for loop. Those will synchronise with screen updates, making the loop dramatically slow. Or maybe it's supposed to be slow? Could be a bug making the faulty design "work"?
‎01-17-2018 08:51 AM
@nathand wrote:
We ordered an evaluation kit for a particular component, and the manufacturer provided a nice GUI to test it. I was excited to discover that the code for their application is available for download on their website. Then I looked at the code and found this unusual approach to stopping a queued state machine:
SpoilerThe Read ADC case constantly enqueues "Read ADC". How do you stop it? Flush the queue, remove all the "Read ADC" elements, and put everything else back in the queue. But what if the consumer loop executed again while flushing the queue? Better flush the queue again (and again, and again) - 10000 times - just to make sure.
"say no more, say no more"
Ben
‎01-25-2018 01:51 AM
This isn't really a Rube Goldbergian construct, more an oversight in a KB (their image, not mine, and not my highlight for Buffer Size):
I will accept that the auto-indexing input to the For Loop is definitely non-zero in this case, but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?
‎01-25-2018 02:05 AM
@thoult wrote:
but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?
Not to mention the error wire. It needs a shift register, or a parallel shift register with merge error inside...
‎01-25-2018 08:36 PM
wiebe@CARYA wrote:
@thoult wrote:
but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?
Not to mention the error wire. It needs a shift register, or a parallel shift register with merge error inside...
The explanation I've heard for this is because a FOR loop can actually execute ZERO times, so stuff on the left doesn't propagate to the right. In case you are wondering how a loop can execute zero times, think of a FOR loop auto-indexing over an empty array...
‎01-26-2018 03:17 AM
billko wrote:In case you are wondering how a loop can execute zero times, think of a FOR loop auto-indexing over an empty array...
That is correct. Been burned a few times from this (empty array being autoindexed and my references go bye bye).
‎01-26-2018 03:27 AM
So what is the solution here then?
On the one hand you would want the error to move through each iteration of the for loop, but on the other hand a zero-sized array wouldn't carry the error from one side to the other.
‎01-26-2018 03:29 AM
@billko wrote:
wiebe@CARYA wrote:
@thoult wrote:
but wouldn't it be nice to see best practice of a shift registered TDMS reference instead of a tunnel?
Not to mention the error wire. It needs a shift register, or a parallel shift register with merge error inside...
The explanation I've heard for this is because a FOR loop can actually execute ZERO times, so stuff on the left doesn't propagate to the right.
So errors on the left not coming out is a feature? That is evil. People advocating this should be forbidden to program in LabVIEW for life (after a warning, have to allow people to make mistakes)).
Try debugging that: the error in propagates just like it should, but only if the for loop executes 0 times (very likely caused by an error), the error is cleared! Even no error handling would be better.
@billko wrote:
In case you are wondering how a loop can execute zero times, think of a FOR loop auto-indexing over an empty array...
I'm quite familiar with that. Probably a lesson I learn in my third week of LabVIEW programming (maybe slightly misjudging by the subsequent decades). The lesson being: use a shift register!
‎01-26-2018 03:58 AM
I should probably have clarified in my post, I meant non-zero length! 🙂
‎01-26-2018 04:00 AM - edited ‎01-26-2018 04:01 AM
@sebster wrote:
So what is the solution here then?
On the one hand you would want the error to move through each iteration of the for loop, but on the other hand a zero-sized array wouldn't carry the error from one side to the other.
Shift registers on both the error and reference tunnels are the way forwards, as they will be passed through even if the loop never executes.
Edit - sorry, missed your 'On the one hand' - wiebe's point about having a parallel wire carrying the initial error with a shift register, then a merge afterwards, feels sensible.