Line | |
---|
1 | #!/usr/bin/perl -w |
---|
2 | |
---|
3 | use strict; |
---|
4 | use Device::SerialPort; |
---|
5 | |
---|
6 | |
---|
7 | my $PortObj = new Device::SerialPort ("/dev/ttyAMA0"); |
---|
8 | $PortObj->baudrate(57600); |
---|
9 | $PortObj->parity("none"); |
---|
10 | $PortObj->databits(8); |
---|
11 | $PortObj->stopbits(1); |
---|
12 | $PortObj->handshake("none"); |
---|
13 | $PortObj->stty_igncr; |
---|
14 | $PortObj->are_match("\r\n"); |
---|
15 | |
---|
16 | $| = 1; |
---|
17 | |
---|
18 | my $count = 0; |
---|
19 | while (1) { |
---|
20 | my $char = $PortObj->lookfor(); |
---|
21 | chomp($char); |
---|
22 | if ($char) { |
---|
23 | print "Read " . $char . "\n"; |
---|
24 | } else { |
---|
25 | sleep(1); |
---|
26 | $count++; |
---|
27 | if ($count % 3 == 0) { |
---|
28 | my $cmd = "\$PFLAC,S,ACFT,0\r\n"; |
---|
29 | print " Send $cmd"; |
---|
30 | my $count_out = $PortObj->write($cmd); |
---|
31 | warn "write failed\n" unless ($count_out); |
---|
32 | warn "write incomplete\n" if ( $count_out != length($cmd) ); |
---|
33 | } |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | exit 0; |
---|
Note: See
TracBrowser
for help on using the repository browser.