Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #188373

Re: Serial Ports and Perl

From "Martin McCormick" <martin.m@suddenlink.net>
Newsgroups linux.debian.user
Subject Re: Serial Ports and Perl
Date 2017-10-27 04:40 +0200
Message-ID <uF2IV-5xu-3@gated-at.bofh.it> (permalink)
References <uF10t-4gy-3@gated-at.bofh.it> <uF1Wx-4TG-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Andy Smith <andy@strugglers.net> writes:
> Hi Martin,

> I have been using it successfully for a long time, but all I do is
> read whole lines from the serial device like:
> 
> my $dev  = '/dev/ttyUSB0';
> my $port = Device::SerialPort->new($dev);
> 
> $port->baudrate(57600);
> $port->write_settings;
> 
> open my $fh, '<', $dev or die "Can't open $dev: $!";
> 

> while (<$fh>) {
>     print "READ: $_\n";
> }
> 
> So, I am only using Device::SerialPort to configure the device,
> while all reading is done by treating it as a normal file.
> 
> I see you are using lookfor(), which I have never used before. From
> a brief look at:
> 
>     
> http://search.cpan.org/~cook/Device-SerialPort-1.002/SerialPort.pm#Methods_for_I/O_Processing
> 
> it seems you should be setting are_match() if you want lookfor() to
> match anything.
> 
> Cheers,
> Andy

I think I am going to call it a day and jump back on it in the
morning but opening the device is something I failed to do.  A
whole new rabit hole to go down and I wouldn't be surprised if
that wasn't the problem all along.

	A perldoc of Device::SerialPort says that lookfor is
supposed to block or hold until a character string emerges from
the port as in /dev/ttyUSB0 or /dev/ttyS1.  When I trace the
code, it just loops as fast as it can and never holds to wait for
anything.  I thought this was strange and if I should have opened
the device, this may explain all the weirdness.  One of the
examples I saw did have a close statement on the device.  I bet I
just missed the need to open a file handle.

	Thanks.  I'll post a message if that worked.

Martin McCormick

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Serial Ports and Perl "Martin McCormick" <martin.m@suddenlink.net> - 2017-10-27 02:50 +0200
  Re: Serial Ports and Perl Andy Smith <andy@strugglers.net> - 2017-10-27 03:50 +0200
    Re: Serial Ports and Perl "Martin McCormick" <martin.m@suddenlink.net> - 2017-10-27 04:40 +0200
      Re: Serial Ports and Perl Richard Hector <richard@walnut.gen.nz> - 2017-10-27 06:50 +0200
    Re: Serial Ports and Perl "Martin McCormick" <martin.m@suddenlink.net> - 2017-10-27 18:50 +0200
  Re: Serial Ports and Perl Henning Follmann <hfollmann@itcfollmann.com> - 2017-10-27 04:00 +0200
  Re: Serial Ports and Perl Fred <fred@blakemfg.com> - 2017-10-27 04:20 +0200

csiph-web