DacoTaco / BarcodeParserBuilder

BarcodeParserBuilder is a .Net ( standard 2.0 & 2.1 ) nuget package to help parse & build barcode strings
https://www.nuget.org/packages/BarcodeParserBuilder
GNU Lesser General Public License v2.1
11 stars 4 forks source link

Retrieve inner payload of EAN/UPC bar codes #1

Closed warnwar closed 2 years ago

warnwar commented 2 years ago

Hello! I am interested in using your barcode parser for a project, but there is one thing that it doesn't seem to do. We have UPC-A barcodes that we expect to parse.

The raw barcode values and your ProductCode field look like this: "300450449108" but I am most interested in getting at the inner payload of the bar code like this: "0045044910".

I know I could remove the first and last digit myself, but it might be nice for the parser to use that SerialNumber field for that inner value.

DacoTaco commented 2 years ago

i looked up the UPC-A specs for a second i have made a mistake it seems. i assumed UPC-A is just a GTIN, which is not completely true, as its made of 12 characters, starting with the Number System Character , followed by 10 digit product code (manufactorer+product code) and 1 check digit, calculated by the same system as a GTIN.

reference : https://www.qorpak.com/pages/guidetoupccodes & https://en.wikipedia.org/wiki/Universal_Product_Code#Number_system_digit

I am not that experienced in the usages/parsing of UPC-A, but is the check digit and/or number system character considered part of the product code, or are those separate entities? like, do programs only need '0045044910' or the full barcode?

i was thinking of maybe creating an UPC-A Barcode type, which has '0045044910' as the product code, and 2 properties with the Number System Character (enum?).

warnwar commented 2 years ago

Thanks for getting back to me so fast.

I can tell you what I think I know: the first digit typically signifies some grouping or family. I'm working on medical software, so my understanding is that the 3 is health-related. That reference link you posted backs that up.

I admit I'm not super experienced with this barcode stuff, but what I'm getting from my scanner look like this: '300450449108' and the value I need is definietely this: '0045044910'. Technically, in my case, that inner value is a code called an NDC. I think any type of code could be stuffed into a UPC-A barcode, but the "Number System Character" and the "Check Digit" are not part of that payload and (in my opinion) are separate.

DacoTaco commented 2 years ago

no problem. though not so very old, ive always found barcodes interresting af haha. and due to lack of anything even remotely decent i made this package and i want to maintain it if i can. im happy to see interest in it tbh :)

right, so UPC (at least UPC-A) sounds like a barcode type on its own, and needs it's own structure. i will see when i can implement this. so far i hope it won't interfere with the GS1/MSI parsing to much... EDIT : nvm, no problems. GTIN-12 = UPC-A. so if its EAN and its 12 digits its an UPC-A

is it ok if i use that barcode you provided in the unit tests of the project? i'll also use some UPC-A barcodes from some games i have around here

warnwar commented 2 years ago

Yeah absolutely feel free to use that barcode as a test. I can find more if that would be helpful.

DacoTaco commented 2 years ago

i might be working on this on sunday, but there are a few minor things i would like to clear up before i work on this.

will this be used in a project that is running in .net 4 or something higher than .net 4? its because ive dropped support for .net 4 since it really needs to die hehe. i can still add it to the .net4 branch though, if you would want that. its easy to build a nuget package that you can host somewhere :)

i was also thinking of adding some sort of UPC-A parsing that would detect the product code depending on the type (aka the first digit) and return that (aka, for example split up the barcode if its type 0-1/6-9. seeing how medical products ( type 3 ) have the full product code in the 10 digits for the product code i assume this is no problem for your purpose? it would mean you'd get an UPC-A barcode class object back with the properties :

from what ive found EAN12 is kinda just the barcode type, and UPC-A is the data inside it, so using the EAN Barcode type & a subtype, it can contain all types of Ean Barcodes, including ISBN, which is inside an EAN13 barcode.

warnwar commented 2 years ago

Apologies about not getting back to you earlier.

The project this would be used in is .net6. I think your dotnetstandard2.0 nuget package was the one I installed for some testing. Your breakdown of the changes for UPC-A sound pretty good. I can get some use from knowing if someone scans a non medical barcode. I saw in one barcode reader that they had a class to represent all the different versions/subtypes of EAN barcodes. Personally, I think that could be overkill and a maintenance nightmare. If I understand it right, I think your version sounds better.

DacoTaco commented 2 years ago

I have altered the design i had in mind a bit, as it ended up more complex than i had anticipated. The barcode sub type makes no sense, as EAN12 & EAN8 are supersets of UPC-A & UPC-E apparently. on top of that, the barcodes is still that, not something else. what i ended up doing however, is add a few properties to the EANBarcode class, which exposes the NumberSystem (aka, the whole 3 = medical system) and add a little bit of EAN Product code parsing. most of them still throw the whole barcode in the product code and call it EAN, but some do some actual parsing. this includes medical barcodes ( 3 in EAN12/UPC-A or 03 for EAN13 ).

parsing the above barcode should result in an EanBarcode class with :

and the class should be buildable back as well, meaning that after parsing it should result in "300450449108"

could you test the attached nuget package to verify? BarcodeParserBuilder.0.0.5-alpha.0.2.zip

i will probably add some more checks in the barcode class to verify no barcode mixup is possible, but the core should be there!

warnwar commented 2 years ago

Wow. I played around with that version and it looks really good. That fits my needs very nicely.

I'm still learning about barcodes and didn't realize until today that NDC is the expected number in the barcode for pharmaceuticals (3) like described here: https://www.gtin.info/barcode-101/ So I think your version follows the spec. I had thought that other coding systems were possible here, but I guess not. This makes things easier for me when I start using the barcode value.

DacoTaco commented 2 years ago

Hey @warnwar ,

i have released 0.0.5 that is basically what i had shared before, but with some minor changes that came up when writing the unit tests. If you have any issues, feel free to let me know!