new returns object only on succeful init
[Biblio-RFID.git] / lib / RFID / Biblio.pm
index b3723fe..f8c7b35 100644 (file)
@@ -11,7 +11,7 @@ use Data::Dump qw(dump);
 
 =head1 NAME
 
-RFID::Biblio - support serial RFID devices
+RFID::Biblio - easy to use API for writing RFID enabled appliaction
 
 =cut
 
@@ -27,17 +27,21 @@ which is sutable for direct mapping to REST JSONP service.
 
 Perhaps a little code snippet.
 
-    use RFID::Biblio;
+       use RFID::Biblio;
 
-    my $rfid = RFID::Biblio->new(
+       my $rfid = RFID::Biblio->new(
                device => '/dev/ttyUSB0', # with fallback to RFID_DEVICE
        );
+
+       # invetory tags in reader range and read data from them
        my $visible = $rfid->scan;
 
-=head1 SUBROUTINES/METHODS
+=head1 METHODS
 
 =head2 new
 
+Open serial port (if needed) and init reader
+
 =cut
 
 sub new {
@@ -47,9 +51,7 @@ sub new {
 
        $self->port;
 
-       $self->init;
-
-       return $self;
+       $self->init && return $self;
 }
 
 =head2 port
@@ -64,9 +66,14 @@ sub port {
        return $self->{port} if defined $self->{port};
 
        my $settings = $self->serial_settings;
-       $settings->{device} ||= $ENV{RFID_DEVICE};
+       my $device   = $settings->{device} ||= $ENV{RFID_DEVICE};
        warn "# settings ",dump $settings;
 
+       if ( ! $device ) {
+               warn "# no device, serial port not opened\n";
+               return;
+       }
+
        $self->{port} = Device::SerialPort->new( $settings->{device} )
        || die "can't open serial port: $!\n";
 
@@ -105,7 +112,7 @@ sub scan {
 }
 
 
-=head1 MANDATORY IMPLEMENTATIONS
+=head1 READER IMPLEMENTATION
 
 Each reader must implement following hooks as sub-classes.
 
@@ -119,15 +126,30 @@ Each reader must implement following hooks as sub-classes.
 
 =head2 read_blocks
 
-  my $hash = $self->read_blocks $tag;
+  my $hash = $self->read_blocks( $tag );
 
-All blocks are under key which is tag UID
+All blocks are under key which is tag UID with array of blocks returned from reader
 
-  $hash = { 'E000000123456789' => [ undef, 'block1', 'block2', ... ] };
+  $hash = { 'E000000123456789' => [ 'blk1', 'blk2', ... ] };
 
 L<RFID::Biblio::3M810> sends tag UID with data payload, so we might expect
 to receive response from other tags from protocol specification, 
 
+=head2 write_blocks
+
+  $self->write_blocks( $tag => $bytes );
+
+  $self->write_blocks( $tag => [ 'blk1', 'blk2', ... ] );
+
+=head2 read_afi
+
+  my $afi = $self->read_afi( $tag );
+
+=head2 write_afi
+
+  $self->write_afi( $tag => $afi );
+
+
 
 =head1 EXPORT
 
@@ -177,6 +199,22 @@ sub as_hex {
 sub hex_tag { uc(unpack('H16', shift)) }
 
 
+=head1 SUPPORTED READERS
+
+Support for different RFID readers is implemented in subclasses:
+
+=head2 3M 810
+
+L<RFID::Biblio::3M810>
+
+=head2 CPR-M02
+
+L<RFID::Biblio::CPRM02>
+
+=head2 librfid
+
+L<RFID::Biblio::librfid>
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>