From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-31-2020 04:12 AM
Hi all
In my code I want to add elapsed time in while loop,how to show time smoothly as sequence. Here is snapshot and comment,for you refer,thanks!
Solved! Go to Solution.
10-31-2020 07:26 AM - edited 10-31-2020 07:28 AM
You are only updating your elapsed time indicator when you state changes which is why it jumps so many seconds.
You need to put your elapsed time logic in a separate loop which is triggered to stop when your main processing loop stops.
I have attached a possibility.
As an aside, Rather than using strings for your states, you are much better off creating a enum type def which contains all of your possible states. This removes any possibility of typos, and if you change the elements in your enum your case structure will automatically update or give you an error at compile time rather than a runtime error.
10-31-2020 03:55 PM
10-31-2020 04:32 PM - edited 10-31-2020 04:35 PM
See if this can give you some ideas.
Note: No inner loops! No local variables
Second Note: You could just connect your elapsed time to the iteration terminal. Same difference. Above code is more flexible, because you might want to change timing in the future.
11-01-2020 01:22 AM
11-01-2020 04:17 AM - edited 11-01-2020 04:20 AM
I have just realised that I didn't attach an altered version of your code in my previous response. See an alternative method here (Based on your new code)
Because each state in your main loop takes >1000ms at a minimum (Because of the wait in some of the cases) I don't see a way of doing this other than having a separate loop. You have got to tell this loop when to stop which I have done using a local variable...There are better ways of doing this but this is the simplest as long as you remember to set its value to false before your loops start.
A couple of more comments regarding your serial comms:
11-01-2020 04:32 AM
Well, if some of your iterations take longer than 1 second, you need to place the timing into a seperate loop as has already been said. Also, if you only want to see whole seconds, don't use a format with fractional seconds for the indicator (I round to nearest instead). Do you really need to wait 1500ms for a response??? What kind of connection is this?
Why do you think you need so much duplicate code? It is probably sufficient to initialize the serial port before the outer loop (or in the init state). You don't need any of the inner loops. Your item1,2,3 cases differ only by two text constants each, so why do you think you need to duplicate everything!!? Isn't there a termination character? Polling for "bytes at port" is wrong in almost all cases.
Here is a very (very!) quick draft that I am sure needs much more work but will give you some ideas. I never use serial, so it would be worth consulting with an expert.
11-02-2020 06:37 PM
Yours comment are very useful, I have changed queue instruct show tick time.Any thing else to change,thanks for us help me for the issue.
11-02-2020 08:53 PM
Wow, now you are way overcomplicating things again with inner loops, local variables, and queues.
All you probably need is half the code!
11-02-2020 09:07 PM