Tags Perl

One of Perl's greatest strengths is CPAN - the staggering collection of modules that help solving a very wide range of tasks. This strength has a catch, though - some of these modules are very, very difficult to install, especially on Windows machines.

One of such modules is Win32::SerialPort and its brethen, which I use at work to amaze my colleagues in showing off that "this Perl thing" can even speak to our hardware via RS232.

Win32::SerialPort is a torture to install, however, requiring a C compiler (not always present in EE development computers) and a lot of tweaking. I managed to install it on my PC some time ago and I don't want to repeat this experience.

But, a need arouse to run custom Perl scripts with SerialPort on another computer. I like working with Perl code instead of a GUI. Send "abs", no probs - uncomment a little code that does it and run, this allows great flexibility. So, to "port" this method to a colleague's PC I used an original approach with PAR:

First, I created a simple "host" script that "use"s SerialPort and other modules I need. This script allows to write a Perl file (using a simple GUI) and then "eval"s it, so that file can use these modules.

The basic idea is demonstrated by the following code:


use Win32::SerialPort;
use [other modules I need];

my $text = join('', <FILE>);

eval($text);

This is packaged with PAR on my PC, hence SerialPort is included. The FILE however can run on any other PC, using the executable generated by PAR.

Then, I wrapped the script in a simple GUI and packed it to an .exe with PAR. Voila ! I can now run my small Perl scripts with Win32::SerialPort even on the laboratory laptop that has no network connection.