views:

314

answers:

1

Hi,

in a small .net c# app I read the usb output of a barcode scanner with LibUsbDotNet http://libusbdotnet.sourceforge.net/V2/Index.html . The problem is that I don't know how to convert the output into something I can read. The scanner is set to output a return after each barcode, so I need for example to detect that. The output is, I think, in groups of 8 bit bytes. It can be installed as a keyboard input. So what do i have to do with the scanner output to turn it into something readble?

A: 

I think (haven't tried it myself - but I've worked quite a bit with barcodescanners) that this example: http://libusbdotnet.sourceforge.net/V2/html/e61bb81e-108b-4f84-a77d-8ccdecebfa31.htm is the example you are looking for. Barcode scanners generally post "strings" followed by a linefeed / carriage-return (or both) just like when you use the keyboard to input the code followed by an enter.

The example uses: Console.Write(Encoding.Default.GetString(e.Buffer, 0, e.Count)); in the event, posting the string to the console. You wont need to write to the device, just the read-event will suffice.

riffnl
Hi riffnl,and thank you for the answer! That's exactly how I tried to read the data from the scanner, based on the read only example from here http://libusbdotnet.sourceforge.net/V2/html/9926451f-29bf-4fae-9233-f6467ed072c7.htm but in the console I only see garbage.
bfi
Can you configure this scanner to read specific type of codes?
riffnl
Yes. From the configuration guide:DECODER SELECTIONEAN/UPCCode 128/EAN 128Code 39Code 32CodabarInterleaved 2/5Default is EAN/UPC (AddOn Off).
bfi
Yes, bar code scanner send a string like a keyboard followed by carriage-return (but you cange change this configuring the device) .I develop same simple application and instead of reading usb port i force focus on a textbox capturing the onchange event.
Flatlineato
Hi Flatlineato, I also thought about the textbox onchange, but I'm worried about losing focus. Also, the frontend of the app is a flash that runs fullscreen, and the flash player disables keyboard input on fullscreen, for security reasons. I don't know if there's a workaround for that, like maybe using zinc to create the projector. So I think reading the usb is the most elegant approach, and then sending stuff to the flash via an xml socket (I have yet to reseach how to do that in .net :) )
bfi