LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with one control in Subvi to use in MainVi...

Hi,

I'll try to explain easy. I have my application with main window, where I do calculates and have one graph data. I use subvi to open the serial port and when I close the subvi, the data is drawed in the mainvi graph. Now I am trying to implement one option to do several test from serial port automatically. I want to have one Control Bottom in subvi, that when I active it, When I close the Subvi acquisition data, automatically active the save bottom and save the file and THEN open again the subvi ready to acquire another run of data. So I only need to start/Finish the data entry and it will going save diferent test in file.

I tried several things, but I have the problem when I active the option. In the first time, appear me BEFORE the execution of Subvi than the option to save the file. In the second run it seems works well, so 3rd,... the problem come when I disable the option in the Subvi and when I close the window in the mainVi the values aren't changed and appear the new save option and Subvi several times, until the iteration change and put 0 value and it works normally again. I am trying to retard the for/else 1 or 2 iterations but I dont know to do it, since The iteration value is increasing from starting the program and when I open the Subvi it only stops to count and when I come back again to Main continues with the last value. I would need the iteration of loop reset to 0 to say to the for/else to wait 2 iterations or use any counter... I tried to do it, but I spent my ideas.

I tried to do one example program in Lv7.1. 

It have the same structure and the same problem that in my program. In this example even I can't close the subvi between it is saving and re-openning it. I suppose since It is so simple, the active value do the subvi open directly.

I hope you tell me any idea to do it.

Regards, Fonsi.

Download All
0 Kudos
Message 1 of 9
(3,354 Views)

Firstly, rethink your architecture. Despite their name, varibles shouldn't be used to pass data around your program. I would suggest you look up the producer/consumer design pattern.

 

Second, your loop does not have a wait command of any sort, this causes your program to remain at the top of the thread stack and stops other system processes running.

 

Your problem is most likely a race condition, espescially as you have no control over which iteration your auto-save and incrementing structures occur in.

 

 

_____________________________
- Cheers, Ed
0 Kudos
Message 2 of 9
(3,349 Views)
I agree. Bad architecture, and too much dependence on local variables. You cannot write a LabVIEW program the same way you write text-based programs. Also, you have a logic flaw. Your bottom case structure is driven by the value of "ActMultiple". If True, you execute a sequence frame. In frame 1 you have another case structure that's based on teh value of ActMultiple. This can never be False, so your inner case is useless.
0 Kudos
Message 3 of 9
(3,342 Views)

Thanks for the fast input!.

I know the structure is not perfect. Keep in mind this example is thet simplier way I can show it. My program is more complex. I have the producter/consumer structure in the real Subvi, since I read from serial port and show it in realtime graph. Later all these data pass across to MainVi with diferent calculate, filters, and graph options.

I did this example to understand better my application way. It works fine. Like I wrote, I would like any idea to do it. I can't modify the structure of have one subvi and get the variable from it. I know I played a lot with variables in the example to get it. But really only fail in that I need retard the for/else, which I didnt get!.

So, any way to retard it?, any way to put any counter or reset the iteration mainloop?. Or any way to do it with diferents tools without vary the structure MAinvi - Subvi data entry?.

Regards.

0 Kudos
Message 4 of 9
(3,332 Views)

Also, you have a logic flaw. Your bottom case structure is driven by the value of "ActMultiple". If True, you execute a sequence frame. In frame 1 you have another case structure that's based on teh value of ActMultiple. This can never be False, so your inner case is useless

 

Yes, you are right!. I forgot put it. Check it now.

Now, it works well, the only problem is when I disabled the option in Subvi, I need another iteration to it works well. How i can retard the execution of the for/else?.

 

Download All
0 Kudos
Message 5 of 9
(3,326 Views)

The reason why you seem to need that "extra run" is due to a race condition. If you watch your code in highlight mode you will see this. You have 3 independent case structure. Let's say you start the VI and then press the "Start Test" button. The main VI is now executing the True part of the top-left case. Meanwhile, the other two case structures are executing since there is no data dependency. They see the values of the local variables as they were when you pressed that "Start Test" button. You set the "Active Multiple Runs" to True. The top-left case ends, and now the loop can go to the next iteration since all code has completed. In this iteration "ActMultiple" is True, so in the bottom case structure you execute the True case where you delay for 0.5 seconds, and then set "NewRun" and "MultSave" to 1. Meanwhile, the other two cases have already run. You now finish this iteration and move to the next. In this iteration the top-left case evaluates to True since "NewRun" is 1. So you get the dialog. While the dialog is up, the other two cases have already finished. You set the "Active Multiple Runs" control to False. The subVI ends, "ActMultiple" is set to False. and the loop iteration completes. Next iteration. Even though "ActMultiple" is False, you are probably thinking that you will get the "NewRun" and "MultSave" set to False because of the bottom case structure, so the top-left and top-right should see the values. This is not what happens. LabVIEW will read the values of the local variables before you enter the bottom case structure to set them. This is the race condition.

 

0 Kudos
Message 6 of 9
(3,305 Views)

smercurio,

Thanks for your reply!.

Yes you are totally right!. I was watching the highlight and yes. I know it is the problem, but I dont know how solve it properly.

Then Should I use queues putting another while loop in parallel?.

Regards.

0 Kudos
Message 7 of 9
(3,299 Views)
The way to solve it is to not use local variables in this way. The local variables create an indepence in your code that in this case you do not want. I don't completely understand what you're trying to accomplish, so I can't say whether you need a separate loop. I tried reading your initial post several times, but I'm sorry, I didn't completely understand your objective, and the objective of this example.
0 Kudos
Message 8 of 9
(3,288 Views)

I'll try again to explain it.

My program is one dyno system. I use it to do runs of engine. So the process is adjust the data, and use this subvi to acquire the data from serial port, in this subvi I have the RealTime graph and some gauges RPM and Km/h in digital and analogic display. When I finish the run I close the subvi and all the data pass to main vi (frontpanel), there I can adjust the curves, use filters, values of weather,input coments... then I can save the curves.

My objetive now is do it automatic. So i dont need to use the mouse to open the subvi, another one to start the acquisition and one more to close, then in the main save with the mouse again. Automatic runs is for one time I fit the data entre, the comments and other things I can use the mouse to open the Subvi and then ACTIVE the Automatic runs, and I leave out the pc. I put in the dyno with the engine and only need to push one external bottom, (with this bottom I can control the start and stop the data entry and the program automatically pass the data to main vi and draw it in thte graph (frontpanel)). Then, If I can do it would be automatic I can do one run test, automatic save it with fitted name and automatically put the subvi again ready to Start with my external bottom. So I can do several test run without touch the keyboard or mouse. Do you get now?.

 

I hope you understand me now.

Regards.

0 Kudos
Message 9 of 9
(3,285 Views)