first chat with boiler
[vrDialog] / dialog.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6 use Device::SerialPort qw(:STAT);
7
8 my $port = Device::SerialPort->new('/dev/ttyUSB0');
9 $port->baudrate(9600);
10 $port->databits(8);
11 $port->parity('none');
12 $port->stopbits(1);
13 $port->handshake('none');
14
15 # disable timeouts
16 $port->read_char_time(500);
17 $port->read_const_time(1000);
18
19 sub v {
20         my ($hex,$desc) = @_;
21         my $bytes;
22         $bytes .= pack('C', hex('0x' . $_)) foreach split(/\s+/,$hex);
23         warn "# $desc\n";
24         warn ">> $hex ",dump( $bytes );
25         $port->write( $bytes );
26
27         my $len = $port->read(1);
28         warn "<< len: ",ord($len);
29         my $data = $port->read(ord($len) - 1);
30         warn "<< ",dump($data);
31
32 }
33
34 v '07 02 00 00 00 04 C4', "hardware version";
35