Jump to content

Banner.jpg.b89429c566825f6ab32bcafbada449c9.jpg

VB.NET coding for custom all sky camera


purgitoria

Recommended Posts

Hi All,

I am currently working on a project to build a remote and robotic observatory which is never cheap and to cut down on costs and provide the most reliable solution i decided to build my own All Sky Cam. As a basis i have used an ImagingSource DMK 33G445 monochrome camera which will be installed inside a home made housing that i am currently just finishing off. The camera i chose is a GigE model which is PoE as i detest USB cables in runs of more than 2 meters and find them completely unreliable and also being PoE i can power cycle the camera via the managed PoE network switch if it needs a reboot. I could have bought one of the cameras available on the market but they are all USB and the software included is pretty basic will not support other brands but the ImagingSource cameras have a downloadable SDK to help create your own software.
I however am an absolute novice when it comes to software and programming but as there is nothing on the market that does what i want other than bundled with equipment costing thousands of £££££ and I decided that I would look at writing my own program that would give me the functions i needed with a modest cost. The camera and housing has cost me around £600 and all of the software including Visual Studio 2012 has all been free and so far i have managed to create a basic interface for the software which allows me to start and stop the live feed, select different devices (TIS devices only), and manipulate settings such as exposure, gain, brightness etc. and i can also write code to save off an image sequence or an AVI video file.
The point i am at now however is that i would like to have 2 checkbox functions that perform specific functions in relation to publishing live image feed for the online interface to my remote observatory. I believe i should be able to have one checkbox with code that when checked by the user (me) will save off an image to a specified location with a set file name on a regular basis and a second check box that when checked will upload that set image to an FTP server (the back end of the website for live online viewing) automatically overwriting the original image file. I however am currently stumped as to how exactly i can code this successfully without the software hanging.
Any VB.NET experts out there willing to point me in the right direction?

What i have so far is the FTP part (i think):

 

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

        If CheckBox1.Checked = True Then
            Timer2.Start()
        End If
        If CheckBox1.Checked = False Then
            Timer2.Stop()
        End If

    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

        Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://speedtest.tele2.net/upload/sky000.jpg"), System.Net.FtpWebRequest)
        request.Credentials = New System.Net.NetworkCredential(txFTPUser.Text, txFTPPass.Text)
        request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        Dim file() As Byte = System.IO.File.ReadAllBytes("C:\Users\Vid Ed\Pictures\All Sky\sky000.jpg")

        Dim strz As System.IO.Stream = request.GetRequestStream()
        strz.Write(file, 0, file.Length)
        strz.Close()
        strz.Dispose()

    End Sub

 

I think this should take the username and password from the input of text boxes within my form and use them as credentials to upload a specific file to a specific location on an FTP server which i can then use as a web display of the current all sky cam view. I have i think coded this to a check box function that will start the FTP upload on a timer basis when the checkbox is checked and when unchecked will disable the timer function and the FTP uploading. What i am concerned about is the error handling and what will happen if the FTP server is not reachable.  Currently if i select an unuseable FTP server my debugging shows me  the following debug before closing down:

A first chance exception of type 'System.Net.WebException' occurred in System.dll
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (530) Not logged in.
The program '[1268] SkyCam.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0)

 

What i want it to do is simply report to the user (me) if the FTP connection fails instead of receiving an unhandled exception but how exactly would i handle this error reporting?

Link to comment
Share on other sites

Add a try block round your code

Try

dim request =......

....

Catch ex as exception

Messagebox.show(ex.message)

Messagebox.show(ex.stacktrace)

End try

End sub

Replace messagebox with your preferred notification method,logging etc.

I am not familiar with the ftp classes but you may want to check that each step has processed correctly.  Ie is request a valid object or still nothing etc.

Rob

Link to comment
Share on other sites

Hi Rob,

 

Thanks for the tip, that has got the messaging working and what i attempted to do was get it to create a log file with the below

 

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

        Try

            Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(txFTPAddress.Text), System.Net.FtpWebRequest)

            request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            Dim file() As Byte = System.IO.File.ReadAllBytes(txFTPAddress.Text)
            request.Credentials = New System.Net.NetworkCredential(txFTPUser.Text, txFTPPass.Text)
            Dim strz As System.IO.Stream = request.GetRequestStream()
            strz.Write(file, 0, file.Length)
            strz.Close()
            strz.Dispose()

        Catch ex As Exception

            MessageBox.Show(ex.Message)
            IO.File.AppendAllText("C:\Users\Public\Documents\SkyCamFTPLog.txt", String.Format("{0}{1}", Environment.NewLine, ex.ToString()))

        End Try

I can get the log file working fine but this will be used unattended a lot of the time so is there any modifier that will get the MessageBox to close on its own after a set time? This will save the issue of having lots of MessabeBox windows open after a period of error.

 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.