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.
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?
Nazir,
There are probably a lot of ways of accumulating the pulse train from a barcode pen.
The concept I used was to feed the input into INT0 or INT1 and configure for edge triggering.
BUT ... Edge triggering on the humble 8051 is only detected on a negative going edge. You will need to generate an interrupt on both edges.
What I did was use an 'exclusive or' gate to programmatically invert the input signal by feeding an output port pin to the input of the gate.
As I said, there are other methods to do this, but this worked very well for me and allowed me to have two barcode pens coming into the CPU; one interrupt input per pen.
Now, I'm very confused.
Are there two "Nezir Patak" in this thread? One that needs help, and one that tells how he solved the problem - the second one also directing the answer to someone named "Nazir" and that doesn't seem to have posted in this thread...
About free code. Most people who answer questions here are professional software developers. The code we write are either owned by the company we work for, or we work as free-lance developers and the code we write may (depending on contract conditions) become the property of the customers we write it for.
Hence, there are noremally no code to give away for free.
Sorry people - And especially to Nezir,
I am the second Nezir Patak!
Not sure how I managed to do that, but I suspect it was something to do with the constant interruptions I keep getting from the phone, colleagues etc. while I was entering my response.
Anyway - Hope the real Nezir finds the text of my response helpful.
The post form for this forum could have been a bit better. Quite a lot of people regularly manages to post using funny names since a new input form always starts with the name field selected, and when entering text in the message box, the name fields are often too high up on the form to be visible.
Thanks for the suggestions and advise. We have a lot of the barcode pens already and we want to use them. I think we will try to do our own board with an 8052.
I understand that you cannot give me all the code (and greedy Erik wants me to pay to much). I would be happy for you to give me any routines to help. I found aimglobal and they have specs for different barcodes but I didnt see one for code 128. Do you know where to get the specs?