Win32::串行二进制通信

发布于 2024-11-25 08:14:24 字数 663 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与酒说心事 2024-12-02 08:14:24

感谢您的回复,但事实证明库中有一个输入函数,使用它和 1 秒的睡眠我能够使我的模块工作。

# 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
    sleep(1);
    my  $recievedData = $class->{"serialPort"}->input;

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.

# 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
    sleep(1);
    my  $recievedData = $class->{"serialPort"}->input;
无边思念无边月 2024-12-02 08:14:24

我记得,在 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文