7 our @EXPORT = qw( hex2bytes as_hex hex_tag );
9 use Device::SerialPort qw(:STAT);
10 use Data::Dump qw(dump);
14 RFID::Serial - 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::Serial->new(
33 device => '/dev/ttyUSB0', # with fallback to RFID_DEVICE
36 =head1 SUBROUTINES/METHODS
56 my $serial_obj = $self->port;
63 return $self->{port} if defined $self->{port};
65 my $settings = $self->serial_settings;
66 $settings->{device} ||= $ENV{RFID_DEVICE};
67 warn "# settings ",dump $settings;
69 $self->{port} = Device::SerialPort->new( $settings->{device} )
70 || die "can't open serial port: $!\n";
72 $self->{port}->$_( $settings->{$_} )
73 foreach ( qw/handshake baudrate databits parity stopbits/ );
77 =head1 MANDATORY IMPLEMENTATIONS
79 Each reader must implement following hooks as sub-classes.
87 my @tags = $self->invetory;
91 my $hash = $self->read_blocks $tag;
93 All blocks are under key which is tag UID
95 $hash = { 'E000000123456789' => [ undef, 'block1', 'block2', ... ] };
97 L<RFID::Serial::3M810> sends tag UID with data payload, so we might expect
98 to receive response from other tags from protocol specification,
103 Formatting functions are exported
107 my $bytes = hex2bytes($hex);
112 my $str = shift || die "no str?";
115 $b =~ s/(..)/\\x$1/g;
119 warn "## str2bytes( $str ) => $b => ",as_hex($bytes) if $debug;
125 print as_hex( $bytes );
131 foreach my $str ( @_ ) {
132 my $hex = uc unpack( 'H*', $str );
133 $hex =~ s/(..)/$1 /g if length( $str ) > 2;
137 return join(' | ', @out);
142 print hex_tag $8bytes;
146 sub hex_tag { uc(unpack('H16', shift)) }
151 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
155 Please report any bugs or feature requests to C<bug-rfid-serial at rt.cpan.org>, or through
156 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RFID-Serial>. I will be notified, and then you'll
157 automatically be notified of progress on your bug as I make changes.
164 You can find documentation for this module with the perldoc command.
169 You can also look for information at:
173 =item * RT: CPAN's request tracker
175 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RFID-Serial>
177 =item * AnnoCPAN: Annotated CPAN documentation
179 L<http://annocpan.org/dist/RFID-Serial>
183 L<http://cpanratings.perl.org/d/RFID-Serial>
187 L<http://search.cpan.org/dist/RFID-Serial/>
192 =head1 ACKNOWLEDGEMENTS
195 =head1 LICENSE AND COPYRIGHT
197 Copyright 2010 Dobrica Pavlinusic.
199 This program is free software; you can redistribute it and/or modify
200 it under the terms of the GNU General Public License as published by
201 the Free Software Foundation; version 2 dated June, 1991 or at your option
204 This program is distributed in the hope that it will be useful,
205 but WITHOUT ANY WARRANTY; without even the implied warranty of
206 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
207 GNU General Public License for more details.
209 A copy of the GNU General Public License is available in the source tree;
210 if not, write to the Free Software Foundation, Inc.,
211 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
216 1; # End of RFID::Serial