my $port = '/dev/ttyUSB1';
$port = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0';
+my $debug = $ENV{DEBUG} || 0;
+
my $ob = new Device::SerialPort ($port)
|| die "Can't open $port: $!\n";
$ob->databits(8) || die "fail setting databits";
$ob->stopbits(1) || die "fail setting stopbits";
$ob->handshake("none") || die "fail setting handshake";
-$ob->debug(1);
+$ob->debug($debug);
my $InBytes = 255;
while ( 1 ) {
my ($count_in, $string_in) = $ob->read($InBytes);
- print "<< $count_in << ",dump($string_in),"\n" if $count_in > 0;
+ print "<< $count_in << ",dump($string_in),"\n" if $debug && $count_in > 0;
$got .= $string_in;
if ( $got =~ m/(OK|E!)\r\n/ ) {
- warn "# got = ",dump( $got );
+ warn "# got = ",dump( $got ) if $debug;
+ my $new;
foreach ( split(/[\r\n]+/,$got) ) {
my ($k,$v) = split(/:\s+/,$_,2);
- $s->{$k} = $v;
+ if ( ! defined $v ) {
+ warn "SKIP: [$_]\n" if $debug;
+ } else {
+ $new->{$k} = $v if ! defined $s->{$k} || $s->{$k} ne $v;
+ $s->{$k} = $v;
+ }
}
- warn "# s = ",dump( $s );
+ warn "# new = ",dump( $new );
$got = '';
if ( @commands ) {
$ob->write( shift(@commands) . "\n" );