5 use Data::Dump qw(dump);
6 use Device::SerialPort qw(:STAT);
8 my $port = Device::SerialPort->new('/dev/ttyUSB0');
11 $port->parity('none');
13 $port->handshake('none');
15 $port->read_char_time(500);
16 $port->read_const_time(1000);
20 foreach my $str ( @_ ) {
21 my $hex = uc unpack( 'H*', $str );
22 $hex =~ s/(..)/$1 /g if length( $str ) > 2;
26 return join(' | ', @out);
31 $bytes .= pack('C', hex('0x' . $_)) foreach split(/\s+/,join(' ',@_));
36 my ($hex,$expect,$desc) = @_;
37 my $bytes = hex2bytes( $hex );
39 warn ">> ",as_hex( $bytes );
40 $port->write( $bytes );
42 my $data = $port->read(1);
43 warn "<< len: ",ord($data);
44 $data .= $port->read(ord($data) - 1);
45 warn "<< ",as_hex($data);
46 warn "?? $expect\n" if $expect;
50 #v '07 02 00 00 00 04 C4', "hardware version";
52 #v '07 0A 00 00 00 04 44', 'software version';
54 v '07 00 01 00 06 0E EA', 'temperatures';