class Beaglebone::UARTDevice
Object Oriented UART
Implementation. This treats the UART
device as an object.
Public Class Methods
Initialize a UART
device. Returns a UARTDevice
object
@param uart should be a symbol representing the UART
device @param speed should be an integer thats a valid speed. @see SPEEDS
@example
uart1 = UARTDevice.new(:UART1, 9600)
# File lib/beaglebone/uart.rb, line 530 def initialize(uart, speed=9600) @uart = uart UART::setup(@uart, speed) end
Public Instance Methods
Disable a UART
device.
@note device trees cannot be unloaded at this time without kernel panic.
# File lib/beaglebone/uart.rb, line 688 def disable UART::disable(@uart) end
Read a character from a UART
device and pass it to the specified block
@example
uart1.each_char { |x| puts "read: #{x}" }
# File lib/beaglebone/uart.rb, line 607 def each_char(&block) UART::each_char(@uart, &block) end
Read characters from a UART
device and pass them to the specified block
@param chars should be the number of chars to read
@example
uart1.each_chars(2) { |x| puts "read: #{x}" }
# File lib/beaglebone/uart.rb, line 617 def each_chars(chars, &block) UART::each_chars(@uart, chars, &block) end
Read lines from a UART
device and pass them to the specified block
@example
uart1.each_line { |x| puts "read: #{x}" }
# File lib/beaglebone/uart.rb, line 625 def each_line(&block) UART::each_line(@uart, &block) end
Convenience method for run_on_each_chars
with chars set to 1 @see run_on_each_chars
# File lib/beaglebone/uart.rb, line 676 def run_on_each_char(callback, repeats=nil) UART::run_on_each_char(callback, @uart, repeats) end
Runs a callback after receiving data from a UART
device This creates a new thread that runs in the background
@param callback A method to call when the data is received. This method should take 3 arguments, the UART
, the line read, and the counter @param chars should be the number of chars to read @param repeats is optional and specifies the number of times the callback will be run
@example
callback = lambda { |uart, data, count| puts "[#{uart}:#{count}] #{data} "} uart1.run_on_each_chars(callback, 2)
# File lib/beaglebone/uart.rb, line 658 def run_on_each_chars(callback, chars=1, repeats=nil) UART::run_on_each_chars(callback, @uart, chars, repeats) end
Runs a callback after receiving a line of data from a UART
device This creates a new thread that runs in the background
@param callback A method to call when the data is received. This method should take 3 arguments, the UART
, the line read, and the counter @param repeats is optional and specifies the number of times the callback will be run
@example
callback = lambda { |uart, line, count| puts "[#{uart}:#{count}] #{line} "} uart1.run_on_each_line(callback)
# File lib/beaglebone/uart.rb, line 638 def run_on_each_line(callback, repeats=nil) UART::run_on_each_line(callback, @uart, repeats) end
Convenience method for run_on_each_chars
with chars and repeats set to 1 @see run_on_each_chars
# File lib/beaglebone/uart.rb, line 664 def run_once_on_each_char(callback) UART::run_once_on_each_char(callback, @uart) end
Convenience method for run_on_each_chars
with chars and repeats set to 1 @see run_on_each_chars
# File lib/beaglebone/uart.rb, line 670 def run_once_on_each_chars(callback, chars=1) UART::run_once_on_each_chars(callback, @uart, chars) end
Convenience method for run_on_each_line
with repeats set to 1 @see run_on_each_line
# File lib/beaglebone/uart.rb, line 644 def run_once_on_each_line(callback) UART::run_once_on_each_line(callback, @uart) end
Set the speed of the UART
@param speed should be an integer thats a valid speed. @see SPEEDS
@example
uart1.set_speed(9600)
# File lib/beaglebone/uart.rb, line 541 def set_speed(speed) UART::set_speed(@uart, speed) end
Stops any threads waiting for data on the specified UART
# File lib/beaglebone/uart.rb, line 681 def stop_read_wait UART::stop_read_wait(@uart) end
Write data to a UART
device
@param data the data to write
@return Integer the number of bytes written
@example
uart1.write("1234") => 4
# File lib/beaglebone/uart.rb, line 553 def write(data) UART::write(@uart, data) end