File reading or writing error

kallileo
2020-10-09
2020-10-10
  • kallileo - 2020-10-09

    I'm using Codesys 3.5.12 and File Access library 3.5.7 to read and write 3 user configuration files and 3 to read default configuration files. The files are not big with around 100 parameters each.

    Usually it works but many times it's randomly throwing the following error:
    ASM_CREATEJOB_FAILED
    5113 Job creation of AsyncManager failed

    I read and write the files sequentially. As soon reading/writing of the first files is complete it goes to the next one. I have also tried to put time delay in between but the error is still there and it's driving me crazy.

     
  • Thomas - 2020-10-09

    Dear Kallileo,
    The number of jobs is limited in the Runtime. This limit applies to all libraries together!!!!

    Do you have several jobs (reading/writting) at the same time?
    == >> Make sure that a new job is not started until the other one is finished.

    Regards Thomas

     
  • Thomas - 2020-10-09

    Sorry, I haven't read that you start a new job after finished the old one. Are other libraries in your project, which use the AsyncManger. F. e. CAA NetBaseSrv

     
  • kallileo - 2020-10-09

    Hi Thomas
    I rewrote the sequential reading and writing code of the 3 files, implementing a simple CASE state machine and it seems that the problem is in the write and read file function block.
    It seems that the error always appear during state 3 when file that was read must be closed as it is shown in the attached picture.
    Below is the code of read file function block.

    IF xReadStart THEN
        CASE uiReadStatus OF
    
        0:  (* Start *)
            fileopen(xExecute:=FALSE);
            fileread(xExecute:=FALSE);
            fileclose(xExecute:=FALSE);
            uiReadStatus:=uiReadStatus+1;
    
        1: (* open a test.txt file *)
            fileopen.sFileName:=sFileName;                               
            fileopen.eFileMode:=1;                 
            fileopen.xExclusive:=TRUE;
            fileopen(xExecute:=TRUE);
            IF fileopen.xDone THEN
                hFile:=fileopen.hFile;
                uiReadStatus:=uiReadStatus+1;
            END_IF
            IF fileopen.xError THEN
                (* error handling*)
                eError := fileopen.eError;
            END_IF     
    
        2:  (* read file*)
            fileread.hFile:=hFile;
            fileread.udiTimeOut:=1000000;                      (* 100ms Timeout *)
            fileread.pBuffer:=ADR(sFileString);
            sFileString := sFileString;
            fileread.szBuffer:=SIZEOF(sFileString);
            fileread(xExecute:=TRUE);
            IF fileread.xDone THEN
                uiReadStatus:=uiReadStatus+1;
            END_IF
            IF fileread.xError THEN
               (* error handling*)
               eError := fileread.eError;
            END_IF
    
        3:  (* close file*)
            fileclose.hFile:=hFile;
            fileclose(xExecute:=TRUE);
            IF fileclose.xDone THEN
                uiReadStatus:=uiReadStatus+1;
                xExtractParams:=TRUE;
            END_IF
            IF fileclose.xError THEN
                (* error handling*)
                eError := fileclose.eError;
            END_IF
    
        4:  //Loop through string until there is no string left or array has hit its limits
                WHILE StrLenA(pstData:= ADR(sFileString)) > 0 DO
                    //Find location of first break point
                    iSplitLocation := StrFindA(pst1:= ADR(sFileString), pst2:= ADR(sSplitChars), uiSearchStart:= 1) - 1;
    
                    //If there is no break point found then set location to size of string
                    IF iSplitLocation = -1 THEN
                        iSplitLocation := DINT_TO_INT(StrLenA(pstData:= ADR(sFileString)));
                    END_IF
    
                    //Copy the part of the string that is needed for the parameter.
                    StrMidA(
                            pst:= ADR(sFileString), 
                            uiInputBufferSize:= SIZEOF(sFileString), 
                            iLength:= iSplitLocation, 
                            iPosition:= 1, 
                            pstResult:= ADR(sShortString), 
                            uiResultBufferSize:= SIZEOF(sShortString));
    
                    //Make sure string is not empty before using up an array spot.
                    IF StrLenA(pstData:= ADR(sShortString)) > 0 THEN
                        arParameters[iCount] := STRING_TO_INT(sShortString);
                        iCount := iCount + 1;
                    END_IF
    
                    //Remove copied components from long string
                    StrDeleteA(pby:= ADR(sFileString), iLength:= (iSplitLocation + 2), iPosition:= 1);
    
                    //Check to see if more parameters can fit in array. If not exit loop
                    IF iCount > MAX_PARAMETERS THEN
                        iCount := 0;
                        EXIT;
                    END_IF 
                END_WHILE
                //xExtractParams := FALSE;
                uiReadStatus := uiReadStatus+1;
    
        5: (* end of procedure *)
            xExtractionComplete := TRUE;    
    
        END_CASE
    ELSE
        eError := FILE.ERROR.NO_ERROR;
        xExtractionComplete := FALSE;
        uiReadStatus:=0;    
    END_IF
    
     
  • kallileo - 2020-10-10

    Found the problem.

    Had to add

     fileopen(xExecute:=FALSE);
     fileread(xExecute:=FALSE);
    

    in state 2 when file read is complete.

    Thanks

     

Log in to post a comment.