I wrote a FB to read the content of specific text files. It chooses a text file depending of the input "bRfidNo", for instance: bRfidNo at 1 would open 1.txt and save the contents on a local array in the PLC. It uses the "File Access" library and its function Blocks.
Thing is, when I use my FB on PLC_PRG and choose manually bRfidNo it works fine. But I wanted too by Startup of the PLC have it read every text file and add all its contents on the local Array. I wrote a Startup subprogramm which is basically a loop of my Read-FB until he readed everything, but it remains stuck on Case 10 of the FB.
Here's the Code of the FB. The "fbRead(xRead) remains stuck on true, so I'm suspecting I'm starting the input wrong on my Startup-program maybe?
fopen.xDone doesn't seem to turn on when I call the FB inside another PRG either, despite that I get no fopen.xError.
CASEuiStepOF(*warteaufTrigger*)0: IFxReadANDbRfidNo>=1ANDbRfidNo<=16THENxRead:=FALSE;xBusy:=TRUE;xReadDone:=FALSE;uiStep:=10;iCounter1:=1;sFilePath:=CONCAT('Local_Buffer\',INT_TO_STRING(bRfidNo)); //Open the buffer.txt of the selected RacksFilePath:=CONCAT(sFilePath,'.txt');END_IF10: (*createoropenmylog-filefortheHEADER*)fopen.sFileName:=sFilePath;fopen.eFileMode:=File.MODE.MREAD;fopen.xExclusive:=TRUE;fopen(xExecute:=TRUE);IFfopen.xDoneTHENhFile:=fopen.hFile;uReadIndex:=0;uiStep:=20;END_IFIFfopen.xErrorTHEN(*errorhandling*)xError:=TRUE;eError:=fopen.eError;END_IF20: (*readlogdatatofile*)fread.hFile:=hFile;fread.pBuffer:=ADR(sStringToRead);fread.szBuffer:=SIZEOF(sStringToRead);fread.udiTimeOut:=100000; //Timeoutfread(xExecute:=TRUE);IFfread.xDoneTHENfread(xExecute :=FALSE);sStringToWork:=sStringToRead;szFileSize2:=fread.szSize;uiStep:=30;END_IFIFfread.xErrorTHEN//ErrorxBusy:=FALSE;xRead:=FALSE;uiStep:=40;END_IF30: (*adapttextdatatoarrays*)FORiCounter1 :=1TO36BY1DOiStringFIND :=stu.StrFindA(ADR(sStringToRead),ADR(CRLF),1); //Find the first line break (;$R$N)StrMidA(//ExtractthefirstPanel-Stringfromthewholereadedtextpst:=ADR(sStringToRead),
uiInputBufferSize:=SIZEOF(sStringToRead),
iLength:=iStringFIND-1,
iPosition:=1,
pstResult:=ADR(sStringMID),
uiResultBufferSize:=SIZEOF(sStringMID));saaList[bRfidNo][iCounter1] :=sStringMID; //Add the Panel to the local Rack ArrayStrDeleteA(pby:=ADR(sStringToRead), iLength:=(iStringFIND+2), iPosition:=1);END_FORuiStep:=40;40: (*closelogfile*)fclose.hFile:=hFile;fclose(xExecute:=TRUE);IFfclose.xDoneTHENfopen(xExecute:=FALSE);fread(xExecute:=FALSE);fclose(xExecute:=FALSE);xReadDone:=TRUE;//xRead:=TRUE;xBusy:=FALSE;//uiStep:=50;iCounter1:=1;//uiStep:=0;END_IFIFfclose.xErrorTHEN//ErrorxBusy:=FALSE;xRead:=FALSE;uiStep:=0;END_IFEND_CASE
And here the Startup-program (I tried too with FORs, Ifs etc, no difference)
Hi all,
I wrote a FB to read the content of specific text files. It chooses a text file depending of the input "bRfidNo", for instance: bRfidNo at 1 would open 1.txt and save the contents on a local array in the PLC. It uses the "File Access" library and its function Blocks.
Thing is, when I use my FB on PLC_PRG and choose manually bRfidNo it works fine. But I wanted too by Startup of the PLC have it read every text file and add all its contents on the local Array. I wrote a Startup subprogramm which is basically a loop of my Read-FB until he readed everything, but it remains stuck on Case 10 of the FB.
Here's the Code of the FB. The "fbRead(xRead) remains stuck on true, so I'm suspecting I'm starting the input wrong on my Startup-program maybe?
fopen.xDone doesn't seem to turn on when I call the FB inside another PRG either, despite that I get no fopen.xError.
And here the Startup-program (I tried too with FORs, Ifs etc, no difference)
Last edit: epinikion 2020-10-23