01-09-2023 08:57 AM
The attached code all works, but I’m hoping some LabVIEW gurus can give me a high-level review of the code structure before I rebuild a similar code. I work mainly with text programming, so I’m sure there are many LabVIEW best practices or alternative structures that could improve on what I’ve got.
Overview: The code controls hardware to operate an experimental burner apparatus and record data. A summary of the function moving from top down in the wiring diagram:
Questions: I would value any feedback on LabVIEW best practices or suggested improvements. In particular:
The attached laser_table_4-4 is an earlier, less cluttered version, and the _5-4 is significantly bloated with additional hardware interfaces.
Solved! Go to Solution.
01-09-2023 09:17 AM
Well at first glance I will tell you this One Big Loop (OBL) is never a good programming architecture.
Consider a Producer/Consumer architecture. Have the Producer Loop handle your data acquisition and the Consumer loop handle analysis and writing to a file.
I might have time to take a closer look later and give more specific advice.
01-09-2023 01:41 PM
Hi d-thomas,
@d-thomas wrote:
Questions: I would value any feedback on LabVIEW best practices or suggested improvements. In particular:
- Is there a better way to accomplish the dual rate operation: with a higher frequency for control functions, and a lower frequency for data read/write? (As it is, the first loop every second takes ~0.4 sec for the DAQmx read and write operations, and then it loops ~20 times during the remaining 0.6 sec without the conditional block.) I don't want to separate this into two separate VIs, as I need parameters and data from both loops to be written to a single output file.
- The Alicat hardware interface includes initialization, runtime communication, and shutdown blocks, so I don’t see any more efficient way to handle multiple modules. (My next version will include six identical blocks for six Alicat flow controllers.)
- I’ve ended up with a lot of very long connection lines, and it seems like writing/reading named variables would be one way of clearing that up. Do you see any other relevant strategies for reducing the clutter?
The attached laser_table_4-4 is an earlier, less cluttered version, and the _5-4 is significantly bloated with additional hardware interfaces.
I can also recommend to use some better code architecture than "one big loop"…
So much room for improvements!
Btw. your "v5.4" VI is an empty file in that ZIP, so we cannot comment on that one.
01-09-2023 03:22 PM
@GerdW and @RTSLVU,
Thank you both for the replies and the suggestions! It will probably take me a while to work in these changes -- including the needed subVIs. But you've given me many good points to work on. (Several were things I never considered: I didn't think of "ToDDT" as an Express VI!)
The biggest structural change would be splitting this into producer/consumer parallel loops. In this case, I would have the controller loop at 20 Hz and the DAQmx at 1 Hz. But I would need to write variables from both loops (at 1 Hz). In the past I've looked at the queue or channel wire options for this, but didn't find any examples that seemed to fit what I'm trying to do. What do you see as the best approach? And are you aware of any examples that involve merging data from two different frequency loops?
Oh, and no need to see the 5.4 version -- I fixed a few things, but mostly it just gets bigger and uglier 🙂
Thanks,
Daniel
01-09-2023 04:48 PM
Bob Schor
01-10-2023 12:03 PM
Bob_schor -- thank you for the note and suggestions! I currently don't have this in a Project file, so that is another thing to correct.
I did find your demo code here: https://forums.ni.com/t5/LabVIEW-Channel-Wires/Channel-wires-vs-NI-QMH-and-DQMH/m-p/4197406 Unfortunately, this was in LV 2019, and I only have 2018. Any chance you could send me a screenshot?
- Daniel
01-10-2023 10:26 PM
Daniel,
If I did this right, here is the Lenny of Pisa demo in LabVIEW 2018. Let me know if you it works for you.
Bob Schor
01-12-2023 04:24 PM
Hi Bob -- Thanks for sending that! I'm able to open it in LV2018, but I get an error message:
Is that a standard LabVIEW component that I can replace?
Daniel
01-12-2023 10:01 PM
Ah, yes. That is the Messenger Writer -- it's "broken" because I "saved for 2018", but don't have 2018 installed, so I couldn't build the Messenger writer.
Delete the writer. Right-click the Cluster (where the Cluster-wire is coming out to connect to the Channel Writer) and choose "Create", which will create another Dropdown, choose "Channel Writer", and then choose "Messenger". If you do this right, some scripting will run, and the Messenger Writer will appear. This will ultimately generate (someplace you can't see it easily, but don't worry about that) the "Write.vi" that is missing. You'll have a similar problem (probably) with the Channel Reader. There is also a Stream Channel Writer/Reader pair. This picture shows the Writers (the Messenger Channel is a cluster, so the Pipe is Pink, while the Stream Channel is an I32, so the Pipe is Blue. The corresponding Readers (which you create sort of the same way, except you need Channel Reader) are the un-arrowed items that resemble the Writers, but with the Data Direction arrow indicating data flowing out from the right edge of the function.
Bob Schor
03-31-2023 12:22 PM
Thank you all again for the helpful suggestions. I'm accepting the Channel Reader/Writer details as the 'solution' as that made the biggest difference in improving my code. For my situation, I ended up with: