Class: Smalrubot::TxRx::Base
- Inherits:
-
Object
- Object
- Smalrubot::TxRx::Base
- Defined in:
- lib/smalrubot/tx_rx/base.rb
Direct Known Subclasses
Constant Summary collapse
- RETURN_CODE =
"\n".ord
Instance Method Summary collapse
- #flush_read ⇒ Object
- #gets(timeout = 0.005) ⇒ Object
- #handshake ⇒ Object
- #read(timeout = 0.005) ⇒ Object
- #write(message) ⇒ Object
Instance Method Details
#flush_read ⇒ Object
37 38 39 |
# File 'lib/smalrubot/tx_rx/base.rb', line 37 def flush_read gets until gets == nil end |
#gets(timeout = 0.005) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/smalrubot/tx_rx/base.rb', line 43 def gets(timeout=0.005) Timeout.timeout(timeout) do s = io.gets Smalrubot.debug_log("gets: %s", s) return s end rescue Exception nil end |
#handshake ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smalrubot/tx_rx/base.rb', line 25 def handshake 5.times do write("!9000000.") line = gets(1) if line && line.match(/ACK:/) flush_read return line.chomp.split(/:/)[1].to_i end end raise BoardNotFound end |
#read(timeout = 0.005) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/smalrubot/tx_rx/base.rb', line 7 def read(timeout = 0.005) line = gets(timeout) if line && line.match(/\A\d+:/) pin, = line.chomp.split(/:/) if pin && return pin, end end end |