LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write data to multiple text files after specific size

Hello,

 

I wrote a code that contineously writes data to  a text file. The problem is I am running this VI for long time and therefore this text file is being bigger in size e.g. more than 10MB. I want to split writing data in this text file after max 1MB size. Can anyone help ????

 

thanks in advance.

0 Kudos
Message 1 of 16
(2,857 Views)

Hey swap15,

 

You could use the "File/Directory Info Function" in the Advanced File VIs and Function palette to check the size. If the file is too big. close it and create a new one.

 

Regards,

CMW

 

0 Kudos
Message 2 of 16
(2,844 Views)

hey CMW,

 

thanks. Do I have to create and close the file in while loop or outside the loop?

0 Kudos
Message 3 of 16
(2,824 Views)

Hi,

 

check for the file size, if it reaches your spezified limit, close it and open/create a new one.. this would be inside the loop. Outside it wouldn't take affect if you are running within the loop.

 

Regards,

CMW

 

0 Kudos
Message 4 of 16
(2,814 Views)

CMW.. wrote:

You could use the "File/Directory Info Function" in the Advanced File VIs and Function palette to check the size. If the file is too big. close it and create a new one.


I would use the Get File Position since this won't cause Windows to have to do so much.  Assuming you are just writing and not setting the file position manually, this will return the size of the file in bytes (file position will always be at the end of the file).


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 5 of 16
(2,806 Views)

Hi guys

 

please have a look on the picture attached. I wrote this code which reads data from CAN port and writes it into a file but the file is getting bigger n bigger. I want to split writing into the file after 1MB. I tried using get size.vi but didn't get any result. can someone help with this?

0 Kudos
Message 6 of 16
(2,774 Views)

Hey Swap15,

 

where did u check the file size? Can't see this in the picture.

 

Regards,

CMW..

0 Kudos
Message 7 of 16
(2,766 Views)

Hey CMW,

 

sorry.......attached wrong. here is the right one. the code is working for me now. plz have a look and tell me if you have any suggestion....

0 Kudos
Message 8 of 16
(2,758 Views)

Hey Swap15,

 

I wouldn't open and close the file in every iteration. As crossrulz said already:


@crossrulz wrote:
Assuming you are just writing and not setting the file position manually, this will return the size of the file in bytes (file position will always be at the end of the file).

It is not necessary to set the position to the end.

I would solve this in a way like shown bleow.

 

Regards,

 

CMW

0 Kudos
Message 9 of 16
(2,747 Views)

Hi,

 

thanks for the suggestion.......... I will try the way you showed............but i want to ask you, what are the drawbacks if I use my code instead.

 

 

regards,

Swap 

0 Kudos
Message 10 of 16
(2,732 Views)