LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open file on click button and save

Hello.

I have a confusing problem - i am trying to save data on click button(data are changing in time). First click -> we create file(for example 1.txt), the next click we create file 2.txt ....etc

The first click is O.K, but the next one is not.

The button doesnt change the state on output => i cannot create another file...

 

Does anyone have an idea whats going on? Where i made a mistake?

0 Kudos
Message 1 of 4
(3,308 Views)

After you first click Zpaisz 2 button, you'll enter in the specific case of EVENT STRUCTURE... now the only way to come out of this case, you need to click stop button.

 

Actually I'll suggest you to build a STATE MACHINE.


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 2 of 4
(3,299 Views)

Thanks, i will try this solution

0 Kudos
Message 3 of 4
(3,287 Views)

Hi Mirasoul,

 

According to your code it looks like you do not understand fully the functionality of Event structure. I would suggest you to go through help http://zone.ni.com/reference/en-XX/help/371361J-01/glang/event_structure/ , mainly part "caveats and recommendations for using events". Also article http://www.ni.com/white-paper/3331/en can help. In addition to that, try to reduce the code inside of an event structure as much as possible.

 

Did you try to turn on the Highlight Execution and see how the program works? Because you have to press "Zapisz 2" button first, then due to dataflow paradigm (described e.g. in http://www.ni.com/gettingstarted/labviewbasics/dataflow.htm )file is opened and every 100ms, random number is written. After clicking on the stop button, program will wait on another event to occur. Additionaly, you cannot stop the program using standard methods (button, timeout) and using abort button is the only way how to do that. If I can recommend you, avoid to use abort button, it can be dangerous and sometimes when you are working with files, you can lose the data easily.

 

You could use state machine, it is common and easy-to-implement architecture, if you want to use events, you can use "Producer/Consumer Design Pattern (Events)" via File > New and there select VI > From Template > Frameworks > Design Patterns. Basic idea of this architecture is that in the top loop, every configured event is caught and in the bottom loop, you implement the functionality. Ideal can be to create a state machine in the bottom loop and just send from top loop command (state) what should be done. So state machine will have states like "Open File", "Write File", "Close File" and you will send this states through queue.

 

Best regards,

Martin

0 Kudos
Message 4 of 4
(3,261 Views)