Example Code

Create Linear Barcodes (UPC, EAN, Code 39, Code 128)

Code and Documents

Attachment

Download All

I've implemented an XControl backed by a set of LabVIEW Classes.  This was recently suggested on the LabVIEW idea exchange

BarcodeExample.png

About:

It supports 4 types of barcodes:

  1. UPC. Most common on retail products sold in the US.
  2. EAN-13. Most common on retail products sold in the rest of the world
  3. Code 39.  Encodes text.  Used on a lot of random things.  Only the basic text encoding is used.
  4. Code 128.  Encodes text in a more compact format than Code 39.  Only encoding B is used.

This is written in LabVIEW 2013 and will be maintained in LabVIEW 2013 because it uses LabVIEW Class Properties.  I've attached a LabVIEW 2010 and LabVIEW 8.5 version, but I won't be updating it very often.

Disclaimer:

This should be considered an incomplete program.  I've done only basic testing on it and I've double checked all my data, but I haven't done any thorough testing.  I've also got some more work to do to speed it up / clean it up.

Directions:

Once you download and unzip the project files, open Example.vi and XCtlExample.vi.  You can use those two examples to understand how to use it.  You can drop Barcode.xctl right on your front panel, configure it with property nodes, and the wire in text for the barcode.  Please test this out and add any feedback to this page.

If you want to implement your own barcode type, derive a new class from BarCode.lvclass and implement the required VIs.  It should be relatively straight forward.  I'd really appreciate it if you send your implementation my way so that I can add it to this project.

Future Plans:

If I keep working on this project, I might tackle these things:

  • 2D Barcodes.  Unfortunately, all are pretty complex and most have expensive specs
    • DataMatrix (unfortunately the spec costs $231)
    • QR Codes (also expensive) In progress [2/8/2012]
    • PDF-417 In progress [2/8/2012]
    • Maxicode (used by UPS on their packages)
  • Better testing

Please post if you know of any place that documents how to generate (or read) DataMatrix, QR Codes, or Maxicode.

-- Mike

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Jervin Justin
NI Employee (retired)
on

Nice!!

Jervin Justin
NI TestStand Product Manager
kamdy
Member
Member
on

I have LabVIEW 2009 and i was not able to load the Example VI because it uses LabVIEW ver. 10 

slipstick
Member
Member
on

The datamatrix section of this website

http://www.adams1.com/stack.html

purports to have a free source for the datamatrix code, here;

http://www.gs1.org/docs/barcodes/GS1_DataMatrix_Introduction_and_technical_overview.pdf

I don't have the background to know if this is sufficient to make these codes or not.

Mr.Mike
NI Employee (retired)
on
The pdf you linked on gs1.org only specifies the standards of writing a datamatrix code (e.g. the size, shape, angles, dimensions, etc), but not how to actually encode one.  I'm looking into the other links on adams1.com.  Thank you.
-- Mike
Mr.Mike
NI Employee (retired)
on
The pdf you linked on gs1.org only specifies the standards of writing a datamatrix code (e.g. the size, shape, angles, dimensions, etc), but not how to actually encode one.  I'm looking into the other links on adams1.com.  Thank you.
-- Mike
Mr.Mike
NI Employee (retired)
on
The pdf you linked on gs1.org only specifies the standards of writing a datamatrix code (e.g. the size, shape, angles, dimensions, etc), but not how to actually encode one.  I'm looking into the other links on adams1.com.  Thank you.
-- Mike
Mr.Mike
NI Employee (retired)
on

So it turns out the ISO spec licenses are extremely restrictive (I'm probably violating the license by saying it's extremely restrictive!): it's single user non-transferable.  And I also found out it's pretty complex; it's not something that I could do soon in my spare time.  Unless someone has access to those specs and wants to implement it in G, I'm more than willing to work with them to come up with an API for 2D barcodes that we can integrate into this project.

-- Mike
SWhite
Member
Member
on

any chance to convert it as previous version, like LabVIEW 8.5?

windows
Member
Member
on

Thanks for the Project!!

Srikanth Chilivery,
mymore
Member
Member
on

the 4 types of barcodes is used by us often. so labview is getting the point.if keeping on working, the project can create linear barcodes c#  as fast speed.keep up with the good work.

