--- cpr-m02.pl 2010/07/09 23:10:05 82 +++ cpr-m02.pl 2010/07/12 10:59:59 83 @@ -287,22 +287,37 @@ } sub cpr { - my $hex = shift; + my ( $hex, $description ) = shift; my $bytes = str2bytes($hex); my $len = pack( 'c', length( $bytes ) + 3 ); my $send = $len . $bytes; my $checksum = cpr_m02_checksum($send); $send .= $checksum; - warn ">> ", as_hex( $send ); - writechunk( $send ); - my $r_len = read_bytes( 1, 'response length' ); + warn ">> ", as_hex( $send ), "[$description]\n"; + $port->write( $send ); + my $r_len = $port->read(1); + warn "<< response len: ", as_hex($r_len), "\n"; $r_len = ord($r_len) - 1; - my $data = read_bytes( $r_len, 'data' ); + my $data = $port->read( $r_len ); warn "<< ", as_hex( $data ); + + warn "## ",dump( $port->read(1) ); } -cpr( '00 52 00' ); +#cpr( 'FF 52 00', 'detect boud rate' ); + +#cpr( '00 65', 'software version' ); + +cpr( 'FF 65', 'get ? info' ); + +cpr( 'FF 69 00', 'get reader info' ); + +cpr( 'FF B0 01 00', '?' ); + +cpr( 'FF 69', '?' ); + +#cpr( '', '?' ); exit; # initial hand-shake with device @@ -654,6 +669,7 @@ my ( $c, $b ) = $port->read(1); die "no bytes on port: $!" unless defined $b; warn "## got $c bytes: ", as_hex($b), "\n"; + last if $c == 0; $data .= $b; } $desc ||= '?';