LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FLAT SEQUENCE ANDO FILE I/O TO WRITE A TEXT FILE

Hi everybody.

 

I have some trouble trying to write my text file. 

 

1. First I pretend to run de VI. 

2. Then start the play button and goes to the true case.

3. Goes to flat sequence and the first frame opens a file.

4. In the second frame, a random number is saved and wrote in "write to text file" until the time finish in my for loop.

5. and the third frame, close the file.

 

My problem is that in the second frame the for loop is not finished yet and immediately goes to the next frame, close the file and the flat sequence starts since the beginning, open and close a new file many times until the times up.

I would like to stay only in my second frame until the time finished. I hope it was clear

 

Thank you.

 

0 Kudos
Message 1 of 5
(1,912 Views)

Hi cheko,

 


@chekoR wrote:

I have some trouble trying to write my text file. 

My problem is that in the second frame the for loop is not finished yet and immediately goes to the next frame,

I would like to stay only in my second frame until the time finished.


What's the point in using this sequence frames at all? Don't you trust "THINK DATAFLOW!"?

When the loop finishes immediatly then the data wired to "N" is less than 1. Did you check this while debugging your code?

Why do you need to divide and multiply by 0.1?

Why don't you use FormatIntoString instead of NumToString followed by ConcatString?

Why do you need to reset "Play"? Wouldn't it be easier to switch this boolean control to a Latching mode?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(1,875 Views)

@chekoR wrote:

 

1. First I pretend to run de VI. 


I would suggest to actually run the VI. Jus pretending doe nothing.

 

 

 

 

Gerd already pointed out most problems.

 

  • Keep it simple and intuitive. Multiplying by 10 seem easier on the brain than dividing by 0.1, right?
  • Value properties are almost never needed. (use local variables if you need to write to a control). Yes, latch action would be more suitable for the play button.
  • You seem to want to reset the play boolean once the loop has completed, so that belongs after the loop, not inside a case structure and associated logic.
  • You are only dealing with relative times, so the "high resolution relative seconds" is the correct function. No need for timestamps converted to DBL.
  • Your while loop spins as fast as the computer allows, consuming all available CPU, especially if not playing. Don't drain your battery!
  • You only need one shift register for the time of done right. Think about it! I would also initialize them.
  • You have serious race conditions because writing to Tiempo(s) and reading from the property node occurs in parallel and you don't know what happens first. No matter what, It is likely that the loop iterates zero times because that's what the value probably always is. (It is either zero or some extremely small number depending on the loop rate).
  • The entire code makes very little sense. What is it supposed to do? Why should the number of iterations depend on some relative time?
  • You don't need the FOR loop becaue the outer while loop is already there to do the looping. When play is pressed, take the start tick and loop at a reasonable rate until the time ahs elapsed, changing back to the idle state.

So.

Have an outer while loop with two states (cases of a case structure) and some reasonable loop time. (1) Saving or (2) not. Open the file before the toplevel while loop and close once the loop has finished.

When play is pressed, take the reference time and go to the saving state. Look at the elapsed time and go back to the idle state once the time has elapsed.

 

Here's a quick draft.

 

0 Kudos
Message 3 of 5
(1,849 Views)

Hello GerdW.

 

Thank you for your answer. Maybe I need to explain why my project doesn't make sense now. I'm a student learning LV The propose of my project is to shake a horn as a vibration machine using output sound controls of LV and at the same time measure the acceleration of a structure and check the vibration response. 

 

Until now I can read acceleration and write output sound without any problem. But now I need to combine with a graphic and easy environment interface for the final user. My code needs to run the VI but without doing nothing of vibration and acceleration, because first I need to set the parameters of the frequency, amplitude, and the time of the test vibration. When I have the parameters I need to push a play button and start my vibration and acceleration measurement test for 60 seconds for example. Then save the acceleration data response in a text file and my test has finished but the program has to continue running if I want to do another test with other parameters and create a new text file for a second test. That's why I try to do a flat sequence and I have a led traying to see whats is happening in my code and understand better but trying to write a file with those conditions is really getting difficult for me.

 

And because I'm learning I tried to do this dummy code to learn how tools work and have a better understanding.  Maybe there are betters tools to do my code but I don't know them yet and I need more experience, this is great software. 

 

Thank you for your help. it really helps me a lot to have a better understanding 

0 Kudos
Message 4 of 5
(1,821 Views)

Hello altenbach.

 

Thank you for your answer and a quick draft. I wrote the reason why my code doesn't,t make sense in the previous answer.

I going to follow your advice to get a clear code.

 

Regards.

0 Kudos
Message 5 of 5
(1,813 Views)