misrraimsp
Member
Member
on

Thanks a lot for the contribution!

FireFly
Member
Member
on

I have a problems with Code128. For example, when I created "001" barcode - My scanner didn't read it.

And I found the problem. If checksum more than 94 (and of course less than 103), we have not information about this character in Code128.lvclass

Mr.Mike
NI Employee (retired)
on

You're right.  It looks like the check digit in that barcode isn't being written.  I'll take a look at what's going wrong.

-- Mike
Mr.Mike
NI Employee (retired)
on

A new version with a fixed Code 128 is up.

-- Mike
bkfillman
Member
Member
on

Hello,

Have you had any opportunity to look further into the 2D barcode option. I have looked at the code you have posted and it is great. Thanks very much.

Mr.Mike
NI Employee (retired)
on

Yes, I have a working QR code generator and PDF-417 generator, but I never finished testing them.  They're significantly more complex than longest bar codes, so there's more to test and more mistakes to make.

-- Mike
bkfillman
Member
Member
on

Mike, I am back working on my project and trying to get a 2d code generator to work, not having much luck. Have you had any more luck with your trials?

Zahkay
Member
Member
on

hey hello everyone

i am having problem with my labview programming. can some1 help me please

this is my coding like i detect my code using webcam ( vision acquisition) and

the main problem is that i need to detect TP022216 but am getting only TP02221

What do u thnk is the problemend 1.JPGend.JPG

Mr.Mike
NI Employee (retired)
on

Zahkay,

You're trying to read a barcode.  This software here is for making a barcode.  I don't recognize thetype of barcode in your image, so I can only speculate on what's going wrong.  Some barcodes have a check digit at the end of them so that the reader can verify it got it correct.  Maybe IMAQ is reading the check digit and not outputting it?  Another potential cause is that the barcode is really poorly printed. It's strange that the bars aren't even printed straight.  I think that IMAQ is reading as much of the barcode as it can, but the last character is too messed up to read correctly.

- Mike

-- Mike
Zahkay
Member
Member
on

yeah sir, scan a barcode to know its content.

the barcode type is code 39 sir.

sir what is the solution to it

i can send you my coding for you to check

Zahkay
Member
Member
on

those barcode is from the ID of the university card

bou6
Member
Member
on

i also have troubles while reading barre code of type 128 however reading barre code of type EAN 13 works well

GurraW
Member
Member
on

Great stuff. Thank you Mike

Desruelle_luc
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

Thanks for the Project!!

Jeannius
Member
Member
on

thanks for the Project.

 

I have a Brother PT-2730 which can accomodate different cartridge size. Using a 0.47" cartridge works great! but switching to a 0.94" inch, I am unable to read the printed label.

I suspect it has to do with the dimension/aspect ratio of the created picture.

 

Any insight?

SpaceCoaster
Member
Member
on

I was playing around with your barcode classes today and came across a partially-incorrect result for a UPC barcode image.  I entered 00000000321.  The graphic shows a 0 for the check digit, but using a hand-scanner on the resulting image shows a 6 as the last digit.  I verified at a Web site that the check digit should be 6.  So, apparently the bars are correct, but the graphic check digit is not.  I'll look quickly to see if I can spot where the problem is, but I thought I'd at least let you know about it.

SpaceCoaster
Member
Member
on

My boss and I just found the error for the incorrect check digit.  

Just swap the two highlighted constants (1 and 3) shown in the code below.

Fix for incorrect UPC-A check digit.PNG

Jeannius
Member
Member
on

Any plans on putting this on GitHub or bitbucket? I have made several modifications to your code (mostly eliminated hard coded number in favor of class variables... Like width between text, barcode heighy, text font size,...)

 

Would love to share with community but still give you proper citation as originator of this. 

 

I would suggest an MIT license. 

emtsteve
Member
Member
on

Hello,

Great code, thanks for posting.  I added a Boolean to switch the human readable on and off.

 

Steve

GaryGC
Member
Member
on

Hi,

Thank you so much for this code. Is there away to reduce the barcode picture size? I need to print but the cuurrent size is just to big.

RyanCheng
Member
Member
on

thanks for you kindly share this code.

Contributors