So... Progress...
PicPaste - test-MJKmXRkM.jpg
Here's the new code:
inprogress = 1
gowrite = 0
FileOpen (c1,"test.jpg",cRandom)
binwrite.new1(c1,True)
Do While sercom.inbuffercount <> 0
sercom.Timeout = 2000
stringtemp = sercom.Inputbyte
If gowrite = 0 Then
If stringtemp = 255 Then
firstbyte = stringtemp
stringtemp = sercom.Inputbyte
LB1.Add("byte one - " & firstbyte & " - " & stringtemp)
If stringtemp = 216 Then
LB1.Add("byte two")
secondbyte = stringtemp
binwrite.writebyte(firstbyte)
binwrite.writebyte(secondbyte)
stringtemp = sercom.Inputbyte
LB1.Add("start img")
gowrite = 1
End If
End If
End If
If gowrite = 1 Then
binwrite.writebyte(stringtemp)
End If
Loop
datatype = ""
FileClose (c1)
inprogress = 0
LB1.Add("done")
My solution to the problem of the echoed data was to look for the bytes for the jpeg standard as 'start of file' : RE:
JPEG - Wikipedia, the free encyclopedia
Any thoughts?
EDIT: the plot thickens - this appears to work only 1 out of every 4-6 times. Could this have something to do with the buffer / timeout? If so - any idea how I can fix it?