Im trying to get a variable on Labview that has an input and an output but i cant find one. Ive found local and global variables but then how do i use them.
I seem to be in the same predicament as you… I get the variables, but wiring anything to them gives broken wires. I think I have only found input variables.
FYI, the variables that I am talking about are in the programming menu.
EDIT: http://zone.ni.com/devzone/cda/tut/p/id/7585 - Looks like “change to read” is what you (I) want.
Chris,
After you create a control or indicator on the front panel (or right-click on a subVI or function and select “create control” or “create indicator” which does this for you automatically), you can create local variables for accessing it by right-clicking on its icon in the block diagram and selecting “create local variable”. If you use the “finger” tool on a local variable, you can change what variable is attached by selecting from all variables in the VI.
Russ
Thats just a local variable i know how to find them but how do i use one to input and output values.
Do what Booksy says - right-click and “change to read” or “change to write” to set it to an indicator/control (aka output/input).
When in doubt, right-click. It unlocks “everything”.
Russ
Yes but i want something that doest both at once that just lets it either read or write. Is there some way to connect a read variable and a write variable
why not make 2?
check whether the value is boolean or numeric, and make sure it wires to the corresponding input.
Yes but will those be connected. I want one value that will be changed by the joystick value and then will change the motor speed not two values. (Im not using the Crio stuff for testing so i cant use get motor speed or set motor speed)
Any wire in LabVIEW can be read from but can only be written to by a single output.
You can create as many local variables (either read or write variety) for the same “physical” variable. You can have many outputs “simultaneously” writing to the same “physical” variable via many local variables (see attached).
Russ
local variables.pdf (18.3 KB)
local variables.pdf (18.3 KB)
Be careful when you write to a variable. Its good practice to only write to a variable in one location, but you can read from the variable in many locations. If you write to a variable in multiple locations you are bound to run into race conditions.
Ok but if i have multiple variables then how do i know which one is which read is connected to which write variable.
That “example” that I published? FULL OF RACE CONDITIONS (intentionally). Good luck trying to figure out the order of precedence in that. I was simply trying to show that it’s possible.
The OS/program will only store 1 “real” copy of the variable in a single memory location. Every function can simultaneously read/write to the single memory location from “anyplace”. But as BLAQmx points out, be careful when you have multiple writes that are happening simultaneously.
You’ll never know which “write” “wins”. That’s why I use sequences to force program flow where necessary. Being a very single-threaded engineer, I use a LOT of stacked sequences.
Russ
Every variable can be either read or written to.I n that sense there is only one variable but two states. This single variable may have multiple copies of readers and writers, but they are all reading and writing from the same place in memory.
Let me know if the screen shot I have attached helps at all.
In your example you have variables with “X” and “Y” in them all i get are "?"s how did you rename the variable.
BLAQmx where do you find the boolean, string, and numeric all i can find are local, global, and shared and how do you name them.
I think you made a typo in your comments. The one says it has one writer and multiple readers, but it actually has one reader, and multiple writers.
You click on the ???s and choose from the list of controls. If you rename a control, the variable also gets renamed.
Greg McKaskle
I think you made a typo in your comments. The one says it has one writer and multiple readers, but it actually has one reader, and multiple writers
I’ll double check and repost the screenshot. Thanks!
In your example you have variables with “X” and “Y” in them all i get are "?"s how did you rename the variable.
BLAQmx where do you find the boolean, string, and numeric all i can find are local, global, and shared and how do you name them.
Tutorial: Local Variable, Global Variable, and Race Conditions
See the section Implementing a Global Variable
I’m not really sure why you want to use variables. You might be thinking too much in terms of procedural programming (like C or even BASIC) instead of treating LabVIEW as a dataflow programming method – which it is.
In LabVIEW programs, wires are essentially the variables. They’re what “hold” values as they move from where they’re produced to where they’re used.
Exactly. All you need to do is wire the output from your Get Axis VI from the Joystick Palette to the Set Speed VI (or equivalent if you are using your Drive motors) from the Motors Palette. You don’t need to use variables at all.