10-30-2019 09:08 AM
I have taken over a LabVIEW program.
The main VI has two WHILE loops.
One WHILE loop is reading the serial port. When 127 bytes are received, the Send Notification function is called.
The other WHILE loop has a Wait for Notification function where the timeout is set to 200ms. This WHILE loop also has a Wait of 10ms.
What happens in this WHILE loop is a notification is not received? Does it wait 200 ms + 10 ms ?
Solved! Go to Solution.
10-30-2019 09:24 AM
@psuedonym wrote:
What happens in this WHILE loop is a notification is not received? Does it wait 200 ms + 10 ms ?
That depends if the wait is in parallel with everything else in the loop. If so, then the loop should be ~200ms.
10-30-2019 09:33 AM
My guess is 200 ms, but it's impossible to know without seeing the code. Do you really even need the 10 ms wait? It would seem to me that you want to read the notifications as fast as they come (and presumably that means that it's waiting some small time for notification).
10-30-2019 09:43 AM
@crossrulz wrote:
@psuedonym wrote:
What happens in this WHILE loop is a notification is not received? Does it wait 200 ms + 10 ms ?
That depends if the wait is in parallel with everything else in the loop. If so, then the loop should be ~200ms.
The rest of the WHILE loop decodes the bytes and displays on LEDs on the front panel.
If the objective is to process the notifier (which are the bytes) as quickly as possible, what changes do I need to make to the Wait for Notification? Do I keep the timeout?
10-30-2019 09:45 AM
@johntrich1971 wrote:
My guess is 200 ms, but it's impossible to know without seeing the code. Do you really even need the 10 ms wait? It would seem to me that you want to read the notifications as fast as they come (and presumably that means that it's waiting some small time for notification).
I am guessing the original programmer wanted to WHILE loop to not "hog" the resources.
10-30-2019 10:06 AM
Any wait, or timeout will allow the scheduler to evaluate if other code can run so there is no need to have an extra Wait if you have a notifier or queue in the loop. The timeout on the notifier/queue allows the scheduler to evaluate if other code can run. In fact, if you have a loop that you want to process as fast as possible but still allow the scheduler to task switch, a Wait with a value of 0 is sufficient.
Now, I would ask why you have a timeout on the notifier at all if the intent is to simply process the data as quickly as possible why do you have a timeout at all? Simply have the notifier wait with an infinite timeout and it will always process the data as soon as it arrives.
10-30-2019 10:13 AM
@Mark_Yedinak wrote:
Any wait, or timeout will allow the scheduler to evaluate if other code can run so there is no need to have an extra Wait if you have a notifier or queue in the loop. The timeout on the notifier/queue allows the scheduler to evaluate if other code can run. In fact, if you have a loop that you want to process as fast as possible but still allow the scheduler to task switch, a Wait with a value of 0 is sufficient.
Now, I would ask why you have a timeout on the notifier at all if the intent is to simply process the data as quickly as possible why do you have a timeout at all? Simply have the notifier wait with an infinite timeout and it will always process the data as soon as it arrives.
I just now tried removing the timeout.
Now if I click on the Stop button in the program which is wired to the stop condition for both WHILE loops, the VI does not stop.
10-30-2019 10:15 AM
External to the loop with the Wait on Notification, you will need to destroy the notifier. In your UI loop that is monitoring the Stop button it should release the notifier after it has detected the stop. Your consumer loop will get an error on the notifier. This will be your indication to stop that loop.
10-30-2019 10:27 AM
@psuedonym wrote:
@johntrich1971 wrote:
My guess is 200 ms, but it's impossible to know without seeing the code. Do you really even need the 10 ms wait? It would seem to me that you want to read the notifications as fast as they come (and presumably that means that it's waiting some small time for notification).
I am guessing the original programmer wanted to WHILE loop to not "hog" the resources.
Yes, but the Wait on notifier will effectively do the same task. There is no need for the additional wait.
10-30-2019 10:33 AM
@Mark_Yedinak wrote:
External to the loop with the Wait on Notification, you will need to destroy the notifier. In your UI loop that is monitoring the Stop button it should release the notifier after it has detected the stop. Your consumer loop will get an error on the notifier. This will be your indication to stop that loop.
If it was a Queue, I would be screaming at you. If you want to process all of the data, then you need to send a sentinel of some sort through the queue to tell the consumer loop to stop (destroying the queue would destroy any data that has not yet been processed). But since we are dealing with a Notifier, it is safe to assume we only care about the latest received data.