LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

local variable problem

hi guys

I'm new to this board and have a bit of a Labview Issue..............

I'm doing a piece of work in labview 7.1.1 & 7.1 @ the moment............(assuming the software differences are minimal and won't affect my work - @ home it's 7.1.1 and uni it's 7.1

got a problem i've encountered in the past and it's seriously annoying me!

ok.............

I have an 8-bit boolean array - i'm taking each bit and storing it into a boolean indicator via a variable

the actual variables themselves on the block diagram are elsewhere outside of this loop and i'm writing to a local variable from the 8-bit array

so the bit from the array stores into the local variable no worries

I have another local variable elsewhere on my VI in a differing while loop that reads the value of this and will react to a change in an event structure

the local variable that is reading in this other loop is not getting the updated value from the boolean indicator, despite it storing into the local variable ok there in another while loop

I was under the impression that local variables were a reliable way of getting info in and out of running loops?

my tutor has suggested it may be thrashing, but my loops are all set with a uniform 'wait until next ms multiple' value in them - he also suggested it may be race conditions and i'm setting a differing value to this variable elsewhere, but there is only the variable itself and the 2 local variables related to it which I have mentioned

does anyone have any suggestions or things to try please? really stuck and this problem is getting my behind 😞

sorry my description is a bit poor, I could provide a screenshot of the work if necessary?

thanks in advance for any help,

Mike

Message Edited by Michael Burgess on 03-13-2005 10:29 AM

0 Kudos
Message 1 of 14
(7,708 Views)
Hi Mike,

I'm not sure, if I fully understand your problem. You need to read and write to a local variable from two different locations in your VI, like in the simplified attached (scrrenshot of an) VI?

If both of your while loops are supposed to run in parallel, make sure that the inputs to one while loop (loop2) don't depend on the output values of the other loop (loop1). Otherwise loop2 can't execute before loop1 is finished.

-B2k
0 Kudos
Message 2 of 14
(7,697 Views)
Local variables are a reliable way to transfer data as long as you don't make a mistake (which can be easy, especially if you have complex VIs). An image of the second while loop (or preferably the code) definitely won't hurt, but before you post - you say your second loop has an event structure. Where is the local in that loop? In or out of the event structure? Here is where an important principle of LV comes into play - a node will execute/be read/written to when all the things before it have completed. If the local is outside the event structure it will be read when the iteration of the loop starts and not when the event executes, so by the time the event is executed, you would still have the value that was read when the iteration started. You can see this if you turn Highlight Execution (the light bulb button) on. If this is not the case, posting the code would probably be best.
Regarding 7.1 and 7.1.1 - I don't know the difference between them (no 7.1.1 here), but if you're managing to open VIs saved in 7.1.1 in 7.1, you shouldn't have a problem.

___________________
Try to take over the world!
0 Kudos
Message 3 of 14
(7,690 Views)
Yes, please attach your code or an image. There is nothing special with a local variable of a boolena array. (See attached example, LabVIEW 7.1). Local variables can lead to complications because of the lack of data flow. How fast are your loops? Do you get no update at all or does it simply lag one iteration behind?
0 Kudos
Message 4 of 14
(7,504 Views)
Hey guys

Many thanks for the swift responses

The posted VI's are along similar lines and are all working fine on my machine here at home

This is a screenshot of the bit that is causing me bother!

It's in a sequence diagram - basically the first part off to the left of the screen sets up a card for I/O in the correct mode, the next sequence contains all of my indicators and controls (I have also tried placing these in the next sequence but to no avail - then the next sequence is the bulk of it - the top loop is reading from Port B on the card - it gets a value between 0 and 255 depending on the status of sensors - so I’m splitting this off and putting them into Boolean indicators - so the correct value is coming out of the top loop into the local variable, but if I probe the 'read' local variable below, it is not getting the new updated value - then if that Boolean logic 'and' is satisfied, I wanted the event structure to react to it - not fully sure the event structure will work, although I can't think of a reason why not

