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

How to create a header in a .csv datalogger

2022-11-07
2022-11-18
  • pumpenheinrich

    pumpenheinrich - 2022-11-07

    Hi everyone,

    I need some advice on how to implement a header in a .csv. I created a dataloger with the libary SysFile. Currently I am checking if my .csv file exist and if not its created. After this iteration new values are written to it with SysFile.AM_APPEND_PLUS. Now I dont now to check if the File is already written or not, to decide if a header should be createt.

    Thanks a lot for every tip or advise.

    Best Regards

     
  • ignat

    ignat - 2022-11-18

    Hi, I have ein paar suggestions, maybe it would helpful.

    By header you mean some first string on the CSV file.

    As I see, you have already checking for "created / not created".
    So I guess you already splitted your code to 'Create File' and 'Append to old'.
    So I suggest just to extend the first part with 'Create File and Write header to it'.

    Maybe you have to arrange it with some CASE construction like:

    CASE iRecordProcedurePointer OF:
        0:
        // some init
        iRecordProcedurePointer := 1;
        1:
        // check existing or not
        IF NOT xExisting THEN
            iRecordProcedurePointer := 2; // go to create part
        ELSE
            iRecordProcedurePointer := 3; // go to append part
        END_IF
        2:
        // create file
        // create string for Header
        // write to file
        iRecordProcedurePointer := 0;
    
        3:
        // create string for Record
        // write to file
        iRecordProcedurePointer := 0;
    END_CASE
    

    OR you can even add some case for writing (because you are always writing) and combine different stringToWrite and fill it with header or process data string

     

Log in to post a comment.