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(' ',@_));
38 for my $i ( 0 .. length($data) - 2 ) {
40 $crc = ( $crc << 1 ) ^ 25;
45 my $byte = ord(substr($data,$i,1));
47 # warn "## ", as_hex(chr($byte)), " crc = ", $crc, " ", as_hex(chr($crc));
49 if ( chr($crc) ne substr($data,-1,1) ) {
50 warn "CRC error for ",as_hex($data), " calulated ", as_hex(chr($crc));
56 my $bytes = hex2bytes( $hex );
59 warn ">> ",as_hex( $bytes );
61 $port->write( $bytes );
63 my $data = $port->read(1);
64 warn "<< len: ",ord($data);
66 goto retry if ord($data) == 0;
68 $data .= $port->read(ord($data) - 1);
70 warn "<< ",as_hex($data);
74 v '07 02 00 00 00 04 C4', "hardware version";
76 v '07 0A 00 00 00 04 44', 'software version';
78 v '07 00 01 00 06 0E EA', 'temperatures';