test serial output
This commit is contained in:
35
test-serial.rb
Normal file
35
test-serial.rb
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
require "rubygems"
|
||||||
|
require "bundler/setup"
|
||||||
|
require "active_record"
|
||||||
|
require "serialport"
|
||||||
|
require "state_pattern"
|
||||||
|
|
||||||
|
|
||||||
|
project_root = File.dirname(File.absolute_path(__FILE__))
|
||||||
|
Dir.glob(project_root + "/app/models/*.rb").each{|f| require f}
|
||||||
|
Dir.glob(project_root + "/app/helpers/*.rb").each{|f| require f}
|
||||||
|
|
||||||
|
connection_details = YAML::load(File.open('config/database.yml'))
|
||||||
|
ActiveRecord::Base.establish_connection(connection_details)
|
||||||
|
|
||||||
|
|
||||||
|
if __FILE__ == $0
|
||||||
|
|
||||||
|
#params for serial port
|
||||||
|
port_str = "/dev/ttyUSB1" #may be different for you
|
||||||
|
baud_rate = 9600
|
||||||
|
data_bits = 7
|
||||||
|
stop_bits = 1
|
||||||
|
parity = SerialPort::EVEN
|
||||||
|
|
||||||
|
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
|
||||||
|
|
||||||
|
#just read forever
|
||||||
|
while true do
|
||||||
|
printf("%c", sp.getc)
|
||||||
|
end
|
||||||
|
|
||||||
|
sp.close #see note 1
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user