implement RFID::Serial->scan and test it
[Biblio-RFID.git] / lib / RFID / Serial.pm
index d23642c..e9435f6 100644 (file)
@@ -32,6 +32,7 @@ Perhaps a little code snippet.
     my $rfid = RFID::Serial->new(
                device => '/dev/ttyUSB0', # with fallback to RFID_DEVICE
        );
+       my $visible = $rfid->scan;
 
 =head1 SUBROUTINES/METHODS
 
@@ -74,6 +75,28 @@ sub port {
 
 }
 
+=head2 scan
+
+  my $visible = $rfid->scan;
+
+Returns hash with keys which match tag UID and values with blocks
+
+=cut
+
+sub scan {
+       my $self = shift;
+
+       warn "# scan tags in reader range\n";
+       my @tags = $self->inventory;
+
+       my $visible;
+       # FIXME this is naive implementation which just discards other tags
+       $visible->{$_} = $self->read_blocks( $_ )->{$_} foreach @tags;
+
+       return $visible;
+}
+
+
 =head1 MANDATORY IMPLEMENTATIONS
 
 Each reader must implement following hooks as sub-classes.