Error When Moving File From USR To SDEXT

Hello,

I have a basic script that generates a file based on tag history. This part seems to be working fine. The issue comes when I am trying to move the file from local usr directory(usr/Reports) to the SD card (usr/sdext/Reports). I see “uact-Export block descriptor writing failed (file open)” when the file copy is scheduled to occur. Any help would be greatly appreciated!!

The code used to generate the one of the files:
///////////////////////////////////////////////////////////////////////
//Temperature Report Functions
///////////////////////////////////////////////////////////////////////
Function SttTempReport()
PRINT “Creating Temperature File…”
//Make sure files are closed prior to reading
CLOSE 1
CLOSE 2
//Open tag history and create daily file
OPEN “exp:$dtHT $ftT $flA $st_m15 $et_s0 $in1” FOR TEXT INPUT AS 1
OPEN “file:/usr/Reports/” + @GetCurrentTimeStamp$() + “TempReport.txt" FOR BINARY APPEND AS 2
//Read history and create first row containing headers
IF EOF 1 THEN GOTO $ReadDone
Line$ = GET 1
IF Line$ = “” THEN GOTO $ReadDone
PosStart% = INSTR 1, Line$, “;”
PosStart% = PosStart% + 1 //Remove ; as well
Keep$ = Line$(PosStart% TO LEN(Line$))
Tab$ = CHR$ 9
Temp$ = @ReplaceStr$(Keep$ , “;”, Tab$)
Temp$ = @ReplaceStr$(Temp$ , "
”, " ")
Temp$ = @ReplaceStr$(Temp$ , “TimeStr”, “Date”)
PUT 2, Temp$
$ReadDone:
CLOSE 1
CLOSE 2
PRINT “Created Temperature File”
EndFN
//
Function BldTempReport()
//Check if its time to create a new file
y% = GETIO “INT_MOVETEMP”
IF (y% = 1) THEN
SETIO “INT_MOVETEMP”, 0
@SttTempReport
ENDIF
PRINT “Temperature file processing…”
//Make sure files are closed prior to reading
CLOSE 1
CLOSE 2
//Open tag history and create daily file
OPEN “exp:$dtHT $ftT $flA $st_m15 $et_s0 $in5” FOR TEXT INPUT AS 1
OPEN “file:/usr/Reports/” + @GetCurrentTimeStamp$() + “_TempReport.txt” FOR BINARY APPEND AS 2
//Skip first header line
Line$ = GET 1
//Loop through the tag history
$ReadNext:
IF EOF 1 THEN GOTO $ReadDone
Line$ = GET 1
IF Line$ = “” THEN GOTO $ReadDone
PosStart% = INSTR 1, Line$, “;”
PosStart% = PosStart% + 1 //Remove ; as well
If PosStart% = 0 Then GOTO $ReadNext
Keep$ = Line$(PosStart% TO LEN(Line$))
PosEnd% = INSTR PosStart%, Line$, “;”
If PosEnd% = 0 THEN GOTO $ReadNext
DateOrig$ = Line$(PosStart% TO PosEnd%)
DateNew$ = CHR$ 34 + DateOrig$(13 TO 20) + " " + DateOrig$(8 TO 11) + “-” + DateOrig$(5 TO 6) + “-” + DateOrig$(2 TO 3) + CHR$ 34 + “;”
KeepNew$ = DateNew$ + Keep$(Len(DateNew$)+1 TO LEN(Keep$))
Tab$ = CHR$ 9
PUT 2, @ReplaceStr$(KeepNew$ , “;”, Tab$)
GOTO $ReadNext
$ReadDone:
CLOSE 1
CLOSE 2
PRINT “Temperature file processed”
//
EndFN
//
And this is the code used to move the files:

