Hi all,
Has anyone got any ideas about where to get some C code to read a barcode?
Ive got a pen but dont know what to plug it to.
Can you send me the code?
Sorry, but I can't just give that away! Maybe someone else could help?
But, if you want help or advice with a specific area, then I might be able to help.
An 8052 with 32K of RAM should easily do the job; assuming that it's running at a decent clock rate. I always found that 14.7456MHz was a good one because it provided near-perfect resolution for acquisition of the barcode swipe and also was good when used to drive an RS232 communication link.
Thanks for the info. The barcode I have to read is called code 128. When I scope I see the pen gives a 5V when it is on black and a 0V when it is on white.
The board Ive got is an 8052 with 32K of RAM.
If you want to do your own decode of barcode elements from raw data, then this really can be quite involved.
Doing it well can be very involved.
Before going too far, you must find out whether you really need to do it. If you do, then you need to be very precise as to which type of barcode you are expected to decode (e.g., code 3 of 9, interleaved 2 of 5, codabar etc).
I did this very same thing a while ago using an 8051 and a little external discrete logic.
You would basically be required to do two things:
1 - Acquire all of the bar and space information from the pen as it is swiped across the media 2 - Store the width of each of those bars and spaces to a buffer, just as a simple time 3 - Take the accumulated times and carry out a decode over those times
There used to be specifications for many different barcodes (I think from an organisation called AIM) that also contained reference decode algorithms.
Be warned - The reference algorithms really must be treated as a 'get you started'. They can be used for simple swipes of high quality printed media, but require a lot of understanding and effort to change them into something that is of more acceptable performance.
Oops! I must either type faster, or writer shorter answers if I want to be first :)
Is this a high-volume project?
If not, I would recommend that you switch to a different bar code pen. If the pen is just an optical scanner, you must decide what bar code types to support, auto-adapt varying baud rate depending on scan speed, evaluate checksums, detect if code is read in reversed order etc. Not impossible to do, but unless it is a high-volume project, it is probably not worth the extra time spent.
Of course you may be lucky, and be a be able to google for good code that may be adapted - and that have a license that makes it possible to use.
Since you call it a pen, I assume that it is a device that is limited to scan one-dimensional bar codes.
" I think I see a pulse for each black bar"
Decoding this is quite advanced - you have to cope with speed variations as the user sweeps the pen, possibly not sweeping in a straight line, imperfections in the barcode, etc, etc,...
You would be far better advised to get a "smart" pen that does the hard work for you.
You might try looking to Agilent (formerly HP) for chips to do this...
Thanks for your reply.
The barcode pen just has a digital (I think TTL) output. The datasheet says that it is a raw output.
When I scope it I think I see a pulse for each black bar.
Any ideas how I can get the data from this?
You need to supply quite a lot more information than that.
A lot of bar code readers emits then bar code as ASCII text on some form of serial interface (PS/2, RS-232, USB, ...)
The manufacturer of the bar code reader normally have data sheets that describes exactly what variants of bar codes the reader can handle, and exactly the format of the messages sent out. Without such a datasheet, it will be up to you to figure out format and framing of the data.
View all questions in Keil forum