LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing data from mainvi to subvi

Hello everyone, 

 

I am fairly new to labview and programming and came up some tricky things, atleast for me.

I searched for the answers and tried one or two solutions but nothing works, or atleast I cant get it to work. Any help would be higly appreciated!

 

  • The thing is, I want my data, what is gathered from an arduino trough serial, available on main and subvi. when I post the data to the subvi the main vi freezes. It has to display it at the same time, or at least at the background untill the subvi is closed. So if I call the subvi the data on the main vi freezes due to the event? And the data the subvi is presenting isnt accurate, it shows exact the same data, it doesnt refresh for some sort of reason.

 

  • Also, I cant get the graphs to use the system time of the computer. I like the graphs to link the system time and maybe sample the data every minute.

 

I dont know how to attacht it properly, i got it on a project base. I hope the attachments are well placed.

 

Anyway, I really want to get into it more, I really appreciate your help!

 

My excuse if my english or expressions are mistaken or misplaced. 

 

Thank you, Geert

Download All
0 Kudos
Message 1 of 10
(4,054 Views)

Hi! 

 

For yours first issue I recommend getting know to Producent-Consumer structures. It'll provide you with independecy of main loop from subVI.

 

Second issue: In order to have time stamp, better is to build waveform and then define Time axis.



0 Kudos
Message 2 of 10
(4,045 Views)

1) Learn to use the Event Structure.  You have several loops that are just polling as fast as possible, eating up lots of CPU resources to do practically nothing.

2) Learn data flow.  A loop cannot iterate until EVERYTHING inside of it is done running.  That means your subVI must be done running before you can go read from your microcontroller again.

3) Why are you using the Baud Rate to set how many bytes to read?  That makes no sense.  Since you are using a termination character, just set the number of bytes to read to a large number.  Use a constant, it will be more efficient.

 

In this case, I would seperate the system into 3 loops.  One loop to do nothing but read from the Arduino, the second to show one display, and a third to show the second display.  Read about User Events.  They will be your friend here as you can use them to send the data from the Arduino to the other two loops that should just be Event Structures inside of While loops anyways.  You can then use a queue or notifier to send the stop command to the serial read loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 10
(4,024 Views)

Dear AdamTrojak and 

 

 

 

programmed the Arduino whit this rate. This is because the Arduino now sends the data more real-time. I know this PIC isnt used for the real-time data aquisition, but this is close enough for me.

 

So seperate the program in 3 loops, with eventstructures.

 

LAbview.png

 

Well, at this point I made some mistakes. I can point some out myself but I don't know how to fix them. And ofcourse, if you see more (and you will 🙂 ) please point them out! 

 

1) Data aquisition runs and reads from the Arduino. But the data isnt shown untill the first loop is finished, so the data will be displayed when the first loop is stopped.

2) The SubVI in the third loop is unresponsive. I cannot call it at this point. (I want to use this stop button, which you can see, as a popupbutton)

3) To end the program it needs to be pushed at all the stop buttons. (The one in the first and second are combined, but the third requires fore some reason the stop button in the Event structure.)

4) Did I make some progress?

 

Your help is highly appreciated!!

0 Kudos
Message 4 of 10
(3,947 Views)

you will make some progress when you will start to learn dataflow.

If you are going to follow crossrulz advice , he was talking about 3 independent while loops( and you made them dependent because next loop is waiting for the eariler one to finish.

you need to go step by step.

1. remove all loops , trun the highlight execution on and run the vi . See how the data is passed to individual nodes.

2. Now put a single while loop, keep initialize visa before the loop and close visa after the loop and put some wait in the loop and see the flow.

3. Learn about event structure as it is clear from your diagram  that you did not learn about it before using( you have put your subvi into timeout case with no timeout value so this case will never execute).

 

Producer consumer, queues and user events are far ahead for now go simple try to learn Dataflow.

 

0 Kudos
Message 5 of 10
(3,871 Views)

Your main problem is that you created a data dependency between the loops.  So one has to complete before the next loop which has to complete before the next loop.  What we want here is parallelism, meaning all three loops can run at the same time as the others.

 

To pass data from one loop to another, use a queue.  Learn the Producer/Consumer, as this will help you understand the idea of parallel processes.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 10
(3,866 Views)

 

 I looked op the producer consumer technique and came up with this;

 

RK Producer Consumer.png

 

At this point the loops are seperated and thus I can make some parallel dashboards, right?

 

I did not process the data yet, but the indicators give me the right data. 

 

todo list Smiley Happy

Make SubVI popup (dasboard 2)

Make datalogger

Send start byte write to arduino

Send stop byte write to arduino

0 Kudos
Message 7 of 10
(3,796 Views)

Be very careful here.  Once an element is dequeued, it is gone from the queue.  What I am getting at is that both loops will NOT see every sample.  They won't even see the same samples.  If you truely want both consumers to process everything, then you need to either use two queues or a User Event.  I recommend going the second queue in this instance.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 10
(3,790 Views)

So this would be better, and see the same samples at the same time.

 

RK Producer Consumer mod.png

 

So if I want to close or stop the program, what is to be done with the stop buttons? I cannot find a usefull solution to stop or close the program with one stopbutton.

0 Kudos
Message 9 of 10
(3,774 Views)

gertjezzz wrote:

So if I want to close or stop the program, what is to be done with the stop buttons? I cannot find a usefull solution to stop or close the program with one stopbutton.


You should be sending a stop command of some sort in the queue to let the consumers know they are done.  In your case, I would send something like the string value "Stop".  So after the producer is complete, you just enqueue that message into both queues.  The consumers then check to see if the string is that stop command and stop when they see it.  Release your queues after their respective consumer loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(3,741 Views)