Let Ruby read the serial port

Hello everyone,

I would like to read a serial port. I’m going to connect want to connect
my Arduino Uno microcontroller board to the computer via USB. It acts as
a virtual serial port automatically. I can already read with the Arduino
IDE’ s serialterminal.

Processing can also read a serialport from a Arduino.

But now I would like to let Ruby read the virtual serialport and save
the data in a variable. And then do a lots of stuff with it.

Is there a special library or gem for this? I already installed libusb
for ruby.

Greetings,

Superpelican

Superpelican X. wrote in post #993185:

Is there a special library or gem for this?

Which platform are you running under?

The ruby-serialport gem worked fine for me (under Linux) when I last
tried it, although that was several years ago.

On Sat, Apr 16, 2011 at 4:14 PM, Brian C. [email protected]
wrote:

Superpelican X. wrote in post #993185:

Is there a special library or gem for this?

Which platform are you running under?

The ruby-serialport gem worked fine for me (under Linux) when I last
tried it, although that was several years ago.

Make sure you have the baud and port number correct.
It’s an often overlooked part of connecting to serial.
https://github.com/tenderlove/ruby-serialport
This might help also.
It also supports windows as well as linux (and theoretically mac)

Andrew McElroy

For windows environement,i use IronRub. Here is an absract:

require “mscorlib”
require “System.Windows.Forms”

def portConfigure(portName,bauds,bits,stop,parity)
@components = System::ComponentModel::Container.new()
@serialPort1 = System::IO::Ports::SerialPort.new(@components)
portName ||= “COM3”
bauds ||= “9600”
bits ||= “8”
stopBits ||= “1”
parity ||= “none”
#puts “Configure…”
@serialPort1.DtrEnable = true
@serialPort1.RtsEnable = true
@serialPort1.PortName = portName
@serialPort1.StopBits = stopBits.to_i
@serialPort1.BaudRate = bauds.to_i
@serialPort1.DataBits = bits.to_i
@serialPort1.Open()
@serialPort1.DataReceived do |sender, e|
buff = @serialPort1.ReadExisting()
scanner(buff)
end
end
def writeString(str)
buf = System::Text::Encoding.GetEncoding(“ASCII”).GetBytes(str)
size = buf.Length
@serialPort1.Write(buf, 0, size)
end

Almost a year ago I used http://rubygems.org/gems/serialport
successfully on
my Mac to talk to USB and Bluetooth Arduinos.

On Sat, Apr 16, 2011 at 7:58 AM, Superpelican X.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs