WhyNotHugo / python-barcode

㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.
http://python-barcode.rtfd.io/
MIT License
556 stars 122 forks source link

Add Full ASCII support for Code39 #23

Open michalzaptk opened 5 years ago

michalzaptk commented 5 years ago

Right now, there is limited ASCII support with Code39.

For example, trying to include a _ in a barcode will produce the error: IllegalCharacterError: The following characters are not valid for Code 39: _

WhyNotHugo commented 5 years ago

Looks like code39 actually supports a limited character set (43 characters in total).

There seems to be an "extended code 39", which uses more characters, by simply representing them with escape codes. For example, _ is encoded by replacing it with %O.

See the table at the end of this page for details: http://www.barcodeisland.com/code39.phtml

I don't think it's wise to automatically use extended code39; I might use a separate writer (eg: extcode39) with support for that.

michalzaptk commented 5 years ago

That was a great find - After cross referencing that doc with my handheld scanner manual, there is a specific setting to activate full ASCII for Code39, which respects those encodings. I imagine most common brand scanners will allow that sort of configuration - Although it seems like the few iOS apps I've tried do not.

This solves the issue from a process standpoint by making some manual changes to my code - Im ok with closing this, unless you want to leave it open as a future milestone.

WhyNotHugo commented 5 years ago

I'll leave this open as a potential enhancement, since it's not too complex to get it done, TBH.

venkatpolisetti commented 4 years ago

@WhyNotHugo This is great module and we are trying to use it to generate code39 barcodes for a car wash scanner kiosk and it somehow accepts only barcodes with a star such as $PKHH24EF. Currently, this module is throwing an exception when it sees the * character there.

In the above conversation, you talked about a new writer extcode39 that extends the ASCII characters the module will process. Is there a way to make it happen?

Thanks.

WhyNotHugo commented 4 years ago

You'd need to subclass Code39. It currently uses this map.

A new map would need to be defined for this subclass, that includes both the above and the extended characters.

Finally, just a single test that confirms that conversion of a few characters works as intended, and that's it.