Handling FTP Library Errors

DarkMann

Member
Licensed User
Longtime User
Hi All,

As part of a project related to our town webcams - RamseyCam - Webcam views of Ramsey, i have written a short routine to capture the images generated by the camera. The idea is to make some timelapse movies of the still images.

I have a very simple program that uses the FTP library to get an image and save it with an incremental filename, every 15 seconds. For the most part, this seems to work very well, but if the camera upload and my attempted downloads occur at the same time, the FTP Library pops up a dialog to tell me there was an error in the download. I don't seem to be able to trap this in any way. I would like to be able to leave the program unattended for anything up to 24 hours, but this is impossible as it stands, as it will just sit there and wait for a keypress.

B4X:
Sub Globals
   'Declare the global variables here.
   Dim locate As String
   Dim counter As Number
   
End Sub

Sub App_Start
   FtpMain.New1
   locate=AppPath & "\captures\cam "
   counter=0
   Timer15.Enabled=False
   FrmMain.Show
End Sub


Sub ButStart_Click
   FtpMain.Open("vip11.freeola.net","***","***")
   FtpMain.SetCurrentDirectory("htdocs")
   FtpMain.SetCurrentDirectory("cameras")
   Timer15.Enabled=True
End Sub

Sub Timer15_Tick
   ErrorLabel(errHandler)
   counter = counter + 1
   retry:
   FtpMain.GetFile("camera_05.jpg",locate & "one\cam_01_" & Format(counter,"D6") & ".jpg")
   FtpMain.GetFile("camera_06.jpg",locate & "two\cam_02_" & Format(counter,"D6") & ".jpg")
   TxtCounter.Text=Format(counter,"D6")
   Return
   errHandler:
   Goto retry
End Sub

Sub ButStop_Click
   Timer15.Enabled=False
   FtpMain.Close
End Sub

There is just a timer, textbox and start and stop buttons on the form and an FTP object to do the work.

So, the question is, can I trap the error from the FTP Library and tell it to ignore it and retry. The file is only unavailable for a second or so, so a simple retry is normally sufficient.

Any help appreciated.

David

UPDATE:

The program has been running all day in the IDE. It has done more than 3200 downloads from each camera without the error. I guess the problem is only appearing when run compiled. Not a problem if that's the case, I will just always run from the IDE.

David
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is strange as the FTP library isn't supposed to show any dialog. I understand that this dialog is different than the regular error message that Basic4ppc show, right?

It is also strange that it works in the IDE and not compiled as the FTP running code is exactly the same in both cases.

If you can reproduce it, please upload a screen shot of the error message.
 

DarkMann

Member
Licensed User
Longtime User
Hello Erel,

The screen grab is attached. It seems to be a normal Basic4PPC dialogue, but I am now almost certain that it only appears when I run the compiled application. I have just tried it again to grab the error screen and it failed at the first step. When run in the IDE it just carried on. I may add some additional logic to get it to show me when it retries after the error trap fires.

The nature of the multiple webcams mean that they send a picture via ftp to a server at a specified interval, but of course they are not in sync to each other. I am grabbing the images at this same interval, but i'm not in sync either. I cannot re-direct the cameras, or I loose the live images on the website, which is their main real purpose.

It isn't something that is overly important, but I like the idea of being able to do this remote time-lapse work with the cameras in the future.

Thanks for your time.

David
error.jpg
 

agraham

Expert
Licensed User
Longtime User
I think the Goto is the problem. From the help for my Exceptions library.

Any exceptions will vector to the latest label specified by the last Errorlabel statement that was executed. If a further exception occurs in the exception handling code without that code having executed any Errorlabel statements the behaviour of the optimised compiler is different to that of the IDE and legacy compiler. An exception occurring within exception handling code in an optimised compiled program will cause an unhandled exception to occur and a message box shown to the user as previously described. In the IDE and a legacy compiled program the exception handling code will be re-entered at its' original entry point, so potentially causing an endless loop.
In a compiled program I think the first exception enters your errorhandler. Because you have used a Goto the retry, and the next error, effectively occurs in your error handling code which, not having seen another Errorlabel, enters the default exception handler. In the IDE, as noted in the quote above, the code is just looping until the error disappears. This is not a good thing!

You can try moving the Errorlabel after the Retry: label but you risk an endless loop and running out of stack space so you would need a retry counter check of some sort. Alternatively, and probably neater, just exit the timer Sub on an error and wait for it to fire again.
 

DarkMann

Member
Licensed User
Longtime User
Hi Andrew,

Thanks for your insight.

For the number of times the program will be used, I don't think it's worth too much effort. I'll probably do what you suggest and simply exit the timer Sub.

I can see that if the error happens repeatedly then it will start to fill up memory fairly rapidly. Fortunately this doesn't happen too often in the real world. It grabbed 5400 frames in around 24 hours and didn't seem to be too heavy on the memory.

I can actually program the cameras to do the job properly if I need to take it a bit more seriously. It's a question of access to them as they are in buildings other than our own, like the local town hall.

Once again, thanks for your time.

David
O
 
Top