Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Create and write data in a file text (csv)

julien
2021-03-10
2021-03-10
  • julien - 2021-03-10

    Hello everybody,

    i try to write data in a file text without succes.
    I use the CAA_File library.
    First problem, I never get the position at the end of the file.
    I know the handling of the files is asynchronous, so I put a timeout between fileof and filwr to make sure the return from fileof.xDone and fileof.xEOF is done correctly.
    If xEOF is false, I increment the position by one and execute filsp (setPosition) and retest fileof (xExecute: = TRUE)
    However my pointer position index increases to values exceeding thousands when there are less than 10 characters.
    I have to write a file of three lines and twenty-one columns from an array of variables (nothing complicated there to loop).
    The loop work as:
    1 - getPosition
    2 - test if xEOF
    3 - If not xEOF then iPosition++, setPosition and back to test xEOF.
    4 - If xEOF then write the data[i] in the text file and back to getPosition for pprocess the data[i+1]
    5 - i and j = maxCounter then filcl

    I can't find the right way to do this with filgp, fileof, and filsp.
    Would you like to explain to me how and how fileof works?
    Thanks.

     

    Last edit: julien 2021-03-10
  • i-campbell

    i-campbell - 2021-03-10

    I do not know the answer to your problem. For me though, I think the CAA File is still very low level and difficult to get right. If you want to save yourself some hassle, use the CSV Utils SL library.

     

Log in to post a comment.