Код: Выделить всё
#!/usr/bin/env perl
use Device::SerialPort;
$PortName = '/dev/ttyS0';
$quiet = '';
$PortObj = new Device::SerialPort ($PortName, $quiet)
|| die "Can't open $PortName: $!\n";
# similar
$PortObj->baudrate(9600);
$PortObj->parity("none");
$PortObj->databits(8);
$PortObj->stopbits(1); # POSIX does not support 1.5 stopbits
$PortObj->handshake("xoff");
#$output_string = "CC02300000000000000000000000000000FE00EE";
#$output_string = "0000000000000000000000000000FE00EE";
$count_out = $PortObj->write(0xCC, 0x02, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0xEE);
# warn "write failed\n" unless ($count_out);
# warn "write incomplete\n" if ( $count_out != length($output_string) );
($count_in, $string_in) = $PortObj->read(100);
warn "read unsuccessful\n" unless ($count_in == $InBytes);
print $string_in;