Thursday, December 17, 2009

Ruby serialport on Win32

Building native extensions is difficult in any scripting language. Having rewritten my TLE encoding and transmission code from C to Ruby on the MacOs, now I'm trying to get the same code to work on Win32, which is likely to be where most people want to use it. Trouble is, Windows doesn't come with a standard build environment. Here's what eventually worked:

1. Install one-click Ruby here:
2. On command line do gem sources -a
gem sources -a
3. Now do gem install hparra-serialport

If you use most of the other serialport forks, or the 1.9.1 rubyinstaller, you'll be out of luck. With the method above, you do not need to add a devkit or a devkit-based one-click installer. The Ruby build above is based on mingw, so you'll need MingW to do Win32 building. To test if it will work, try the command 'make' in your command window. You should get the error: No targets specified, not the error 'make' is not recognized.

Now it's time to test it on Win32 ...

Update: it works! The only oddity I found was that under Win32 a getc call would produce a nil object if there was nothing available from the port. Not sure if this is the most elegant way to deal with it, but I just looped around to ignore those.

No comments:

Post a Comment