Quoting Voytek Eymont <[EMAIL PROTECTED]>:
on first read, I get only 'half' of output, followed my 'wrong offset',
see below:
Right,
You must wait till the end of line character is received, and not when
data is available.
Set up a variable called 'linebuffer' or something...
keep adding characters in your loop until you receive a carriage-return.
Once you have your carriage return, process the line, and clear the
linebuffer.
Regards
David
On Wed, June 25, 2008 12:14 am, Gonzalo Servat wrote:
On Tue, Jun 24, 2008 at 10:56 AM, Voytek Eymont <[EMAIL PROTECTED]> wrote:
Works for me:
my $str = 'a1566b0c203d1477e0f205g';
if( $str =~ /a(\d+)b\dc(\d+)d(\d+)e\df(\d+)g/ ) { printf( "DEPTH: %.1f\n",
$1/10 );
printf( "AIR TEMP: %.1f\n", $2/10 ); }
Gonzalo, thanks
so my problem is not in parsing expression, then
on first read, I get only 'half' of output, followed my 'wrong offset',
see below:
# ./aa.pl
Read: a6b0c213
T1 Lvl: 0, Temp: 0 T2 Lvl: 0, Temp: 0
Read: 1e0f221ga6b0c213
T1 Lvl: 0, Temp: 0 T2 Lvl: 0, Temp: 0
Read: 1e0f221ga6b0c211
T1 Lvl: 0, Temp: 0 T2 Lvl: 0, Temp: 0
Read: 1e0f221ga6b0c211
T1 Lvl: 0, Temp: 0 T2 Lvl: 0, Temp: 0
Read: 1e0f221ga6b0c212
T1 Lvl: 0, Temp: 0 T2 Lvl: 0, Temp: 0
aa.pl:
--------
[EMAIL PROTECTED] tank]# cat aa.pl
#!/usr/bin/perl
#
# Pool an Aqualogger via a serial port and write the temp and
# level values to a temporary file for use by other scripts.
#
# Steve Cliffe - <[EMAIL PROTECTED]>
#
# April 2007
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";
$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 $gotit = "";
until ("" ne $gotit) {
$gotit = $port->lookfor; # poll until data ready
sleep 1; # polling sample time
}
$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";
}
--snip--
--------
Minicom outputs this:
Welcome to minicom 2.1
OPTIONS: History Buffer, F-key Macros, Search History Buffer, I18n
Compiled on Jan 7 2007, 04:48:39.
Press CTRL-A Z for help on special keys
a2b0c213d1e0f222ga2b0c213d1e0f222ga2b0c213d1e0f221g
**though** sometimes, in Minicom, I see some garabage as first 10 or 20 chars
Minicom captures as follows:
[EMAIL PROTECTED] tank]# cat minicom.cap
[EMAIL PROTECTED]
tank]#
--
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