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');Â //Maybethisdoesn'tworkproperly???:|Â Â 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