在Perl下,在Linux上打开Serial :: Device作为文件会重置我的Arduino,但我不希望它被重置。可以通过脉冲DTR复位Arduino,因此默认情况下打开串行设备必须是脉冲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);
方法打开设备即可完成,但我无法使用该方法,因为我无法检查串行缓冲区中是否有数据等待。在我的程序中,测试数据等待是一项艰难的要求。
答案 0 :(得分:2)
您需要更改端口的termios设置中的HUPCL位。这将持续到其他东西改变它(我已经看到相同发行版的不同版本默认不同)
参见man termios和man stty
以下shell命令可能工作 - 未经测试:
stty -F /dev/ttyUSB1 -hupcl