Awesome Open Source
Awesome Open Source


RubySerial is a simple Ruby gem for reading from and writing to serial ports.

Unlike other Ruby serial port implementations, it supports all of the most popular Ruby implementations (MRI, JRuby, & Rubinius) on the most popular operating systems (OSX, Linux, & Windows). And it does not require any native compilation thanks to using RubyFFI

The interface to RubySerial should be (mostly) compatible with other Ruby serialport gems, so you should be able to drop in the new gem, change the require and use it as a replacement. If not, please let us know so we can address any issues.

Build Status Build status Test Coverage


$ gem install rubyserial


require 'rubyserial'
serialport = '/dev/ttyACM0' # Defaults to 9600 baud, 8 data bits, and no parity
serialport = '/dev/ttyACM0', 57600
serialport = '/dev/ttyACM0', 19200, 8, :even


write(data : String) -> Int

Returns the number of bytes written. Emits a RubySerial::Error on error.

read(length : Int) -> String

Returns a string up to length long. It is not guaranteed to return the entire length specified, and will return an empty string if no data is available. Emits a RubySerial::Error on error.

getbyte -> Fixnum or nil

Returns an 8 bit byte or nil if no data is available. Emits a RubySerial::Error on error.


A wrapper error type that returns the underlying system error code and inherits from IOError.

Running the tests

The test suite is written using rspec, just use the rspec command.

Test dependencies

To run the tests on OS X and Linux, you must also have the socat utility program installed.

Installing socat on OS X

brew install socat

Installing socat on Linux

sudo apt-get install socat

Test on Windows

To run the tests on Windows requires com0com which can be downloaded from here:


Apache 2.0. See LICENSE for more details.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
ruby (12,917
serialport (27
serial-ports (20