Linux serial comm with Uno rev3 problems.

ok as promised here is some daemon code that I threw together. This is a combination of examples from the perl cookbook and from the arduino playground. This right now works under linux and doesn't handle much else aside from my application so far. But could be used as an example.

The server/daemon:

#!/usr/bin/perl

use IO::Socket;
use Device::SerialPort;

my $sock;
my $sockname = '/tmp/serialcom';
my $MAXLEN =4;
my $mesg;

# init serial port
my $port = Device::SerialPort->new("/dev/ttyACM0");
$port->baudrate(9600); # you may change this value
$port->databits(8); # but not this and the two following
$port->parity("none");
$port->stopbits(1);

# setup the Unix socket
unlink $sockname;
$sock = IO::Socket::UNIX->new(Local     => $sockname,
                              Type      => SOCK_DGRAM,
                              Listen    => 5) or die $@;
# Wait for arduino to reset
sleep(5);

while(1) {
  $sock->recv($mesg, $MAXLEN);
  $port->write($mesg);
}

Here is the client:

#!/usr/bin/perl

use IO::Socket;

my ($mesg) = @ARGV;

my $sockname = '/tmp/serialcom';
my $MAXLEN = 4;
my $sock;

$sock = IO::Socket::UNIX->new(Peer     => $sockname,
                              Type     => SOCK_DGRAM,
                              Timeout  => 10) or die $@;

if( length($mesg) < 5) {
  $sock->send($mesg);
} else {
  print "Message too long\n";
}

Mind this is just quick and dirty code that has a fair amount of hard coded values. But I am putting this up in hopes that this might help someone else.