LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a global for device handle

I am wondering if it is a good or bad practice (or perhaps doesn't matter) to keep the handle of an open device as a global variable. See image below for example:

 

global device handle.gif

www.vartortech.com
0 Kudos
Message 1 of 10
(4,026 Views)

I find it better to use an Action Engine to control your devices.  That way the reference stays local to the VI.


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 2 of 10
(4,022 Views)

@crossrulz wrote:

I find it better to use an Action Engine to control your devices.  That way the reference stays local to the VI.


These days I actually prefer to use a LVOOP object. You can create a singleton object so no wires need to be passed. The benefit of using this method is taht you can create various methods (what would have been actions selected with the ENUM in the action engine) but you have the freedom of having different connector panes. Much more flexible.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 10
(4,009 Views)

Here's a reference for the Singleton Pattern in case you want to go that route.  https://decibel.ni.com/content/docs/DOC-13462


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 4 of 10
(4,000 Views)

So I guess the comments so far points to "there are alternatives, but it is OK".

www.vartortech.com
0 Kudos
Message 5 of 10
(3,997 Views)

No, the comments go to "your approach may work, but using alternatives might reduce errors..."

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(3,988 Views)

@GerdW wrote:

No, the comments go to "your approach may work, but using alternatives might reduce errors..."


 

"may work"... What problems I might face?

www.vartortech.com
0 Kudos
Message 7 of 10
(3,982 Views)

Hi,

 

"Race Conditions" are a big topic, whenever you don't obey the DATAFLOW...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 10
(3,975 Views)

@Enrique wrote:

@GerdW wrote:

No, the comments go to "your approach may work, but using alternatives might reduce errors..."


 

"may work"... What problems I might face?


People randomly closing your task and not updating the task...

Multiple people trying to muck with the device at the same time (race condition)...

 

Please, learn from our experience.  Do not go the route of using a global to hold your task.  You will be much better off if you contain your drivers using an Action Engine or a Singleton.


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
Message 9 of 10
(3,965 Views)

OK, race conditions, I am well aware of that.

 

"People closing things"... yes can happen. (I found this funny, imagining people inside your code Smiley Tongue)

 

I think I had the insight. Thanks for your responses!

www.vartortech.com
0 Kudos
Message 10 of 10
(3,941 Views)