在 Ruby 中需要串行端口通信方面的帮助 [英] Need assistance with serial port communications in Ruby

查看:25
本文介绍了在 Ruby 中需要串行端口通信方面的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过 Ruby 中的串行端口进行一些通信.根据我的研究,用于串行通信的现代库似乎并不多,我能找到的最新材料是 2006 年的.有什么我不知道的宝石吗?

I need to do some communications over a serial port in Ruby. From my research, it appears that there aren't many modern libraries for serial communications and the newest material I can find is from 2006. Are there any gems that I'm not aware of?

我最终需要与连接到 USB 的串行设备保持通信(我可以确定端口没问题),以便像这样(有点 Ruby 式的伪代码)来回通信.

I ultimately need to maintain communications with a serial device attached to USB (I can figure out the port no problem) for back and forth communications like so (somewhat Ruby-esque pseudo code).

def serial_write_read
  if serial.read == "READY"
    serial.write "1"
    until serial.read == "OK"
      serial.write "5"
    end
    return when serial.read == "DONE"
  end
end

推荐答案

串口规格永远不会变,我不会担心库的年代.

The serial port specification has not changed in forever, I wouldn't worry about how old the libraries are.

我假设你看到了 这个 2006 年关于 ruby​​ 和串行端口的文章

I'm assuming you saw this article from 2006 about ruby and serial ports

这里有人得到了那里提到的 Ruby-SerialPort 库今年可以在 Mac 上工作.

Here's someone who got the Ruby-SerialPort library mentioned there to work on macs this year.

还有这篇旧帖 来自 ruby​​ talk,关于与 Win32 串行 API 的接口.

There's also this old post from ruby talk, about interfacing to the Win32 Serial API.

这篇关于在 Ruby 中需要串行端口通信方面的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