7 our @EXPORT = qw( hex2bytes as_hex hex_tag );
9 use Device::SerialPort qw(:STAT);
10 use Data::Dump qw(dump);
14 RFID::Biblio - easy to use API for writing RFID enabled appliaction
18 our $VERSION = '0.01';
25 This module tries to support USB serial RFID readers wsing simple API
26 which is sutable for direct mapping to REST JSONP service.
28 Perhaps a little code snippet.
32 my $rfid = RFID::Biblio->new(
33 device => '/dev/ttyUSB0', # with fallback to RFID_DEVICE
36 # invetory tags in reader range and read data from them
37 my $visible = $rfid->scan;
43 Open serial port (if needed) and init reader
61 my $serial_obj = $self->port;
68 return $self->{port} if defined $self->{port};
70 my $settings = $self->serial_settings;
71 my $device = $settings->{device} ||= $ENV{RFID_DEVICE};
72 warn "# settings ",dump $settings;
75 warn "# no device, serial port not opened\n";
79 $self->{port} = Device::SerialPort->new( $settings->{device} )
80 || die "can't open serial port: $!\n";
82 $self->{port}->$_( $settings->{$_} )
83 foreach ( qw/handshake baudrate databits parity stopbits/ );
89 my $visible = $rfid->scan;
91 Returns hash with keys which match tag UID and values with blocks
98 warn "# scan tags in reader range\n";
99 my @tags = $self->inventory;
102 # FIXME this is naive implementation which just discards other tags
103 foreach my $tag ( @tags ) {
104 my $blocks = $self->read_blocks( $tag );
106 warn "ERROR: can't read tag $tag\n";
107 delete $visible->{$tag};
109 $visible->{$tag} = $blocks->{$tag};
117 =head1 READER IMPLEMENTATION
119 Each reader must implement following hooks as sub-classes.
127 my @tags = $self->invetory;
131 my $hash = $self->read_blocks( $tag );
133 All blocks are under key which is tag UID with array of blocks returned from reader
135 $hash = { 'E000000123456789' => [ 'blk1', 'blk2', ... ] };
137 L<RFID::Biblio::3M810> sends tag UID with data payload, so we might expect
138 to receive response from other tags from protocol specification,
142 $self->write_blocks( $tag => $bytes );
144 $self->write_blocks( $tag => [ 'blk1', 'blk2', ... ] );
148 my $afi = $self->read_afi( $tag );
152 $self->write_afi( $tag => $afi );
158 Formatting functions are exported
162 my $bytes = hex2bytes($hex);
167 my $str = shift || die "no str?";
170 $b =~ s/(..)/\\x$1/g;
174 warn "## str2bytes( $str ) => $b => ",as_hex($bytes) if $debug;
180 print as_hex( $bytes );
186 foreach my $str ( @_ ) {
187 my $hex = uc unpack( 'H*', $str );
188 $hex =~ s/(..)/$1 /g if length( $str ) > 2;
192 return join(' | ', @out);
197 print hex_tag $8bytes;
201 sub hex_tag { uc(unpack('H16', shift)) }
204 =head1 SUPPORTED READERS
206 Support for different RFID readers is implemented in subclasses:
210 L<RFID::Biblio::3M810>
214 L<RFID::Biblio::CPRM02>
218 L<RFID::Biblio::librfid>
222 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
226 Please report any bugs or feature requests to C<bug-rfid-serial at rt.cpan.org>, or through
227 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RFID-Biblio>. I will be notified, and then you'll
228 automatically be notified of progress on your bug as I make changes.
235 You can find documentation for this module with the perldoc command.
240 You can also look for information at:
244 =item * RT: CPAN's request tracker
246 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RFID-Biblio>
248 =item * AnnoCPAN: Annotated CPAN documentation
250 L<http://annocpan.org/dist/RFID-Biblio>
254 L<http://cpanratings.perl.org/d/RFID-Biblio>
258 L<http://search.cpan.org/dist/RFID-Biblio/>
263 =head1 ACKNOWLEDGEMENTS
266 =head1 LICENSE AND COPYRIGHT
268 Copyright 2010 Dobrica Pavlinusic.
270 This program is free software; you can redistribute it and/or modify
271 it under the terms of the GNU General Public License as published by
272 the Free Software Foundation; version 2 dated June, 1991 or at your option
275 This program is distributed in the hope that it will be useful,
276 but WITHOUT ANY WARRANTY; without even the implied warranty of
277 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
278 GNU General Public License for more details.
280 A copy of the GNU General Public License is available in the source tree;
281 if not, write to the Free Software Foundation, Inc.,
282 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
287 1; # End of RFID::Biblio