fix bytes array passwd to write_blocks
[Biblio-RFID.git] / lib / RFID / Biblio / 3M810.pm
index f5e38d6..1b37a46 100644 (file)
@@ -1,5 +1,26 @@
 package RFID::Biblio::3M810;
 
+=head1 NAME
+
+RFID::Biblio::3M810 - support for 3M 810 RFID reader
+
+=head1 DESCRIPTION
+
+This module implement serial protocol (over USB/serial adapter) with 3M 810 RFID
+reader, often used in library applications.
+
+This is most complete implementation which supports full API defined
+in L<RFID::Biblio>. This include scanning for all tags in reader
+range, reading and writing of data, and AFI security manipulation.
+
+This implementation is developed using Portmon on Windows to capture serial traffic
+L<http://technet.microsoft.com/en-us/sysinternals/bb896644.aspx>
+
+Checksum for this reader is developed using help from C<selwyn>
+L<http://stackoverflow.com/questions/149617/how-could-i-guess-a-checksum-algorithm>
+
+=cut
+
 use warnings;
 use strict;
 
@@ -25,11 +46,18 @@ sub init {
        my $self = shift;
        $port = $self->port;
 
+       # disable timeouts
+       $port->read_char_time(0);
+       $port->read_const_time(0);
+
        # drain on startup
        my ( $count, $str ) = $port->read(3);
        my $data = $port->read( ord(substr($str,2,1)) );
        warn "drain ",as_hex( $str, $data ),"\n";
 
+       $port->read_char_time(100);      # 0.1 s char timeout
+       $port->read_const_time(500); # 0.5 s read timeout
+
        setup();
 
 }
@@ -206,7 +234,9 @@ sub read_blocks {
 sub write_blocks {
        my $tag = shift;
        $tag = shift if ref $tag;
-       my $data = join('', @_);
+
+       my $data = shift;
+       $data = join('', @$data) if ref $data eq 'ARRAY';
 
        warn "## write_blocks ",dump($tag,$data);
 
@@ -274,12 +304,9 @@ sub write_afi {
                my $data = shift;
 
                if ( my $rest = _matched $data => '09 00' ) {
-
-                       my $tag = substr($rest,0,8);
-                          $afi = substr($rest,8,1);
-
+                       my $tag_back = hex_tag substr($rest,0,8);
+                       die "write_afi got $tag_back expected $tag" if $tag_back ne $tag;
                        warn "# SECURITY ", hex_tag($tag), " AFI: ", as_hex($afi);
-
                } elsif ( $rest = _matched $data => '0A 06' ) {
                        warn "ERROR writing AFI to $tag ", as_hex($data);
                        undef $afi;