PDA

View Full Version : Perl Newbie... What's wrong ?



catdna
2010-01-27, 17:07
Hi All

Been a while since I've been on here - show's how robust these little players are ! - but I'm trying my hand at some Perl hacking (never done perl before, so please be gentle :) )

I've recently bought a new Onkyo NR807 amp which has an ethernet interface for controlling the receiver. I've knocked up some sample perl scripts which turn the player on / off and switch inputs etc.

Ok... I know there's the IR blaster plugin, but I thought I'd have a stab at modifying the code in the plugin to call my scripts. Plus, it gets rid of the dangling IR blaster blu-tacked to the front of my nice new shiny amp !

Now, after I've made my changes, the plugin refuses to load when SqueezeCenter is restarted... no idea why, the logs aren't really that helpful :( ...



[10-01-27 17:22:08.9856] Slim::Utils::PluginManager::enablePlugins (493) Error: Couldn't load Plugins::IRBlaster::Plugin


My changes (and this is my first time with perl as I've already said) are basically this for powering on the amp :



use IO::Socket;

my $sock = new IO::Socket::INET (
PeerAddr => '192.168.1.69',
PeerPort => '60128',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;

$cmd="!1PWR01";

$length=length($cmd);
$length=$length+1;
$code =chr($length);

$line = "ISCP\x00\x00\x00\x10\x00\x00\x00$code\x01\x00\x00\ x00".$cmd."\x0D";
print $sock $line;
$cmd="!1SLI20";
$line = "ISCP\x00\x00\x00\x10\x00\x00\x00$code\x01\x00\x00\ x00".$cmd."\x0D";

print $sock $line;
close($sock);


I tested from a command line (windows xp running ActivePerl) and it works just fine, however, if I mod the 'Plugin.pm' file for the IRBlaster plugin...

1. place 'use IO::Socket;' at the top of the file by the rest of the 'use' statements

2. In the 'sub handlePowerOnOff {' routine, I place my power-on code where the status is checked (not including the 'use IO::Socket' line obviously.. but the rest exactly as typed above).

- nothing ! well, not suprising as the plugin refuses to load.

Any one care to give this perl newbie a few pointers where I could be going wrong ?

Ta

Chris

erland
2010-01-27, 21:19
You should start Squeezebox Server with the parameter: --d_startup

This will show more descriptive error messages at the startup if something fails.

It's hard to say exactly what's wrong without actually running it with --d_startup so you see the whole error but I'm guessing the plugin has a "use strict" at the top, if it does I think you need to use "my " before each variable on the first row it's mentioned. For example:
my $cmd="!1PWR01";
Instead of:
$cmd="!1PWR01";