05-16-2014 02:57 AM
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.
05-16-2014 04:04 AM
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
05-16-2014 06:50 AM
hey CMW,
thanks. Do I have to create and close the file in while loop or outside the loop?
05-16-2014 07:47 AM
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
05-16-2014 11:03 AM
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).
05-19-2014 03:59 AM
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?
05-19-2014 04:36 AM
Hey Swap15,
where did u check the file size? Can't see this in the picture.
Regards,
CMW..
05-19-2014 04:57 AM
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....
05-19-2014 06:04 AM
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
05-19-2014 07:03 AM
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