LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send LVClass content between loops

Hi all,

 

I just started learning Classes and I have doubt when converting my existing project to OOP based.

To read Digital Input from NI devices, normally I make a parallel loop that keep acquire the boolean array and shove it into an FGV, then use it wherever I need. I intended to translate it into something like this (just ignore the local variable :D) 

Snippet.png

 

1) (Aside from the Parent/Child selector) Is this okay, or it's not recommended? I read in another thread that FGV and OOP shouldn't be used together in one architecture for easier trace and debugging. Though personally I prefer option 2 to prevent clutter when using more devices. I put the global outside the class method just in case i want to use more than 1 device, but basically it's part of the class that should be configured be used when someone using this class.

 

2) Since DVR doesn't work with dynamic dispatch, is there any way to work around it? Let's say I want to change the hardware from NI to something that use Modbus, which of course have different initialization and read method.

 

I want to make sure I get the basic right before continuing. Any input is appreciated and thanks!

0 Kudos
Message 1 of 9
(1,462 Views)

Your picture is too small and to blurry.  And I can't open a .rar.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 9
(1,430 Views)

@paul_cardinale wrote:

Your picture is too small and to blurry.


Hover over the picture and click on the icon that shows up at the upper right.  That will open the picture full size in a new tab.

 

(Newly added forum feature in the last few weeks.)

0 Kudos
Message 3 of 9
(1,421 Views)

Sorry paul,

Here is the .zip version. As for the picture, that's a vi snippet though. I can click to zoom it on my laptop.

 

Note: I'm using LV2018 on Win10 Home

0 Kudos
Message 4 of 9
(1,418 Views)

It seems kind of odd to have a loop that's constantly reading devices and then putting the data someplace to be read later.

I'm generally opposed to mirroring data (unless there's a really good reason to do so).

Why not just read the devices as you need the data?

 

As for workarounds for no DD with DVRs, there's not much.  You can use an In Place Element structure to dereference the DVR, or

you can use the attached files.

"If you weren't supposed to push it, it wouldn't be a button."
Download All
0 Kudos
Message 5 of 9
(1,356 Views)

Seems like you should just be using a simple Producer/Consumer.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(1,352 Views)

@paul_cardinale wrote:

Why not just read the devices as you need the data?


I need to poll an Emergency Button all the time. The project is to test a product using some procedures. If the Emergency is pressed at anytime, all the Digital Output should reset to its safe state.

So since I need to read the input in parallel all the time, I thought why not just put the data inside an FGV instead to make it easier to trace (the acquisition only happen in 1 loop). And I just realize, that could result in not-real-time data (though in this project, the other input aren't that crucial). Should I change it to read the device instead of FGV?

 

And for the original subject, the purpose is trying to make an NI-Device class that can easily be used in N+1 condition. If I want to use Digital Input from NI-6151 and NI-9181, then I just need to drop the NI-DI class twice with a few configuration, then I can use the data anywhere in the program (including in different loops). Should I use the DVR-styled FGV for this? Because otherwise, I don't think I can't use the same instance in other loops.

I've used LabVIEW for some years now, but I just started learning the OOP (mostly from online source and the free NI training material since covid-19), so it's a little bit hard to change the mindset.

 

@crossrulz wrote:

Seems like you should just be using a simple Producer/Consumer.


Normally I use Producer/Consumer with QMH. But I must admit I tend to do some "duct tape" programming after the customer ask for quick and urgent improvement (and sometimes without proper documentation). I'm trying to repair that style, and people seems like OOP is recommended for more maintainable source code.

0 Kudos
Message 7 of 9
(1,312 Views)

 

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 9
(1,309 Views)

Hi Gabriel92,

Its nice to start looking at LVOOP as this way of programming has its own best benefits.As i see in the code you used class DVR as some global variable. I did not understand your intention here as the object can itself hold its the data  once its set methods are called...The same data can be called at all the places in your code using the get methods by passing ...Instead of using global variables,i can say that using the get method will make your code a more LVOOP one..

 

Regards,
Srikrishna


0 Kudos
Message 9 of 9
(1,260 Views)