05-01-2019 12:51 PM
@gkartik wrote:
"So, the calculation and the 8 reads can happen in any order! Imagine, 4 reads of stale data, a write to the indicator and 4 reads of new data! as an example! without dataflow the values read are unknowable."
I don't know how local variables work. But from what you are saying, the data transfer from the indicator to all other local variables don't happen simultaneously. So it can cause problems and wiring can eliminate them. Am I correct? Can you some simple example to demonstrate your idea.
The intent of the local variable is to provide the current value of the control/indicator being read. Because your code does not have dataflow dependency it will attempt to run in parallel. The order in which parallel code runs is unpredictable. The local variable will not read the control/indicator until the local variable is ready to be read. In the meantime it could be possible for the value of the control/indicator to have changed.
Attached is a quickly written vi where I added waits to control the order of execution to show what can happen. In my example Numeric 2 and Numeric 3 both read from local variables from Numeric 1, but Numeric 2 reads the data, then Numeric 1 writes new data, then Numeric 3 reads the data. Thus Numeric 2 and Numeric 3 have different values.
05-01-2019 12:58 PM
Wires enforce ordering, because they have a direction. Things that receive data from a wire (e.g. indicators, or input terminals of other nodes) cannot run until data becomes available on that wire from the source (each wire can have only one source, but multiple destinations).
When you use a Local Variable, essentially you're allowing multiple sources for the "same" data. But you don't specify when they should be read (indeed, without ugly use of Flat Sequence Structures or similar, it's quite difficult to enforce ordering for a Local Variable). As a result, their values might be read at any time within their 'sequence block' (possibly not a real term - I mean the frame around them, e.g. For loop, While loop, Case Structure, etc), and if you have multiple copies, (especially containing reads and writes) they might not be the same.
I put together an example, but it didn't initially show the behaviour I'd expect. Once I added some parallelism, it very quickly fell apart (but possibly that's not representative of your situation). None-the-less, it does illustrate something 🙂
05-01-2019 01:18 PM
@gkartik wrote:
@altenbach Could you please suggest me some resources from where I could learn good programming styles. Because it is difficult to make a good readable VI without good programming practices.
When I got started in LabVIEW, I bought Peter Blume's "The LabVIEW Style Book" (and I've been bugging Peter to write a second edition for about a half-dozen years). I read it cover to cover at least three times my first year, and have read it several more times. I adopted and adapted many of his points, and try to "hint" to colleagues to adapt "better style", focusing on neat wiring, "one-screen" block diagrams, encapsulating detail in sub-VIs, making icons (even if only 3-4 lines of "text-in-a-box"), and always writing a minimum VI Description.
Bob Schor
05-01-2019 01:32 PM
Quick, albeit ugly looking, method based on @Kyle97330 excellent suggestion.
Lots more can be done, 2012 vi attached.
mcduff
05-01-2019 01:43 PM
@gkartik wrote:
@altenbach Could you please suggest me some resources from where I could learn good programming styles. Because it is difficult to make a good readable VI without good programming practices.
LabVIEW ships with many examples and design templates that you should inspect closely. There are also plenty of online examples and even books as suggested by others.
Nothing beats hands-on experience and constant exercise. Write code, step back and think about better alternatives. Make mistakes, recognize the mistakes, correct the mistakes and learn from them (and never make the same mistake twice!), make new mistakes, etc. Repeat!
Analogy: You cannot become a faster runner by only reading books about running. You primarily need to run as much as possible! Still, a book about running physiology (nutrition, posture, pacing, etc.) can help you get more efficient faster while avoiding injuries.
05-01-2019 02:44 PM - edited 05-01-2019 02:49 PM
Thinking more about the Giant Block Diagram and Plethora of Local Variables, I agree with McDuff's depiction of @Kyle97330's suggestion. I'd go a few steps more:
Here is the code (as a LabVIEW 2016 Snippet -- I also attached the VI and TypeDef).
No Local Variables
I probably shouldn't mention this (as it is my first time presenting at NIWeek, and I'm slightly nervous), but I'll be discussing "Using and Abusing Channel Wires" on Monday, May 20 at 4:30 pm. It will be a tad more complicated than the above ...
Bob Schor
P.S. -- of course I forgot to attach my VI and Control, but was saved by the Edit Your Reponse button ...
05-01-2019 02:47 PM
@Bob_Schor wrote:
I probably shouldn't mention this (as it is my first time presenting at NIWeek, and I'm slightly nervous), but I'll be discussing "Using and Abusing Channel Wires" on Monday, May 20 at 4:30 pm. It will be a tad more complicated than the above ...
As long as you show your code, I think you will be fine, and give an excellent talk.
mcduff
05-01-2019 03:02 PM
Drat! I think I used the correct Snippet, but attached a flawed VI. Here's the correct one, with my apologies.
Bob Schor
05-01-2019 03:05 PM - edited 05-01-2019 03:07 PM
@mcduff wrote:
As long as you show your code, I think you will be fine, and give an excellent talk.
Well, they provide a PowerPoint Template which means "pictures of code", but I will have Laptop with VIs as well (and have a few "Show Code Now" slides ...).
Bob Schor
05-02-2019 11:51 AM
@billko wrote:
@JÞB wrote:
@billko wrote:
Unfortunately, the forum does "pre-processing" of pictures before displaying them, so your snippet won't work. You'll have to upload the snippet as a file. I'm already afraid of what I'm seeing though. You know that LabVIEW doesn't really flow left to right; it just appears that way because you connect the nodes together from left to right - usually. That being said, the "floating code" that you have in there can execute at any time it feels, and if you have locals attached to it, you may or may not be operating with stale data.
Bill, you can download the png from the picture manager then the snippet works fine
Perhaps we should update the sticky at the top of the forum?
Bill, read the thread! That info is in there 😄