paicolman
Member
Hi,
I want to write a string into a file. This has to happen within a funcion (FUN, no FB) since I want to use it to log stuff to a file, triggered by the mein program.
My problem is:
If I step through my code, it works fine, but as soon as I run it normally, the FB_FileOpen keeps bBusy HI until it gets a timeout, regardless of timeout values or twincat pace (I'm using the simulation, not the real CX). Any idea what I'm doing wrong?
Here´s my code:
FUNCTION LogInfo : BOOL
VAR_INPUT
sID : STRING;
sInfo : STRING;
END_VAR
VAR
sMsgToLog : STRING; Step: SINT;
hFileHandle: UINT;
fbCreateLogFile : FB_OpenLogFile;
fbFileClose :FB_FileClose;
CreateOrAppend: DWORD;
fbFileOpen : FB_FileOpen;
fbFilePutString : FB_FilePuts;
x: INT;
END_VAR
fbFileOpen(bExecute := FALSE);
fbFileOpen( bExecute:=TRUE,
sNetId := '192.168.1.2.1.1',
sPathName:='C:\ADSLOG.TXT',
ePath := PATH_GENERIC,
tTimeout := T#2S,
nMode := CreateOrAppend);
WHILE (fbFileOpen.bBusy) DO
x := x + 1;
fbFileOpen(bExecute:=FALSE);
END_WHILE
hFileHandle:=fbFileOpen.hFile;
sMsgToLog := 'Whatever I need to write';
fbFilePutString(bExecute := FALSE);
fbFilePutString(bExecute := TRUE,
sNetId := '192.168.1.2.1.1',
hFile := hFileHandle,
sLine := sMsgToLog);
WHILE (fbFilePutString.bBusy) DO
fbFilePutString(bExecute:=FALSE);
END_WHILE
fbFileClose(bExecute := FALSE);
fbFileClose(bExecute := TRUE,
hFile := hFileHandle);
WHILE (fbFileClose.bBusy) DO
fbFileClose(bExecute:=FALSE);
END_WHILE
I want to write a string into a file. This has to happen within a funcion (FUN, no FB) since I want to use it to log stuff to a file, triggered by the mein program.
My problem is:
If I step through my code, it works fine, but as soon as I run it normally, the FB_FileOpen keeps bBusy HI until it gets a timeout, regardless of timeout values or twincat pace (I'm using the simulation, not the real CX). Any idea what I'm doing wrong?
Here´s my code:
FUNCTION LogInfo : BOOL
VAR_INPUT
sID : STRING;
sInfo : STRING;
END_VAR
VAR
sMsgToLog : STRING; Step: SINT;
hFileHandle: UINT;
fbCreateLogFile : FB_OpenLogFile;
fbFileClose :FB_FileClose;
CreateOrAppend: DWORD;
fbFileOpen : FB_FileOpen;
fbFilePutString : FB_FilePuts;
x: INT;
END_VAR
fbFileOpen(bExecute := FALSE);
fbFileOpen( bExecute:=TRUE,
sNetId := '192.168.1.2.1.1',
sPathName:='C:\ADSLOG.TXT',
ePath := PATH_GENERIC,
tTimeout := T#2S,
nMode := CreateOrAppend);
WHILE (fbFileOpen.bBusy) DO
x := x + 1;
fbFileOpen(bExecute:=FALSE);
END_WHILE
hFileHandle:=fbFileOpen.hFile;
sMsgToLog := 'Whatever I need to write';
fbFilePutString(bExecute := FALSE);
fbFilePutString(bExecute := TRUE,
sNetId := '192.168.1.2.1.1',
hFile := hFileHandle,
sLine := sMsgToLog);
WHILE (fbFilePutString.bBusy) DO
fbFilePutString(bExecute:=FALSE);
END_WHILE
fbFileClose(bExecute := FALSE);
fbFileClose(bExecute := TRUE,
hFile := hFileHandle);
WHILE (fbFileClose.bBusy) DO
fbFileClose(bExecute:=FALSE);
END_WHILE