2013年1月14日 星期一

[Perl] How to communicate serial port by using perl program


[Perl] How to communicate serial port by using perl program



#!/usr/bin/perl



use Device::SerialPort;



my $port = Device::SerialPort->new("/dev/ttyUSB0");

$port->databits(8);

$port->baudrate(115200);

$port->parity("none");

$port->stopbits(1);

$port->read_char_time(0);

$port->read_const_time(20);





$port->lookclear;

$port->write("cli ? \r");



sleep(2);

while (1) {

    my ($rb, $byte) = $port->read(1);

    if ($rb > 0) {

        print $byte;

    } else {

        last;

    }

}



Reference :



Related Posts:

0 意見:

張貼留言