use new svg template
[Biblio-RFID.git] / scripts / program.pl
index 122a81a..7dbfc7f 100755 (executable)
@@ -6,29 +6,30 @@ use strict;
 use Data::Dump qw(dump);
 use Getopt::Long;
 use lib 'lib';
-use RFID::Biblio::Readers;
-use RFID::Biblio::RFID501;
+use Biblio::RFID::Reader;
+use Biblio::RFID::RFID501;
 
 my $reader;
 my $afi;
+my $debug = 0;
 
 GetOptions(
        'reader=s', => \$reader,
        'afi=i',    => \$afi,
+       'debug+',   => \$debug,
 ) || die $!;
 
 my ( $sid, $content ) =  @ARGV;
 die "usage: $0 [--reader regex_filter] [--afi 214] E0_RFID_SID [barcode]\n" unless $sid && ( $content | $afi );
 
-my @rfid = RFID::Biblio::Readers->available( $reader );
+my $rfid = Biblio::RFID::Reader->new( $reader );
+$Biblio::RFID::debug = $debug;
 
-foreach my $rfid ( @rfid ) {
-       my $visible = $rfid->scan;
-       foreach my $tag ( keys %$visible ) {
-               next unless $tag eq $sid;
-               warn "PROGRAM $tag with $content\n";
-               $rfid->write_blocks( $tag => RFID::Biblio::RFID501->from_hash({ content => $content }) );
-               $rfid->write_afi(    $tag => chr($afi) ) if $afi;
-       }
+foreach my $tag ( $rfid->tags ) {
+       warn "visible $tag\n";
+       next unless $tag eq $sid;
+       warn "PROGRAM $tag with $content\n";
+       $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash({ content => $content }) );
+       $rfid->write_afi(    $tag => chr($afi) ) if $afi;
 }