TwinCat file writing issues

jasauno1

Member
Join Date
Jun 2009
Location
Green Bay, WI
Posts
4
I am writing an array into a csv file of string type. The problem I am running into is that the old string value seems to "hang around" once I change it.


For example:

W_WO_Data: ARRAY [1..20] OF STRING(12);

WO_Data[1]:='test12345';

(*Now I write to the csv file using the function blocks shown below, and test12345 appears as expected*)

(*Now I change string value*)
WO_Data[1]:='abcdef';

(*Now I write to the csv file a second time using the same function blocks shown below, and now abcdef345 appears*)



I am using the following function blocks:
fb_FileOpen (*using FOPEN_MODEwrite as my mode*)
fb_FileWrite
fb_FileClose

Anyone have any idea how to overwrite the entire string value?
The only way I can get the string value to "reset" is by re-downloading the program.
Please let me know if more information is needed.

Thank you very much in advance for taking time to look at this.
 
Unfortunately, the fix function did not work for me. I have attached a pic of what is happening when I write to the csv.
fb_FileWrite.jpg

Does anyone know of a library that includes a different set of file open/write/save functions I could try?
 
Hi
You need to write your strings to the file by looping through your array using FB_FilePuts for each string - FB_FileWrite just copies bytes, so you get any junk left in the string after the zero termination byte from previous assignements.

(Strings in TwinCAT are null-terminated - when a value is assigned, the characters are copied in followed by a zero byte to mark the end of the string. Any bytes after this are not written too, hence they 'hang around'.)

Roger
 

Similar Topics

Hello to everyone, I am trying to achieve simple writing of a string to a text file in TwinCAT. The code I am using can be found below. Problem...
Replies
3
Views
5,191
Hi everyone, I'm a last year student at the university in Ghent, and for my thesis i need to write a TwinCAT program that writes data to a .daq...
Replies
0
Views
154
Hello, I was wondering if anyone know how to upload a PLC program to the Beckhoff TwinCAT 3 from a file? i.e. without having the development pc...
Replies
0
Views
797
Hello TwinCAT wizards. Once more this exhausted soul cries for help for something that is probably so very easy to solve for the wizards. When I...
Replies
4
Views
3,322
Hi I was trying to write a csv in twincad and I used the sample code from beckhoff...
Replies
5
Views
6,116
Back
Top Bottom