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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Notifier - for loop

Solved!
Go to solution

Hello,

 

I am making a parallel program so I need to use a notifier to tell one of this processes that one has an event.

 

To make it easier I build a more simple program.

 

I have a FOR loop that iterates for 1000 times. I need that each iteration is executed once a Ready (OK) button is pressed, and if it's not needs to wait until is pressed. Also, I need to have a STOP button that if pressed at anytime, stop the program.

 

I built a notifier WHILE structure to make the waiting until is Ready button is pressed, and an EVENT structure to poll the READY and STOP buttons.

 

can you tell me what I am doing wrong?

0 Kudos
Message 1 of 60
(4,393 Views)

Hi Stavros,

 

can you tell me what I am doing wrong?

A lot is wrong in your image:

- You constantly request for a notifier and delete it in your inner loop.

- You have a wait function in your FOR loop, when you want to wait for a notifier…

- You have a long running FOR loop in your event case, which is a no-go!

- Why not just read the notifier with a timeout? No need to use a while loop at all!

- You haven't used the automatic block diagram cleanup function…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 60
(4,368 Views)

Hi Gerd,

 

 

Thanks for answering.

 

here some clarifications:

 

A lot is wrong in your image:

 

- You constantly request for a notifier and delete it in your inner loop.

I delete the notifier constantly because I need to use it only once, maybe I am missunderstanding how it is used.

- You have a wait function in your FOR loop, when you want to wait for a notifier…

The wait function was only to allow me to see the changing numbers.

- You have a long running FOR loop in your event case, which is a no-go!

Why you mean by no-go? I only added the "conditional terminal" in case I wanted to stop it.

- Why not just read the notifiers with a timeout? No need to use a while loop at all!

timeout? do you mean a stop timed structure? I used a while because I wanted to be waiting and don't run another FOR iteration until the Ready button is pressed again.

- You haven't used the automatic block diagram cleanup function…

yes, You are right in this. I just wanted to be focus on the functionality first.

 

can you give me some tips how can I improve this or make it simpler? maybe changing or replacing some structures......

0 Kudos
Message 3 of 60
(4,361 Views)

Hi Stavros,

 

timeout? do you mean a stop timed structure?

No, no additional structure.

Just the timeout input of the ReadNotifier function! (Read the help for this function!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 60
(4,350 Views)

OK, so you meant about the timeout variable in "Wait on notification", but by default is -1. I can't use a certain time, because I need to wait undefinetily until notification is received.

 

why my stop button is not working?

0 Kudos
Message 5 of 60
(4,330 Views)

Hi Stavros,

 

why my stop button is not working?

Because you wait for ever on a notification…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 60
(4,315 Views)

Hi Stavros,

 

waiting indefinitely without the possibility to shut down is rarely a good idea. However I think that you're thinking a bit complicated for this: If you just want to wait for the button to be pushed, a simple event structure within the for loop would be your best bet. That event could also handle the stop case.

 

Antoher Question I'm wondering about is this: you want a program that has the user clock 1000 times befor it's finished? Why? How would you feel if Microsoft gave you a program like that?



Remember Cunningham's Law
0 Kudos
Message 7 of 60
(4,304 Views)

Hello Peter,

 

As I told before, this is a simplifier case of a bigger program.

In my real program I do not count until 1000, but I have an array file which is read by the for loop, line by line.

 

I need to get those parameters, to execute another loop process, for that reason I need the events. Which in this case, are simplified by buttons, but actually are triggered signals.

 

You are rigth that I am complicating me a lot.

 

The case you mentioned it's fair enough, but before this process I am running another task, which I wanted to be holded until a Begin button is pressed.

 

So to sum up I should required a begin button, stop button, and "variable?"(trigger signal) as events to manipulate this for loop.

 

Managing this trigger signals, I thought using Notifiers was the best option, maybe the buttons can be used in a single event structure?

0 Kudos
Message 8 of 60
(4,281 Views)

Maybe it's clearer to see it in an image.

 

This file is wrong also, but helped me to figure it out a better idea.......

 

 

The FOR loop goes until the end of the inserted file.(EOF)

0 Kudos
Message 9 of 60
(4,266 Views)

Hi Stavros,

 

Maybe it's clearer to see it in an image.

A VI would be so much better…

 

But still:

It seems your event structure is called before the loop. You try to react on events in your loop, but the event structure can only process the events once the loop has finished (THINK DATAFLOW!). A classical deadlock loop!

 

- Put your UI event processing in a parallel running loop.

- Use shift registers for references.

- As told you before: IndexArray can be resized! It does not need constant inputs if used correctly!

- Use the cleanup tool!

- Get the notifier reference once before the loop, close it once after the loop!

- Don't use a while loop in a FOR loop in this application, it's not needed here!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 60
(4,245 Views)