12-05-2012 12:28 PM
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:
12-05-2012 12:37 PM
I find it better to use an Action Engine to control your devices. That way the reference stays local to the VI.
12-05-2012 01:43 PM
@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.
12-05-2012 01:59 PM
Here's a reference for the Singleton Pattern in case you want to go that route. https://decibel.ni.com/content/docs/DOC-13462
12-05-2012 02:01 PM
So I guess the comments so far points to "there are alternatives, but it is OK".
12-05-2012 02:14 PM
12-05-2012 02:24 PM
@GerdW wrote:
No, the comments go to "your approach may work, but using alternatives might reduce errors..."
"may work"... What problems I might face?
12-05-2012 02:33 PM
12-05-2012 02:57 PM
@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.
12-06-2012 08:32 AM
OK, race conditions, I am well aware of that.
"People closing things"... yes can happen. (I found this funny, imagining people inside your code )
I think I had the insight. Thanks for your responses!