class Smalrubot::TxRx::Base
Constants
- RETURN_CODE
Public Instance Methods
flush_read()
click to toggle source
# File lib/smalrubot/tx_rx/base.rb, line 37 def flush_read gets until gets == nil end
gets(timeout=0.005)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/smalrubot/tx_rx/base.rb, line 7 def read(timeout = 0.005) line = gets(timeout) if line && line.match(/\A\d+:/) pin, message = line.chomp.split(/:/) if pin && message return pin, message end end end
write(message)
click to toggle source
# File lib/smalrubot/tx_rx/base.rb, line 17 def write(message) n = io.write(message) Smalrubot.debug_log('write: %s(A:%d, E:%d)', message, n, message.length) if n != message.length raise "FATAL: n(#{n}) != message.length(#{message.length})" end end