check if response is Dx and try to recover
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 27 Jul 2010 13:07:29 +0000 (15:07 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 27 Jul 2010 13:07:29 +0000 (15:07 +0200)
lib/RFID/Serial/3M810.pm

index 2c27e4d..9a01e1b 100644 (file)
@@ -67,6 +67,18 @@ sub cmd {
                $r_len = $port->read(3);
        }
 
+       # FIXME sometimes, reader returns left-over junk
+       if ( ! ord(substr($r_len,0,1)) && 0xD0 ) {
+               warn "INVALID reponse ",as_hex($r_len);
+               my $c;
+               while ( $c ne "\xD6" ) {
+                       $c = $port->read(1) || return;
+                       warn "# c ",as_hex($c);
+               }
+               $r_len = $c . $port->read(2);
+               warn "FIXED ",as_hex($r_len);
+       }
+
        wait_device;
 
        my $len = ord( substr($r_len,2,1) );