05-10-2010 06:12 AM
Helo community!
I'm trying to set my GPIB parameters and some COM parameters with Global Variables. The reason I want to do this is that I have several VIs using the same instruments. I'm starting those VIs with an eventhandler in a Top level VI. Those VIs wont run simultaniously. I don't want to set my connection parameters in every VI but am looking for a solution to set them once in th top level VI. My first idea was to use Global variables. However, I haven't worked with them jet so my aproach might be wrong.
I would greatly apreciate some help on how to do this
Florian
05-10-2010 08:41 AM
I believe your approach is correct: that's what global variables are intended for. Furthermore, GPIB address is set once and for all, so no risk of race conditions.
However I'm not a guru, maybe there's a risk I don't see?
Regards
05-10-2010 09:23 AM
Hello xdaf!
Thanks for the reply. However, I can't conect a global variable to where I set my GPIB Adress. Like I said, I never worked with Variables so a simple example would be very helpfull.
thx Florian
05-10-2010 09:37 AM
There's a thread in the Breakpoint forum debating the "evilness" of global variables. You can read that if you wish. I do not sit in the "global variables are evil" camp, but they can easily be abused/misused by newbies. The primary problem that regulars on these forums see is that of race conditions. There are other issues, such as data copying, but for something relatively simple like GPIB addresses, that's a non-issue.
Can you use global variables for what you're doing? Yes. Is it a good solution? Define "good solution" is my first response.
An alternative is to use a class-based approach for your instruments. This approach is scalable, but obviously more complicated, and requires a little knowledge in object-oriented programming. I use a pseudo-class-based approach in the programming I do primarily because the object-oriented support in LabVIEW 8.2 is flaky. It's all based around storing the instrument information around a LV-2 style global, aka functional global, aka Action Engine.
05-10-2010 09:37 AM
FlorianJ wrote:Hello xdaf!
Thanks for the reply. However, I can't conect a global variable to where I set my GPIB Adress. Like I said, I never worked with Variables so a simple example would be very helpfull.
thx Florian
Examples ship with LabVIEW. Open the Example Finder and search for "global".