Class: Artoo::Adaptors::Roomba
- Defined in:
- lib/artoo/adaptors/roomba.rb
Overview
Connect to a Roomba
Instance Attribute Summary collapse
-
#sp ⇒ Object
readonly
Returns the value of attribute sp.
Attributes inherited from Adaptor
Instance Method Summary collapse
-
#connect ⇒ Boolean
Creates serial or tcp connection.
-
#disconnect ⇒ Boolean
Closes connection to device.
-
#finalize ⇒ Boolean
Closes connection if already connected.
-
#send_bytes(bytes) ⇒ Object
Send bytes to device.
Methods inherited from Adaptor
#connect_to, #connect_to_serial, #connect_to_tcp, #connect_to_udp, #connected?, #initialize, #reconnect
Constructor Details
This class inherits a constructor from Artoo::Adaptors::Adaptor
Instance Attribute Details
#sp ⇒ Object (readonly)
Returns the value of attribute sp.
9 10 11 |
# File 'lib/artoo/adaptors/roomba.rb', line 9 def sp @sp end |
Instance Method Details
#connect ⇒ Boolean
Creates serial or tcp connection
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/artoo/adaptors/roomba.rb', line 21 def connect if port.is_serial? @sp = connect_to_serial @sp.dtr = 0 @sp.rts = 0 else @sp = connect_to_tcp end super end |
#disconnect ⇒ Boolean
Closes connection to device
44 45 46 47 |
# File 'lib/artoo/adaptors/roomba.rb', line 44 def disconnect @sp.close super end |
#finalize ⇒ Boolean
Closes connection if already connected
13 14 15 16 17 |
# File 'lib/artoo/adaptors/roomba.rb', line 13 def finalize if connected? @sp.close end end |
#send_bytes(bytes) ⇒ Object
Send bytes to device
33 34 35 36 37 38 39 40 |
# File 'lib/artoo/adaptors/roomba.rb', line 33 def send_bytes(bytes) bytes = [bytes] unless bytes.respond_to?(:map) bytes.map!(&:chr) Logger.debug "sending: #{bytes.inspect}" res = [] bytes.each{|b| res << @sp.write(b) } Logger.debug "returned: #{res.inspect}" end |