Hi,
Finally I managed to cleanup the code of my Perl script for recording data from IRToy.
Currently it is working with Win32::SerialPort module (windows only AFAIK).
Change COM4 to other COM port if needed;
There is a 'secret' function to dump (to stdout) the received bytes and the calculated time. To enable this function just create an empty file with name 'irtoy.dump' in the folder where the script is running.
G:ProjectsEclipse-3.6IRToy>irtoy_record.pl test
Sampling mode enabled!
Press key on remote or CTRL+C to terminate
Processed: test000 min=18(383.9994us), sum=9505.0000, multiply=21.3333, len=400
Processed: test001 min=18(383.9994us), sum=27773.0000, multiply=21.3333, len=1000
Terminating on signal SIGINT(2)
BR,
Anton
[quote author="anton.todorov"]
Hi,
Finally I managed to cleanup the code of my Perl script for recording data from IRToy.
Currently it is working with Win32::SerialPort module (windows only AFAIK).
[/quote]
There is a PERL module Device::SerialPort (http://http://search.cpan.org/~cook/Device-SerialPort/SerialPort.pm) that provides the equivalent win32 serial API for Linux and other POSIX like systems. It doesn't appear to be very commonly packaged, so you generally have to install it from CPAN.
# Set up the serial port for Windows
use Win32::SerialPort;
my $port = Win32::SerialPort->new($mysport); #change to your com port
#setup serial port for Linux
#use Device::SerialPort;
#my $port = Device::SerialPort->new($mysport); #change to your com port
Here is a cross-platform method. You can also automate it with defines, but I couldn't find the example where I did that.
committed new version of irtoy_record.pl with linux/windows compatibility, the functions are in separate USBIRToy.pm, added some comments.
BR,
Anton
[quote author="ian"]
Here is a cross-platform method. You can also automate it with defines, but I couldn't find the example where I did that.
[/quote]
There are a couple of ways of accomplishing this automatically. I thought there was a version of Device::SerialPort or maybe a similarly named module that wraps the whole things for you.
#!/usr/bin/perl
#
# use by platform.
#
BEGIN {
our $ostype = lc($^O); # Magic variable for OS type.
our $SerialModule;
if ($ostype eq "mswin32") {
print "Windows 32n";
$SerialModule = "Win32::SerialPort";
} elsif ($ostype eq "cygwin") { perl in cygwin envronment
$SerialModule = "Win32::SerialPort"; # Cygwin win32 or Posix Device::SerialPort??
print "Cygwinn";
} else {
print "Assuming POSIX compatible OS, using Device::SerialPortn";
$SerialModule = "Device::SerialPort";
}
eval "use $SerialModule";
print "eval returned $retn";
}
print "Using: $SerialModulen";
# Get SerialPort object
$com = $SerialModule->new();
UPDATE: never mind, already included in USBIRToy.pm.
Note: I should point out, most Perl distributions that I've seen do not include either Win32::SerialPort or Device::SerialPort, so I users will need to install the module by using CPAN or what ever packaging system matches the version of perl they are using.
For windows users, ActiveState's Perl distribution does have Win32::SerialPort, so PPM, ActiveState's automatic package manager can be used to install it.
You are correct. Just updated the wiki with instructions how to install needed perl module depending on the platform (ActiveStatePerl, Ubuntu, RedHat, FreeBSD)
Hi, I'm not sure if this is the best thread for this but I had a small issue with the Perl module on my Linux box (Ubuntu 11.04) - the read_interval function called in USBIRToy.pm doesn't seem to exist in the module... at least the version that I installed from the repo (v1.04-2 i386). If you comment out the $rs->read_interval(60) on line 91 (latest from SVN) it works just fine.
@taintedkernel Thanks for the tip!