ADBlock is blocking some content on the site

ADBlock errore

Need assistance with serial port communications in Ruby

StackOverflow https://stackoverflow.com/questions/167858


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?

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"
    return when serial.read == "DONE"


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

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

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

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


Just because searching for ruby-serialport will lead you sometimes here:

toholio's github repo no longer seems to be active (as of 09/2010). The published gem comes from


While the serial standard has not changed, the way Ruby Gems interact with Ruby C extensions changed enough over the years so that the RubyForge serial port extension would not play well. There have been some patches over the years on RubyForge to fix that, but it hasn't been pretty. The great news is that Github has allowed an incredible acceleration in the activity to clean up the Ruby serial port extension. At least three different people are cross-branching their serial port code on Github. You can search on Github, but I believe that Toholio has the latest code, which recodes and repackages the Ruby serial port as a Ruby Gem. (Yea!)


It works great for me on Linux, solving the earlier conflict with the latest Ruby Gems release. On Windows, I'm still having a problem getting it working. Compiling Ruby extensions on Windows is never very easy, but that is a whole 'nuther can of worms. I'm just happy that people are working on the Ruby serial port support again. I've asked Toholio to generate a Windows binary gem, which would solve everyone's problems, and he says it's on his list to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow