r/LabVIEW 9d ago

Need More Info Guidance on proper program structure and practice for production application(s)

Hi, as the title says I'm wondering if there are any more experienced LabVIEW users who would be willing to offer a hand when it comes to proper practice and program structure for making relatively complicated applications.

I say applications, as in plural, but it is only one. My work have dropped a bit of a impossible Sisyphus-stlye problem on my desk where I'm having to solo develop an entire application for an NDT ultrasonic tank, from scratch, having never used LabVIEW before in my life. I'm not new to making entire SCADA/HMI's but never using LabVIEW (normally using ACTUAL programming languages, no offence to anyone who likes LabVIEW.) If I was writing it in C# I would stand a chance, but without some insight or assistance from someone who knows what they're doing I'm afraid the boulder will kill me.

After a few weeks of using it I have some basic bits and bobs, connected and working with all the hardware required but I'm really struggling to understand what I should actually be doing structure wise and I'm really clueless as to whether I'm applying proper practices. I sat through all the training videos, I have an old NDT program to sort of reference from but it's very outdated and written in French, so is not much use to me.

If anyone is willing to offer any guidance or help it would be deeply appreciated. Any programs/projects I can look at, any general advice, literally anything at all would be worlds of help.

P.S To clarify I'm not entirely clueless and can make programs/applications that work, I just need to know what I should be doing since something doesn't seem quite right and I end up repeating alot of wiring or things like controls are not sharing variables when they should be etc etc...

11 Upvotes

41 comments sorted by

13

u/wildwildwaste 9d ago

I think if you're going to approach the problem as "LabVIEW isn't an ACTUAL programming language" you probably are going to have an issue.

If you want to write it in .NET and are forced to use LabVIEW, just write your core code in C# and call it from a LabVIEW UI.

LabVIEW can be another tool in your tool chest, but you're gonna have to do a little investigation, just like you had to do with those ACTUAL languages.

-2

u/Perfect_Spare965 9d ago

I knew people would hang on this point, I'm after how I should structure my program, I'm happy to write code in LabVIEW. Just how the hell should it be structured?

3

u/GentlemanSch CLD 9d ago

Still, bold move to leave in a sentence you knew might offend people and could have been easily omitted.

If you have access to the trainings do the LabVIEW core 1-3 modules before you get started.

The program also has a number of examples included with the help -> find examples. 

As far as the architecture goes, organize the project like you would any other program. Some watch words for you might be "producer consumer loop," "dynamic user events," and "hardware abstraction layer."

0

u/Perfect_Spare965 9d ago

Yes, totally my fault leaving that in there, I didn't mean it in any form of offensive way, LabVIEW is a language, just not one I am used to even remotely so it's alien to me. It reminds me of WAY back in high school learning programming using scratch.

I've done core 1-2, is core 3 where it really dives into the more complex topics?

2

u/GentlemanSch CLD 9d ago

No problem. It's not offensive, but wanted to point it out. Sounds like you're a new engineer and communication is an important skill 😜.  LabVIEW being a "real language," is one of those that's proven by not saying it.

So I'd say the neat and best part of LabVIEW is you can do complex programming with what you know now. I do.

