Hello
I am trying to write multiple lines into one file but in different time (like a log file), but I did not success.
I tried this on KSS 8.6.x
I am able to write multiple lines at one time like this, but this is not what I need:
Code
CWRITE($FCT_CALL,stateT,modusT,"krl_fopen",sPath[],"a",iHandle)
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, "Data 1")
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, "Data 2")
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, "Data 3")
CWRITE($FCT_CALL,stateT,modusT,"krl_fclose",iHandle)
I want this to work:
Code
CWRITE($FCT_CALL,stateT,modusT,"krl_fopen",sPath[],"a",iHandle)
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, "Data 1")
CWRITE($FCT_CALL,stateT,modusT,"krl_fclose",iHandle)
CWRITE($FCT_CALL,stateT,modusT,"krl_fopen",sPath[],"a",iHandle)
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, "Data 2")
CWRITE($FCT_CALL,stateT,modusT,"krl_fclose",iHandle)
CWRITE($FCT_CALL,stateT,modusT,"krl_fopen",sPath[],"a",iHandle)
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, "Data 3")
CWRITE($FCT_CALL,stateT,modusT,"krl_fclose",iHandle)
Display More
I tried all the "Mode for opening" variables (r, a, w ... ) without success.
The krl_fopen works fine at the first time, creates the file, write into it and close it, but at the 2nd time I am not able to open it, I got error MSG_NO = -2 => "Operation failed"
How can I open and write the same a file several time?
This is the source code:
Code
&ACCESS RVO
&PARAM EDITMASK = *
DEF FileTest()
CHAR sLogFileName[100]
CHAR sPath[100]
sLogFileName[] = "log.txt"
WriteFile(sLogFileName[], "alma")
WriteFile(sLogFileName[], "korte")
HALT
END
GLOBAL DEF WriteFile(sPath[]:IN,sData[]:IN)
CHAR sPath[]
CHAR sData[]
DECL STATE_T stateT
DECL MODUS_T modusT
INT iHandle
modusT=#sync
iHandle=0
CWRITE($FCT_CALL,stateT,modusT,"krl_fopen",sPath[],"a",iHandle)
CheckSTAT("krl_fopen", stateT)
CWRITE($FCT_CALL,stateT,modusT,"krl_fwriteln",iHandle, sData[])
CheckSTAT("krl_fprintf", stateT)
CWRITE($FCT_CALL,stateT,modusT,"krl_fclose",iHandle)
CheckSTAT("krl_fclose", stateT)
END
DEF CheckSTAT(sInKRL:IN, stateTIN:IN, sPath[]:IN)
CHAR sInKRL[]
DECL STATE_T stateTIN
CHAR sPath[]
DECL STATE_T stateTSW
CHAR sInfo[30]
INT iOffset
iOffset = 0
IF stateTIN.RET1 == #CMD_ABORT THEN
ON_ERROR_PROCEED
sPath[] = sPath[]
IF $ERR.Number==0 THEN
SWRITE(sInfo[], stateTSW, iOffset, "%s: %s MSG_NO: %i", sInKRL[], sPath[], stateTIN.MSG_NO)
ELSE
SWRITE(sInfo[], stateTSW, iOffset, "%s MSG_NO: %i", sInKRL[], stateTIN.MSG_NO)
ENDIF
SWITCH stateTIN.MSG_NO
CASE -1
MsgQuit("Internal error!", sInfo[])
CASE -2
MsgQuit("Operation failed!", sInfo[])
CASE -3
MsgQuit("There is no file open!", sInfo[],)
CASE -4
MsgQuit("End of file has been reached!", sInfo[],)
CASE -5
MsgQuit("Maximum size of directory C:\KRC\ROBOTER\UserFiles has been reached!", sInfo[])
CASE -6
MsgQuit("File already open!", sInfo[])
CASE -7
MsgQuit("Positioning of the file pointer outside the limits of the file!", sInfo[])
CASE -8
MsgQuit("File system not available: error in specification of target directory!", sInfo[])
CASE -10
MsgQuit("Invalid number of function parameters transferred!", sInfo[])
CASE -11
MsgQuit("At least one function parameter has an invalid value!", sInfo[])
CASE -12
MsgQuit("At least one function parameter has an incorrect data type!", sInfo[])
CASE -13
MsgQuit("At least one function parameter is not a variable although a variable is expected!", sInfo[])
CASE -14
MsgQuit("At least one function parameter string is blank!", sInfo[])
CASE -15
MsgQuit("At least one function parameter string is too long!", sInfo[])
CASE -16
MsgQuit("At least one function parameter string contains invalid characters!", sInfo[])
CASE -30
MsgQuit("Direct access to the ROBOTER directory is not permissible!", sInfo[])
CASE -31
MsgQuit("Invalid absolute path!", sInfo[])
CASE -32
MsgQuit("Mount point not found!", sInfo[])
CASE -40
MsgQuit("File cannot be opened because 11 files are already open!", sInfo[])
CASE -42
MsgQuit("The format string contains an invalid format statement!", sInfo[])
CASE -43
MsgQuit("The nbr of values to be read in the format str does not correspond to the nbr of transferred parameters!", sInfo[])
CASE -44
MsgQuit("An invalid format was specified for one parameter!", sInfo[])
DEFAULT
MsgQuit("Unknown MSG_NO: %1!", sInKRL[], stateTIN.MSG_NO)
ENDSWITCH
ENDIF
END
Display More