karlek
Member
There's already been some discussion about writing to a file in TwinCAT, but I didn't see that someone encountered problem similar to mine.
My code here is written for testing purposes, task cycle time is 500 ms so every 6 seconds I write a string (consisting of date, time, voltage and current in one phase) into a file. Embedded PC is CX8090 and I write the file onto a C disk on my laptop.
Problem I am facing is that approximately every ~50 minutes (when my text file size gets somewhere around 24-25 kb) my program gets stuck at step 2 - opening of a file. Error HEX code is 0x70C, which means "File not found. Invalid file name or file path." (as stated in Beckhoff documentation - https://infosys.beckhoff.com/englis...ibsystem/html/tcplclibsys_fb_fileopen.htm&id=).
When this happens, I have to reboot my CX to be able to write again to a file. Even if I stop the PLC program, change the name of the file in which I want to log (so basically I try to log into a completely new file), download new program and run the program it doesn't help.
Has anybody got any clues what is bugging me here? If you need any more piece of information or if I forgot something, I'll be glad to give more details.
My code here is written for testing purposes, task cycle time is 500 ms so every 6 seconds I write a string (consisting of date, time, voltage and current in one phase) into a file. Embedded PC is CX8090 and I write the file onto a C disk on my laptop.
Code:
VAR
adresa :T_AmsNetId:='169.254.113.214.1.1';
otvoriDatoteku :FB_FileOpen;
zatvoriDatoteku :FB_FileClose;
fPuts :FB_FilePuts;
hFile :UINT;
bFileOpen :BOOL;
bFileOpenBusy :BOOL;
bFileOpenError :BOOL;
nFileOpenErrId :UDINT;
bFileCloseBusy :BOOL;
bFileCloseError :BOOL;
nFileCloseErrId :UDINT;
bFilePuts :BOOL;
bFilePutsBusy :BOOL;
bFilePutsError :BOOL;
nFilePutsErrId :UDINT;
BState :UINT;
END_VAR
CASE BState OF
0:
otvoriDatoteku(bExecute:=FALSE);
BState := BState + 1;
1:
otvoriDatoteku(
sNetId:=adresa,
sPathName:='c:\testfile6.txt',
nMode:=FOPEN_MODEAPPEND,
ePath:=PATH_GENERIC,
bExecute:=TRUE,
bBusy=>bFileOpenBusy,
bError=>bFileOpenError,
nErrId=>nFileOpenErrId);
BState := BState + 1;
2:
otvoriDatoteku();
IF (NOT otvoriDatoteku.bError AND NOT otvoriDatoteku.bBusy) THEN
hFile:=otvoriDatoteku.hFile;
fPuts(bExecute:=FALSE);
BState := BState + 1;
ELSIF otvoriDatoteku.bError THEN
BState := 0;
END_IF
3:
fPuts(
sNetId:=adresa,
hFile:=hFile,
sLine:=stringDat,
bExecute:=TRUE,
bBusy=>bFilePutsBusy,
bError=>bFilePutsError,
nErrId=>nFilePutsErrId);
BState := BState + 1;
4:
fPuts();
IF(NOT fPuts.bError AND NOT fPuts.bBusy) THEN
zatvoriDatoteku(bExecute:=FALSE);
BState := BState + 1;
END_IF
5:
zatvoriDatoteku(
sNetId:=adresa,
hFile:=hFile,
bExecute:=TRUE);
BState := 0;
END_CASE
When this happens, I have to reboot my CX to be able to write again to a file. Even if I stop the PLC program, change the name of the file in which I want to log (so basically I try to log into a completely new file), download new program and run the program it doesn't help.
Has anybody got any clues what is bugging me here? If you need any more piece of information or if I forgot something, I'll be glad to give more details.
Last edited: