0

Im trying to download a photo from an rs232 camera.. but when I write the data to file it seems corrupted.. when I look in a hex editor every second value is 00..

I'm assuming Im messing something up with the encoding.. when I'm writing into a byte array..

Excuse my poor code its been a long time since I've touched .net
(any pointers in the right direction would be greatly appreciated.. or general comments on improving the current code/ method)

Dim InPacket(0 To 2000) As Byte
      Dim photo As Byte()
      Dim x As Integer = 0

        Dim BytesToRead As Integer ' may as well get in batches
        Dim i As Integer
        Do
            If SerialPort1.BytesToRead = 0 Then Exit Do ' no more bytes
            BytesToRead = SerialPort1.BytesToRead
            If BytesToRead > 2000 Then BytesToRead = 2000
            SerialPort1.Read(InPacket, 0, BytesToRead) ' read in a packet
            For i = 1 To BytesToRead
                ' process the bytes 
                ' Debug.Print(InPacket(i).ToString)
                ReDim photo(x + 1)
                photo(x) = InPacket(i)
                x = x + 1
            Next i
        Loop

        My.Computer.FileSystem.WriteAllBytes("photo.jpg", photo, True)

Edited by ievolve: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by ievolve
0

sorry.. actually all values show as 00 in the hex editor..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.