Permalink
Browse files

Add a serial-monitor executable

  • Loading branch information...
1 parent 6686c0f commit 5cd8d89718474625cdfda992a665dc112ae21e20 @railsbob railsbob committed Feb 9, 2012
Showing with 46 additions and 2 deletions.
  1. +26 −0 bin/serial-monitor
  2. +1 −1 em-serialport.gemspec
  3. +1 −1 lib/em-serialport/version.rb
  4. +18 −0 readme.md
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'bundler/setup'
+require 'em-serialport'
+
+EM.run do
+ if ARGV.size < 1
+ STDERR.print "Usage: #{$0} /dev/tty.usbserial-ABCDEFGH\n"
+ exit(1)
+ end
+
+ serial = EventMachine.open_serial(ARGV[0], 9600, 8, 1, SerialPort::NONE)
+ serial.on_data do |data|
+ puts "received: " + data.to_s
+ end
+
+ Thread.new do
+ while TRUE do
+ serial.send_data STDIN.gets.chomp
+ end
+ end
+
+ puts "Serial monitor initialized. Enter data followed by a newline character."
+ puts "Ctrl-C to stop"
+end
View
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.executables = ['serial-monitor']
s.require_paths = ["lib"]
s.add_dependency "eventmachine", "0.12.10"
@@ -1,5 +1,5 @@
module Em
module Serialport
- VERSION = "0.0.1"
+ VERSION = "0.0.2"
end
end
View
@@ -19,3 +19,21 @@ If you are on Mac, you need to set up a virtual USB serial port by installing a
end
end
+## Serial Monitor
+
+The gem comes with a simple command line Serial Monitor. Launch it as:
+
+ bundle exec serial-monitor /dev/tty.usbserial-xxxxxxxx
+
+Here is a working example, tested with an [https://github.com/railsbob/arduino-examples/tree/master/echo_server](arduino echo server). It simply reads and writes data to serial port from command line.
+
+ Serial monitor initialized. Enter data followed by a newline character.
+ Ctrl-C to stop
+ hello
+ received: hello
+ A very long sentence
+ received: A v
+ received: ery long
+ received: sentence
+
+

0 comments on commit 5cd8d89

Please sign in to comment.