SetEndOfFile in WinCC

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
sweigl
Posts:2
Joined: Thu Jul 28, 2016 11:17 am

SetEndOfFile in WinCC

Post by sweigl »

Hello,

I am Using WinCCOA 3.14 on Win 7 64 Bit.
I got a question about file operations in WinCC. I am searching for a function like the SetEndOfFile function.

My Problem:
My Script is writing data to a file in a while loop. Before writing to the file I am setting the filepointer to the start of the file via fseek (f, 0, SEEK_SET);.
If my data has less bytes in this loop then in my last loop there are old bytes left in the file from the last writing operation. I want to set the end of file where I stopped writing in this loop to avoid problems with old bytes from the last loop.

See Code attached.

Code: Select all

main()
{
    int err; // error code
    const string fileName = "C:/TEMP/TEST.csv";
    
    file f = fopen(fileName, "w");
    err = ferror(f); //Output possible errors
    if ( err )
    {
        DebugN("fopen Error");
        return;
    }
    else
    {
        while(true) //
        {
            delay(1,500);
            
            int speed;
            dpGet("System1:Car1.speed",speed);
            string data = "speed_in;"+speed+"\\n";
            fseek (f, 0, SEEK_SET);
            fputs(data, f);
            fflush (f);
            
            SetEndOfFile(f);
        }
    }
    fclose(f);
}
If speed changes from 10 to 9 there is one byte less written to the file which results in two “\\n” one from this loop and one from the last loop because it has not been overwritten.

Is there a way to get SetEndOfFile() to work in WinCC or is there a similar function which works in WinCC?

Best regards,
Stefan Weigl

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: SetEndOfFile in WinCC

Post by mkoller »

The only thing you can do now is to close the file after writing and reopen it in the next loop, so that it is recreated as empty.

sweigl
Posts:2
Joined: Thu Jul 28, 2016 11:17 am

Re: SetEndOfFile in WinCC

Post by sweigl »

Although I wanted to avoid this if possible I was afraid that closing and reopening the file is the only way.

Thanks for your assistance and have a nice weekend

3 posts • Page 1 of 1