Log in

No account? Create an account

November 30th, 2003

How did I get myself into this...

Some time ago, we got my wife a really nice looking Canon N1240U scanner for her Powerbook. The real beauty of this scanner is that it's bus powered, so you don't need to lug around a power brick when you want to take it somewhere. It's also much smaller than most other scanners.

When we first got the scanner, the only drivers for it were for OS 9, so back to Classic we went whenever any scanning needed to be done. OS X drivers were promised though, so it wasn't so bad.

OS X drivers arrived quite some time ago, and I vaguely remember my wife complaining about their installation... let some time pass til I wanted to scan something.

I simply could not believe how poorly put together the drivers for this super simple scanner were. First, you have to download two files. Uncompress them, they are both installers. Ok, no biggie. Run the first, it installs an installer (wtf?) which I then run. It installs some files somewhere on my hard drive, I have no idea where. At this point, I still can't scan. So I run the second installer which installs yet another installer. This one runs and gives me some sort of scanning program that looks like it was written for someone's high school programming project back in 97.

Ok, so it looks pretty bad, at least I can scan. I go about my business. Some time later, I'm looking at my system logs, and they are full of entries from some process looking for a USB device. A bit of investigation revealed that the installers added a couple of apps to my login items, one of which adds a entry to my system logs once every second.

It was at this point that I decided to do something that I never thought that I would. I decided to try to write a driver for the scanner.

So, now I'm looking for info on how to go about it. I've got some stuff here, I'll post more about it later.

More on scanner drivers

So far I've found a lot of really good info on writing a scanner driver. I think that I should have everything that I need to accomplish the task, given the time and patience (and perhaps some caffeine)

I first want to point out what great resources Apple gives away to developers. XCode is a sweet IDE, and totally free with Panther. Apple also has available free for download all sorts of useful SDK's relating to various aspects of OS X. The one that I found right off was the Image Capture Architecture SDK, complete with a short overview of how to write a scanner plugin, and a compilable project to get you started with a complete plugin framework. All I have to do is add the code to access the device. Along with that there is also a great tutorial on doing all the rest of that under OS X. All of this info is at http://developer.apple.com. Right now I'm basically reading through all the info that Apple has on accessing USB devices, and how the ICA framework works.

Once I have all of the above figured out, I'll need to know how to work the scanner in question. I was very lucky in that respect. I took a look at SANE, the scanner framework for Linux. The latest version of SANE claims complete support for the N1240U and the LIDE 30. So I grabbed the latest snapshot, and started looking around to see what info might be in there. Reading someone else's code is never fun, but it does seem to be fairly well laid out, and I should be able to refer to it to find out more. Fortunately for me, the developer of the plugin (plustek) that I looked at also posted links to a good bit of technical info on the chipset of the printer. Included in that is what is basically an SDK from National Semiconductor on how to talk to the chip. The reason that this scanner can be so small is that it's all done in one piece of silicon (plus a DRAM module, ok, so 2 chips) the single chip does all of the work, from talking to the host via USB to controlling the lamp and stepper motor. It's quite amazing.

At this point I discovered something quite startling. I never knew before how incredibly stupid a scanner is, at least this one. I must tell it to do everything, and I mean everything. I have to tell the scanner when to turn on the lamp. I even have to do the color calibration myself. All of the work is done by the driver. The scanner does nothing. Amazing stuff.

So now I'm busy learning OS X's IOKit framework. After that, I plan to write a demo app that can find and access the scanner, turn the light on, move the carriage, etc. Then I'll need to get bulk data transfer down. Perhaps at that point I'll try to graft my code into the Apple supplied framework and see if I can't get an image out of it.

Sweet! New ICA SDK

Sweet. Apple released a new version of the Image Capture SDK. I don't expect many changes, but I'm mostly worried about Panther right now, so this is good stuff.