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 );
40 warn ">> ",as_hex( $bytes );
41 $port->write( $bytes );
43 my $data = $port->read(1);
44 warn "<< len: ",ord($data);
46 goto retry if ord($data) == 0;
48 $data .= $port->read(ord($data) - 1);
49 warn "<< ",as_hex($data);
50 warn "?? $expect\n" if $expect;
54 v '07 02 00 00 00 04 C4', "hardware version";
56 v '07 0A 00 00 00 04 44', 'software version';
58 v '07 00 01 00 06 0E EA', 'temperatures';