Friday, 27 August 2010

And by that, I mean I gave it back to my manager. Of course, what I really mean there is that work is over!

I'd say it was an interesting experience. So writing documentation is probably not what I'd want to do for a living, but it was OK for a summer job to pass the time.

It's really a Windows shop there, which wasn't great. On the other hand, I don't have a problem with Office. It's really quite nice, especially if you're trying to script it. Don't even ask how to do any scripting in OpenOffice. Conversely, the ribbon was not amazing. It requires too many clicks to do anything and its layout changing is annoying.

Sunday, 15 August 2010

Update: The ModemManager rule should really only apply to the USB device, not the TTY. I updated the rule below to be a bit more specific.

Around the end of July, I ordered a Bus Pirate from Seeed Studio. It took about a week to ship, which is pretty quick, I think. I picked it up from the post office on Tuesday.

After opening the package and plugging it in, I was greeted with nice blinky lights, and my computer didn't start smoking, so that was a good sign. However, I seemed to run into a bug, where every few lines or so, the display would be screwed up. I started with minicom, until I found out that I could talk to the bus using screen instead. But the output was still not working. Even if I did something simple like press Enter repeatedly, after 5 or so lines, the prompt would show incorrectly. That was kind of disappointing, since Seeed had put a sticker on it for passing QC, so I thought I had a bad cable or set up something wrong.

But today, I finally hit a stroke of luck. One time, upon connecting, I noticed something writing to the port. The text started with AT... and I of course recognized those as modem commands. I remembered a bug report or blog post about ModemManager messing with (things that look like) serial ports.

ModemManager works alongside NetworkManager to provide support for connecting through GSM and CDMA modems. The problem is that a lot of modems suck and ModemManager needs to probe serial ports to see if it's really a modem. Since I'm on a desktop and I probably wouldn't ever use a modem, I could just remove it, but then what would I do on the laptop?

So I set out to find how to blacklist a serial port from ModemManager. I couldn't just get ModemManager to ignore all Bus Pirates, because it identifies itself as a generic FTDI USB-to-serial converter. While I can let Dangerous Prototypes go for that since it's a little hacking board, I'm sure there are actual companies using an FTDI chip who don't identify their modem devices uniquely. Thus, blacklisting the entire FTDI series was out.

All was not lost however, as ModemManager's blacklist basically works through udev. Because USB device numbers are not static, I was already using a udev rule to give me a static device name for the Bus Pirate (from the Arch Linux wiki). After a quick look at the ModemManager blacklist rules, I found that it uses ENV{ID_MM_DEVICE_IGNORE}="1" to signal to ModemManager to ignore a device.

So, to sum it all up, you need to create a udev rule in /etc/udev/rules.d/98-bus-pirate.rules:

Check the Arch wiki for how to get the proper serial number. The first rule sets up a /dev/buspirate device node link so you have a memorable name to use (instead of /dev/ttyUSB#). It also sets permissions so that it's accessible to the users group. Make sure to add your user to that group and you won't need to be root to use the Bus Pirate. The second rule sets a variable on the USB device so that ModemManager doesn't attempt to probe it.

To connect, just use screen. I set up an alias to run screen /dev/buspirate 115200 8N1 and it works great. Now I just need to get something to hack on with it.

Friday, 13 August 2010

So I recently had to create a whole bunch of invites. Not a huge number like a thousand, but more than enough that I didn't want to make each one individually. Anyway, I decided to make them in Scribus. It's semi-professional, and has grade-A output. After the fact, I'd say that it was a pretty good choice, except for a few annoying wrinkles.

The Good

On the good side, Scribus is really stringent about printing issues (though that wasn't as much of a concern this time). It's really good at getting you to use proper fonts. And I really love the ability to use math in any entry field. OK, this doesn't seem like a lot, but overall it's pretty good, and I don't want to go listing out everything!

The Bad

The reason why I say it's only semi-professional is because of these wrinkles. There was one annoying crash, but fortunately, it went away after an upgrade. The real problems are mostly non-intuitiveness, where things don't happen how you'd like. I'm having a hard time remembering them as I think I've grown accustomed to it all. Actually, one thing I remember is that the style editor acts very oddly. If you're editing styles, the style information never stays in sync with the style you have selected. Nine times out of ten (I made that stat up), stuff will be disabled as if you've selected a built-in non-editable style even when you haven't. Oh, and the undo stack is pretty weird. Why does Scribus seem to think I've edited the document when I just saved and Scribus isn't even in focus!

The Ugly

However, out of all things, I think the most disappointing was the scripting API. I mean, automating stuff was one of the things I hoped to do. I did eventually get that done, but it was not fun getting there, and took way too long.

Originally, I planned to create a template, and then write a script which created a Scribus file for each invite. This idea didn't work out at all as the importing broke stuff. That's OK, because then I had the better idea of using a Master Page, with each invite as a separate page. Scribus has the ability to export each page separately, so this worked out well. I could put everything on the Master Page except the small bit with the name which would be different for each page.

The problems really arise from the fact that the scripting API is not well thought-out. It may use Python, but it's not at all Pythonic. It's not even self-consistent. When you change an object's properties, you can specify its name, or work with the mysterious "selection". That selection could be a whole object, or it could be some text within the object. Sometimes, after calling a function, the selection is gone! Exporting to a PDF involves a PDFfile object, while nowhere else is a class used.

Scribus files seem to be XML, but the scripting API does not take any advantage of that. All you get is a handful of top-level functions, and stuff to modify that mysterious selection. It's really too bad, because with a proper object model, I'm sure you could do some really cool stuff.

The End

In the end, I did end up with a script that worked. It was based of the mail-merge script on the Scribus wiki. It didn't do what I originally wanted, but it did get the job done. And of course, the invites did turn out awesome.

But after trying that, going back to VBA in MS Office was a bit of a relief.

Sunday, 8 August 2010

Round about last week, I switched my desktop from Gentoo to Fedora. It took a few days to get everything the way I wanted. But it only took that long because I had lots of data to backup and (selectively) restore, and I only worked in the evenings. Fortunately, a "re-install" is way less painful than Windows, since all you really need to keep is your home directory. I just don't know how Windows users live through it, especially without all their programs in a convenient package manager. I can happily say I have never re-formatted Windows for any reason (and that's not because I don't used it).

I guess there are a few reasons for the switch. I'd say it basically boils down to the following three:

Gentoo wasn't updating fast enough for things I wanted. I can't say whether this is a general trend, but at least for packages I wanted, it was slow, and I could see that Fedora was getting those updates.

My computer is getting older and packages are getting bigger. It's not been too bad (except for god-awful C++ programs that use Boost), but I don't want to work my system so hard as it gets older.

And the most important: I got lazier. Not lazy enough to install Ubuntu though!

I guess I'll see how well Fedora fairs. I've just got an audio bug or two to fix (already reported) and it should be good. Eventually, I should go see if my cx18 works, too.