Jump to content
task

Selecting a Design Pattern

Recommended Posts

I have written many, many programs in LV but I'm sorry to say that I have not kept up with upgrading my coding skills. The last few years I've only written very simple programs that didn't have to do too much. We are a very small company that has really been struggling so taking a training class is not on the menu but I'm having a hard time finding examples, the examples I find are so simple.

My problem is how to go about selecting a design pattern. I am upgrading/enhancing a program that I wrote over 10 years ago and obviously want to use good techniques. I understand all the concepts but start to get overwhelmed when I start using one technique and figure out things that won't work, start over with a different idea, won't work...etc.

In the old program (don't kill me) I basically used a 3-stage sequence (initialize, main, destroy) with the main consisting of two parallel while loops inside a while loop, one to do stuff every 10ms and the other to capture user events. I know, I know, I can see eyes rolling. I won't get into the excessive amount of local variables used...

Very simply put, I want to do the exact same thing but better...read/write digital, read/write analog (user changes the analog control), user presses buttons to open/close valves, store data, and of course update my display values every 250 ms.

Since I have an actual project to work on (finally) I want to do it correctly. I've decided to start with a producer/consumer format and build from there.

Comments? Suggestions? I'm hopefully getting a few more projects soon and hopping back onto the LV train.

Thanks.

Share this post


Link to post
Share on other sites

Hi

Have you considered using classes?

Often when I want tasks running in parallel, I think about using 2 loops in my main VI, producers/consumer, but then I realize that I probably will need more parallel loops in the future.

So I go with a spawning VI for every parallel task I want to use.

So if you like to know how to get started you can watch these videos and download this code:

http://goop.endevo.n.../DesignPatterns

http://goop.endevo.n...videos/Debugger

http://goop.endevo.n...er/Debugger.zip

If you want to use the GDS tool you can download it here.

//Mikael

  • Like 1

Share this post


Link to post
Share on other sites

My problem is how to go about selecting a design pattern. I am upgrading/enhancing a program that I wrote over 10 years ago and obviously want to use good techniques.

Can you incorporate the requested changes into the existing code without rewriting it? Even if the current code is embarrassing at least you know it works.

I understand all the concepts but start to get overwhelmed when I start using one technique and figure out things that won't work, start over with a different idea, won't work...etc.

Unless you sit down with someone and go over your specific requirements, that's kind of what you have to do. Try something out, see why it doesn't work. Try something else, see why it doesn't work. Eventually you learn the limits of different design patterns and know when not to use them.

In the old program (don't kill me) I basically used a 3-stage sequence (initialize, main, destroy) with the main consisting of two parallel while loops inside a while loop

Why parallel loops inside another loop?

I've decided to start with a producer/consumer format and build from there.

Producer/consumer is a good starting point. I suggest avoiding the QSM implementation. Beyond that it's difficult to predict what problems you might run into. ("Cloud the future the dark side does.") It all depends on your requirements.

How precise does your timing need to be? Do you really have to execute your process every 10 ms? Is 15 ms okay? 20 ms? What about the 250 ms UI updates? Is 300 ms on occasion acceptable? 500 ms? If those are strict timing requirements you might have to add additional loops to execute those processes without other interference.

Share this post


Link to post
Share on other sites

Thank you MikaelH and Daklu...I will be looking at the links in a bit. I will be using the bulk of my existing program since I know it works on 3 other machines but I am embarrassed by it! Daklu, I have no idea why the two parallel loops inside of another main loop, I believe I had an issue with both stopping at one point. Probably overkill.

99.99% of my customers never see my code but one time I had a customer basically hand my a$$ to me over how bad my coding style was! He had been afforded the luxury of taking every available class from NI and worked at a very large company where he basically had time to try out stuff. I'm the only software engineer in a 5 person company so things are a little tighter!

Thanks again and I'll probably bug you both at some point with hopefully simple questions. I've never worked with classes so this will be a new venture.

Share this post


Link to post
Share on other sites

I'm the only software engineer in a 5 person company so things are a little tighter!

Labview's license allows you to install a copy at home. If it's been 10 years since you've done any substantial programming and you have clients waiting on your code I suggest doing that and spending a lot of time trying out different ways of implementing the practice CLD exams.

I've never worked with classes so this will be a new venture.

Like Mikael, I'd approach your problem using classes. However, depending on your experience and requirements it might not be the best solution for you. Learning the basics of OOP isn't terribly hard. Learning how to do OOP in a way that solves your problem takes much longer. On my first OOP project I ended up rewriting it nearly from scratch at least 3 times because I was running into issues that I couldn't solve with the architecture or class hierarchy I had created.

Share this post


Link to post
Share on other sites

I have it installed on my laptop so I can keep working on it at home but there is an issue that I'm currently working with NI on...MAX will not function correctly on the laptop even though it does on another identical one. Very frustrating. I was on the phone with tech support last Friday for 4.5 hours to no avail. I need it to work because I can't haul my desktop with me when I travel to load updates on my realtime PXI systems.

I decided to clean up my old code first and then start manipulating it. Worst case scenario, I know the old code works fine. This is probably the best project to experiment with because it's not hot right now and it's not overly complex. The "Manual" part of the machine is pretty simple but the "Testing" mode is going to be a little trickier (data storage, graphing, recalling data for comparison, etc).

Thanks again for all your help!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.