LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Semaphor between VI and its clone

Solved!
Go to solution

Hello fellow LV enthusiasts,

 

I have a question on the possibility of something.
I made a program that saves measured data into an excel file. Working great, no worries.
Now, I want to be able to clone the VI, so I can run to measurement at the same time. The clone and the original will both need to save data in the same excel sheet.
I will need a semaphor or something. So when one of the both processes is writing, the other VI has to wait.

Is it possible to create a semaphor that both VIs can use?

Greetings and thanks for reading!

0 Kudos
Message 1 of 8
(3,029 Views)

yes. but this sounds more like a producer consumer to me. http://www.ni.com/white-paper/3023/en


Learning LabVIEW since January 2013
0 Kudos
Message 2 of 8
(3,026 Views)

That looks interesting, but its not a producer/consumer case, because there is no consumer. Just two producers that share the same file to save data to.

0 Kudos
Message 3 of 8
(3,019 Views)

A function to store the data can be the consumer.

 

Also you can put the write function in an non reentrant vi. No semaphore required.  Those functions can be used only ones at the same time and if it is called more than ones it will wait until it is done to continue with the next one. 


Learning LabVIEW since January 2013
Message 4 of 8
(3,015 Views)

Ohh I see! I never used cloning before. I want to clone the entire VI.
So if I leave the VI that saves to Excel as non re-entrant. either the clone, OR the original can use the function?
That already solves the problem then... 😄

0 Kudos
Message 5 of 8
(2,976 Views)
I would recommend not cloning the VI while the file logging is in it. Move the logging to its own loop and pass it data with a queue. No need for a semaphore then.
Message 6 of 8
(2,967 Views)

A queue sounds good!

Right now I have several functions that write data to the excel sheet. However, in the end they all use the "Write Cell Value.vi". (I know its not very fast, but in this case its totally okay, since the measurement takes hours anyway.)

 

I could replace the "Write Cell Value.vi" with an own one that draws data out of an internal Queue and then uses "Write Cell Value.vi".
Now Im not sure what you mean by having the file logging in "its own loop".  How do I do this?

Thanks for the help so far!

0 Kudos
Message 7 of 8
(2,943 Views)
Solution
Accepted by topic author Arvel

Here is a very basic screenshot of the general idea. This is not working code, nor should it be used exactly as it is here; I leave references open. Again, disclaimer, this is just to show a concept. Here, you have 3 loops, all of them are putting data in the logging queue. The logging loop dequeues the data and writes it to the log file. You may need to make your queue element have some identifier so you know where the data came from (for example, use a cluster with a string or enum that defines the loop that sent the data, along with the data). That way you can write it to the correct cell in your spreadsheet.

 

 

 

Message 8 of 8
(2,925 Views)