[luau] Serial with Perl

whenever whatever at whoever.net
Tue Mar 26 23:46:52 PST 2002


got it kinda working but I am having problem when reading the port, it only 
display about 256 char.  ie: after I login, I did a command 'ls', I have to 
press enter(\r or \n) to see the next  256 char. and so on, then all my key 
stroke got entered after the display, anyone have any idea how to fix that?

#!/usr/bin/perl -w
use strict;
use Device::SerialPort;
use Time::HiRes qw(time alarm sleep);

my $config = './serial.conf';
my $dev = '/dev/ttyS0';

my $port = new Device::SerialPort($dev);

if (not -e $config)
{
  print "making new config file $config\n";
  $port->baudrate(19200);
  $port->handshake('xoff');
  $port->databits(8);
  $port->parity("none");
  $port->stopbits(1);
  $port->save($config);
}

while (<>)
{
        $port->write("$_");
        $port->write_drain();
        my $data = "";

    while (1)
        {
        sleep(0.25);
        my $read = $port->input();
        next if not length($read);
        $data .= $read;
        print $data;
        last;
        #last if $data =~ / ( \? .*|\$)\r\n/;
        }
}

On Monday 25 March 2002 07:41 pm, you wrote:
> From: whenever <whatever at whoever.net>
>
> >Reply-To: luau at videl.ics.hawaii.edu
> >To: luau at videl.ics.hawaii.edu
> >Subject: [luau] Serial with Perl
> >Date: Mon, 25 Mar 2002 17:43:45 -1000
> >
> >Anyone does serial programming here? I need to send commands and recieve
> >results from a serial port that has a VT`100 emulation on the other end. 
> > I don't want to use expect, perl would be great/easier for me, but I
> > haven't done serial code before, can someone give me an example? I have
> > looked at Device::SerialPort, IO:Tty, Comm.pl(last choice on this one or
> > FileHandler) and POSIX::termios, I am still a little lost there.
> >
> >Thanks
> >_______________________________________________
> >LUAU mailing list
> >LUAU at videl.ics.hawaii.edu
> >http://videl.ics.hawaii.edu/mailman/listinfo/luau
>
> I wanted to do the same thing, since I love to work with modems and serial
> ports, but all I could find was this limited stuff -
>
> http://www.linuxdoc.org/HOWTO/Serial-Programming-HOWTO/
>
> You probably already have this.  Wish the examples were a bit more meaty.
> If you find anything else, let me know.
>
> /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
> Patrick Kennedy
>
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
> _______________________________________________
> LUAU mailing list
> LUAU at videl.ics.hawaii.edu
> http://videl.ics.hawaii.edu/mailman/listinfo/luau



More information about the LUAU mailing list