Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tweak examples. Make sure debug messages are filtered out.

  • Loading branch information...
commit 9526d4dc19d1c8565d4a7917035232013574c22e 1 parent a1d12a9
@vickash vickash authored
View
15 examples/ethernet.rb
@@ -0,0 +1,15 @@
+#
+# This example shows how to use an Arduino with an Ethernet shield and the du_ethernet.ino sketch loaded.
+# Replace the IP address in this example with the IP you used when uploading the sketch.
+# The Ethernet shield uses up pin 13, so you'll need an LED on pin 5 to make sure it's working.
+#
+require File.expand_path('../../lib/dino', __FILE__)
+
+connection = Dino::TxRx::TCP.new("192.168.0.77")
+board = Dino::Board.new(connection)
+led = Dino::Components::Led.new(pin: 5, board: board)
+
+[:on, :off].cycle do |switch|
+ led.send(switch)
+ sleep 0.5
+end
View
24 examples/ser2net.rb
@@ -1,29 +1,31 @@
#
-# Example showing how to access an Arduino over a ser2net connection.
-# Running ser2net on the machine with the Arduino will serve up the serial interface over the network interface.
-# You can then communicate with that Arduino over your local network or the Internet.
-# Note that we're using ser2net in raw mode so we can connect to it from Ruby with Dino::TxRx::TCP.
+# This example shows how to use an Arduino on a remote machine via ser2net.
+# Running ser2net serves up the serial connection over the network interface,
+# so you can communicate with the Arduino over your local network or the Internet.
#
# Example ser2net command for an Arduino UNO on Mac:
-# ser2net -u -C "9000:raw:0:/dev/cu.usbmodem621:115200"
+# ser2net -u -C "3466:raw:0:/dev/cu.usbmodem621:115200"
+#
+# Note that we're using ser2net in raw TCP mode and not telnet mode which is more common.
#
-# Replace 9000 with the port number you want to use and /dev/cu.usbmodem621 with your Arduino device.
+# Replace /dev/cu.usbmodem621 with your Arduino device.
# Arduino UNOs are usually /dev/ACM0 under Linux.
#
-# ser2net is preinstalled on many Linuxes. Install ser2net on Mac with:
+# ser2net is preinstalled on many Linuxes. Install ser2net at the Mac Terminal with:
# brew install ser2net
#
-# http://sourceforge.net/projects/ser2net/ for more info on configuring ser2net.
+# http://sourceforge.net/projects/ser2net/ for more info on installing and configuring ser2net.
#
require File.expand_path('../../lib/dino', __FILE__)
-# The host and port for the telnet connection must be passed in as arguments.
-connection = Dino::TxRx::TCP.new("localhost", 9000)
+# The remote ser2net host is the first argument for a new TxRx::TCP.
+# The second argument, port number, is optional. 3466 is default. This must match the port ser2net uses on the remote machine.
+connection = Dino::TxRx::TCP.new("127.0.0.1", 3466)
board = Dino::Board.new(connection)
led = Dino::Components::Led.new(pin: 13, board: board)
[:on, :off].cycle do |switch|
led.send(switch)
sleep 0.5
-end
+end
View
6 lib/dino/tx_rx/base.rb
@@ -10,7 +10,7 @@ def read
@thread ||= Thread.new do
loop do
line = gets
- if line
+ if line.match /\A\d+:/
pin, message = line.chop.split(/:/)
pin && message && changed && notify_observers(pin, message)
end
@@ -38,10 +38,10 @@ def handshake
begin
write("!9000000.")
Timeout::timeout(0.1) do
- line = gets.to_s.chop
+ line = gets.to_s
if line.match /ACK/
flush_read
- return line.split(/:/)[1].to_i
+ return line.chop.split(/:/)[1].to_i
end
end
rescue
View
2  spec/lib/board_spec.rb
@@ -84,6 +84,7 @@ def io_mock(methods = {})
it 'should set the mode for the given pin to "in" and add a digital listener' do
subject
subject.should_receive(:write).with("0012001")
+ subject.should_receive(:write).with("0112000")
subject.should_receive(:write).with("0512000")
subject.add_digital_hardware(mock1 = mock(:part1, pin: 12, pullup: nil))
end
@@ -108,6 +109,7 @@ def io_mock(methods = {})
it 'should set the mode for the given pin to "in" and add an analog listener' do
subject
subject.should_receive(:write).with("0012001")
+ subject.should_receive(:write).with("0112000")
subject.should_receive(:write).with("0612000")
subject.add_analog_hardware(mock1 = mock(:part1, pin: 12, pullup: nil))
end
View
4 spec/lib/tx_rx/usb_serial_spec.rb
@@ -71,9 +71,9 @@ module Dino
IO.should_receive(:select).and_return(true)
Thread.should_receive(:new).and_yield
subject.should_receive(:loop).and_yield
- mock_serial.should_receive(:gets).and_return("foo:bar\n")
+ mock_serial.should_receive(:gets).and_return("02:00\n")
subject.should_receive(:changed).and_return(true)
- subject.should_receive(:notify_observers).with('foo','bar')
+ subject.should_receive(:notify_observers).with('02','00')
subject.read
end
Please sign in to comment.
Something went wrong with that request. Please try again.