LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sharing a refnum between case structures

I would like to output some data to a file with a custom header and data format.  I have created a simple true/false case structure within a while loop where the data is aquired.  If the while loop count is 0, I would like to output a custom header to a file using the "Write to a Text File Function".  For this fuction I planned on leaving the file name blank so it will prompt the user with a file dialog.  If not on the first iteration of the while loop I would like to send my data to the same file with the header using the "Write to Text File Function" again.  I would like to use the output refnum from the "Write to Text File Function" and use it as input for the second function that writes the data.  Any ideas?  I am unsure how to share the refnum between the case structures so there is only one file dialog shown to the user.  I have attached a sample vi.

0 Kudos
Message 1 of 9
(3,633 Views)

You should store the file refnum in a shift register (right-click the border of the while loop, add shift register).

0 Kudos
Message 2 of 9
(3,630 Views)

Just for a good reference, you should do some research on the State Machine architecture.  I can't find my normal page now (on a different computer than normal right now), but here's a good example I found really quick.

https://decibel.ni.com/content/groups/northeast-oh-labview-users/blog/2009/09/08/state-machines


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 9
(3,614 Views)

Hello!

 

A bit old thread but I'd like just a clarification for file refnums as well:

I have a state machine structure (basicly a case structure with different file operations in each case).

I open file in one case, and pass in into feedback loop outside the case structure and input it back to the case structure.

 

Is it so that because I exit the case structure, the file refnum becomes invalid? Or should it stay persistent until I explicitly use close file VI?

I am experiencing an error code = 1 when trying to close a file that I opened in other case.

 

If so, what are my options to preserve a valid file I/O refnum? shift register? global variable? local variable? some other?

I feel that my files are getting closed without any warning!

 

 

 

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

How are you runing your vi? With Run button?

Doesn't your vi have a while loop?

0 Kudos
Message 5 of 9
(3,492 Views)

@Turzt wrote:

Hello!

 

A bit old thread but I'd like just a clarification for file refnums as well:

I have a state machine structure (basicly a case structure with different file operations in each case).

I open file in one case, and pass in into feedback loop outside the case structure and input it back to the case structure.

 

Is it so that because I exit the case structure, the file refnum becomes invalid? Or should it stay persistent until I explicitly use close file VI?

I am experiencing an error code = 1 when trying to close a file that I opened in other case.

 

If so, what are my options to preserve a valid file I/O refnum? shift register? global variable? local variable? some other?

I feel that my files are getting closed without any warning!

 

 

 


No VI hard to answer.

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

@Turzt wrote:

I have a state machine structure (basicly a case structure with different file operations in each case).

I open file in one case, and pass in into feedback loop outside the case structure and input it back to the case structure.


Why are you using a Feedback Node in a State Machine?  Why not just use the shift register?  In this case, that would make things a little cleaner.

 

My guess to your problem is that you are not passing the reference through all of your cases.  But without code, it is impossible to actually debug.


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
Message 7 of 9
(3,469 Views)

The reason for using feedback node for state machine state and other variables is that the state machine is in a subVI which is inside a main VI.

If I put neverending while loop into subVI, the subVI never exits and the main VI gets stuck waiting the subVI.

 

I made a test and put while loop and shift register outside the state machine. Now it works. So, I must not ever exit the structure that contains the "open file" VI.

So I guess I must open the file in the main level and just pass requests from the state machine subVI. I don't want to create file immediately at start, but I need

to wait user command to create file and start logging data into file, and then other user command to stop logging and close the file.

 

 

0 Kudos
Message 8 of 9
(3,438 Views)

Could you please clarify your question?

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