LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use last value if new value not avaliable after a certain amount oft time

Hey guys,

 

So I want the loop below to execute every half second,

 

looptiming.png

 

however the "read power in" VI takes around 5 seconds to return a value, which means the loop can only operate every 5 seconds (it waits on a value from the "read power in" VI.

 

Is there a way to tell the program to use the last value of power returned from "get power" every 0.5 seconds if no new value has been returned?

 

 

0 Kudos
Message 1 of 9
(3,305 Views)

Without knowing what is within Read Power In, I would say, spawn a thread and get that thread to call Read Power In and update a global (or control via a refnum).

 

 

A

0 Kudos
Message 2 of 9
(3,294 Views)

Hey,

 

thanks so much for the reply, this is whats in "read power in", there is a small delay inside it to allow a request to be sent to the serial port and a reply given back.

 

get power.png

 

are there any examples of what youre suggesting? I'm rather new to this and amn't sure exactly what you mean.

 

Thanks again,

Dan.

0 Kudos
Message 3 of 9
(3,285 Views)

So this 'small delay' is set to 5 seconds? That would be the only thing causing the subVI to take so long to return. Your loop rate is probably 500 msec so what you would do is write the last valid value to a shift register. Add a Boolean status to the subVI that would indicate that some bytes were actually read and use that to determine when to update the shift register.

 

You are concantanating the read string with an empty string. This serves no purpose. In your main VI, you are doing an equal comparison to a floating point number. This should never be done.

 

I would suggest you also look at the producer/consumer design template.

0 Kudos
Message 4 of 9
(3,280 Views)

What is the purpose of the delay?  Can the equipment not report more than every 5 seconds?

 

If it is a self imposed delay and only caused by the how often the HW is updating, then screw the delay and just remember the last voltage.  If there is nothing at the port, then use the old value, otherwise, read it and use the new value.  No need for an additional thread.

 

Also, take heed of the advice by the others.  I was not looking at those things, just specifically at your question, but what they said is very important.

 

 

A

0 Kudos
Message 5 of 9
(3,272 Views)

The delay is 0.5 seconds and it was added in the drivers by the manufacturer of an external piece of test equipement that I am interfacing with labview.

 

If it is removed, then an error occurs when reading in the data string, so unfortunatly it has to be left in place.

 

 

What I basically need is the "read power in" to output the last value of power when it is called, instead of waiting 5 seconds on a new value every time, then use the new value after 5 seconds.

0 Kudos
Message 6 of 9
(3,266 Views)

There is no reason for the delay. You are parsing the data at all times - even when there are 0 bytes read. If the are 0 bytes available, the subVI should simply return. That is a mistake in your code. Have you done any of the suggested improvements? When you have and if you continue to have issues, post back. 

0 Kudos
Message 7 of 9
(3,256 Views)

If you are getting an error due to parsing, then yes, you are causing the error by not checking how much data you are getting back from the hardware.

 

If you fix that, then you can know when you have to output the last value if no data is available.

 

 

A

0 Kudos
Message 8 of 9
(3,244 Views)

Ahhh, I see why you did this.  I thought that diagram looked familiar.  You posted this question: http://forums.ni.com/t5/LabVIEW/Search-string-value-to-return-integer/td-p/1330516

 

You need to use a USR (uninitialised shift register) to remember what the last string was that was not processed and prepend it to the last one. Attached is an example.  The inner loop breaks up the string but remembers where it was broken the last time to allow it to spit out the next part of the string on it's next call.  The outter loop reassembles the string and only spits it out if it has gotten a full string.

 

 

A

 

 

0 Kudos
Message 9 of 9
(3,199 Views)