Module: XBee

Defined in:
lib/ruxbee/config.rb,
lib/ruxbee/rfmodule.rb,
lib/ruxbee/xbee_api.rb,
lib/ruxbee/xbee_cmd.rb,
lib/ruxbee/at_commands.rb,
lib/ruxbee/frame/frame.rb,
lib/ruxbee/frame/at_command.rb,
lib/ruxbee/frame/base_frame.rb,
lib/ruxbee/frame/modem_status.rb,
lib/ruxbee/frame/receive_packet.rb,
lib/ruxbee/frame/received_frame.rb,
lib/ruxbee/frame/transmit_status.rb,
lib/ruxbee/frame/transmit_request.rb,
lib/ruxbee/frame/receive_packet_16.rb,
lib/ruxbee/frame/at_command_response.rb,
lib/ruxbee/frame/explicit_rx_indicator.rb,
lib/ruxbee/frame/remote_command_request.rb,
lib/ruxbee/frame/remote_command_response.rb,
lib/ruxbee/frame/explicit_addressing_command.rb,
lib/ruxbee/frame/io_data_sample_rx_indicator.rb

Defined Under Namespace

Modules: ATCommands, Config, Frame Classes: BaseAPIModeInterface, BaseCommandModeInterface, RFModule, Series1APIModeInterface, Series2APIModeInterface, XBeeV1CommandModeInterface, XBeeV2CommandModeInterface

Class Method Summary collapse

Class Method Details

.new(dev_str, baud, mode, operation_mode = :API) ⇒ Object

creates a new instance on Command or API mode mode is a Symbol, either :API_S1, :API_S2 or :CMD



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruxbee.rb', line 11

def XBee.new(dev_str, baud, mode, operation_mode = :API)
  # check for valid mode descriptor
  unless mode.is_a? Symbol and (mode == :API_S1 or mode == :API_S2 or mode == :CMD)
    raise "Not a valid mode, choose :API_S1, :API_S2 or :CMD"
  end

  unless operation_mode.is_a? Symbol and (operation_mode == :API or operation_mode == :AT)
    raise "Not a valid operation_mode, choose :API or :AT"
  end
  
  # defaults to: data_bits = 8, parity = 0, stop_bits = 1
  uart_conf = XBee::Config::XBeeUARTConfig.new(baud)

  case mode
  when :API_S1
    XBee::Series1APIModeInterface.new(dev_str, uart_conf, operation_mode)
  when :API_S2
    XBee::Series2APIModeInterface.new(dev_str, uart_conf, operation_mode)
    # Series2APIModeInterface.new(dev_str, uart_conf, operation_mode, transmission_mode = :SYNC)
  when :CMD
    XBee::BaseCommandModeInterface.new(dev_str, uart_conf.baud, uart_conf.data_bits, uart_conf.stop_bits, uart_conf.parity)
  else
    raise "Unknown Exception, no mode was found"
  end
end