Quoting Voytek Eymont <[EMAIL PROTECTED]>:

yes, I thought it was something like that, I recall some REXX script we
had for SMSsing, it had stuff like that to process comm port;

there must be some ready made perl code like that, any thoughts where to
look for such ? (I'm just a water tank gauge installer....)

Well you are almost there....

Problem is that the UART has a 16 byte buffer (or something like that) and your processor is way too fast. These characters are coming in probably at 1 line per second.

In the old script your processor was spinning out before it had even finished receiving the line of data....

try something like this... it isn't debugged... you will have to do that.. i cannot ensure it is right or it will work....

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) {
        my $linebuffer = "";
        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