Skip to content
This repository

A simple serial port library for Ruby

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

== RB232

A simple serial port library for Ruby.

Licensed under the MIT license (See COPYING file for details)

Author: James Smith ( /




This library is a simple serial port library for Ruby.

You may ask, why not just use ruby-serialport? Mainly because the GPL license
it is under is too restrictive for my purposes. This code is under the MIT
license, so you can do anything you like with it.


1) Enable gems from gemcutter, if you haven't already done so:
    > sudo gem install gemcutter
    > sudo gem tumble

2) Install gem
    > sudo gem install rb232


Currently you can read from a serial port, but not write back. The code is only 
tested on Linux and Snow Leopard - other unixes *may* work, but Windows is right
 out for now. Watch this space for further developments!


The following code will read a 10-character string from the specified port,
using the default port settings (9600/8/n/1/no flow control)

      @port ='/dev/ttyUSB0')
      message = @port.read_string(10)

You can provide alternative settings when you create a new port:'/dev/ttyS0', :baud_rate => 19200, 
                                    :data_bits => 7, 
                                    :parity => true, 
                                    :stop_bits => 2,
                                    :hardware_flow_control => true)

Note that OSX doesn't currently have hardware flow control support.

See or RB232::Port
documentation for more details.

If you are using a simple text protocol over RS232, you can use the
RB232::TextProtocol class to help you out. It automatically monitors the port
and splits messages up by detecting separator characters. See for an example of
how to use this class.
Something went wrong with that request. Please try again.