#106 Library SysFileWrite - New File

closed
None
2020-04-17
2020-04-17
dgm-mt
No

Hello,

First of all, I am pretty new working with CodeSys and this is my first question here on this webpage, I´m not sure if this is the correct way to do it...

What I´m trying to do using the "SysFile" library, is create a .txt file and write some info in there.
I can create the file, and I can write into it, but what I can´t do is create a new file on this document.
For example, I need the next:
Line 1
Line 2
But, what I have always is:
Line1 Line2
I tried "$n", "LF", and a lot of command that I found on internet but I can´t make it work.

This is what I have programmed:


VAR
Aux_OpenFile : BOOL;
Aux_Texto1 : BOOL;
Aux_CloseFile : BOOL;
File_Name : STRING;
pResult : POINTER TO SysFile.RTS_IEC_RESULT;
FileHandle : SysFile.RTS_IEC_HANDLE;
Texto_1 : STRING;
Texto_2 : STRING;
Texto_3 : STRING;
END_VAR

//Open File
IF Aux_OpenFile THEN
File_Name := 'd:/test.txt';
FileHandle := SysFileOpen (szFile:=File_Name, am:=AM_WRITE, pResult:=pResult);
Aux_OpenFile := FALSE;
END_IF

//Write File
IF Aux_Texto1 THEN
SysFileWrite (hFile:=FileHandle, pbyBuffer:=ADR(Texto_1), ulSize:=5, pResult:=pResult);
SysFileWrite (hFile:=FileHandle, pbyBuffer:=ADR(Texto_2), ulSize:=1, pResult:=pResult);
SysFileWrite (hFile:=FileHandle, pbyBuffer:=ADR(Texto_3), ulSize:=5, pResult:=pResult);
Aux_Texto1 := FALSE;
END_IF

//Close File
IF Aux_CloseFile THEN
SysFileClose (hFile:=FileHandle);
Aux_CloseFile := FALSE;
END_IF


Thanks in advance to anybody that can help me.

Best regards

Diego

Discussion

  • i-campbell

    i-campbell - 2020-04-17
    • status: open --> closed
     

Log in to post a comment.