Monday, September 10, 2018

Counting bars in Code 128

I was trying to decode a generated barcode by hand and it was just too hard. So why not use my favorite new language, darkbasic classic.

I load the bitmap and then just display the bar widths and manually look it up in the table at https://en.wikipedia.org/wiki/Code_128.

Quick and dirty but so much easier than trying to count pixels by hand...








So why only 107 symbols in Code 128?

Sometimes you just wonder why things have a certain number of possibilities. Like code 128 barcodes. Why does it have a certain # of symbols?

From https://en.wikipedia.org/wiki/Code_128

It's got a constant 11 bit width with 3 bars and 3 spaces. Each bar can be from 1 to 4 units thick.

So you have 6 bars and they can have 4 possibilities each.

You'd think it would be 4 * 4 * 4 * 4 * 4 = 4096 possibilities, but the number of units all has to add up to 11.

Let's write some javascript to do some counting for us:




and it dutifully gives us 216 possibilities.

If we remove half of those 216 taking away the reverse bit patterns, we get 108 which is pretty close to the 107 symbols that you can have in code 128.

Friday, August 31, 2018

darkbasic classic and warrenview

Years ago, there was this cool program called warrenview which would display pictures as a 3d plane that you could rotate around. I had a cd of darkbasic classic and decided to install it and start fiddling around. It's very idiosyncratic but it's fast and fun and a bit addictive to try things out and see what happens. I remember the old Amiga AMOS Basic and DarkBasic Classic (DBC) reminds me of it. It can be fiddly to get things working but it doesn't seem to crash.

DBC is a bit archaic (the built in editor is 640x480 even if you have a full HD monitor). PRINT doesn't scroll the screen when you hit the bottom of the screen or use a monospace font. Once you activate the 3d system it will tend to overwrite everything on the screen unless you disable the background with BACKDROP OFF. You can set things but not retrieve the same state, like SCALE TEXTURE. It's a one way street with write only and you have to remember what you set it to.

If you want to write text to the screen, the automatic refreshing system will overwrite it unless you refresh it every 60th of a second even when you use SYNC ON and SYNC. Putting in a WAIT 5000 or SLEEP 5000 will have the text disappear within the next 60th of a second.

Why do comments have to start with a backtick? Why not a single quote like QBASIC? (That one is hardwired, man! Must unlearn...)

And my personal favorite, when the editor is running (just editing your program, not running a program), cpu usage is 100%. (Why Lisa, why?)

Anyway, here's my attempt at recreating warrenview in DBC. There's something really satisfying about spinning the picture with the mouse at 60 fps.









Tuesday, July 3, 2018

Code 39 intercharacter gap

I was fiddling with my barcode scanner and an old UPS barcode.

It was obviously code 39 but when I made my own version of it using one of the online web barcode generators, the bars didn't look the same. The pattern was very similar but subtly different.

What I discovered is that the intercharacter gap is wide instead of narrow. According to https://en.wikipedia.org/wiki/Code_39, "Characters are separated by an additional narrow space."


I wonder if a larger intercharacter gap made it easier to decode years ago.


So here's the original barcode with a freshly generated version underneath for comparison.


Saturday, June 16, 2018

xrandr: why not just have --setcvtmode 1920x1080@60

I have fiddled with xrandr a lot and I wish that it'd be easier to just specify a resolution and refresh rate in one line.

Something like

xrandr --output VGA-1 --setcvtmode 1920x1080@60

instead of having to do:


$ cvt 1920 1080 60
# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
Modeline "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync


then copying and pasting the modeline into xrandr --newmode

$ xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync

and then adding the mode to the VGA-1

$ xrandr --addmode VGA-1 "1920x1080_60.00"

and then finally actually setting the mode

$ xrandr --output VGA-1 --mode "1920x1080_60.00"


You can do things like use awk:

xrandr --newmode `cvt 1920 1080 60 | awk 'NR==2 {for (i=2;i<=NF;i++) printf("%s ",$i);}'`
xrandr --addmode VGA-1 `cvt 1920 1080 60 | awk 'NR==2 {for (i=2;i<=2;i++) printf("%s ",$i);}'`

but why not have it all in a single command, and maybe have an option for trying it out and reverting to the previous settings in 10 seconds, in case your monitor doesn't like it.



something like:

xrandr --output VGA-1 --setcvtmode 1920x1080@60 --trymode 10

That would make it much less cumbersome. Why does it have to be hard?

Thursday, June 14, 2018

Mysterious unscannable barcode on my service tag

So I was fiddling with my barcode scanner and was scanning the barcode of my Dell Service Tag. There were actually two barcodes on the tag, one that would scan that was Code 128, and the other that would not.

I did some detective work and figured out the one that wouldn't scan must be Interleaved Code 2 of 5.

From the wikipedia page at https://en.wikipedia.org/wiki/Interleaved_2_of_5 I figured out how to manually decode it. It's actually pretty simple once you know that it encodes pairs of numbers, the widths of the black bars being the first number and the widths of the gaps being the second number.

Interleaved 2 of 5 has a start code of nnnn and stop code of Wnn which makes it a bit easier to spot now that I know what I'm looking for.

So for example the I2of5 barcode on my Optiplex 745 Desktop was "0019". Plugging that number into my Brother P-touch software and selecting I2of5 makes the exact same barcode.

But why wouldn't it scan?

I found a manual for my Symbol Spark and looked at its configuration barcodes, and enabled the I2of5 but it still wouldn't scan.

So I scanned the MIN Length I2of5 and then 0 and 0. (The Symbol Spark expects two digits when you scan the configuration barcodes and I was baffled why it wasn't working because I was only scanning a single number).

Now that I've got it configured correctly, the barcode scanner would scan those previously "invisible" barcodes.

Wednesday, June 6, 2018

Soundbar is so irritating

So I got a soundbar for my TV. It sounds great with deep sound, but it's kind of irritating too.

Sometimes I don't want the "full" sound experience, (like late at night) so I'll switch to TV speakers only.

It doesn't pass through the HDMI signal through unless I have the sound bar turned on and select HDMI on the sound bar.

So I'll have to turn it on, and then switch to TV SPK.

If I accidentally hit the channel change on the TV, then it switches the soundbar automatically to DIGITAL IN. So then you've got to switch the soundbar back to HDMI, and it takes a few seconds for the TV to lock on to the HDMI, then switch back to TV SPK.

When using the soundbar's DIGITAL IN, if you haven't got the TV speakers muted, there's a slight delay in the sound so you get that weird sound effect of multiple tvs on (like you're watching all the TVs at the target store). If I could just have a slight video delay on the TV to get things to match perfectly... You can add audio delay at the soundbar but that just makes the delay worse.

There's just too much switching and fiddling around. It's almost so irritating that I'm feel like pulling the sound bar. I just want everything simple. You turn it on, it works. And it's perfectly in sync.


It doesn't sound like much, just pressing a couple of buttons. It's the 100th time you do it and you wonder why it just doesn't work seamlessly.