在Ruby中的串行端口通信方面需要帮助 [英] Need assistance with serial port communications in 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年)红宝石和串行端口
I'm assuming you saw this article from 2006 about ruby and serial ports
这是有人得到了 Ruby-SerialPort
Here's someone who got the Ruby-SerialPort library mentioned there to work on macs this year.
还有这是来自ruby的老帖子,内容涉及与Win32串行API的接口。
There's also this old post from ruby talk, about interfacing to the Win32 Serial API.
这篇关于在Ruby中的串行端口通信方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!