added socket connection to remote serial port
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 18 Jan 2015 18:37:02 +0000 (19:37 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 18 Jan 2015 18:37:02 +0000 (19:37 +0100)
dialog.pl

index 6e3445e..2174f07 100755 (executable)
--- a/dialog.pl
+++ b/dialog.pl
@@ -3,10 +3,12 @@ use warnings;
 use strict;
 
 use Data::Dump qw(dump);
-use Device::SerialPort qw(:STAT);
-
 my $debug = $ENV{DEBUG} || 0;
 
+=for serial_port
+
+use Device::SerialPort qw(:STAT);
+
 my $port = Device::SerialPort->new('/dev/ttyUSB0');
 die "can't open serial port" unless $port;
 $port->baudrate(9600);
@@ -28,9 +30,33 @@ sub write_serial {
        return $port->write( $bytes );
 }
 
+=cut
+
 # TODO: implement remote serial port
 # remserial -x 2 -p 23000 -s "9600 raw" /dev/ttyUSB0
 
+use IO::Socket::INET;
+
+my $sock = IO::Socket::INET->new(
+       PeerAddr => '192.168.1.148',
+       PeerPort => '23000',
+       Proto    => 'tcp'
+);
+
+sub read_serial {
+       my $len = shift;
+       my $buffer;
+       $sock->read( $buffer, $len );
+       warn "## read $len ",as_hex($buffer) if $debug;
+       return $buffer;
+}
+
+sub write_serial {
+       my $bytes = shift;
+       return $sock->print( $bytes );
+}
+
+
 sub as_hex {
        my @out;
        foreach my $str ( @_ ) {