Class: XBee::RFModule
Overview
This is it, the base class where it all starts. Command mode or API mode, version 1 or version 2, all XBees descend from this class.
Direct Known Subclasses
Constant Summary collapse
- VERSION =
"2.1"
Instance Attribute Summary collapse
-
#api_mode ⇒ Object
Returns the value of attribute api_mode.
-
#command_character ⇒ Object
Returns the value of attribute command_character.
-
#command_mode_timeout ⇒ Object
Returns the value of attribute command_mode_timeout.
-
#firmware_rev ⇒ Object
readonly
Returns the value of attribute firmware_rev.
-
#guard_time ⇒ Object
Returns the value of attribute guard_time.
-
#hardware_rev ⇒ Object
readonly
Returns the value of attribute hardware_rev.
-
#node_discover_timeout ⇒ Object
Returns the value of attribute node_discover_timeout.
-
#node_identifier ⇒ Object
Returns the value of attribute node_identifier.
-
#operation_mode ⇒ Object
Returns the value of attribute operation_mode.
-
#serial_number ⇒ Object
readonly
Returns the value of attribute serial_number.
-
#transmission_mode ⇒ Object
Returns the value of attribute transmission_mode.
-
#xbee_serialport ⇒ Object
Returns the value of attribute xbee_serialport.
-
#xbee_uart_config ⇒ Object
Returns the value of attribute xbee_uart_config.
Instance Method Summary collapse
- #in_command_mode ⇒ Object
-
#initialize(xbee_usbdev_str = "/dev/tty.usbserial-A7004nmf", uart_config = XBeeUARTConfig.new, operation_mode = :AT, transmission_mode = :SYNC) ⇒ RFModule
constructor
This is the way we instantiate XBee modules now, via this factory method.
-
#read_timeout(type = :short) ⇒ Object
XBee response times vary based on both hardware and firmware versions.
- #version ⇒ Object
Methods included from XBee
Constructor Details
#initialize(xbee_usbdev_str = "/dev/tty.usbserial-A7004nmf", uart_config = XBeeUARTConfig.new, operation_mode = :AT, transmission_mode = :SYNC) ⇒ RFModule
This is the way we instantiate XBee modules now, via this factory method. It will ultimately autodetect what flavor of XBee module we’re using and return the most appropriate subclass to control that module.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby_xbee.rb', line 84 def initialize(xbee_usbdev_str = "/dev/tty.usbserial-A7004nmf", uart_config = XBeeUARTConfig.new, operation_mode = :AT, transmission_mode = :SYNC) unless uart_config.kind_of?(XBeeUARTConfig) raise "uart_config must be an instance of XBeeUARTConfig for this to work" end unless operation_mode == :AT || operation_mode == :API raise "XBee operation_mode must be either :AT or :API" end unless transmission_mode == :SYNC || transmission_mode == :ASYNC raise "XBee transmission_mode must be either :SYNC (Synchronous) or :ASYNC (Asynchronous)" end self.xbee_uart_config = uart_config @xbee_serialport = SerialPort.new( xbee_usbdev_str, uart_config.baud, uart_config.data_bits, uart_config.stop_bits, uart_config.parity ) @xbee_serialport.read_timeout = self.read_timeout(:short) @guard_time = GuardTime.new @command_mode_timeout= CommandModeTimeout.new @command_character = CommandCharacter.new @node_discover_timeout = NodeDiscoverTimeout.new @node_identifier = NodeIdentifier.new @operation_mode = operation_mode @api_mode = ApiEnableMode.new @transmission_mode = transmission_mode end |
Instance Attribute Details
#api_mode ⇒ Object
Returns the value of attribute api_mode.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def api_mode @api_mode end |
#command_character ⇒ Object
Returns the value of attribute command_character.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def command_character @command_character end |
#command_mode_timeout ⇒ Object
Returns the value of attribute command_mode_timeout.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def command_mode_timeout @command_mode_timeout end |
#firmware_rev ⇒ Object (readonly)
Returns the value of attribute firmware_rev.
75 76 77 |
# File 'lib/ruby_xbee.rb', line 75 def firmware_rev @firmware_rev end |
#guard_time ⇒ Object
Returns the value of attribute guard_time.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def guard_time @guard_time end |
#hardware_rev ⇒ Object (readonly)
Returns the value of attribute hardware_rev.
75 76 77 |
# File 'lib/ruby_xbee.rb', line 75 def hardware_rev @hardware_rev end |
#node_discover_timeout ⇒ Object
Returns the value of attribute node_discover_timeout.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def node_discover_timeout @node_discover_timeout end |
#node_identifier ⇒ Object
Returns the value of attribute node_identifier.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def node_identifier @node_identifier end |
#operation_mode ⇒ Object
Returns the value of attribute operation_mode.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def operation_mode @operation_mode end |
#serial_number ⇒ Object (readonly)
Returns the value of attribute serial_number.
75 76 77 |
# File 'lib/ruby_xbee.rb', line 75 def serial_number @serial_number end |
#transmission_mode ⇒ Object
Returns the value of attribute transmission_mode.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def transmission_mode @transmission_mode end |
#xbee_serialport ⇒ Object
Returns the value of attribute xbee_serialport.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def xbee_serialport @xbee_serialport end |
#xbee_uart_config ⇒ Object
Returns the value of attribute xbee_uart_config.
74 75 76 |
# File 'lib/ruby_xbee.rb', line 74 def xbee_uart_config @xbee_uart_config end |
Instance Method Details
#in_command_mode ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ruby_xbee.rb', line 107 def in_command_mode sleep self.guard_time.in_seconds @xbee_serialport.write(self.command_character.value * 3) sleep self.guard_time.in_seconds @xbee_serialport.read(3) # actually do some work now ... yield if block_given? # Exit command mode @xbee_serialport.write("ATCN\r") @xbee_serialport.read(3) end |
#read_timeout(type = :short) ⇒ Object
XBee response times vary based on both hardware and firmware versions. These constants may need to be adjusted for your devices, but these will work fine for most cases. The unit of time for a timeout constant is ms
123 124 125 126 127 128 129 130 131 |
# File 'lib/ruby_xbee.rb', line 123 def read_timeout(type = :short) case type when :short 1200 when :long 3000 else 3000 end end |
#version ⇒ Object
77 78 79 |
# File 'lib/ruby_xbee.rb', line 77 def version VERSION end |