pixtenduser2 - 2020-06-16

Dear programmers,

I'm trying to write a programm, which reads and writes a config file to the raspberry pi filesystem.
When I start the Pi, I want to read out the config and when I press a button ("save"), I want the programm to read out some variables and write them into the config file (.csv).
I'm using the File Access library from 3S, but I can't get it to work.
The problem is, that the function blocks "FILE.write" and "FILE.close don't work correctly in my setup.
The eError outputs always return "handle invalid". I tried multiple settings for the csv-file (test.csv). I copied a valid version (filled with string data) of this file to the raspberry pi, I gave it the chmod 777 and 666 permissions, I let the programm create a new file and so on. But every time, I get "invalid handle". The FILE.open always returns a hfile (handle) with "0", and the write- and/or close-FB can't finish.
If I copy a valid file to the raspberry, it has "0" size after opening and writing with my code.

Can you explain me how I get to manage this problem? I would be very thankful for some advice.

I added the code which I used:

VAR
    bConfigWrite_Index : BYTE;
    xWriteConfig : BOOL;
    sTEST: STRING := 'TEST';
    FB_OpenFile : FILE.Open;
    FB_WriteFile : FILE.Write;
    FB_CloseFile : FILE.Close;


    xOpenFile : BOOL;
    xOpenFile_DONE : BOOL;
    xOpenConfig_Error : BOOL;
    eFileMode_Config : FILE.MODE;
    eError_Config : FILE.ERROR;

    xWriteFile : BOOL;
    xAbortFile : BOOL;
    xWriteFile_DONE : BOOL;
    xWriteConfig_Error : BOOL;
    eError_Write : FILE.ERROR;

    xCloseFile : BOOL;
    xCloseConfig_DONE : BOOL;
    xCloseConfig_Error : BOOL;
    eCloseConfig_Error : FILE.ERROR;
END_VAR


// PROGRAMM

CASE bConfigWrite_Index OF

    0:  IF xWriteConfig THEN
                    xOpenFile := TRUE;
                    eFileMode_Config := File.MODE.MWRITE;
                    bConfigWrite_Index := 10;
                    xWriteConfig := FALSE;
        END_IF


    10: IF xOpenFile_DONE THEN
                    xOpenFile := FALSE;
                    bConfigWrite_Index := 20;
            END_IF


    20: xWriteFile := TRUE;
            bConfigWrite_Index := 21;


    21: IF xWriteFile_DONE THEN
                    xWriteFile := FALSE;
                    bConfigWrite_Index := 30;
             END_IF

    30: xCloseFile := TRUE;
            bConfigWrite_Index := 40;


    40: IF xCloseConfig_DONE THEN
                    xCloseFile := FALSE;
                    bConfigWrite_Index := 0;
             END_IF

END_CASE


FB_OpenFile(
        xExecute:= xOpenFile, 
        xDone=> xOpenFile_DONE, 
        xBusy=> , 
        xError=> xOpenConfig_Error, 
        sFileName:= '/home/pi/test/test.csv', 
        eFileMode:= eFileMode_Config, 
        xExclusive:= FALSE, 
        eError=> eError_Config, 
        hFile=> );

FB_WriteFile(
            xExecute:= xWriteFile, 
            xAbort:= xAbortWrite, 
            udiTimeOut:= 100000, 
            xDone=> xWriteFile_DONE, 
            xBusy=> , 
            xError=> xWriteConfig_Error, 
            xAborted=> , 
            hFile:= FB_OpenFile.hFile, 
            pBuffer:= ADR(sTEST), 
            szSize:= SIZEOF(sTEST), 
            eError=> eError_Write);

FB_CloseFile(
        xExecute:= xCloseFile, 
        xDone=> xCloseConfig_DONE, 
        xBusy=> , 
        xError=> xCloseConfig_Error, 
        hFile:= FB_OpenFile.hFile, 
        eError=> eCloseConfig_Error);