Skip to content

Instantly share code, notes, and snippets.

@nishantmodak
Created June 20, 2013 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishantmodak/5821947 to your computer and use it in GitHub Desktop.
Save nishantmodak/5821947 to your computer and use it in GitHub Desktop.
Serial Port Ruby
require "serialport"
#params for serial port
port_str = "/dev/ttyUSB0" #may be different for you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
#just read forever
while true do
while (i = sp.gets.chomp) do # see note 2
puts i
#puts i.class #String
end
end
sp.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment