1 package RFID::Serial::3M810;
3 use base 'RFID::Serial';
7 device => "/dev/ttyUSB0",
16 my ( $hex, $description, $coderef ) = @_;
17 my $bytes = hex2bytes($hex);
18 if ( substr($bytes,0,1) ne "\xD5" ) {
19 my $len = pack( 'c', length( $bytes ) + 3 );
20 $bytes = $len . $bytes;
21 my $checksum = checksum($bytes);
22 $bytes = "\xD6\x00" . $bytes . $checksum;
25 warn ">> ", as_hex( $bytes ), "\t\t[$description]\n";
26 $port->write( $bytes );
28 my $r_len = $port->read(3);
31 warn "# wait for response length 5ms\n";
32 $r_len = $port->read(3);
35 my $data_len = ord(substr($r_len,2,1)) - 1;
36 my $data = $port->read( $data_len );
37 warn "<< ", as_hex( $r_len . $data ),"\n";
39 $coderef->( $data ) if $coderef;
44 my ( $got, $expected ) = @_;
45 die "got ", as_hex($got), " expected ", as_hex($expected)
46 unless substr($expected,0,length($got)) eq $got;
52 cmd( 'D5 00 05 04 00 11' => 'hw version' . sub {
54 assert $data => '04 00 01';
55 my $hw_ver = join('.', unpack('CCCC', substr($data,3)));
56 print "hardware version $hw_ver\n";
60 '13 04 01 00 02 00 03 00 04 00', 'FIXME: stats?', sub { assert(shift,
61 '13 00 02 01 01 03 02 02 03 00'