Class: Bitlash
- Inherits:
-
Object
show all
- Defined in:
- lib/rubitlash.rb
Overview
Constant Summary
collapse
- PROMPT =
">\s"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(port_addr, baud = 57600, verbose = false, name = "Bitflash##{(rand*1000).to_i}") ⇒ Bitlash
Returns a new instance of Bitlash.
27
28
29
30
31
|
# File 'lib/rubitlash.rb', line 27
def initialize(port_addr, baud=57600, verbose=false, name="Bitflash##{(rand*1000).to_i}")
@port_addr, @baud, @name = port_addr, baud, name
self.verbose = verbose
self.open
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
63
64
65
66
|
# File 'lib/rubitlash.rb', line 63
def method_missing(m, *args)
cmd = args.size > 0 ? "print #{m.to_s}(#{args * ','})" : "print #{m.to_s}"
self.talk(cmd)
end
|
Instance Attribute Details
#baud ⇒ Object
Returns the value of attribute baud.
26
27
28
|
# File 'lib/rubitlash.rb', line 26
def baud
@baud
end
|
#port ⇒ Object
Returns the value of attribute port.
26
27
28
|
# File 'lib/rubitlash.rb', line 26
def port
@port
end
|
#port_addr ⇒ Object
Returns the value of attribute port_addr.
25
26
27
|
# File 'lib/rubitlash.rb', line 25
def port_addr
@port_addr
end
|
Instance Method Details
#[](var) ⇒ Object
51
52
53
|
# File 'lib/rubitlash.rb', line 51
def [](var)
self.talk "print #{var.to_s}"
end
|
#[]=(var, value) ⇒ Object
55
56
57
|
# File 'lib/rubitlash.rb', line 55
def []=(var,value)
self.talk "#{var.to_s}=#{value.to_i}"
end
|
#close ⇒ Object
38
|
# File 'lib/rubitlash.rb', line 38
def close; @port.close; end
|
#macro(name, cmd) ⇒ Object
59
60
61
|
# File 'lib/rubitlash.rb', line 59
def macro(name,cmd)
self.talk "#{name}:=\"#{cmd}\""
end
|
#open ⇒ Object
33
34
35
36
|
# File 'lib/rubitlash.rb', line 33
def open
@port = SerialPort.new(@port_addr, 57600, 8, 1, SerialPort::NONE)
@port.expect(/>\s/)
end
|
#talk(string) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/rubitlash.rb', line 44
def talk(string)
@port.puts string
reply = @port.expect(/#{PROMPT}/)[0]
reply =~ /(.*)\n\r(.*)\n\r/
return $2
end
|
#verbose ⇒ Object
40
|
# File 'lib/rubitlash.rb', line 40
def verbose; $expect_verbose; end
|
#verbose=(bool) ⇒ Object
42
|
# File 'lib/rubitlash.rb', line 42
def verbose=(bool); $expect_verbose=bool; end
|