LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to execute an action after a fixed amount of time

Hi,

This is what i need to do.

Inside my while loop i need to update an indicator after a fixed amount of time.
Say the user enters 1 sec, the value should be updated every second.
Actually the value is continously being read from the RS232 port but i want it to be displayed only after a user specified amount of time.
Any help would be much apprectiated, i am in kind of an urgent situation.

Second question:

How do i get system time to get stored in a spreadsheet file with other interger values ???

I have attached my Block Diagram to make things more clear.

Thank you.
0 Kudos
Message 1 of 11
(3,506 Views)
1/ You should move your wait function to the firts frame : here you are executing the bottom FOR loop n times, with a delay of 0.2 s, then you wait n seconds.
2/ you probably can improve the bottom loop and generate an array of doubles, using the auto indexing property of FOR loops, then convert eventually to a cluster using the array to cluster function.
3/ There are several Time functions in the Time & Dialog subpalette that can be used to either generate a string indicating time and/or date, or time indicated as seconds. Depending on the way you want the time to be expressed the solutions are different : the attached vi presents several techniques, including string and file concatenation...

CC
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 11
(3,493 Views)
Hi Gagan,

You'll have to bear with me because I don't have LV installed on this PC.

The first think to remove is the outer frame. You should be able to accomplish what you need by using a while loop and a case statement within the while loop.

The while loop is to run until an event stops it (also a good idea is to have an actual stop button which can be ORed with another boolean event).

Use the Case Statement to update the display upon a given amount (increment) of time.

You can take a timestamp at the beginning of your vi to initialize the time, read the new time within the while loop and compare if it is greater than the first by the desired amount of time, if so, then update the display. An easy implementation is to reset the timestamp within the case statement and simply compare the difference in time to trigger the case statement.

Since you would already be using the system time to trigger the update, then you have access to its value.
I unfortunately can't remeber where it resides on the Functions Palette.. sorry. (I think it is under Synchronization... Use help, it will find it).

The last point is that you can also update the spreadsheet from within the Case Statement and store the timestamp.

Hope this helps.

If you are not successful, let me know, I can whip up a quick VI tonight as an example.

JLV.

😄
0 Kudos
Message 3 of 11
(3,372 Views)
Hi,

Thanks for your response, I think the storing the time you suggested will work the way i want.
But regarding the wait state, if i enter a delay stage any where in the while loop i am unable to read from the RS232 correctly.
Therefore i need a way that i can count the number of seconds elapsed and then take an action. The number of seconds should be user specified. Could you please help me reagarding this.

Thank you
Gagan
0 Kudos
Message 4 of 11
(3,487 Views)


@Gagan_01 wrote:
Hi,

Thanks for your response, I think the storing the time you suggested will work the way i want.
But regarding the wait state, if i enter a delay stage any where in the while loop i am unable to read from the RS232 correctly.
Therefore i need a way that i can count the number of seconds elapsed and then take an action. The number of seconds should be user specified. Could you please help me reagarding this.

Thank you
Gagan


Sorry, but I can't see how the fact to insert a delay into the while loop could affect the RS232 readings. Have you the same difficulty with a simplified vi, reading one serial port only ?
Chilly Charly    (aka CC)
0 Kudos
Message 5 of 11
(3,476 Views)
Yes i have the same problem. My instrument is continously streaming data. Therefore if i introduce a delay , it does not read the correct data. But when no delay is added it displays the change in data.
0 Kudos
Message 6 of 11
(3,470 Views)


@Gagan_01 wrote:
...My instrument is continously streaming data. Therefore if i introduce a delay , it does not read the correct data. But when no delay is added it displays the change in data.



So, the problem is due to the fact that, between 2 readings, you have received characters on the serial port, and of course, since you read only 20 chars, the info does not correspond to what you are waiting for.
There is only one solution : change the way you are retrieving the info : Read all the chars that have been received and stored in the serial port buffer, and process the corresponding string to extract the relevant info.

CC
Chilly Charly    (aka CC)
0 Kudos
Message 7 of 11
(3,467 Views)
Sorry, Isn't that what i am doing.
The problem seems to be that when i read the first stream of data from the instrument and then wait for say 5 seconds to read the next string of data i do not read the correct value.
Whereas if i read continously without a delay i read the correct values.
If you could send me a VI explaning how i can do this i would be very greatful.

Also note that the instrument (pressure manometer) does not always send the same number of bytes, but i am certain that it will not exceed 20 bytes.

Thanks
Gagan
0 Kudos
Message 8 of 11
(3,448 Views)
Sorry, Isn't that what i am doing.
The problem seems to be that when i read the first stream of data from the instrument and then wait for say 5 seconds to read the next string of data i do not read the correct value.
Whereas if i read continously without a delay i read the correct values.
If you could send me a VI explaning how i can do this i would be very greatful.

Also note that the instrument (pressure manometer) does not always send the same number of bytes, but i am certain that it will not exceed 20 bytes.

Thanks
Gagan
0 Kudos
Message 9 of 11
(3,448 Views)

@Gagan_01 wrote:
...Isn't that what i am doing...

Oh yes it is : as you wrote in your previous post your instrument is sending bytes on the serial port whatever you do. These bytes are received by the PC and stored in a buffer, again independently of your vi. When your serial read operation begins, you are reading the first bytes that were stored in the buffer, and might have been there for hours, depending on the size of the buffer and of the operating time... Of course if your reading rate is high enough, you will be able to empty progressively the buffer.
To convince yourself you just have to add a "VISA bytes at serial port" function and read the number of bytes that are stored in the buffer. You will observe that this numberr is a function of your reading rate.
You need to synchronize the readings with the rate the bytes are sent by your instrument. There are 2 solutions :
1/ most of the serial instruments can send data either continuously (as in the present case) or upon request, when they receive a special command from the PC. Use this second mode if your instrument allows it. That will solve all your problems.
2/ if you can only work on a data stream, the technique is more tricky : if the number of bytes in the buffer is larger than twice the requested number of bytes (since the first byte may not be properly positionned in the string), read all the available bytes, then parse the string to extract the last chunk of data that starts and ends with the string separator. Else, wait until there are enough bytes in the buffer...
Good luck, come back when you have a better look of the situation and have decided of the strategy that you will adopt.

CC

Message Edited by chilly charly on 04-22-2005 06:35 AM

Chilly Charly    (aka CC)
0 Kudos
Message 10 of 11
(3,440 Views)