Hello, I am a bit of a newbie to the whole programming world but have learnt a fair bit over the passed few months. My latest stumbling block is writing to a csv file created in my programme on the pi. I can create the file successfully, and write to it each time a :BOOL is triggered TRUE. However each time I trigger this switch, I overwrite the existing data. I am using .CAA library.
Where am i going wrong in the code below, this is taken from the example in the help section and amended slightly for my string/ triggers. I first of all create a file with one case/one :BOOL name RUN. Then the file is opened again in the Append mode by :BOOL named FiWr but still seems to overwrite each time is triggered rather than adding to the end of the file
Var
RUN: BOOL;
FiWr: BOOL;
FINSTR:= CONCAT(SEMFINSTR,'$R$N');
csvwrite:= UDINT:=0;
END_VAR
xFileStdInit:= RUN;
IF NOT xFileStdInit THEN
filop(xExecute:=FALSE);
filcl(xExecute:=FALSE);
filwr(xExecute:=FALSE);
filrd(xExecute:=FALSE);
xFileStdInit:=TRUE;
uiFileStdState:=0;
ELSE
CASE uiFileStdState OF
0:(* create a new file *)
filop.sFileName:=sFileName;
filop.eFileMode:=FILE.MODE.MRDWR;
filop.xExclusive:=TRUE;
filop( xExecute:=TRUE);
IF filop.xDone THEN
hFile:=filop.hFile;
uiFileStdState:=1;
END_IF
IF filop.xError THEN
(* error handling*)
;
END_IF
1:(* close file - TestFile.txt *)
filcl.hFile:=hFile;
filcl( xExecute:=TRUE);
IF filcl.xDone THEN
uiFileStdState:=2;
END_IF
IF filcl.xError THEN
(* error handling*)
;
END_IF
2:(* end of example *)
;
END_CASE
END_IF
IF NOT FiWr THEN
filop(xExecute:=FALSE);
filcl(xExecute:=FALSE);
filwr(xExecute:=FALSE);
filrd(xExecute:=FALSE);
FiWr:= TRUE;
csvwrite:=0;
ELSE
CASE csvwrite OF
0:(* create a new file *)
filop.sFileName:=sFileName;
filop.eFileMode:=FILE.MODE.MAPPD;
filop.xExclusive:=TRUE;
filop( xExecute:=TRUE);
IF filop.xDone THEN
hFile:=filop.hFile;
csvwrite:=1;
END_IF
IF filop.xError THEN
(* error handling*)
;
END_IF
1:(* write text in the file *)
filwr.hFile:=hFile;
filwr.pBuffer:=ADR(FINSTR);
szFileSize1:=SIZEOF(FINSTR);
filwr.szSize:=szFileSize1;
filwr.udiTimeOut:=100000; (* 100ms Timeout *)
filwr( xExecute:=TRUE);
IF filwr.xDone THEN
csvwrite:=2;
END_IF
IF filwr.xError THEN
(* error handling*)
;
END_IF
2:(* close file - TestFile.txt *)
filcl.hFile:=hFile;
filcl( xExecute:=TRUE);
IF filcl.xDone THEN
csvwrite:=4;
END_IF
IF filcl.xError THEN
(* error handling*)
;
END_IF
3:(* end of example *)
;
END_CASE
END_IF
I hope you can help
