Click here to Skip to main content
Licence Apache
First Posted 20 Sep 2007
Views 66,295
Downloads 851
Bookmarked 48 times

USPS OneCode Barcodes

By drdigit | 3 Oct 2008
USPS One Code - Intelligent Mail Barcode (4-State Customer Barcode) - implementation with VB 2008
1 vote, 5.9%
1

2

3
2 votes, 11.8%
4
14 votes, 82.4%
5
4.89/5 - 17 votes
1 removed
μ 4.22, σa 1.74 [?]

Introduction

This is not a typical article. The focus is on Intelligent Mail Barcode (4 State Customer Barcode) or USPS OneCode implementation as a direct solution for anyone who needs it. The downloads include one VB.NET and one C# class – VS2008 with .NET 3.5 syntax - that generate the string expression of OneCode barcodes and decode a barcode string. The code (uncommented) is a modified fraction of the Pathenon project (covers all known 1D and 2D barcodes) that you will read here on The Code Project in the near future, hopefully. I've noticed that there is no related article, so there you are with an ASAP solution for this new USPS symbology.

Basic Information

Intelligent Mail Barcode, also known as the USPS OneCode Solution or USPS 4-State Customer Barcode (abbreviated 4CB, 4-CB, or USPS4CB), is the latest barcode symbology of the United States Postal Services. It combines routing ZIP code information and tracking information into a single 4-state code. It effectively encodes data from POSTNET and PLANET barcodes into a single barcode while providing a greater range of tracking data.

A 4-state barcode is based on a tracker with ascenders and descenders. The four possible states are tracker (neither ascender nor descender), full (both ascender and descender), ascender only, and descender only. The Intelligent Mail barcode consists of 65 bars as a result of encoding data fields of the following types:

Tracking Code

  • Barcode Identifier as 2 digits (2nd digit must be 0–4)
  • Service Type Identifier as 3 digits
  • Mailer Identifier as 6 or 9 digits and
  • Serial Number as 9 (when used with 6 digit Mailer ID) or 6 (when used with 9 digit Mailer ID) digits

Routing Code

  • Delivery Point ZIP Code as 0, 5, 9, or 11 digits

The above fields, with a maximum of 31 digits in length, are encoded via a complex process (involving big integers and transposed lookups) to bars expressed as a string with 65 characters in the range of A, D, T, F. More information and specifications can be found here.

Conclusion

Note once again that this is not a typical article, but a direct solution for people dealing with this complex barcode symbology.

Thanks for your time.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

About the Author

drdigit



United Kingdom United Kingdom

Member
Passionate "hands on" solution oriented developer, coding since 1983 with proficiency in VB (from v1 to .NET 2010), C#, MS SQL (from v6.0a to 2008 R2), mySQL (from v4 to v6), XML/XSL/XSD, (D)HTML, JavaScript, ... and fluency in PHP, working as a freelancer in GR, IE and UK.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionOneCode Barcode Generator for .NET PinmemberKeepDynamic5:07 9 Jan '12  
GeneralMy vote of 4 Pinmemberncik91:52 2 Aug '11  
GeneralDecoder in plan C PinmemberMember 420048216:22 19 Sep '10  
AnswerRe: Decoder in plan C Pinmemberdrdigit22:57 19 Sep '10  
GeneralBarcode PinmemberJones xxx14:19 26 May '09  
Generalhelp pls.... Pinmemberlakshmi priya.t.n18:41 29 Jan '09  
AnswerRe: help pls.... Pinmemberdrdigit12:47 31 Jan '09  
GeneralCompilation error Pinmemberrobertjb2010:45 7 Jan '09  
AnswerRe: Compilation error Pinmemberdrdigit6:14 8 Jan '09  
GeneralHere is another Implementation for .Net (C#) using USPS provided dll and fonts PinmemberMember 42299179:43 13 Nov '08  
One needs to get the USPS encoder and font for generating the Intelligent Mail Barcode.
Go to: http://ribbs.usps.gov/onecodesolution/
Request your username and password from usps. You should get it in a day.
 
Download: uspsEncoderMsWindows32-1.2.0.zip, USPS4CBFONTS.zip from the URL above.
Unzip and copy the encoder (uspsEncoderMsWindows32-1.2.0\modules\c\usps4cb.dll) to the Windows directory.
Copy the font (USPS4CBFONTS\nonAfpFontsv1r2m0\fonts\truetype) to the Windows\Fonts directory.
User guide is under the directory - uspsEncoderMsWindows32-1.2.0\userGuide\. Do the following to your .Net project.
 
Step 1: Use the USPS published encoder (Windows C dll) to encode the barcode string.

//Definition
[DllImport("usps4cb.dll", EntryPoint = "USPS4CB")]
public static extern int USPS4CB(
[MarshalAs(UnmanagedType.LPStr)] String TrackString,
[MarshalAs(UnmanagedType.LPStr)] String RouteString,
[MarshalAs(UnmanagedType.LPStr)] StringBuilder buf);

//declare variable to hold the encoded bar string
StringBuilder BarString = new StringBuilder(65); //keep to 65 since encoder returns //65 specific characters
//Sample Function Call
int RetCode = USPS4CB("01234567094987654321", "01234", BarString);
 
Step 2: Use the encoded string (BarString) from above to display the barcode using the font USPS4CB.
 
This way we can get both the return code and the encoded string. Happy Intelligent Mail Barcode programming.
 
Lakshmi Narayanan
Software Developer

QuestionSample application Pinmemberamarbank7:38 23 Nov '10  
GeneralRe: Here is another Implementation for .Net (C#) using USPS provided dll and fonts Pinmembercrobbins9:56 6 Jan '11  
GeneralRe: Here is another Implementation for .Net (C#) using USPS provided dll and fonts PinmemberSid Torres9:12 15 Jun '11  
QuestionRe: Here is another Implementation for .Net (C#) using USPS provided dll and fonts Pinmemberbendece17:09 25 Feb '11  
QuestionIncorrect Decode Example Pinmembervoxdisc17:35 10 Nov '08  
AnswerRe: Incorrect Decode Example Pinmemberbheiland3:15 22 May '09  
GeneralRe: Incorrect Decode Example PinmemberGylfi Ingvason9:59 27 May '09  
GeneralRe: Incorrect Decode Example Pinmemberbheiland14:59 27 May '09  
AnswerRe: Incorrect Decode Example Pinmemberbheiland15:04 27 May '09  
GeneralRe: Incorrect Decode Example Pinmemberbheiland15:23 27 May '09  
GeneralRe: Incorrect Decode Example PinmemberGylfi Ingvason8:02 28 May '09  
GeneralRe: Incorrect Decode Example Pinmemberbheiland12:28 28 May '09  
GeneralRe: Incorrect Decode Example PinmemberGylfi Ingvason6:20 29 May '09  
GeneralRe: Incorrect Decode Example [modified] Pinmemberfwsouthern18:31 1 Nov '10  
GeneralRe: Incorrect Decode Example Pinmemberbheiland4:31 14 Apr '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 3 Oct 2008
Article Copyright 2007 by drdigit
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid