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

CAA File lib documentation is wrong

2018-08-06
2018-08-06
  • nsg@nsgroup.it - 2018-08-06

    Hi, I read the documentation for CAA File library but it's not up to date; I wrote a fix, and it's compiling but File.Open.xError is true and the file isnt written nor opened nor created.
    The code i used was:

    FUNCTION File_Handle : BOOL
    VAR_INPUT
       n:STRING(255);
       str:STRING(255);
       
    END_VAR
    VAR
       err:BOOL:=FALSE;
       filop:      FILE.Open;
       filwr:      FILE.Write;
        filrd:      FILE.Read;
        filcl:      FILE.Close;
       
       sFileName:  STRING(255):= 'TestFile.txt';
        hFile:      DWORD;
       
       sFileString:    STRING:='';
        szFileSize1:    UINT := 0;
        szFileSize2:    UINT := 0;
    END_VAR
    

    //------------------------------------------------------------------------------------------------------------//

    (* create a new file *)
            filop.sFileName:=n;
            filop.eFileMode:=FILE.MODE.MWRITE;
            filop.xExclusive:=FALSE;
            filop( xExecute:=TRUE);
            IF filop.xDone THEN
                hFile:=filop.hFile;
            END_IF
            IF filop.xError THEN
                (* error handling*)
                err:=TRUE;
          ELSE
             err:=FALSE;
            END_IF      
          (* write text in the file *)
            filwr.hFile:=hFile;
            filwr.pBuffer:=ADR(str);
            szFileSize1:=SIZEOF(str);
            filwr.szSize:=szFileSize1;
            filwr.udiTimeOut:=100000;       (* 100ms Timeout *)
            filwr( xExecute:=TRUE);
            IF filwr.xDone THEN
             ;
            END_IF
            IF filwr.xError THEN
                (* error handling*)
                err:=TRUE;
            ELSE
             err:=FALSE;
            END_IF
          
          File_Handle:=err;
    

    Do you have any solution? ty

     
  • josepmariarams - 2018-08-06

    It doesnt works because you are creating file objects inside a function. Everytime you call the function the objects are redefined.

    Execute has to pass from false to true.

    Be carefull in call file objects from inside realtime, its blocks the realtime.

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • nsg@nsgroup.it - 2018-08-06

    why the read function block doesn't have an output string???

    Do you have any solution? ty

     

Log in to post a comment.