cancelar
Mostrando resultados para 
Pesquisar então 
Você quer dizer: 

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
Mensagem 1 de 10
4.733Exibições

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



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
Mensagem 2 de 10
4.729Exibições

@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
Mensagem 3 de 10
4.716Exibições

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



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
Mensagem 4 de 10
4.707Exibições

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

www.vartortech.com
0 Kudos
Mensagem 5 de 10
4.704Exibições

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
Mensagem 6 de 10
4.695Exibições

@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
Mensagem 7 de 10
4.689Exibições

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
Mensagem 8 de 10
4.682Exibições

@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.



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
Mensagem 9 de 10
4.672Exibições

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

 

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

 

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

www.vartortech.com
0 Kudos
Mensagem 10 de 10
4.648Exibições