Home > Archive > PERL Miscellaneous > March 2004 > Perl Serial io on linux
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Perl Serial io on linux
|
|
| T.Paakki 2004-03-28, 10:22 pm |
| I recently bought a serial port attached touchscreen LCD display and
wanted to control it via perl on Linux (Zaurus).
Has anyone done this before? I was thinking it would go something
like this:
Display Splash on touchscreen
Wait for tap on touchscreen
read from local file containing temperature values
clear display
wait for response
display temp screen
loop until done is pressed
The only examples I've seen detail modem communications or just a
terminal, I'm looking for automated control.
any help would be appreciated!
Thanks
Travis
| |
|
| T.Paakki wrote:
> I recently bought a serial port attached touchscreen LCD display and
> wanted to control it via perl on Linux (Zaurus).
>
> Has anyone done this before? I was thinking it would go something
> like this:
....
> read from local file containing temperature values
> clear display
> wait for response
> display temp screen
> loop until done is pressed
>
> The only examples I've seen detail modem communications or just a
> terminal, I'm looking for automated control.
Can you run Expect on a Zaurus?
| |
| T.Paakki 2004-03-29, 12:33 pm |
| So far, expect is not an option. I'm not sure why.
| |
|
| T.Paakki wrote:
> So far, expect is not an option. I'm not sure why.
There is an Expect.pm module for Perl that works with serial ports. Too
bad if it won't compile on Zaurus.
| |
| John Sterling 2004-03-29, 10:35 pm |
| Bill wrote:
> T.Paakki wrote:
>
>
>
> There is an Expect.pm module for Perl that works with serial ports. Too
> bad if it won't compile on Zaurus.
>
You don't really need Expect.pm to do this. One of the techs at work
asked me how to drive the serial port with Perl the other day. I came
up with this pretty quickly. I am logging into an HPUX system from a
Linux system then running the ioscan command. You should be able to do
something similar for your display. You just have to understand it's
protocol.
#!/usr/local/bin/perl
use strict;
use warnings;
sub readUntil {
my $port = shift;
my $pat = shift;
my $data = "";
my $buf = "";
my $br;
my $timeout = 10000;
do {
$br = sysread($port, $buf, 256);
$data .= $buf if $br > 0;
} while ($data !~ /$pat/i && $timeout--);
return $data;
}
my $port;
open ($port, "+</dev/ttyS0") || die "cannot open port S0: $!\n";
# you will have to tweak this depending on your comm protocol
# my guess is that raw might do what you want
system("stty 9600 raw < /dev/ttyS0");
syswrite($port, "\r");
readUntil($port,"login:");
syswrite($port, "$user\r");
readUntil($port,"assword");
syswrite($port,"$password\r");
readUntil($port,"Terminal Type?");
syswrite($port,"vt100\r");
readUntil($port,"#");
syswrite($port, "ioscan\r");
# I am just dumping the output of the ioscan command to a file
# you probably want to do something else
my $output = readUntil($port,"#");
my $outfile;
open ($outfile,">data.txt");
print $outfile $output;
close $outfile;
syswrite($port, "exit\r");
close $port;
-John
It isn't pretty but it works.
|
|
|
|
|