2

在 Perl 下,在 Linux 上打开 Serial::Device 作为文件会重置我的 Arduino,但我不希望它被重置。Arduino可以通过脉冲DTR复位,因此打开串口设备必须默认脉冲DTR。

我的问题是:如何防止我的 Arduino 被重置(DTR 被脉冲)?

这个最小的代码重置了我的 Arduino:

use Device::SerialPort;
use Symbol qw( gensym );
my $handle = gensym();
my $PortName = '/dev/ttyUSB1';
my $PortObj = tie( *$handle , "Device::SerialPort" , $PortName ) or die "Cannot open serial port: $!\n";
# At this point the Arduino is being reset.

我知道这只是通过使用PortObj = new Device::SerialPort ($PortName, $quiet, $lockfile);方法打开设备来完成,但我不能使用该方法,因为我无法检查串行缓冲区中是否有数据等待。在我的程序中,测试数据等待是一项硬性要求。

4

1 回答 1

2

您需要更改端口的 termios 设置中的 HUPCL 位。这将一直持续到其他东西改变它(我已经看到同一个发行版的不同版本默认它不同)

参见 man termios 和 man stty

以下 shell 命令可能有效 - 未经测试:

stty -F /dev/ttyUSB1 -hupcl
于 2012-04-28T15:56:32.857 回答