05-31-2013 01:47 AM
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!
Solved! Go to Solution.
05-31-2013 01:54 AM
yes. but this sounds more like a producer consumer to me. http://www.ni.com/white-paper/3023/en
05-31-2013 02:18 AM
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.
05-31-2013 02:31 AM - edited 05-31-2013 02:36 AM
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.
06-02-2013 07:03 PM
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... 😄
06-02-2013 07:43 PM
06-03-2013 01:58 AM
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!
06-03-2013 10:46 AM - edited 06-03-2013 10:48 AM
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.