Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rubyserial

> 编程语言
Open source

FFI Ruby library for RS-232 serial port communication

156 stars0 likes1 views
WebsiteGitHub

About

FFI Ruby library for RS-232 serial port communication

rubyserial

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 https://github.com/ffi/ffi.

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.

Installation

$ gem install rubyserial

Usage

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

Methods

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.

RubySerial::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

bash
brew install socat

Installing socat on Linux

bash
sudo apt-get install socat

Test on Windows

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

https://github.com/hybridgroup/rubyserial/raw/appveyor_deps/setup_com0com_W7_x64_signed.exe

License

Apache 2.0. See LICENSE for more details.

Issues· 12 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyrubyserial-portsserialport

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言