apologies...

there was a fatal flaw... so this is the update..

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) {
        until (index($linebuffer,"\r") <> -1) {
$linebuffer = $linebuffer + $port->lookfor; # 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";
}

--
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