boombuler / barcode

a barcode creation lib for golang
MIT License
1.41k stars 167 forks source link

Code 128A? #16

Closed anders closed 7 years ago

anders commented 7 years ago

I need to encode the string FNC3+"$P\rI", but encoding \r (carriage return) requires code 128A. Further investigation reveals this library only supports 128B and 128C. Any chance you could add 128A as well?

(FNC3+"$P\rI" is a special code to begin/end programming Datalogic-brand barcode scanners)

boombuler commented 7 years ago

I will have a look at this. I think the biggest Problem will be to find the mapping for the A-Table.

anders commented 7 years ago

I think the A table should be: " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e"

I generated this using (and based on http://www.adams1.com/128table.html):

func c128TableA() string {
    result := []rune{}
    // first part
    for i := 32; i < 96; i++ {
        result = append(result, rune(i))
    }

    // control codes
    for i := 0; i < 31; i++ {
        result = append(result, rune(i))
    }
    return string(result)
}

func main() {
    log.Printf("%q", c128TableA());
}
boombuler commented 7 years ago

According to http://www.adams1.com/128table.html it should even include \x1f ?!?

Would be great if you could provide some tests. But It will not be required :) Gonna fix this asap.

anders commented 7 years ago

Yes, you're right, I initially included \x1f but seemed like an off by one (comparing the length of the table already in your code).

I'm reading some of these Datalogic codes by hand.

enter/end programming = <Start A><FNC3>$P<CR>I<STOP>
restore EU factory config = <Start B><FNC3>$P,Ae,P<Code A><CR><STOP>

If you'd like I could write some tests for these codes. I've already noticed that these don't include a checksum and there's no way to disable that atm.

boombuler commented 7 years ago

Tests would be great! I've just added the A encoding table, but the encode function must be changed too. Might take some time -.-

boombuler commented 7 years ago

Hope this all works as expected. If not let me know.

anders commented 7 years ago

Thanks, didn't expect you to work on this so quickly!

I can encode "$P\r" now, and an older model barcode scanner reads it, but the other codes don't register... I will look into it.