LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global variable in Instrument Drivers

Solved!
Go to solution

Hi,

 

We are designing an Instrument Driver for our devices. We do have VI's that does the same operation but with different Inputs and this Input is a cluster of references.

 

I would like to gain knowledge if all this VI's can be clubbed together by making those clusters as global variables. Through this way I hope we will significantly optimizie our code.

 

We are also looking for the drivers to get certified by the NI so looking for any sort of solution if making global won't be a good solution for achieving optimization.

 

Thanks In Advance,

VIvek

0 Kudos
Message 1 of 5
(2,650 Views)
Solution
Accepted by topic author vivekkde

I don't quite understand what you mean by "clubbed together". Using global variables will not magically make your code more efficient. There's uses for global variable, and there are places where they should not be used. A reasonable use is to hold data used by muliple processes, though a queue is in most cases a better way to go.

 

The best way to see how to write an instrument driver is to download recent instrument drivers from the NI Instrument Driver Network. Look for the ones that are project-based as these are done in 8.x and are quite recent. Don't bother with the old drivers - they're a mess. You should be able to find something that's similar to your instrument and use it as a template. There's also an Instrument Driver Wizard that comes with LabVIEW. Another source of information is the NI Knowledge Base. Do a search, and you'll find lots of information. Like this: Developing LabVIEW Plug and Play Instrument Drivers.

 

You should also read over Ben's nugget on Action Engines

Message 2 of 5
(2,633 Views)

Hi,

 

By clubbing together mean i want to create a generic VI. Now this VI will work with different different control Input but the logic for all of them is same. Hence I am looking for something like a global variable that will hold the appropriate Cluster and hence want to know whether the usage of global variable in the instrument drivers are accepted or not.

 

Thanks in Advance,

Vivek

0 Kudos
Message 3 of 5
(2,597 Views)

teststand wrote:

...and hence want to know whether the usage of global variable in the instrument drivers are accepted or not.

 

Thanks in Advance,

Vivek


I view "with a jaundice eye"* any code that uses a global variable.

 

I suggest you do a search on "globals evil" to get a feel for how globals are viewed.

 

Ben

 

* Shakespeare, Hamlet Act I Scene 2 (?)

Message Edited by Ben on 03-09-2009 08:11 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 5
(2,579 Views)
Whether or not global variable use in instrument drivers is accepted or not is the wrong question. It's no different than asking whether for-loops are accepted or not. Global variables are a programming tool, just like for-loops. They have their uses. You should design your instrument drivers using the proper architecture, and then it will usually become obvious whether a global variable is the right way to go. The link I gave you before are a good starting point. You should start there. Ben's suggestion about searching for "globals are evil" is also a good suggestion. Keep in mind that there are 2 camps on this. One camp is the "globals are evil", and the other is "globals have their uses". Do not succumb to either dogma. Read what is said, understand the principles, and make your own decision.
Message 5 of 5
(2,568 Views)