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)