Turning a Serial Byte stream into an image...

Tex8503

Active Member
Licensed User
Longtime User
Hey folks,
So I'm working on a project where I'm using the camera from a barcode scanner and sending commands serially to tell it to get an image and return it.

Only problem is that - after I send the commands I get data back and I have no idea how to turn that serial data that is coming in, into an image. The scanner is returning a jpeg - but I'm still lost.

Anyone have any idea how I can go about doing this?
 

Tex8503

Active Member
Licensed User
Longtime User
That might be the solution for B4A ... but I don't think it is for B4PPC... Help?

EDIT: Also - I'm not actually doing this in WinMo - I'm doing this in Windows Desktop.
 

mjcoon

Well-Known Member
Licensed User
That might be the solution for B4A ... but I don't think it is for B4PPC... Help?

EDIT: Also - I'm not actually doing this in WinMo - I'm doing this in Windows Desktop.

Why not do it that way in B4P? (Though not using the given interface.)

IIRC on the desktop there should be something called a memory file that would avoid actually storing on disk. But I do not remember any detail or know how to use it via B4P.

Another vague recollection: JPEG is not ideal for B&W images and is that not all a bar-code scanner would be capable of? Just seems strange...

Mike.
 

Tex8503

Active Member
Licensed User
Longtime User
Well I'm open to suggestions... (There actually is a color barcode scanner we might switch too soon - but for my tests, it is B&W).

I'm unaware of an output stream command in B4P - but if someone has an example - that'd help too.

My goal would be to display it on screen BEFORE creating the file.

As for formats - I can tell the scanner what to send the data in - the default is jpeg - but it can also do KIM, TIFF binary group 4 compressed, TIFF grayscale, uncompressed binary, uncompressed grayscale, and BMP.

Maybe one of the others would accomplish what I want in an easier fashion?
 

Tex8503

Active Member
Licensed User
Longtime User
Here's my current code for trying to save the serial data stream:

binwrite is a binaryfile object
sercom is a serialex object

FileOpen (c1,"test.jpg",cRandom)
binwrite.new1(c1,True)
binwrite.writebytes(sercom.InputArray)
FileClose (c1)

But the resulting file doesn't work as a jpg.
 

Tex8503

Active Member
Licensed User
Longtime User
Could be that. Is there a way I can check ? Also - if I output the sercom.inputstring - It looks like the scanner is echoing my commands too... so I'm trying to figure out if what I'm doing SHOULD work and that I just need to figure out the rest...
 

mjcoon

Well-Known Member
Licensed User
Could be that. Is there a way I can check ? Also - if I output the sercom.inputstring - It looks like the scanner is echoing my commands too... so I'm trying to figure out if what I'm doing SHOULD work and that I just need to figure out the rest...

Since you say that the scanner can do a number of different formats but "looks like the scanner is echoing my commands", does that mean that you have a marketing description of scanner capability rather than the full protocol definition? :sign0161:

Maybe getting data in a simpler format (if larger) would make it easier to recognise what you get.

BTW I don't remember the binaryfile object; which library is it from? (I might need one!) *Cancel that question; I was just searching dll-version-listings*

Mike.
 
Last edited:

Tex8503

Active Member
Licensed User
Longtime User
So - I think I'm issuing the correct commands. This is a test bed app for something bigger - other commands work, such as getting the scanner to actually scan with a serial command and I get the data back as a sercom.inputstring command.

But I've never tried to do anything with transmitting a file serially and thats where I think I'm running into a the problem.

I don't know how changing the format is going to help me recognize it.

I think binaryfile was included with B4P 6.90
 

Tex8503

Active Member
Licensed User
Longtime User
Ok... that makes sense. So If I look at the data from scanning the picture and I see my commands being echo concatenated with what appears to be picture data - I might be able to figure it out...

If I can separate that information - then write the binary data to a file - the jpg image should display correctly - correct?
 

Tex8503

Active Member
Licensed User
Longtime User
I don't know if this helps or not - but if I do sercom.inputstring and write it to a file - the file starts off with:


Now IMGSNP1B. and IMGSHP2P0L843R639B0T0M8D1S6F100J. are two commands I'm sending that appear to be being echoed.

I just looked it up and JFIF seems to be an identifying marker for a jpeg file...
 

Tex8503

Active Member
Licensed User
Longtime User
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?
 
Last edited:

Tex8503

Active Member
Licensed User
Longtime User
I think part of my problem is I'm going byte by byte to do the image detection... But I don't know how to do this any faster...

:BangHead:

EDIT: Ok - So I dumped out my detection code and using notepad++ figured out where the old data ends and begins a bit more accurately. There's a group seperator byte that denotes where the crap ends and the image beings. The problem is I'm only getting about half the image still... Thoughts?
 
Last edited:

Tex8503

Active Member
Licensed User
Longtime User
So I finally got it to work (yay!)
My 'hello world' image... : PicPaste - test-zQnYlpnq.jpg
I know ... not very exciting.

It does work (about 1/3 of the time...) so it's just cleaning things up and making it work better..

So my next task would be making it so we can do a live preview before the image is captured.

Does anyone know how I'd go about taking the byte data and displaying it as an image in my app WITHOUT saving it to a file and loading the file up ?
 
Top