Win32::串行二进制通信
我正在尝试使用 Win32::Serial 端口(perl 模块)与嵌入式系统上的 UART 进行通信。它在发送数据方面似乎工作正常,但由于某种原因它无法接收数据。我希望除了 read() 之外还有另一个函数可以显示读取的数据吗?
# Write Serial Data to Port in Little Endian Form
foreach my $intermValue (@writeData) {
my $msb = int($intermValue/256);
my $lsb = ($intermValue - $msb*256);
# Writing LSB first and MSB after (Little Endian Form)
print "Writing: LSB: ".$lsb." MSB: ".$msb."\n";
$class->{"serialPort"}->transmit_char($lsb);
$class->{"serialPort"}->transmit_char($msb);
}
# Read Data From Serial Port
my ($countIn, $recievedData) = $class->{"serialPort"}->read($expectedBytes);
谢谢
I am trying to communicate with a UART on a embedded system using the Win32::Serial port (perl module). It seems to work fine in terms of sending the data, but for what ever reason it is unable to receive the data. I hoping is there another function besides read() that will be show the read data?
# Write Serial Data to Port in Little Endian Form
foreach my $intermValue (@writeData) {
my $msb = int($intermValue/256);
my $lsb = ($intermValue - $msb*256);
# Writing LSB first and MSB after (Little Endian Form)
print "Writing: LSB: ".$lsb." MSB: ".$msb."\n";
$class->{"serialPort"}->transmit_char($lsb);
$class->{"serialPort"}->transmit_char($msb);
}
# Read Data From Serial Port
my ($countIn, $recievedData) = $class->{"serialPort"}->read($expectedBytes);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您的回复,但事实证明库中有一个输入函数,使用它和 1 秒的睡眠我能够使我的模块工作。
Thanks for your reply, but it turns out there is a input function in the library, using that and a 1 second sleep I was able to make my module work.
我记得,在 Win32 ActivePerl 上,您可以在文件名中指定端口,如下所示:
open(my $fh, '+>COM1') or die "COM1: $!";
binmode($fh);
我已经成功地使用了这个,但我从未成功地使用过 Win32:Serial!也许有帮助?
As I recall, on Win32 ActivePerl you can specify ports in the filename like this:
open(my $fh, '+>COM1') or die "COM1: $!";
binmode($fh);
I've successfully used this, but I never successfully used Win32:Serial! Maybe it helps?