PDA

View Full Version : Making global variables in LabVIEW.


Joshamuffin
01-19-2009, 12:00 PM
I made separate VI's to control the drive motors. In the default program, there are global variables that are device references. I need to make my own device references for the joystick and the motors. Otherwise I would have to copy/paste the code directly into the main body, which I would like to avoid.

Russ Beavis
01-19-2009, 12:35 PM
What's the question?

If you right-click on the "cRIO" in your LabVIEW project window, you should be able to create a "global" that you can copy whatever controls and indicators you'd like into. The "global" actually looks and feels exactly like the front panel of a VI. It's just a container for arbitrary data.

You can drag any variable within the global into any VI within the project and share the data.

You can probably also modify the global that is in the default project by adding new variables.

Globals can be very useful for sharing data across VIs that are called from the same "main" VI. Just be careful with race conditions and multiple writes to the same variable at the "same" time (especially if you've got multiple programmers who want to write to a single global variable). In general, I like to limit "writes" to one VI and let every other VI "consume" the data.

Russ