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:(*endofexample*);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
it seems we have kind of the same problem here, but you are one step ahead of me. So I also want to write & read a csv-file in a certain directory. As my code is mostly similar and you wrote
Zitat:
I can create the file successfully, and write to it each time a :BOOL is triggered TRUE.
I want to ask you: Where is your file stored? And where in your code do you influence on where it's going to be stored?
Did you solve your problem? I know it's been one year already, but hopefully you care to help me a bit
Kind regards,
SpeedyG
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you opening the file in write W or append A mode?
I've not looked at your library, but the one I used allowed me to open the file with append to add data - just be careful the file doesn't get too large.
Sent from my iPhone using Tapatalk Pro
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: Primitive Source
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
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
END_IF
I hope you can help
Hi Primitive Source,
it seems we have kind of the same problem here, but you are one step ahead of me. So I also want to write & read a csv-file in a certain directory. As my code is mostly similar and you wrote
I want to ask you: Where is your file stored? And where in your code do you influence on where it's going to be stored?
Did you solve your problem? I know it's been one year already, but hopefully you care to help me a bit
Kind regards,
SpeedyG
Are you opening the file in write W or append A mode?
I've not looked at your library, but the one I used allowed me to open the file with append to add data - just be careful the file doesn't get too large.
Sent from my iPhone using Tapatalk Pro