Create Txt file in column-wise

Siavash-80
2012-11-08
2012-11-12
  • Siavash-80 - 2012-11-08

    Dear All,

    I would like to save data in txt file for plotting by Matlab. Following code I am using but result is not that one I want I have shifted to right in each row:
    PROGRAM PLC_PRG
    VAR
    hFile: DWORD;
    szFilePath: STRING:= 'C:\ay.txt';
    wNewLine: ARRAY[1..20] OF STRING;
    (wNewLine:STRING;)
    dwWritten:DWORD;
    CloseFile: BOOL;
    ay:STRING;
    i: INT:= 1 ;
    strString:STRING;
    Lenght: INT;
    SizeoFile: DINT;
    END_VAR

    hFile := SysFileOpen(szFilePath, 'a');

    WHILE (i <> 30) DO

    ay :=INT_TO_STRING(i);
    
    dwWritten:= SysFileWrite(hFile, ADR(ay), SIZEOF(ay));
    strString := CONCAT(ay, '$R$L');
    i := i+1;
    

    END_WHILE

    Lenght := LEN(strString);
    (Close the Opened File)
    CloseFile := SysFileClose(hFile);
    SizeoFile := SysFileGetSize(szFilePath);

    Result in ay.txt file I am looking for:
    1
    2
    3
    4
    5
    6
    ...30
    RESULT I GOT:

    IMG: ay.png

     
  • pnn - 2012-11-09

    you write to file var ay which doesn't contain CRLF, write strString instead

     
  • Siavash-80 - 2012-11-12

    pnn hat geschrieben:
    you write to file var ay which doesn't contain CRLF, write strString instead

    Hi,

    Thanks for your reply, How can perform CRLF in CodeSys . I solved the problem with "CONCAT" and "$R$N". And now I have problem how to save data in 2 columns in excel file. In such way that if I could plot each column.

     
  • shooter - 2012-11-12

    put a comma in between the columns so it will be a CDF

    and check your string length strstring:string(3);

     

Log in to post a comment.