Hi, I'd like some help with the serial port code from my hacked up program below. I have a electricity monitoring device thats hooked up to my pc's serial port. The device outputs XML every six seconds. I want to read some of the values from the XML and put them into a database.
The code below does work but it isn't getting the whole XML feed at six second intervils. I've had a look at the documentation for SerialPort but it's going over my head. #! perl -w use strict; use Win32::SerialPort 0.11; use DBI; use DBD::mysql; my $DBstore = DBI->connect( 'dbi:mysql:elec:localhost: 3306','elec','elec'); my $ob = Win32::SerialPort->start ("tpj4.cfg") || die; for (my $qwe = 100000000; $qwe >= 1; $qwe--) { sleep 1; my ($count, $result) = $ob->read(900); if ($result =~ m!<ch1><watts>0*(\d+)</watts></ch1>.*<ch2><watts>0*(\d +)</watts></ch2>.*<ch3><watts>0*(\d+)</watts></ch3>.*<tmpr>([\d.]+)</ tmpr>!) { my $wattsx = $1; my $wattsy = $2; my $wattsz = $3; my $temp = $4; my $Total = $wattsx + $wattsy + $wattsy; my $sql = qq{ insert into readings (units,temp) VALUES ($wattsx, $temp) }; $DBstore->do( $sql ); print "Temp : $temp Watts Ch1 : $wattsx Watts Ch2 : $wattsy Watts ch3 : $wattsz Watts Total : $Total in KWh \n"; } } undef $ob; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/