Created
June 20, 2013 11:17
-
-
Save nishantmodak/5821947 to your computer and use it in GitHub Desktop.
Serial Port Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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