Quoting Voytek Eymont <[EMAIL PROTECTED]>:

you need to fix this line, so it does the read.
         $linebuffer =. $port->read;       # poll until data ready

I don't have any of the earlier emails.... but your first version must have been correct.


 -----------------------
 #!/usr/bin/perl

 use Device::SerialPort qw( :PARAM :STAT 0.07 );

 my $MAXVAR = 20;        # Maximum data variation (%)

 my $port=Device::SerialPort->new("/dev/ttyS0");
 my $tmpfile = "/var/tmp/aqualogger";
 my $linebuffer = "";

 $port->baudrate(2400);
 $port->databits(8);
 $port->parity("none");
 $port->read_char_time(0);     # don't wait for each character
 $port->read_const_time(1000); # 1 second per unfulfilled "read" call
 $port->are_match("d");

 # Main loop

 while (1) {

     # Read a full line of data
     until (index($linebuffer,"\r") != -1) {
         $linebuffer =. $port->read;       # poll until data ready
         sleep 1;                          # polling sample time
     }

     print "Full line received\nNow processing...";

     # Extract what we need for the next step
     $gotit = substr $linebuffer,1,index($linebuffer,"\r");

     # We must put any stray characters after the terminator back
     # into the linebuffer as they will form the start of the next
     # line.
     $linebuffer = substr $linebuffer, index($linebuffer,"\r");

     $gotit =~ /a(\d+)b\dc(\d+)d(\d+)e\df(\d+)g/;
     $level1 = $1 / 10;
     $temp1 = $2 / 10;
     $level2 = $3 / 10;
     $temp2 = $4 / 10;
     printf "Read: %s\n", $gotit;
     print "T1 Lvl: $level1, Temp: $temp1 T2 Lvl: $level2, Temp: $temp2\n";
 }



--
Voytek

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html




--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to