CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Mon Jun 26, 2017 2:54 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat May 06, 2017 5:59 pm 
Offline

Joined: Tue Feb 28, 2017 8:43 pm
Posts: 7
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 :D


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited