--- 3m-810.pl 2008/10/03 12:31:58 18 +++ 3m-810.pl 2008/10/03 15:38:08 19 @@ -6,9 +6,17 @@ use Data::Dump qw/dump/; use Carp qw/confess/; +use Getopt::Long; my $debug = 0; +my $device = "/dev/ttyUSB0"; +my $baudrate = "19200"; +my $databits = "8"; +my $parity = "none"; +my $stopbits = "1"; +my $handshake = "none"; + my $response = { 'd500090400110a0500027250' => 'version?', 'd60007fe00000500c97b' => 'no tag in range', @@ -21,13 +29,23 @@ 'd60017fe00000502e00401003123aa26e00401003123aa283124' => 'tag #1 + tag red-stripe', }; +GetOptions( + 'd|debug+' => \$debug, + 'device=s' => \$device, + 'baudrate=i' => \$baudrate, + 'databits=i' => \$databits, + 'parity=s' => \$parity, + 'stopbits=i' => \$stopbits, + 'handshake=s' => \$handshake, +) or die $!; + =head1 NAME 3m-810 - support for 3M 810 RFID reader =head1 SYNOPSIS -3m-810.pl [DEVICE [BAUD [DATA [PARITY [STOP [FLOW]]]]]] +3m-810.pl --device /dev/ttyUSB0 =head1 DESCRIPTION @@ -52,16 +70,8 @@ =cut -# your serial port. -my ($device,$baudrate,$databits,$parity,$stopbits,$handshake)=@ARGV; -$device ||= "/dev/ttyUSB0"; -$baudrate ||= "19200"; -$databits ||= "8"; -$parity ||= "none"; -$stopbits ||= "1"; -$handshake ||= "none"; - -my $port=new Device::SerialPort($device) || die "new($device): $!\n"; +my $port=new Device::SerialPort($device) || die "can't open serial port $device: $!\n"; +warn "using $device $handshake $baudrate $databits $parity $stopbits" if $debug; $handshake=$port->handshake($handshake); $baudrate=$port->baudrate($baudrate); $databits=$port->databits($databits); @@ -108,8 +118,8 @@ warn "## tags ",as_hex($tags), " [$tl] = ",dump( $tags ) if $debug; print "seen $nr tags: ", join(',', @tags ) , "\n"; - # XXX read first tag - read_tag( @tags ); + # read data from tag + read_tag( $_ ) foreach @tags; } ) } @@ -158,6 +168,8 @@ } +exit; + for ( 1 .. 3 ) { # ++-->type 00-0a @@ -188,7 +200,7 @@ { my $str=shift; my $count = $port->write($str); - print "#> ", as_hex( $str ), "\t[$count]" if $debug; + print "#> ", as_hex( $str ), "\t[$count]\n" if $debug; } sub as_hex { @@ -239,6 +251,9 @@ our $dispatch; sub dispatch { my ( $pattern, $coderef ) = @_; + + $dispatch->{ $pattern } = $coderef; + my $patt = substr( str2bytes($pattern), 3 ); # just payload my $l = length($patt); my $p = substr( $assert->{payload}, 0, $l );