Monday, December 21, 2009

'Compiling' Ruby Applications For Windows

In my qrpTracker satellite tracking project, I've written an Arduino library that stores and retrieves compacted information for satellite tracking. This is suited for the EEPROM memory aboard the arduino's chip, or memory chips accessed through the I2C bus. But the Arduino needs to get this data from somewhere, and so I'm also writing a server program for PCs that compacts the information and sends it to the Arduino through a serial connection.

My first version was written in C, not because I'm comfortable with C -- in fact this Arduino stuff is my first full-blown C or C++ programming, but rather because the datatypes on the Arduino are all defined in C terms and I thought it would be easier to get that right in C. However, I soon found that it was nearly impossible to write serial code that could work on multiple platforms, Win32 being particularly difficult.

Since I've been enjoying programming in Ruby lately, I decided to see what could be done on that platform. As it turns out, the careful datatyping can be done with Ruby's Array.pack() command, and with some difficulty, I was able to get a cross-platform serial port library working for me on Windows. Finally, I used wxruby to start a GUI for the program. But the last, and crucial, step was to see if I could make an all-in-one executable, especially for Windows, out of all this.

Enter OCRA, the one-click ruby application builder. I was really impressed with this. gem install ocra, then ocra ruby_file.rb and you have an application. The --console switch will force a console application; and the --window switch will make it a GUI. One caveat: if you make a window application, comment out any puts or other statements that print to the command line. If you don't your program will exit unceremoniously.

If you'd like to try them out, you'll find them at my public DropBox folder. The commandline version should actually send bytes up your serial port, and will play nicely with, the corresponding Arduion example code. The GUI version just emulates the satellite chosing window in SatPC32 and provides some menu items to specify TLE, modeline and subtone files.

No comments:

Post a Comment