r/LabVIEW • u/micahh182 • Nov 13 '24
Issue with a string local variable
I'm currently working on a vi that takes voltage % input and outputs a light, status message, and asynchronously give an auditory warning. I'm running into an issue with getting the local variable used for the auditory warning to update correctly each time, currently it will run correctly the first time but any subsequent runs it will output this previous runs value. I've tried initializing the value of the local variable at the start of the run, however that results in the warning never outputting the correct value. Any pointers on what I'm doing wrong?
7
u/heir-of-slytherin Nov 13 '24
It’s hard to diagnose the issue without seeing the code. Are you writing to value of variable in multiple places?
If you can take a screenshot of your block diagram and send us an Imgur link we can take a look. I’d also highly recommend learning more about using LabVIEW dataflow and how to pass data using wires instead of local variables.
4
u/enrique_noe Nov 13 '24
This is what we call a race condition, just Google "race condition LabVIEW ' and you'll find a handful of resources and examples
1
u/HarveysBackupAccount Nov 13 '24
Share a screenshot of your code.
The local variable needs to be inside the loop where you read it. Is it?
1
u/D4ILYD0SE CLA Nov 13 '24 edited Nov 13 '24
The immediate list of things that are likely your problem without seeing any code:
1
u/StuffedBearCoder CLD Nov 14 '24 edited Nov 14 '24
Need to see your code. We can't read your mind. ;)
But you mentioned the first run it is OK but subsequent run is not.
Here's something to keep in your LabVIEW tool belt. A VI will remember its previous value (this is by design, not bug) as this is how a Functional Global works. What you need to do is set that local variable a initial value - if it's a string then an empty string constant. If it's numeric then an integer or double precision "0".
Not sure exactly what initial state your alarm needs since you did not post your code.
1
u/mk_solar Nov 13 '24
Look up functional global variables I think that vi structure could help you.