Announcement

Collapse
No announcement yet.

Help interfacing the uCam

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help interfacing the uCam

    In another thread I posted a quite detailed explanation of how to get the uDrive talking to both vb.net and to assembly language. However, a similar process with the uCam is proving much more difficult.

    Ok, tools of the trade include software that can talk to the serial port (vb.net and robot basic) and two serial ports so you can loop data back and emulate things. Also, a serial port sniffer is essential which I got for free but I see they are charging a small royalty now http://www.serial-port-monitor.com/index.html Ultimately this is going to be ported to the Propeller but for the moment the task is getting it working talking to a PC

    I have the software supplied with the device which is very useful for following the commands.

    The problem is that to create this software takes hours (days even) building it up one line at a time and checking it works. I've got as far as command AA04 but it is proving very hard to debug.

    Problems: The device shuts down if you only get half way through doing something. So lots of power cycles are required. The reset command AA08 does not seem to work. And even the supplied software hangs quite often, so clearly this doesn't have a reliable reset mechanism. Bootups are inconsistent - you can send it a series of commands and get ACKs back, and they cycle the power, give the same commands and it won't work. The number of initialisation commands can be up to 60 but sometimes it works with only one, and it is unclear when to stop sending these, and the number can vary so doing one for one comparisons with the supplied program is difficult. And doing comparisons is difficult too - eg in section 5.4.1 is a supplied series of instructions for a 640x480 jpeg but the trace is not the same on the supplied program - eg there is no command for a snapshot AA05, and the command for the size is AA01 00 07 07 07 but on the trace it is AA01 00 07 03 07. The package size doesn't match either.

    Having spent a whole day on this (and having cracked the code for the uDrive), I'm wondering if there is some more information available:

    * A reliable reset mechanism that works regardless of the module being only half way through a previous initialisation
    * A consistent number of initialisation packets - even if this means adding in time delays between various steps
    * And if at all possible, some source code so it is possible to single step through the commands and trace things more slowly?

    Also, maybe my module was a one-off, but it came supplied with a D9 connector (at no extra cost, thanks++), but the power and data lines were transposed inside the D9 shell (lucky RS232 is robust!)

    Any help with some source code would be most appreciated!

    Addit: This is only partially complete, but it is returning the first 512 bytes of the picture now. Reboots are still unreliable, and there is an extra Ack needed that isn't in the manual. But we are making progress!

    Dim WithEvents SerialPort As New IO.Ports.SerialPort ' serial port declare
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) ' for sleep statements
    Public InPacket(0 To 2000) As Byte ' bug with serial.write strings like chr(255) won't go out
    Public OutPacket(0 To 50) As Byte ' usually only send out a few bytes though so could make this smaller
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim i As Integer

    SerialPort.PortName = TextBox1.Text
    SerialPort.BaudRate = TextBox2.Text
    SerialPort.Parity = IO.Ports.Parity.None ' no parity
    SerialPort.DataBits = 8 ' 8 bits
    SerialPort.StopBits = IO.Ports.StopBits.One ' one stop bit
    SerialPort.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response
    Try
    SerialPort.Open() ' open the port
    SerialPort.DiscardInBuffer() ' clear the input buffer
    'Reset()
    'Sleep(1000)
    'GetPacket()
    TextBox3.Text += "Waking up camera" + vbCrLf
    Application.DoEvents()
    i = 0
    Do
    Synch()
    Sleep(10) ' wait for response
    Application.DoEvents() ' update the display
    i += 1
    TextBox3.Text += "."
    Loop Until i > 60 Or SerialPort.BytesToRead >= 6
    If i > 60 Then TextBox3.Text += "No response after 60 tries" + vbCrLf
    TextBox3.Text += vbCrLf + "Waiting 3 secs to adjust brightness and colour" + vbCrLf
    GetPacket()
    Sleep(1000) ' delay
    SerialPort.DiscardInBuffer() ' clear the input buffer
    SendAck()
    Sleep(2000) ' to adjust brightness etc
    jpeg() ' send instructions for a jpeg
    GetSixBytes()
    PackageSize()
    GetSixBytes()
    'Snapshot()
    'GetSixBytes()
    GetPicture()
    GetSixBytes()
    SendAck() ' yes this is needed but it isn't in the manual
    ' now get 512 bytes
    Get512Bytes()
    SerialPort.Close()
    Catch ex As Exception
    SerialPort.Close()
    TextBox3.Text += "Timeout error" + vbCrLf

    End Try
    End Sub
    Private Sub GetPacket()
    ' read 6 bytes back from the uCam
    Dim i As Integer
    Dim h As String
    SerialPort.Read(InPacket, 0, 6) ' read 6 bytes back
    For i = 0 To 5
    h = Hex(InPacket(i))
    If Val("&H" + h) < 16 Then h = "0" + h ' add leading zero
    TextBox3.Text += h + " "
    Next
    If InPacket(1) = 15 Then ' NAK error
    TextBox3.Text += " Error number (p10 manual) = " + Str(InPacket(4))
    End If
    If InPacket(1) = 14 Then ' ACK - print number
    TextBox3.Text += "Ack command " + Str(InPacket(2)) + " number " + Str(InPacket(3))
    End If
    TextBox3.Text += vbCrLf
    Application.DoEvents() ' refresh the display
    End Sub
    Sub GetSixBytes()
    Do
    Loop Until SerialPort.BytesToRead >= 6
    GetPacket()
    End Sub
    Private Sub Get512Bytes()
    TextBox3.Text += "Waiting for bytes to come in..." + vbCrLf
    Application.DoEvents()
    Sleep(2000)
    TextBox3.Text += "Number of bytes to read " + Str(SerialPort.BytesToRead) + vbCrLf
    'SerialPort.Read(InPacket, 0, 512) ' read 512 bytes back
    ' but is it 512+ the header bytes?
    Application.DoEvents()
    End Sub


    Private Sub SendAck()
    OutPacket(0) = &HAA
    OutPacket(1) = &HE
    OutPacket(2) = &HD
    OutPacket(3) = &H0
    OutPacket(4) = &H0
    OutPacket(5) = &H0
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    Private Sub jpeg()
    ' jpeg 640
    OutPacket(0) = &HAA
    OutPacket(1) = &H1
    OutPacket(2) = &H0
    OutPacket(3) = &H7
    OutPacket(4) = &H3
    OutPacket(5) = &H1 ' tiny jpeg for testing first
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    Private Sub PackageSize()
    ' 512 bytes
    OutPacket(0) = &HAA
    OutPacket(1) = &H6
    OutPacket(2) = &H8
    OutPacket(3) = &H0
    OutPacket(4) = &H2 ' 2*256
    OutPacket(5) = &H0
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    Private Sub Snapshot()
    ' take the picture
    OutPacket(0) = &HAA
    OutPacket(1) = &H5
    OutPacket(2) = &H0
    OutPacket(3) = &H0
    OutPacket(4) = &H0
    OutPacket(5) = &H0
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    Private Sub GetPicture()
    ' gets an ack then gets the bytes
    OutPacket(0) = &HAA
    OutPacket(1) = &H4
    OutPacket(2) = &H5
    OutPacket(3) = &H0
    OutPacket(4) = &H0
    OutPacket(5) = &H0
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    Private Sub Reset()
    ' issue a reset command
    OutPacket(0) = &HAA
    OutPacket(1) = &H8
    OutPacket(2) = &H0
    OutPacket(3) = &H0
    OutPacket(4) = &H0
    OutPacket(5) = &H0
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    Private Sub Synch()
    OutPacket(0) = &HAA
    OutPacket(1) = &HD
    OutPacket(2) = &H0
    OutPacket(3) = &H0
    OutPacket(4) = &H0
    OutPacket(5) = &H0
    SerialPort.Write(OutPacket, 0, 6)
    End Sub
    End Class

  • #2


    A quick update. 4dsystems kindly sent me their latest testing software. It is *much* better than the one currently on the website as it prints out the Rx and Tx data packets and I've made a lot of progress.

    What I've found though is that the module still gets very unhappy from time to time and simply stops communicating. So I've built a little 'hard reset' circuit using a 555 and 4 transistors, and this listens to the RS232 line and if there is a signal then it turns on the uCam.

    The 555 is configured as a retriggerable monostable with a time delay of about 4 seconds. So if the uCam hangs, simply wait 4 seconds and it will turn off, and then turn it on again with a byte on the RS232 line and it is ready to go.

    I'm finding it responds to a synch after only two or three tries when it is powered up. So this is much simpler than the 'up to 60' tries mentioned in the manual.

    If you want to keep the camera alive, just send acks every second or so.

    Now we have consistent startups and no hangs, the code is proving much easier to write. Stay tuned!

    Attached files RS232_555.pdf (32.4 KB)

    Comment


    • #3


      Getting very close now. Got most of a picture - just need to work out how the last packet works:

      Waking up camera
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00
      => AA 0D 00 00 00 00

      Waiting 3 secs to adjust brightness and colour
      AA 0E 0D 00 00 00
      => AA 01 00 07 01 01
      AA 06 08 C8 00 00
      AA 04 05 00 00 00
      = 10
      SerialPort.Read(InPacket, 0, 10) ' read 10 bytes back
      TextBox3.Text += " "
      For i = 0 To 5
      h = Hex(OutPacket(i))
      If Val("&H" + h) < 16 Then h = "0" + h ' add leading zero
      TextBox3.Text += h + " "
      Next
      TextBox3.Text += vbCrLf
      SerialPort.Write(OutPacket, 0, 6) ' send it out
      Application.DoEvents() ' refresh the display
      End Sub
      Private Sub GetEntirePicture()
      Dim i As Integer
      Dim PacketNumber As Integer
      i = 0
      PacketNumber = 0
      Do
      SendPictureAck(PacketNumber) ' ack to get the next packet
      GetTwoHundredBytes()
      i += 200 ' add 200 - change this packet size later??
      PacketNumber += 1 ' add 1 to packetnumber
      Loop Until i > 1000 ' nominal number at present as hangs on last packet
      'Loop Until i >= Filesize ' not working on last packet as yet
      ' send F0F0 final packet received
      End Sub

      End Class

      Comment


      • #4
        More experiments.

        When you send the command "get picture" AA 04 05 it returns some bytes which are supposed to be the file size (I think). I'm multiplying byte 5 byte 256 and adding byte 4. Maybe the maths is wrong, but with an 80x64 jpg, on the last packet it is returning 42 more bytes than I would expect.

        On bigger file sizes it returns more spare bytes, and sometimes there are more bytes than a remaining packet size.

        I'm not sure of a way around this. Maybe ignore the returned size of the file and keep checking packets till they stop coming. But that slows things down. Maybe do some maths to find the value to correct the file size.

        Addit: I think I found an explanation. In the returned data packet, say it is 200 bytes, then according to the manual the first two will be and ID, the second two the size of the returned packet "C2", and the last two are a checksum. So when you ask for 200 bytes you get back 194. Which equals "C2" in hex. And further, I was getting back 7 packets, and was 6 bytes short per packet, and 42 bytes over at the end and.... 6x7=42.

        So I think the answer is to keep a counter going based on PacketSize-6.

        Back to coding...

        Yes that works. I've got a manual system that checks the vb.net input buffer for how many bytes, and I've got my maths, and they are coming up with the same number regardless of the jpg size:

        RemainingBytes = SerialPort.BytesToRead ' get remaining bytes
        ExpectRemaining = Filesize - ((PacketSize - 6) * PacketNumber) + 6 ' what I think should be there

        Good, news, now I know exactly how many bytes to read on that last packet

        (in the manual is a formula "Number of packages = Image size / (Package size – 6)". But it is not 100% clear of the rounding of the value. The old problem of whether 2.49 rounds to 2, and whether 2.99 also rounds to 2, or whether 2.50001 rounds to 3). I think it is easier in a way to keep a track of the bytes that have come in and when they get within n-6 of the filesize, to call that the last packet.

        Addit - all working. Lots of tweaks along the way and probably easiest to post the code and a screenshot. Lots of commented out code - I'll leave it there for the moment as it might be useful to uncomment it.

        ' James Moxham moxhamj at internode.on.net
        ' for testing uCam by 4DSystems
        Imports System.IO ' needed to run various calls
        Imports Strings = Microsoft.VisualBasic ' so can use things like left( and right( for strings
        Public Class Main
        Dim WithEvents SerialPort As New IO.Ports.SerialPort ' serial port declare
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) ' for sleep statements
        Public InPacket(0 To 2000) As Byte ' bug with serial.write strings like chr(255) won't go out
        Public OutPacket(0 To 50) As Byte ' usually only send out a few bytes though so could make this smaller
        Public Filesize As Long ' size of file coming back
        Dim JPEGArray(0 To 200000) As Byte
        Dim JPEGCounter As Long
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        SerialPort.PortName = TextBox1.Text
        SerialPort.BaudRate = TextBox2.Text
        SerialPort.Parity = IO.Ports.Parity.None ' no parity
        SerialPort.DataBits = 8 ' 8 bits
        SerialPort.StopBits = IO.Ports.StopBits.One ' one stop bit
        SerialPort.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response
        JPEGCounter = 0
        Try
        SerialPort.Open() ' open the port
        SerialPort.DiscardInBuffer() ' clear the input buffer
        TextBox3.Text = "" ' clear text box
        TextBox3.Text += "Waking up camera" + vbCrLf
        Application.DoEvents()
        i = 0
        Do
        Synch()
        Sleep(100) ' wait for response
        Application.DoEvents() ' update the display
        i += 1
        Loop Until i > 60 Or SerialPort.BytesToRead >= 6
        If i > 60 Then TextBox3.Text += "No response after 60 tries" + vbCrLf
        TextBox3.Text += vbCrLf + "Waiting 3 secs to adjust brightness and colour" + vbCrLf
        GetPacket()
        Sleep(1000) ' delay
        SerialPort.DiscardInBuffer() ' clear the input buffer
        SendAck()
        Sleep(2000) ' to adjust brightness etc
        'jpeg160x128() ' send instructions for a jpeg
        'jpeg80x64() ' send instructions for a jpeg
        jpeg320x240()
        GetSixBytes()
        'Snapshot() ' leave out snapshot for the moment, this does a ?raw image
        'GetSixBytes()
        PackageSizeVariable()
        GetSixBytes()
        GetPicture()
        GetSixBytes() ' do it twice to get 12 bytes
        GetSixBytes() ' this package has the size of the file coming back
        GetFileSize() ' returns filesize and displays it
        GetEntirePicture() ' get all the picture
        SerialPort.Close()
        SaveJPEG() ' save the file
        TextBox3.Text += "Saved to C:\UCAM.JPG" + vbCrLf
        DisplayJPEG()
        Catch ex As Exception
        SerialPort.Close()
        TextBox3.Text += "Timeout error" + vbCrLf
        End Try
        End Sub
        Private Sub GetPacket()
        ' read 6 bytes back from the uCam
        Dim i As Integer
        Dim h As String
        SerialPort.Read(InPacket, 0, 6) ' read 6 bytes back
        TextBox3.Text += "<= "
        For i = 0 To 5
        h = Hex(InPacket(i))
        If Val("&amp;H" + h) < 16 Then h = "0" + h ' add leading zero
        TextBox3.Text += h + " "
        Next
        If InPacket(1) = 15 Then ' NAK error
        TextBox3.Text += " Error number (p10 manual) = " + Str(InPacket(4))
        End If
        If InPacket(1) = 14 Then ' ACK - print number
        TextBox3.Text += "Ack command " + Str(InPacket(2)) + " number " + Str(InPacket(3))
        End If
        TextBox3.Text += vbCrLf
        Application.DoEvents() ' refresh the display
        End Sub
        Sub GetSixBytes()
        Do
        Loop Until SerialPort.BytesToRead >= 6
        GetPacket()
        End Sub
        Sub GetNBytes(ByVal n As Integer)
        Dim i As Integer
        Dim h As String
        Dim LineOfHex As String
        Do
        Loop Until SerialPort.BytesToRead >= n ' wait till n bytes in buffer
        SerialPort.Read(InPacket, 0, n) ' read n bytes back
        TextBox3.Text += "<= "
        For i = 0 To n - 1 ' loop zero to n-1
        'h = Hex(InPacket(i))
        'If Val("&amp;H" + h) < 16 Then h = "0" + h ' add leading zero
        'LineOfHex += h + " "
        If i > 3 And i < n - 2 Then ' discard first 4 and last 2 bytes
        JPEGArray(JPEGCounter) = InPacket(i) ' store in the jpeg array
        JPEGCounter += 1 ' increment
        End If
        Next
        'TextBox3.Text += LineOfHex + vbCrLf ' display the actual bytes
        'Application.DoEvents() ' refresh the display
        End Sub

        Private Sub SendAck()
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;HE
        OutPacket(2) = &amp;HD
        OutPacket(3) = &amp;H0
        OutPacket(4) = &amp;H0
        OutPacket(5) = &amp;H0
        WritePacket()
        End Sub
        Private Sub SendPictureAck(ByVal Packetnumber As Integer) ' for getting picture packets
        Dim HighByte As Integer
        Dim LowByte As Integer
        HighByte = Packetnumber \ 256
        LowByte = Packetnumber Mod 256
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;HE
        OutPacket(2) = &amp;HFF ' ack for picture packets
        OutPacket(3) = HighByte
        OutPacket(4) = LowByte
        OutPacket(5) = &amp;H0
        WritePacket()
        End Sub
        Private Sub jpeg80x64()
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;H1
        OutPacket(2) = &amp;H0
        OutPacket(3) = &amp;H7 ' copied 7,1,1 off the ucam software
        OutPacket(4) = &amp;H1
        OutPacket(5) = &amp;H1 ' tiny 80x64 jpeg for testing first
        WritePacket()
        End Sub
        Private Sub jpeg160x128()
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;H1
        OutPacket(2) = &amp;H0
        OutPacket(3) = &amp;H7 ' copied 7,9,3 off the ucam software
        OutPacket(4) = &amp;H9
        OutPacket(5) = &amp;H3 ' 160x128 jpeg
        WritePacket()
        End Sub
        Private Sub jpeg320x240()
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;H1
        OutPacket(2) = &amp;H0
        OutPacket(3) = &amp;H7 ' copied 7,9,5 off the ucam software (can go to 640x480 but a bit grainy at that size)
        OutPacket(4) = &amp;H9
        OutPacket(5) = &amp;H5
        WritePacket()
        End Sub
        Private Sub PackageSizeVariable()
        ' use the size of the package in textbox6
        If Val(TextBox6.Text) >= 256 Then MsgBox("This code only goes to 256, need to recode for 512")
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;H6
        OutPacket(2) = &amp;H8
        OutPacket(3) = Val(TextBox6.Text) ' 64 to 512 maybe other values too
        OutPacket(4) = &amp;H0 ' zero
        OutPacket(5) = &amp;H0 ' zero
        WritePacket()
        End Sub
        Private Sub Snapshot()
        ' take the picture
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;H5
        OutPacket(2) = &amp;H0
        OutPacket(3) = &amp;H0
        OutPacket(4) = &amp;H0
        OutPacket(5) = &amp;H0
        WritePacket()
        End Sub
        Private Sub GetPicture()
        ' gets an ack then gets the bytes
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;H4
        OutPacket(2) = &amp;H5
        OutPacket(3) = &amp;H0
        OutPacket(4) = &amp;H0
        OutPacket(5) = &amp;H0
        WritePacket()
        End Sub
        Private Sub Synch()
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;HD
        OutPacket(2) = &amp;H0
        OutPacket(3) = &amp;H0
        OutPacket(4) = &amp;H0
        OutPacket(5) = &amp;H0
        WritePacket()
        End Sub
        Private Sub FinalPictureAck()
        OutPacket(0) = &amp;HAA
        OutPacket(1) = &amp;HE
        OutPacket(2) = &amp;H0
        OutPacket(3) = &amp;H0
        OutPacket(4) = &amp;HF0
        OutPacket(5) = &amp;HF0
        WritePacket()
        End Sub
        Private Sub GetFileSize()
        Filesize = InPacket(4) * 256 + InPacket(3)
        TextBox3.Text += "File size = " + Str(Filesize) + " bytes" + vbCrLf
        End Sub
        Private Sub WritePacket()
        Dim i As Integer
        Dim h As String
        TextBox3.Text += "=> "
        For i = 0 To 5
        h = Hex(OutPacket(i))
        If Val("&amp;H" + h) < 16 Then h = "0" + h ' add leading zero
        TextBox3.Text += h + " "
        Next
        TextBox3.Text += vbCrLf
        SerialPort.Write(OutPacket, 0, 6) ' send it out
        Application.DoEvents() ' refresh the display
        End Sub
        Private Sub GetEntirePicture()
        ' tested with packet size = 10 to 250
        Dim i As Integer
        Dim PacketNumber As Integer
        Dim PacketSize As Integer
        Dim RemainingBytes As Integer
        Dim ExpectRemaining As Integer
        PacketSize = Val(TextBox6.Text)
        i = 0
        PacketNumber = 0
        Do
        SendPictureAck(PacketNumber) ' ack to get the next packet
        GetNBytes(PacketSize)
        i += (PacketSize - 6) ' add packetsize minus 6 as the first 4 and last two bytes of the packet are ID x 2, size x 2 and the last two are checksums
        PacketNumber += 1 ' add 1 to packetnumber
        'TextBox3.Text += "Picture bytes received = " + Str(i) + vbCrLf
        'Label3.Text = "Packet: " + Str(PacketNumber) + " = " + Str(Int(i * 100 / Filesize)) + "%"
        Loop Until i > (Filesize - (PacketSize - 6))
        SendPictureAck(PacketNumber) ' send for the last packet
        'Sleep(1000) 'delay to get the last packet, must be long enough to get all n bytes at slowest rate eg 14400
        'RemainingBytes = SerialPort.BytesToRead ' get remaining bytes
        ExpectRemaining = Filesize - ((PacketSize - 6) * PacketNumber) + 6 ' what I think should be there
        'TextBox3.Text += "Remaining bytes in last packet = " + Str(RemainingBytes) + vbCrLf ' display them
        'TextBox3.Text += "Expect this many bytes = " + Str(ExpectRemaining) + vbCrLf
        'GetNBytes(RemainingBytes)
        GetNBytes(ExpectRemaining) ' now confident enough to get what is calculated to be there, not what is there
        'TextBox3.Text += "There should be zero bytes left in the buffer = " + Str(SerialPort.BytesToRead) + vbCrLf
        FinalPictureAck()
        Application.DoEvents() ' refresh the display
        End Sub
        Private Sub SaveJPEG()
        ' Create a file and write the byte data to a file.
        Dim oFileStream As System.IO.FileStream
        oFileStream = New System.IO.FileStream("C:\UCAM.JPG", System.IO.FileMode.Create) ' save in root directory
        oFileStream.Write(JPEGArray, 0, JPEGCounter - 1)
        oFileStream.Close()
        End Sub
        Private Sub DisplayJPEG()
        PictureBox1.Load("C:\UCAM.JPG")
        End Sub
        End Class

        Comment


        • #5


          So I think the answer is to keep a counter going based on PacketSize-6.
          Yes, that is correct.
          Mark

          Comment


          • #6


            Nice work Dr Acula.

            The higer resolution will help more!!! I am playing with it i can post the code if i can make higer resolution working.

            Thanks,
            Chatty

            Comment


            • #7


              Hi Chatty,

              I've just realised that with a serial port sniffer and also the new code that 4dsystems sent me, working out all the codes for different resolutions is quite easy. But without those tools, it is a bit tricky to work out what numbers to send. 

              Chatty, what resolution do you want, and do you want jpeg or raw? I could then look up the codes for you and post some new code.

              Comment


              • #8


                Hi Dr Acula,

                I need 640x480 resolution with jpeg. Please let me know if you can figure this out.

                Thanks,
                Chatty

                Comment


                • #9


                  Just testing it now.

                  The Init command for a jpeg at 640x480 is
                  AA 01 00 07 09 07

                  Cheers, James Moxham

                  Sent commands in [ ] brackets, Rx bytes in < > brackets

                  Complete trace for a 640x480 jpeg. Package size of 200 (C8)
                  Even with a 555 one shot completely powering the board down after a while (and hence forcing a real reset) it is quite variable getting it to boot up and respond. I've found a timeout circuit is essential as it will sometimes get itself muddled and refuse to ever respond to synch commands and the only answer is to cycle the power supply.

                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00] Response missing
                  Sync failed, is uCam connected?
                  Sync [AA 0D 00 00 00 00]
                  ACK [AA 0E FF 00 00 00]
                  Initial [AA 01 00 07 09 07]
                  Set Pkg size [AA 06 08 C8 00 00]
                  Get Picture [AA 04 05 00 00 00]
                  ACK [AA 0E FF 00 00 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 01 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 02 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 03 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 04 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 05 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 06 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 07 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 08 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 09 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 0A 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 0B 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 0C 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 0D 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 0E 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 0F 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 10 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 11 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 12 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 13 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 14 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 15 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 16 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 17 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 18 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 19 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 1A 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 1B 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 1C 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 1D 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 1E 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 1F 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 20 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 21 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 22 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 23 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 24 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 25 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 26 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 27 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 28 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 29 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 2A 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 2B 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 2C 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 2D 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 2E 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 2F 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 30 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 31 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 32 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 33 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 34 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 35 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 36 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 37 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 38 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 39 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 3A 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 3B 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 3C 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 3D 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 3E 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 3F 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 40 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 41 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 42 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 43 00]
                  (Camera Data received)
                  ACK [AA 0E FF 00 44 00]
                  Image size =13088

                  Comment


                  • #10


                    Hi James,

                    is it working?

                    Comment


                    • #11


                      Yes, it is working in vb.net. Not in CP/M yet, and not sure why as the strings are identical, but I was testing on a day when it was 43C and maybe the RS232 timing was out or something. 

                      Comment


                      • #12


                        Hello,
                        I'm using the uCamDemo application to understand better the uCam and use it after in my final application.
                        I succeeded to receive answer from the camera, after sending Sync command 25 times or so. My question for the moment could sound stupid, but, I don't find the Acknowledge command to the camera.
                        I received from the cammera Ack and Sync (which I see with a scope connected to TX of the camera), but I didn't find how to send Ack to continue with other commandas.
                        Can anyone help me?
                        Thanks

                        Comment


                        • #13


                          No need help, I found the problem.
                          Thanks anyway.

                          Comment


                          • #14


                            Hello,
                            Can anyone tell me that is that my acknowledge is ok or not....

                            Serial port COM1 successfully reconfigured.
                            000aa
                            0000e
                            0000d
                            0000c

                            *****************************************
                            Data is successfully written.

                            Thanks
                            sabbir

                            Comment


                            • #15


                              An acknowledge is 6 bytes. Assuming you are showing 4 bytes as words, what you have shown so far is part of a valid acknowledge.
                              Mark

                              Comment

                              Working...
                              X