FUNCTION Move_Reports()
//Check if SD card is inserted or if there is enough space
SETSYS INF,“LOAD”
SDCardSize$ = GETSYS INF, “SDExtFree”
SDCardSize_Int% = Val SDCardSize$
Print SDCardSize_Int%
IF SDCardSize_Int% > 10000 THEN // 10 MB remains
//Check all directories exist and if not then create them
bF1 = FS “isDir”, “/usr/sdext/Reports”
bF2 = FS “isDir”, “/usr/sdext/Reports/Temperature”
bF3 = FS “isDir”, “/usr/sdext/Reports/Pressure”
bF4 = FS “isDir”, “/usr/sdext/Reports/Events”
IF (bF1 = -1) THEN FS “mkDir”, “/usr/sdext/Reports”
IF (bF2 = -1) THEN FS “mkDir”, “/usr/sdext/Reports/Temperature”
IF (bF3 = -1) THEN FS “mkDir”, “/usr/sdext/Reports/Pressure”
IF (bF4 = -1) THEN FS “mkDir”, “/usr/sdext/Reports/Events”
//Create File Names
F_NAME1$ = @GetYestTimeStamp$() + “_EventReport.txt”
F_NAME2$ = @GetYestTimeStamp$() + “_TempReport.txt”
F_NAME3$ = @GetYestTimeStamp$() + “_PressReport.txt”
//Check if source files exist
bFN1 = FS “isFile”, “/usr/Reports/” + F_NAME1$
bFN2 = FS “isFile”, “/usr/Reports/” + F_NAME2$
bFN3 = FS “isFile”, “/usr/Reports/” + F_NAME3$
//Check yesterdays file already exists
bFC1 = FS “isFile”, “/usr/sdext/Reports/Events/” + F_NAME1$
bFC2 = FS “isFile”, “/usr/sdext/Reports/Temperature/” + F_NAME2$
bFC3 = FS “isFile”, “/usr/sdext/Reports/Pressure/” + F_NAME3$
//Copy the Event Report
IF (bFN1 = 1) THEN
IF (bFC1 = -1) THEN
EBD_STRING$ = “$dtUF$uf/Reports/” + F_NAME1$
FILENAME$ = “/usr/sdext/Reports/Events/”+ F_NAME1$
WRITEEBD EBD_STRING$, FILENAME$
ActionID% = GETSYS Prg, “ACTIONID”
PRINT ActionID%
ENDIF
ENDIF
//Copy the Temperature Report
IF (bFN2 = 1) THEN
IF (bFC2 = -1) THEN
EBD_STRING$ = “$dtUF$uf/Reports/” + F_NAME2$
FILENAME$ = “/usr/sdext/Reports/Temperature/”+ F_NAME2$
WRITEEBD EBD_STRING$, FILENAME$
ActionID% = GETSYS Prg, “ACTIONID”
ENDIF
ENDIF
//Copy the Pressure Report
IF (bFN3 = 1) THEN
IF (bFC3 = -1) THEN
EBD_STRING$ = “$dtUF$uf/Reports/” + F_NAME3$
FILENAME$ = “/usr/sdext/Reports/Pressure/”+ F_NAME3$
WRITEEBD EBD_STRING$, FILENAME$
ActionID% = GETSYS Prg, “ACTIONID”
ENDIF
ENDIF
ELSE
LOGEVENT “EUM Card full or not present”, -1
ENDIF
ENDFN

When in the code does this error get triggered? It seems like it might be failing to find the file you are trying to open or when it tries to open and write to the file. Make sure the files and directories you using exist and are accessible. Are you able to access then over FTP?

Another though is the file could already be getting accesses when you try to open it again causing it to be inaccessible.

The error occurs when the Move_Reports Function is triggered. I can access the files and folders from Filezilla and move the files from the source directory to my local laptop. The files shouldn’t be in a read state at this point but is there way to see if a file is being used/read? Then I could confirm that.

Also, I power cycled the unit and then ran the Move_Reports function and it worked fine. Is it possible that when I am running the BldTempReport function it is failing, and that is leaving the file open? Is there a way to close all open files on an error?

It might help to narrow down what file is actually being used. How is the move report being called? Based on you explanation thinking you are running several scripts on a timer or some other trigger? It might help to use a timer and space them out to prevent them from accessing files at the same time.

Can you share a backup with support files so I can have a better idea on how the script is running?

Deryck

I have uploaded the backup file to google drive as when I tried to upload it, it said it was to big.

Hi Sean,

Im not seeing anything in particular that would be blocking access. Does the error happen every time the function is called? Are any other functions getting called at the same time that are accessing either an EBD or file?

Deryck

Hey Deryck,

After the reboot, I have let the system run without even looking at it. Today when I checked it things seemed to operating correctly. Could we give it another couple of days to see if it crashes? Is it possible that maybe the file was being read through FTP at the same time as the basic script was trying to write to it and that caused the issue?

Sean

Hi Sean,

That could have been the case the error seems to indicate something else was accessing the file blocking the IDE from accessing it. I don’t really see anything specific in your basic script but accessing it via FTP could have been one reason.

Deryck

Hey Deryck,

I have left the system running now for a week and things seem to be functioning fine. Maybe it just needed a reboot, or I have staggered my automatic FTP fetch so it shouldnt overlap with the a file write. Thanks for the help!

Sean

Great, glad its working!

Have a great week!

Deryck