I'm using Codesys V3.5 SP10 Patch 4 pbF with File Access lib 3.5.7.0 and want to write down my measurement results into a logfile.txt. Creating and writing into the logfile works well. However only the last result is written into the logfile. There is only one entry. What can I do to get all events into my logfile. A statemachine didn't helped. Here is my code:
PROGRAMWRITE_LOGVAR
  dirOpen  : FILE.Open;
  fileClose : FILE.Close;
  fileWrite : FILE.Write;
  dirClose  : FILE.DirClose;
  hFile : CAA.HANDLE;
  hDir : CAA.HANDLE;
  projectpath : CAA.FILENAME;
  filename  : CAA.FILENAME;
 Â
  str_writestr:STRING;
 Â
  time_object_get :DTU.GetDateAndTime;END_VAR
str_writestr:='';time_object_get(xExecute:=TRUE);dirOpen(sFileName:=GVL.filename_log, eFileMode:=FILE.MODE.MWRITE, xExecute:=TRUE);IFNOTtime_object_get.xErrorANDNOTtime_object_get.xBusyANDNOTtime_object_get.xErrorTHEN
   GVL.logtime:=time_object_get.dtDateAndTime;
  time_object_get(xExecute:=FALSE);END_IFIFdirOpen.xDoneANDNOTdirOpen.xErrorTHEN
  hFile :=dirOpen.hFile;
  str_writestr:=CONCAT(DT_TO_STRING(GVL.logtime),'');
  str_writestr:=CONCAT(str_writestr,GVL.logstring);
  str_writestr:=CONCAT(str_writestr,'$R$N'); //Maybe this doesn't work properly??? :|
  fileWrite(hFile:=hFile, pBuffer:=ADR(str_writestr), szSize:=TO_UDINT(StrLen(ADR(str_writestr))), udiTimeOut:=100000, xExecute:=TRUE);
 Â
IFfileWrite.xDoneANDNOTfileWrite.xErrorANDNOTfileClose.xDoneTHEN
    fileClose(hFile:=hFile, xExecute :=TRUE);
  ELSIFfileClose.xDoneTHEN
    dirOpen(xExecute:=FALSE);
    fileClose(xExecute:=FALSE);
    fileWrite(xExecute:=FALSE);
  END_IFEND_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Comingback4u hat geschrieben:
MWRITE mode is like creating a new file every time. So unless you change the pointer to the end of the file it will constantly erase the data.
Try changing:
Hello,
I'm using Codesys V3.5 SP10 Patch 4 pbF with File Access lib 3.5.7.0 and want to write down my measurement results into a logfile.txt. Creating and writing into the logfile works well. However only the last result is written into the logfile. There is only one entry. What can I do to get all events into my logfile. A statemachine didn't helped. Here is my code:
This may help, especially section "File – internal pointer"
https://help.codesys.com/webapp/Examples;product=CAA_FILE;version=3.5.13.0
MWRITE mode is like creating a new file every time. So unless you change the pointer to the end of the file it will constantly erase the data.
Try changing:
To:
To:
Thanks guys!!!This one worked for me