We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
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.
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?
" 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...
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.
Oops! I must either type faster, or writer shorter answers if I want to be first :)
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.
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.
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.
Can you send me the code? send me an e-mail and I will tell you where to send a check for $12,870 and the code will be sent to you.
Erik
Whats with the $870? Surely the hardware you need is cheaper than that...
send me an e-mail and I will tell you where to send a check for $12,870 and the code will be sent to you.
That is a lot of money!
What is your email address?
What code will you send?
Will it do code 128?
Any others?
That is a lot of money! a reasonable price for software like this.
What is your email address? this week: Erikm@digrec.com
It's been a while, I do not have this code in my hands right now, but hope to have it somewhere (on a computer that is not at this location) and have to dig it out. Maybe somebody (David Rose? "Sorry, but I can't just give that away") will make you an offer. If no offer comes out as accepted, I'll dig for it this weekend.
Although I'd like to undercut Erik, I'd probably find that my employer might get a bit upset if I offered the code to anyone.
Developed in his time, sole ownership, blah blah blah!
I think Erik is trying to be funny?
HA HA - very sarcy and not helpful!
How would be the best way of getting the pulses from the pen? I think polling might not work well, and I think I must use an interrupt. But should it be edge or level?
Can you give me any ideas please?
"I think Erik is trying to be funny?"
Not really: several contributors have told you that this is not a trivial exercise, and yet you continue to ask to be given free, complete code!
"very sarcy and not helpful!"
Your request looked more like a demand for a freebie than for "help".
"I think polling might not work well, and I think I must use an interrupt."
Now you're getting somewhere!
Whether polling is workable depends on what else your processor has to do - since a barcode swipe is only relatively brief, it might be possible to stop everything else and poll the input during a swipe...
"But should it be edge or level?"
Probably edge: what you want is to detect the start of a bar - which would be an edge. You then need to time the width of the bar.
As already mentioned, this just gives you the raw bar timings - you then have to process that to allow for irregular and skewed scanning, poor-quality printing, etc, then decode that, etc, etc,...
Barcode scanners are relatively cheap on ebay - do you really need to do this from scratch for yourself?
Have you tried looking on the Agilent site, or others?