10-26-2009 10:26 AM
Hello,
I am developing a VI that measures some current values and saving them in *.xls files. I am using 9 analog input channels and i have 9 case structures that manage file saving. ( creates a new file when acquiring 40,000 samples so i get i.e IA1,IA2 ......IAn or IB1, IB2 ..... IBn files and so on for every channel).
The problem is that straight away after I start the VI, I get error 1 , pin pointing all the close file funtions I am using in the VI
'' Possible reason(s):
LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @. ''
I have checked all the file names, input clusters and paths i am using and i dont see anything wrong.
Could you please gimme some advice on this??
Please find attached screenshots of the VI.
Cheers,
Panos
10-27-2009 12:58 PM
Hi Panos,
It sounds like you should be using the file path to close the file, not the refnum.
Flash
10-28-2009 09:35 AM
A_Patel wrote:Hi Panos,
It sounds like you should be using the file path to close the file, not the refnum.
Flash
Hi A_Patel,
first of all thank you for your reply.
Could you please elaborate? My VI is based on an older VI ( actually that one was developed with Labview 6.x or somethin') and it was using those Close File functions you have already seen in my snapshots. The only reason for using those instead of the existing in present versions of Labview Close File function, is that with the old Close File I can get the dup refnum of the closed file while the new close file only provides the path. My input clusters are all linking to the files through refnums. As long as a new file is created, the cluster is updated and returns the info through a shift register.
If you could suggest a more effective way or how I can actually perform the same task by closing the file with file paths, I would be extremely happy to help me out on this
Please find attached my VI's. They are in a developing stage right now but main tasks of the code are complete.
I thank you in advance,
Panos
PS. I am using a NI PCI- 6254 with two SCB-68 connector blocks
10-28-2009 10:40 AM - edited 10-28-2009 10:44 AM
Since you are going with a newer version of LabVIEW now, and it is a huge jump from LV6 to LV 2009, it is time to start cleaning up some code and replace some of the ancient functions. The white icon Close+.VI is one of them.
I think there is a good logical reason why the new Close File icon (yellow) doesn't have a duplicate refnum coming out. Since you close the file in the function, the refnum becomes invalid. There is way you could ever use it again after the function. The old white icon has a duplicate refnum because looking at the context help, it looks like it doesn't necessarily always close the file depending on what boolean value is wired into the bottom.
I think there is a lot of thinks you could do to clean up the code. There are 9 sections of case structures on the right hand side that all appear to do the same thing (perhaps on different data). They are prime places where a subVI should be created so that you don't duplicate code unnecessarily. It would probably cut your screen real estate to 1/10th to 1/20th of its current size.
Those case structures are stacked 3 layers deep, so there could be some logic flaw going on there you can't see. If possible, rethink the logic going into the case structures so that the depth of the structures can be reduced. I think this might be the source of your problem as many of the cases involve a Close File. Sometimes the new function, sometimes the old function. There are a lot of logic paths and it seems like many of them could close the file and make the refnum invalid. Yet the refnum gets stored into a cluster saved in a shift register. Unless your logic is flawlessly executed, there is a good possibility there is a logic path that causes a file to be written to with an invalid refnum.
I think there are 3 architectures that could help. One would be based on a state machine that would remember the current state of each of those file paths to determine whether they need to be opened, closed, written to, or read from.
The second is a producer/consumer architecture. The data that is to be written to should be passed off to a consumer loop by way of a queue. Let the consumer loop handle the file operations.
The third would be an Action Engine or a functional global variable. It could store the array or cluster of file renums. Perhaps also a status for each one that tells whether the refnum is valid or not. Let the action engine handle the storage of the refnums so you don't have to string refnum wires through the whole VI and bundle them all up into a cluster at the end.
PS. On your front panel, "Incline Plain" should be spelled "Inclined Plane"
10-29-2009 08:38 AM - edited 10-29-2009 08:39 AM
Ravens Fan wrote:Since you are going with a newer version of LabVIEW now, and it is a huge jump from LV6 to LV 2009, it is time to start cleaning up some code and replace some of the ancient functions. The white icon Close+.VI is one of them.
I think there is a good logical reason why the new Close File icon (yellow) doesn't have a duplicate refnum coming out. Since you close the file in the function, the refnum becomes invalid. There is way you could ever use it again after the function. The old white icon has a duplicate refnum because looking at the context help, it looks like it doesn't necessarily always close the file depending on what boolean value is wired into the bottom.
I think there is a lot of thinks you could do to clean up the code. There are 9 sections of case structures on the right hand side that all appear to do the same thing (perhaps on different data). They are prime places where a subVI should be created so that you don't duplicate code unnecessarily. It would probably cut your screen real estate to 1/10th to 1/20th of its current size.
Those case structures are stacked 3 layers deep, so there could be some logic flaw going on there you can't see. If possible, rethink the logic going into the case structures so that the depth of the structures can be reduced. I think this might be the source of your problem as many of the cases involve a Close File. Sometimes the new function, sometimes the old function. There are a lot of logic paths and it seems like many of them could close the file and make the refnum invalid. Yet the refnum gets stored into a cluster saved in a shift register. Unless your logic is flawlessly executed, there is a good possibility there is a logic path that causes a file to be written to with an invalid refnum.
I think there are 3 architectures that could help. One would be based on a state machine that would remember the current state of each of those file paths to determine whether they need to be opened, closed, written to, or read from.
The second is a producer/consumer architecture. The data that is to be written to should be passed off to a consumer loop by way of a queue. Let the consumer loop handle the file operations.
The third would be an Action Engine or a functional global variable. It could store the array or cluster of file renums. Perhaps also a status for each one that tells whether the refnum is valid or not. Let the action engine handle the storage of the refnums so you don't have to string refnum wires through the whole VI and bundle them all up into a cluster at the end.
PS. On your front panel, "Incline Plain" should be spelled "Inclined Plane"
Message Edited by Ravens Fan on 10-28-2009 11:44 AM
Hi Ravens Fan,
thank you very much for the detailed answer, really appreciate it.
About having one common subVI in order to replace the 9 case structures, i am not quite sure how I can define in that subVI the file name and path in the unbudle cluster in the 3rd level of the case structure where actually forms the new filename and path for every single new file created (i.e IA1, IA2, IA3 .... IAn). I can define inputs on such a subVI for everything else but dont know about that thing.(actually that unbundle by name is the only thing that makes these 9 cases different).
Regarding the use of refnums after the close function, if I replace the old close file functions with the new ones, I dont have to feeedback a path or a refnum to the output cluster on the right?
About programming techniques, I am not so experienced the time being but I would be really happy if you could please suggest knowledge database in NI site so I can have a look.
And yeah, you are definitely right! I am not a native speaker of english and sometimes i do these kinda silly mistakes!
Thank you!
Panos
10-29-2009 10:05 AM
Saloutios wrote:
About having one common subVI in order to replace the 9 case structures, i am not quite sure how I can define in that subVI the file name and path in the unbudle cluster in the 3rd level of the case structure where actually forms the new filename and path for every single new file created (i.e IA1, IA2, IA3 .... IAn). I can define inputs on such a subVI for everything else but dont know about that thing.(actually that unbundle by name is the only thing that makes these 9 cases different).
I see basically two things that are different in each case structure. One is which items you unbundle from the cluster. The second is which indicators you write to. I would move the unbundle function to outside the case structure and feed in the Path and the Filename as individual items into the case structure. Now you can unbundel the specific items outside the subVI, and the code inside the subVI in the case structure can be the same. For the indicators, you can create a reference to the specific indicators outside the case structure and thus outside the subVI. Feed the references into the subVI through controls on the subVI's front panel/connector panel. Now use the reference to update a value property node of those references. Now you've decouple the indicator update from specfic controls so that the code inside the subVI is identical.
Regarding the use of refnums after the close function, if I replace the old close file functions with the new ones, I dont have to feedback a path or a refnum to the output cluster on the right?
Correct. The refnum has become invalid anyway, so it is now useless. What you can do is create an Not a Refnum constant and have that go into the tunnels that lead to the bundle and shift register. It would actually be a little safer. You could also check to make sure a Refnun is valid before trying to use it and raise an error if it is not. That could help you in debugging the logic path of the code.
About programming techniques, I am not so experienced the time being but I would be really happy if you could please suggest knowledge database in NI site so I can have a look.
Keep reading the forums.
Take the LabVIEW tutorials if you haven't already, or haven't taken and training courses.
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six HoursSearch for and read up on any information on state machine and producer/consumer architecture. As well as Ben's action engine nugget I linked to in the other post.
Learning about those 3 things, you can probably handle the vast majority of programming problems thrown at you.
11-03-2009 09:54 AM
Hi Ravens Fan,
I'd like to sincerely thank you for the help, it has been really useful. Sorry for the delay replying but I was away and didnt have any internet access.
I already started implementing some of the changes you suggested and it seems that the VI is definitely clearing out. As soon as I have everything done I am gona update you of the progress.
Thank you again, catch you up!
Panos
11-03-2009 09:58 AM
12-07-2009 12:37 PM - edited 12-07-2009 12:39 PM
Ravens Fan wrote:
You're welcome. Thanks for checking back in and letting me know that things are working out.
Hello Ravens Fan,
coming back to inform you of the progress i had regarding my VI.
I tried to implement the changes you suggested but it seemed it was impossible for me avoid the invalid reference number error. It seems that there is a data flow problem or as you said the refnum is lost inside the saving case structures. So I tried to reduce the problem from 10 AI to 4 AI and implement a combination of State Machines and Producer Consumer architectures. So I ended up to the attached VI.
I would like to ask you if you could please assist me on the following issues:
1. As you can see, I am using my digital outputs to turn on/off the relays controling the high voltage. The problem is that I would like to manually stop i.e sample A from acquiring data and having a low state to the relay controling the voltage of that channel. Still I wanna still run the test without interruption for sample B. How can I achieve that without having to create a different queue for each sample?
2. When I am pressing the stop button, I get an error that the Dequeue function of the Logging data queue has lost the reference number. I know this is an issue with Queues but I am kinda confused of what I have read about it here.
I thank you in advance!
Panos
PS : I know that since the VI has radically changed maybe my message is not anymore relevant to the thread title but I wanted to connect it with my older post. So I would like the mods to excuse me for any discomfort.
12-07-2009 12:39 PM