7 our @EXPORT = qw( hex2bytes as_hex hex_tag );
9 use Device::SerialPort qw(:STAT);
10 use Data::Dump qw(dump);
14 RFID::Biblio - support serial RFID devices
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
35 my $visible = $rfid->scan;
37 =head1 SUBROUTINES/METHODS
57 my $serial_obj = $self->port;
64 return $self->{port} if defined $self->{port};
66 my $settings = $self->serial_settings;
67 my $device = $settings->{device} ||= $ENV{RFID_DEVICE};
68 warn "# settings ",dump $settings;
71 warn "# no device, serial port not opened\n";
75 $self->{port} = Device::SerialPort->new( $settings->{device} )
76 || die "can't open serial port: $!\n";
78 $self->{port}->$_( $settings->{$_} )
79 foreach ( qw/handshake baudrate databits parity stopbits/ );
85 my $visible = $rfid->scan;
87 Returns hash with keys which match tag UID and values with blocks
94 warn "# scan tags in reader range\n";
95 my @tags = $self->inventory;
98 # FIXME this is naive implementation which just discards other tags
99 foreach my $tag ( @tags ) {
100 my $blocks = $self->read_blocks( $tag );
102 warn "ERROR: can't read tag $tag\n";
103 delete $visible->{$tag};
105 $visible->{$tag} = $blocks->{$tag};
113 =head1 MANDATORY IMPLEMENTATIONS
115 Each reader must implement following hooks as sub-classes.
123 my @tags = $self->invetory;
127 my $hash = $self->read_blocks( $tag );
129 All blocks are under key which is tag UID with array of blocks returned from reader
131 $hash = { 'E000000123456789' => [ 'blk1', 'blk2', ... ] };
133 L<RFID::Biblio::3M810> sends tag UID with data payload, so we might expect
134 to receive response from other tags from protocol specification,
138 $self->write_blocks( $tag => $bytes );
140 $self->write_blocks( $tag => [ 'blk1', 'blk2', ... ] );
144 my $afi = $self->read_afi( $tag );
148 $self->write_afi( $tag => $afi );
154 Formatting functions are exported
158 my $bytes = hex2bytes($hex);
163 my $str = shift || die "no str?";
166 $b =~ s/(..)/\\x$1/g;
170 warn "## str2bytes( $str ) => $b => ",as_hex($bytes) if $debug;
176 print as_hex( $bytes );
182 foreach my $str ( @_ ) {
183 my $hex = uc unpack( 'H*', $str );
184 $hex =~ s/(..)/$1 /g if length( $str ) > 2;
188 return join(' | ', @out);
193 print hex_tag $8bytes;
197 sub hex_tag { uc(unpack('H16', shift)) }
202 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
206 Please report any bugs or feature requests to C<bug-rfid-serial at rt.cpan.org>, or through
207 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RFID-Biblio>. I will be notified, and then you'll
208 automatically be notified of progress on your bug as I make changes.
215 You can find documentation for this module with the perldoc command.
220 You can also look for information at:
224 =item * RT: CPAN's request tracker
226 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RFID-Biblio>
228 =item * AnnoCPAN: Annotated CPAN documentation
230 L<http://annocpan.org/dist/RFID-Biblio>
234 L<http://cpanratings.perl.org/d/RFID-Biblio>
238 L<http://search.cpan.org/dist/RFID-Biblio/>
243 =head1 ACKNOWLEDGEMENTS
246 =head1 LICENSE AND COPYRIGHT
248 Copyright 2010 Dobrica Pavlinusic.
250 This program is free software; you can redistribute it and/or modify
251 it under the terms of the GNU General Public License as published by
252 the Free Software Foundation; version 2 dated June, 1991 or at your option
255 This program is distributed in the hope that it will be useful,
256 but WITHOUT ANY WARRANTY; without even the implied warranty of
257 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
258 GNU General Public License for more details.
260 A copy of the GNU General Public License is available in the source tree;
261 if not, write to the Free Software Foundation, Inc.,
262 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
267 1; # End of RFID::Biblio