I’m still new to Labview so may have a glaring error, but you know the deal - stare at your own code for too long and you overlook silly mistakes! I looked at using queues and notifiers to pass the data around but had trouble making it work - I could do a simple VI for queues no worries, but when it came to reading from the card and using them it was a different matter!

Thanks for your help guys!

Mike
0 Kudos
Message 5 of 14
(7,683 Views)
You can only attach one file at a time, so your code wasn't posted. If you want to post more than one file, you can zip your files or, if posting only VIs, you can save them as an LLB (File>>Save with Options).
From looking at your picture, it looks as if what I said earlier is the correct explanation. The event structure only executes when one of its events is fired. When you probe the local in the bottom loop, you're actually not getting any value at all - depending on your probe, you'll either see a grayed out FALSE, meaning that the code didn't run through there, or you'll see a dark green LED, meaning basically the same, but indistinguishable from a regular False LED. The code at the top of the bottom loop is executed once and then the event structure waits for your event. If you wire an indicator from the i of the bottom loop you'll see that the loop doesn't advance. If you want this loop to iterate constantly, you should wire the 5 into the timeout input of the event structure.

___________________
Try to take over the world!
0 Kudos
Message 6 of 14
(7,677 Views)
I agree with tst. THe event structure block your lower left loop. It only spins if an event occurs.

You have several paralell loops all running at 5ms and one contains an event structure AND some code outside the event structure.

I suggest the following:

Place the event structure in it's own private loop, you don't need a timeout event or a wait statement here, but please add a stop event. Right now, your VI is "unstoppable" ;).

All code from the other while loops (including the code fragment right above your event structure) can probably go in a single second while loop.
0 Kudos
Message 7 of 14
(7,666 Views)
thanks a lot!

I can't actually test it yet as i'm at home and it's for my project at uni - the device in question is there you see

but what you said about the loop not iterating was bob on - indicator on loop iterations stood still - have just tested that and wiring that 5 to the timeout case as well sorted the loop - also you were right about the greyed out false in the lower loop - didn't realise you see, thought it was a regular false - I always get problems with local variables - I tried to do a similar thing with queues and notifiers, as attached (the file in the .LLB is 'Run.vi' - have included the sub VIs too), but this did absolutely nothing too - I'm suspecting the same problem with the event structure timeout applies here? I'd much rather use queues and notifiers if I can - it's far more elegant, quicker operation times and I have a definite use for queues to monitor items in my system - thoughts? Sorry to trouble you guys - just for my final year project so i'm fairly worried about getting myself in a pickle! Going to try and alter the attached one too!

cheers for your help - finger's crossed it'll start to work when I check tomorrow!!!!

I do like Labview - a lot! Frustates me sometimes though when I get stuck 😄
0 Kudos
Message 8 of 14
(7,664 Views)
would you be able to give me a little more info on a 'stop' event please altenbach - do you mean, say, a stop button in one loop on the 'stop if true' condition, then a local variable to that stop button on other running loops?

thanks for your help guys - very useful!
0 Kudos
Message 9 of 14
(7,660 Views)
I can't look at your code at the moment, but I would like to point out a few things -
An event structure is supposed to be used to catch events, often as a user interface device. When these events don't occur, the loop that holds the event structure does not iterate, thus saving CPU resources. This explains why your queues didn't work either. A timeout event is only supposed to be used in very specific cases. Stop case - create a stop button and add a "Value change" event for that button. Wire T out of that case into the stop condition. All other cases will default to F. Note that if you don't place the terminal inside the loop it won't be read and if you're using a latched boolean it won't jump back to F. Queues and notifiers are basically designed to be read once while local variables act like variables in other languages. I think that for many cases there is no need to use complex structures like queues and notifiers when a local can do the job. A similar behaviour to that of the event structure can be used by using remove from queue with a timeout of -1 (wait forever). This way, the function will wait until an element is placed in the queue. As a matter of fact this, in conjunction with event structures, is used to create a convenient device called a queued task handler.
I hope this wasn't too long and too "off" the subject.

___________________
Try to take over the world!
0 Kudos
Message 10 of 14
(7,653 Views)