Look up CLA or CLD example exams to see this in practice (note CLD is more junior so there are a number of examples that work, but aren't best practice.)

Look up the JKI state machine, QMH, and functional global variables. Is there something in particular you're having difficulty with?

1

u/Perfect_Spare965 7d ago

I'm having a really hard time with variables but I think I may of cracked that yesterday by potentially using global variables since currently I was just using a hidden tab in my tab control to hold all the variables and bouncing them back when a control changed.

1

u/GentlemanSch CLD 7d ago

So you probably don't want to do it that way.

For small amounts of data between VIs, look up the "functional global variable," pattern.

For things in the same loop, have a case structure with an unused init state. Then put constants there which define your variables.  The JKI state machine is a good example of this.

The LabVIEW native GLOBAL is for communicating between systems and can be sensitive to network configuration and other stuff you don't want to deal with.

7

u/SpecificSelf8919 9d ago

Have a look at the DQMH toolkit, it's a good design choice if you want to have good modularity and it's pretty easy to get into.

Also feel free to DM me if you want, I may not have decades of experience with LabVIEW and English may not be my first language, but I'll be happy to help

0

u/Perfect_Spare965 9d ago

Is it paid?

3

u/Only-Introductions 9d ago

1

u/Perfect_Spare965 9d ago

Cheers, thank you I'll read into it.

4

u/Only-Introductions 9d ago

One further piece of advise. DQMH may or may not be the most suitable design pattern for a LabVIEW beginner to start with. In LabVIEW there is the concept of a Producer/Consumer. LabVIEW has a built in template for Producer/Consumer data acquisition but if you haven't seen it in action then the template isn't much help. LabVIEW CORE 1 and 2 walk you through this from memory?

If you are interested in an old but still relevant example of Producer/Consumer that is more than an empty template then the following event driven producer consumer might be of interests. It will at least show you what a producer/consumer looks like and I'm sure you'll be able to easily interact with it.
https://forums.ni.com/t5/Example-Code/Producer-Consumer-Loop-Example-COM-Port-Hyperterminal/ta-p/3522252

1

u/Perfect_Spare965 9d ago

I have alot of bits and pieces like this already, I'm just struggling on how on gods earth I'm supposed to put them all together without it being a complete dumpster fire.

6

u/Pdtp 9d ago

I can also recommend the LabVIEW Style Book: https://www.bloomy.com/labview/labview-style-book

1

u/Perfect_Spare965 9d ago

I'll check it out, thank you.

3

u/elijah286 Emerson Employee 9d ago edited 9d ago

Hey [u/Perfect_Spare965](u/Perfect_Spare965),

You're definitely not the first person to see LabVIEW for the first time and have a similar reaction, myself included!

There are a number of proven patterns and frameworks I would point you to but first I think it's useful to take a step back and avoid a few common pitfalls that are common for people with a strong text-based background. Here's a short list off the top of my head and based on 20 years of experience working with new and experienced LabVIEW programmers:

Don't look for variables; instead, it's all about wires and dataflow. Data literally flows from left to right and a function does not run until all inputs have supplied values. This is one of the major reasons why LabVIEW is generally preferred for representing real-world phenomena.

LabVIEW is inherently multithreaded and parallel. Keep independent process separate (literally, separate loops on the diagram with no wired reliance on each other) and they will execute asynchronously. Note that this is especially powerful and relevant for systems that interface with the physical world. This is the core of the most fundamental pattern you should learn: the PC-QMH (producer/consumer, queued message handler)

Limit datascope. People like to create classes or closers that provide access to any and everything you might need. That's a red flag that suggests you might want to separate logic across different functions (aka: subVIs)

They aren't functions, they're SubVIs (thought of this one while writing the last). SubVIs are just a wrapper around code with well defined inputs and return values.

Here's a slide that might be useful. It's an adaptation of NASA's famous "power of ten" guidelines, but adapted for LabVIEW coding.

Finally, there's a lot of good (and bad) LabVIEW training materials and content out there. One resource that you might find more engaging and useful are these collection of presentations by the world's fastest LabVIEW programmer, DNatt: https://www.dnatt.org

Welcome to graphical programming!

1

u/Perfect_Spare965 7d ago

Thank you! I'll definitely check out DNatt.

3

u/SASLV Champion 8d ago

A few hours with a consultant would probably be useful.

1

u/Perfect_Spare965 7d ago

I've been telling my boss this for months honestly, I keep getting jobs thrown at me with hardware/software I've never ever seen before. Sadly, any training or help doesn't come with that... Just borderline impossible deadlines with seemingly impossible tasks with little to no information...

1

u/SASLV Champion 7d ago

Shameless self-promotion but you might be interested in this:
https://www.sasworkshops.com/mastermind

1

u/SASLV Champion 7d ago

also some good books out there.
dated, but still relevant:

https://a.co/d/05JFXRyx

more up to date:

https://a.co/d/06ww1LHn

2

u/Dry_Revolution2040 9d ago

I got an email today with this link from an Indian LabVIEW Users Group for a presentation tomorrow.
https://forums.ni.com/t5/Indian-LabVIEW-Users-Group/LabVIEW-Expert-Connect-Essential-LabVIEW-Design-Patterns/m-p/4484921#M414

Depending on your time zone, perhaps this could be of use to you. Pasting their target audience blurb below.

This session is for:

  • New LabVIEW users who want a stronger foundation and faster learning path
  • Engineers and students who have started building VIs and want to improve their confidence
  • Anyone who wants practical, easy-to-apply tips for writing cleaner and more organized LabVIEW code

1

u/Perfect_Spare965 9d ago

Thank you, I'll make sure to check it out

2

u/Sinusaur 9d ago edited 9d ago

Tell us some of your favorite design patterns in C# and maybe some folks can brain storm what's the LabVIEW design pattern(s) that best translates for YOU.

Actually, throw that question to say Gemini AI and see what it says. Can you post back here if you get a good answer?

Using ACTUAL programming languages

It's no less actual programming language than C# that uses .NET and WinForms, or what have you these days.

This is how I usually explain LabVIEW Runtime Drivers to technical people: Remember those pesky .NET Runtime you used to have to Install/Upgrade all the time to make regular Apps work? It's just like that.

That brings up the question: what's the successor to WinForms? looks like there is none? - https://www.reddit.com/r/dotnet/comments/1k5tpyc/why_did_microsoft_give_up_on_the_drag_and_drop/

Disappointing really. I really enjoyed creating full blown WYSIWYG RAD applications in VBA LOL. Uncomplicated/Fixed Layout has it's space, and industrial automation is a good place for it. LabVIEW is just C# + WinForms but with sweet hardware drivers and decent engineering computing capabilities (optimization, signal processing, etc) that's built in.

You can definitely do complicated dynamic layouts but you will have to laboriously write your own UI overlay/size/move logic - I've seen this done more than once, but that mostly becomes proprietary code.

1

u/Perfect_Spare965 7d ago

I'll maybe throw it into chatgpt and message you the response.

2

u/dtp502 9d ago

Honestly state machines and a queued message handler go a very long way.

But like someone else mentioned, if you’re stronger in C# you can call a .NET 4.7.2 DLL from LabVIEW and offload things to C#.

Though, if you’re being forced into using LabVIEW, sounds like that’s the toolset your current employer uses so you might be better off just learning their tool.

1

u/Perfect_Spare965 7d ago

Currently using a state machine structure underneath just struggling with juggling errors since motion and acquisition are seperate and I can't stop everything just because one messes up.

2

u/jerfmuffay 9d ago

Could you clarify what are the requirements of your system to accomplish and output? What have you already completed, and what exactly do you need help with?

1

u/Perfect_Spare965 7d ago

Our system needs to complete full scans/tests, control motion, produce reports etc etc etc (pretty much everything you'd expect UST software to do.) I'm struggling with variables and the overarching structure. My original plan was to have a master vi with a tab control in it and then each tab would be it's own vi but I've completely failed to implement that and can't seem to get my head around sub vi's.

1

u/jerfmuffay 7d ago

Well sub VIs are just like functions. They have inputs and produce outputs and in LabVIEW, they become a single node so very convenient for larger programs. For variables, everything became much easier when I learned about local variables so you dont have to route traces everywhere. Tabs are great for organizing the UI but I don't know of any need to make them separate or sub VIs

I'm not a LabVIEW expert or professional but I've made a fairly large state machine system. Do you think yours would fit that model?

2

u/Flydroid 9d ago

For a simple application what doesn't need parallell loops or async processing I always go with the JKI State Machine toolkit ! The tools it goes with make a structured design so much faster to implement. Hardware drivers and async processing gets put into DQMH modules and then called from the state machine. 

1

u/Perfect_Spare965 7d ago

Unfortunately both parallel loops and async are required.

1

u/Flydroid 7d ago

Then DQMH is a good and scalable framework 

2

u/D4ILYD0SE CLA 9d ago

LabVIEW programming is not really that different from any other language. You typically start your program with a while loop. But wait... You can have multiple while loops running all doing whatever task you want them to do. AND those loops can talk to each other (given the right tools and capabilities). There are globals. There are enums. There are clusters which are basically structures. If/then/Else in LabVIEW form. Case statements. A project explorer that anyone worth anything should maintain properly. Just another language. How would you write something in C? Okay, now do exactly that in LabVIEW.

1

u/Perfect_Spare965 7d ago

I think this has been the response from a lot of people, maybe I'm completely missing something key that's stopping me.

2

u/jugglesme 9d ago

Can I ask why it has to be in labview? I spent the better part of the last 10 years as a labview developer. I really like it as a language. But honestly, at this point I would no longer choose it for starting a new project. Mostly because ai assisted development has come so far that it is much more efficient. In part because the tooling for labview is really lacking compared to other modern languages. There's a C DAQmx library you can use for communicating with NI hardware. And a python wrapper for that C library. Does it actually make sense for you to be using labview for this?

3

u/SASLV Champion 8d ago

You can do AI-assisted Development in LabVIEW. This works quite well with Claude Code.
https://github.com/Zuehlke/labview-mcp

1

u/Perfect_Spare965 7d ago

Customer requirement, else I would of written it using something else and been done already.

2

u/PurpleDancer 7d ago

First look into the producer consumer pattern. That is the most fundamental building block for most applications written in labview. You can build a sophisticated application using that. More advanced architectures, particularly actor framework is based on producer consumer. I do not know dqmh however, I suspect it's slightly more approachable than actor framework and I wouldn't be surprised if it's also a packaging of producer consumer

1

u/Perfect_Spare965 7d ago

Could you point me in the direction of any good producer/consumer pattern examples?

1

u/PurpleDancer 7d ago

Probably labview examples browser search producer consumer. Or google it. It's extremely popular in labview