Jump to content

Timed While Loop for Serial Port Read


lizimunro

Recommended Posts

I need a while loop to run for an exact number of minutes whilst reading data from the serial port. I am currently using the elapsed time function but instead of looping for precisely one minute it will run for about 1 minute 20 seconds because it checks the time at the beginning of the loop and if the minute is reached just after the last check it takes several seconds to reach the check point again.

Ideally I would like the user to select the number of minutes for the run and for data to be read from the serial port for this time exactly and no more.

Any advice would but be great :-)

Thanks

Download File:post-10705-1203941249.vi

Link to comment

QUOTE(lizimunro @ Feb 25 2008, 04:08 AM)

I think you will do yourself a favor by getting rid of the express vi. just read the system time before you start, and loop every 100ms. In every iteration, check the elapsed time the old-fashioned way: subtract the start time from the current time.

You will also get a pleasing side-effect in that your STOP button will be polled at the new faster loop rate, so you can stop the loop right away rather than waiting for a minute.

Link to comment

QUOTE(jdunham @ Feb 25 2008, 11:37 PM)

I think you will do yourself a favor by getting rid of the express vi. just read the system time before you start, and loop every 100ms. In every iteration, check the elapsed time the old-fashioned way: subtract the start time from the current time.

You will also get a pleasing side-effect in that your STOP button will be polled at the new faster loop rate, so you can stop the loop right away rather than waiting for a minute.

Thanks - will try that :-)

Link to comment

I have changed te express vi so I am now checking against system time. The time needs to start at the visa write function just before the loop starts. I think I am missing something or have made an error as the timing is still not exact. I still have to wait a few seconds until the check time section is executed and the time reached triggered. I don't seem to have speeded the loop up to execute once every 100ms.

I am relatively new to Labview so may be misunderstanding this completely!

Attached is the updated vi Download File:post-10705-1204025858.vi

Link to comment

QUOTE(lizimunro @ Feb 26 2008, 06:37 AM)

Your "Time Improving.vi" seems to work fine on my pc (within .2 seconds of the requested time), but I of course don't have the same serial stream as you do.

Have you been watching the error codes to make sure things are working well and not timing out, which would add 10 seconds with the default timeout. Other than that I don't see what could be adding the extra seconds.

Link to comment

QUOTE(lizimunro @ Feb 27 2008, 05:19 PM)

Thanks for the advice. I think it is the serial read that is slowing the loop down as the timer seems to work fine in isolation! It just seems to take about 9 seconds to loop round and so if the time elapsed at the beginning of the loop there is a delay before anything is done about it.

I don't know why that should happen. But you should be able to determine if the reading is taking a long time with a breakpoint before and after the Visa Read. Also put a probe on the Visa Read error-out wire to see if there are any errors (ignore warnings that there may be more chars available).

You should be able to track down the problem source with judicious use of breakpoints and probes.

(As a side note, it seems odd that you are sending the "Radio Selection Code" (F,V, or P) twice, but maybe that is necessary.)

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.