Output barcode control codes using ZXing?

1.6k views Asked by At

Without changing any ZXing source code, is there a way to output control codes in a barcode using ZXing on Android?

Edit: The reason that I don't want to edit source code is because I would like to use the "scan via intent" process. If I have to edit source, then I'll have to embed the entire project into my project instead.

For instance, I have a GS1-128 barcode that currently outputs text 21417341123. I would instead like to see something like [Start C][FNC1]21417341123[Stop].

If I can get the raw data from the scan, that would also be OK. But the "rawBytes" value is only for the data (21417341123 portion) and doesn't include the control codes. I saw the question ZXing Result.getRawBytes(), what exactly is it?, but the solution to use getByteArrayExtra("SCAN_RESULT_BYTE_SEGMENTS_0"); returns null.

If it is not possible to do this without changing code, then I will need to modify the ZXing source. I am just trying to see if I can do what I want without modifying source.

2

There are 2 answers

4
Sean Owen On BEST ANSWER

Usually when people ask this question, they are talking about FNC codes in a format like Code 128. These don't have a printable representation in the result, although FNC1 is translated as "]C1" or ASCII 29 as per the spec. The others really don't correspond to anything in the output, so don't result in any characters.

It looks like you're asking about a "START C" code. This too really isn't part of the string encoded by the barcode. It's an internal marker that tells it to switch sets for parsing the rest of the barcode.

Raw bytes make a bit more sense for other formats where there is clearly an underlying byte representation that is then further translated. For Code 128 it will give you all the (non-control) codes found in the barcode rather than the interpreted string. This is not what you want.

For your purpose you would have to modify the code. I think this only makes sense for some artificial use case .

2
user3181923 On

The raw bytes returned in the result are the code word indices. What character or control code a code word means depends on what code set is active.

http://en.wikipedia.org/wiki/Code_128

But since the start code is missing, the buffer is practically useless. I've modified it to include the start character to suit my purposes.