写入Perl中的串口

Str*_*dle 1 linux perl serial-port expect

我需要与Perl脚本中的串口通信.我需要发送字符并读取输入并搜索字符串.

实现这一目标的最简单方法是什么?通过使用"expect"或在Perl中打开/ dev/ttys0设备?还是其他一些方法?

我更喜欢使用perl,但我不知道它是否简单并且具有预期的功能.

ask*_*pen 5

my $port = new Device::SerialPort("/dev/ttyS0"); 
$port->user_msg(ON); 
$port->baudrate(9600); 
$port->parity("none"); 
$port->databits(8); 
$port->stopbits(1); 
$port->handshake("xoff"); 
$port->write_settings;

$port->lookclear; 
$port->write("some command to com-port");

my $answer = $port->lookfor;
# or my $answer=$port->read(255);
Run Code Online (Sandbox Code Playgroud)