Class: XBee::BaseAPIModeInterface

Inherits:
RFModule
  • Object
show all
Defined in:
lib/apimode/xbee_api.rb

Constant Summary collapse

VERSION =

Version of this class

"1.1.0"

Instance Attribute Summary

Attributes inherited from RFModule

#command_character, #command_mode_timeout, #firmware_rev, #guard_time, #hardware_rev, #node_discover_timeout, #node_identifier, #operation_mode, #serial_number, #transmission_mode, #xbee_serialport, #xbee_uart_config

Instance Method Summary collapse

Methods inherited from RFModule

#in_command_mode, #read_timeout

Methods included from XBee

#getresults, new

Constructor Details

#initialize(xbee_usbdev_str, uart_config = XBeeUARTConfig.new, operation_mode = :AT, transmission_mode = :SYNC) ⇒ BaseAPIModeInterface

Returns a new instance of BaseAPIModeInterface.



10
11
12
13
14
15
16
# File 'lib/apimode/xbee_api.rb', line 10

def initialize(xbee_usbdev_str, uart_config = XBeeUARTConfig.new, operation_mode = :AT, transmission_mode = :SYNC)
  super(xbee_usbdev_str, uart_config, operation_mode, transmission_mode)
  @frame_id = 1
  if self.operation_mode == :AT
    start_apimode_communication
  end
end

Instance Method Details

#association_indicationObject

Association Indication. Read information regarding last node join request:

  • 0x00 - Successful completion - Coordinator started or Router/End Device found and joined with a parent.

  • 0x21 - Scan found no PANs

  • 0x22 - Scan found no valid PANs based on current SC and ID settings

  • 0x23 - Valid Coordinator or Routers found, but they are not allowing joining (NJ expired) 0x27 - Node Joining attempt failed

  • 0x2A - Coordinator Start attempt failed‘

  • 0xFF - Scanning for a Parent



125
126
127
128
# File 'lib/apimode/xbee_api.rb', line 125

def association_indication
  @association_indication ||= get_param("AI","n")
  if @association_indication == nil then @association_indication = 0 end
end

#baudObject

retrieves the baud rate of the device. Generally, this will be the same as the rate you’re currently using to talk to the device unless you’ve changed the device’s baud rate and are still in the AT command mode and/or have not exited command mode explicitly for the new baud rate to take effect.



326
327
328
329
330
# File 'lib/apimode/xbee_api.rb', line 326

def baud
  @xbee_serialport.write("ATBD\r")
  baudcode = getresponse
  @baudcodes.index( baudcode.to_i )
end

#baud!(baud_rate) ⇒ Object

sets the given baud rate into the XBee device. The baud change will not take effect until the AT command mode times out or the exit command mode command is given. acceptable baud rates are: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200



336
337
338
339
# File 'lib/apimode/xbee_api.rb', line 336

def baud!( baud_rate )
  @xbee_serialport.write("ATBD#{@baudcodes[baud_rate]}\r")
  getresponse if self.transmission_mode == :SYNC
end

#channelObject

returns the channel number of the XBee device. this value, along with the PAN ID, and MY address determines the addressability of the device and what it can listen to



242
243
244
245
246
247
248
249
250
251
252
# File 'lib/apimode/xbee_api.rb', line 242

def channel
  # channel often takes more than 1000ms to return data
  tmp = @xbee_serialport.read_timeout
  @xbee_serialport.read_timeout = read_timeout(:long)
  @xbee_serialport.write("ATCH\r")
  if self.tranmission_mode == :SYNC
    response = getresponse
    @xbee_serialport.read_timeout = tmp
    response.strip.chomp
  end
end

#channel!(new_channel) ⇒ Object

sets the channel number of the device. The valid channel numbers are those of the 802.15.4 standard.



256
257
258
259
260
261
262
263
264
265
266
# File 'lib/apimode/xbee_api.rb', line 256

def channel!(new_channel)
  # channel takes more than 1000ms to return data
  tmp = @xbee_serialport.read_timeout
  @xbee_serialport.read_timeout = read_timeout(:long)
  @xbee_serialport.write("ATCH#{new_channel}\r")
  if self.transmission_mode == :SYNC
    response = getresponse
    @xbee_serialport.read_timeout = tmp
    response.strip.chomp
  end
end

#destination_highObject

Returns the high portion of the XBee device’s current destination address



209
210
211
# File 'lib/apimode/xbee_api.rb', line 209

def destination_high
  @destination_high ||= get_param("DH")
end

#destination_high!(high_addr) ⇒ Object

Sets the high portion of the XBee device’s current destination address Parameter range: 0 - 0xFFFFFFFF



216
217
218
219
# File 'lib/apimode/xbee_api.rb', line 216

def destination_high!(high_addr)
  self.xbee_serialport.write("ATDH#{high_addr}\r")
  getresponse if self.transmission_mode == :SYNC
end

#destination_lowObject

Returns the low portion of the XBee device’s current destination address



195
196
197
# File 'lib/apimode/xbee_api.rb', line 195

def destination_low
  @destination_low ||= get_param("DL")
end

#destination_low!(low_addr) ⇒ Object

Sets the low portion of the XBee device’s destination address Parameter range: 0 - 0xFFFFFFFF



202
203
204
205
# File 'lib/apimode/xbee_api.rb', line 202

def destination_low!(low_addr)
  @xbee_serialport.write("ATDL#{low_addr}\r")
  getresponse if self.transmission_mode == :SYNC
end

#dio(port) ⇒ Object

reads an i/o port configuration on the XBee for analog to digital or digital input or output (GPIO) this method returns an I/O type symbol of:

:Disabled :ADC :DI :DO_Low :DO_High :Associated_Indicator :RTS :CTS :RS485_Low :RS485_High

Not all DIO ports are capable of every configuration listed above. This method will properly translate the XBee’s response value to the symbol above when the same value has different meanings from port to port.

The port parameter may be any symbol :D0 through :D8 representing the 8 I/O ports on an XBee



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/apimode/xbee_api.rb', line 391

def dio( port )
  at = "AT#{port.to_s}\r"
  @xbee_serialport.write( at )
  if self.transmission_mode == :SYNC
    response = getresponse.to_i

    if response == 1  # the value of 1 is overloaded based on port number
      case port
      when :D5
        return :Associated_Indicator
      when :D6
        return :RTS
      when :D7
        return :CTS
      end
    else
      @iotypes.index(response)
    end
  end
end

#dio!(port, iotype) ⇒ Object

configures an i/o port on the XBee for analog to digital or digital input or output (GPIO)

port parameter valid values are the symbols :D0 through :D8

iotype parameter valid values are symbols: :Disabled :ADC :DI :DO_Low :DO_High :Associated_Indicator :RTS :CTS :RS485_Low :RS485_High

note: not all iotypes are compatible with every port type, see the XBee manual for exceptions and semantics

note: it is critical you have upgraded firmware in your XBee or DIO ports 0-4 cannot be read (ie: ATD0 will return ERROR - this is an XBee firmware bug that’s fixed in revs later than 1083)

note: tested with rev 10CD, fails with rev 1083



435
436
437
438
439
# File 'lib/apimode/xbee_api.rb', line 435

def dio!( port, iotype )
  at = "AT#{port.to_s}#{@iotypes[iotype]}\r"
  @xbee_serialport.write( at )
  getresponse if self.transmission_mode == :SYNC
end

#dio_change_detectObject

reads the bitfield values for change detect monitoring. returns a bitmask indicating which DIO lines, 0-7 are enabled or disabled for change detect monitoring



444
445
446
447
# File 'lib/apimode/xbee_api.rb', line 444

def dio_change_detect
  @xbee_serialport.write("ATIC\r")
  getresponse if self.transmission_mode == :SYNC
end

#dio_change_detect!(hexbitmap) ⇒ Object

sets the bitfield values for change detect monitoring. The hexbitmap parameter is a bitmap which enables or disables the change detect monitoring for any of the DIO ports 0-7



452
453
454
455
# File 'lib/apimode/xbee_api.rb', line 452

def dio_change_detect!( hexbitmap )
  @xbee_serialport.write("ATIC#{hexbitmask}\r")
  getresponse if self.transmission_mode == :SYNC
end

#exit_command_modeObject

exits the AT command mode - all changed parameters will take effect such as baud rate changes after the exit is complete. exit_command_mode does not permanently save the parameter changes when it exits AT command mode. In order to permanently change parameters, use the save! method



574
575
576
# File 'lib/apimode/xbee_api.rb', line 574

def exit_command_mode
  @xbee_serialport.write("ATCN\r")
end

#fw_revObject

Retrieve XBee firmware version



132
133
134
# File 'lib/apimode/xbee_api.rb', line 132

def fw_rev
  @fw_rev ||= get_param("VR","n")
end

#get_param(at_param_name, at_param_unpack_string = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/apimode/xbee_api.rb', line 35

def get_param(at_param_name, at_param_unpack_string = nil)
  frame_id = self.next_frame_id
  at_command_frame = XBee::Frame::ATCommand.new(at_param_name,frame_id,nil,at_param_unpack_string)
  puts "Sending ... [#{at_command_frame._dump.unpack("C*").join(", ")}]"
  self.xbee_serialport.write(at_command_frame._dump)
  if self.transmission_mode == :SYNC
    r = XBee::Frame.new(self.xbee_serialport)
    if r.kind_of?(XBee::Frame::ATCommandResponse) && r.status == :OK && r.frame_id == frame_id
      if block_given?
        yield r
      else
        #### DEBUG ####
        if $DEBUG then
          print "At parameter unpack string to be used: #{at_param_unpack_string} | "
          puts "Debug Return value for value: #{r.retrieved_value.unpack(at_param_unpack_string)}"
        end
        #### DEBUG ####
        at_param_unpack_string.nil? ? r.retrieved_value : r.retrieved_value.unpack(at_param_unpack_string).first
      end
    else
      raise "Response did not indicate successful retrieval of that parameter: #{r.inspect}"
    end
  end
end

#get_remote_param(at_param_name, remote_address = 0x000000000000ffff, remote_network_address = 0xfffe, at_param_unpack_string = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/apimode/xbee_api.rb', line 79

def get_remote_param(at_param_name, remote_address = 0x000000000000ffff, remote_network_address = 0xfffe, at_param_unpack_string = nil)
  frame_id = self.next_frame_id
  at_command_frame = XBee::Frame::RemoteCommandRequest.new(at_param_name, remote_address, remote_network_address, frame_id, nil, at_param_unpack_string)
  puts "Sending ... [#{at_command_frame._dump.unpack("C*").join(", ")}]" 
  self.xbee_serialport.write(at_command_frame._dump)
  if self.transmission_mode == :SYNC
    r = XBee::Frame.new(self.xbee_serialport)
    if r.kind_of?(XBee::Frame::RemoteCommandResponse) && r.status == :OK && r.frame_id == frame_id
      if block_given?
        yield r
      else
        at_param_unpack_string.nil? ? r.retrieved_value : r.retrieved_value.unpack(at_param_unpack_string).first
      end
    else
      raise "Response did not indicate successful retrieval of that parameter: #{r.inspect}"
    end
  end
end

#getresponse(echo = false) ⇒ Object

returns results from the XBee echo is disabled by default



587
588
589
590
591
592
593
# File 'lib/apimode/xbee_api.rb', line 587

def getresponse( echo = false )
  if echo == true
    r = XBee::Frame.new(self.xbee_serialport)
  else
    getresults( @xbee_serialport, echo )
  end
end

#hw_revObject

Retrieve XBee hardware version



138
139
140
# File 'lib/apimode/xbee_api.rb', line 138

def hw_rev
  @hw_rev ||= get_param("HV","n")
end

#io_inputObject

Forces a sampling of all DIO pins configured for input via dio! Returns a hash with the following key/value pairs: :NUM => number of samples :CM => channel mask :DIO => dio data if DIO lines are enabled :ADCn => adc sample data (one for each ADC channel enabled)



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/apimode/xbee_api.rb', line 473

def io_input

  tmp = @xbee_serialport.read_timeout
  @xbee_serialport.read_timeout = read_timeout(:long)

  @xbee_serialport.write("ATIS\r")
  if self.transmission_mode == :SYNC
    response = getresponse
    linenum = 1
    adc_sample = 1
    samples = Hash.new

    if response.match("ERROR")
      samples[:ERROR] = "ERROR"
      return samples
    end

    # otherwise parse input data
    response.each_line do | line |
      case linenum
      when 1
        samples[:NUM] = line.to_i
      when 2
        samples[:CM] = line.strip.chomp
      when 3
        samples[:DIO] = line.strip.chomp
      else
        sample = line.strip.chomp
        if ( !sample.nil? && sample.size > 0 )
          samples["ADC#{adc_sample}".to_sym] = line.strip.chomp
          adc_sample += 1
        end
      end

      linenum += 1
    end

    @xbee_serialport.read_timeout = tmp
    samples
  end
end

#io_output!(hexbitmap) ⇒ Object

Sets the digital output levels of any DIO lines which were configured for output using the dio! method. The parameter, hexbitmap, is a hex value which represents the 8-bit bitmap of the i/o lines on the XBee.



461
462
463
464
# File 'lib/apimode/xbee_api.rb', line 461

def io_output!( hexbitmap )
  @xbee_serialport.write("ATIO#{hexbitmap}\r")
  getresponse if self.transmission_mode == :SYNC
end

#neighborsObject

Neighbor node discovery. Returns an array of hashes each element of the array contains a hash each hash contains keys: :MY, :SH, :SL, :DB, :NI representing addresses source address, Serial High, Serial Low, Received signal strength, node identifier respectively. Aan example of the results returned (hash as seen by pp):

[{:NI=>" ", :MY=>"0", :SH=>"13A200", :SL=>"4008A642", :DB=>-24},
 {:NI=>" ", :MY=>"0", :SH=>"13A200", :SL=>"4008A697", :DB=>-33},
 {:NI=>" ", :MY=>"0", :SH=>"13A200", :SL=>"40085AD5", :DB=>-52}]

Signal strength (:DB) is reported in units of -dBM.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/apimode/xbee_api.rb', line 153

def neighbors
  frame_id = self.next_frame_id
  # neighbors often takes more than 1000ms to return data
  node_discover_cmd = XBee::Frame::ATCommand.new("ND",frame_id,nil)
  #puts "Node discover command dump: #{node_discover_cmd._dump.unpack("C*").join(", ")}"
  tmp = @xbee_serialport.read_timeout
  @xbee_serialport.read_timeout = Integer(self.node_discover_timeout.in_seconds * 1050)
  @xbee_serialport.write(node_discover_cmd._dump)
  responses = []
  #read_thread = Thread.new do
  begin
    loop do
      r = XBee::Frame.new(self.xbee_serialport)
      # puts "Got a response! Frame ID: #{r.frame_id}, Command: #{r.at_command}, Status: #{r.status}, Value: #{r.retrieved_value}"
      if r.kind_of?(XBee::Frame::ATCommandResponse) && r.status == :OK && r.frame_id == frame_id
        if r.retrieved_value.empty?
          # w00t - the module is telling us it's done with the discovery process.
          break
        else
        responses << r
        end
      else
        raise "Unexpected response to ATND command: #{r.inspect}"
      end
    end
  rescue Exception => e
    puts "Okay, must have finally timed out on the serial read: #{e}."
  end
  @xbee_serialport.read_timeout = tmp
  responses.map do |r|
    unpacked_fields = r.retrieved_value.unpack("nNNZxnCCnn")
    return_fields = [:SH, :SL, :NI, :PARENT_NETWORK_ADDRESS, :DEVICE_TYPE, :STATUS, :PROFILE_ID, :MANUFACTURER_ID]
    unpacked_fields.shift #Throw out the junk at the start of the discover packet
    return_fields.inject(Hash.new) do |return_hash, field_name|
      return_hash[field_name] = unpacked_fields.shift
      return_hash
    end
  end
end

#network_reset!(reset_range) ⇒ Object

Performs a network reset on one or more modules within a PAN. The module responds immediately with an “OK” and then restarts the network. All network configuration and routing information is lost if not saved.

Parameter range: 0-1

  • 0: Resets network layer parameters on the node issuing the command.

  • 1: Sends broadcast transmission to reset network layer parameters on all nodes in the PAN.



541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/apimode/xbee_api.rb', line 541

def network_reset!(reset_range)
  if reset_range == 0
    @xbee_serialport.write("ATNR0\r")
  elsif reset_range == 1 then
    @xbee_serialport.write("ATNR1\r")
  else
    #### DEBUG ####
    if $DEBUG then
      puts "Invalid parameter provided: #{reset_range}"
    end
    #### DEBUG ####
  end
end

#next_frame_idObject



18
19
20
# File 'lib/apimode/xbee_api.rb', line 18

def next_frame_id
  @frame_id += 1
end

#node_idObject

returns the node ID of the device. Node ID is typically a human-meaningful name to give to the XBee device, much like a hostname.



271
272
273
# File 'lib/apimode/xbee_api.rb', line 271

def node_id
  @node_id ||= get_param("NI")
end

#node_id!(new_id) ⇒ Object

sets the node ID to a user-definable text string to make it easier to identify the device with “human” names. This node id is reported to neighboring XBees so consider it “public”.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/apimode/xbee_api.rb', line 279

def node_id!(new_id)
  tmp = @xbee_serialport.read_timeout
  @xbee_serialport.read_timeout = read_timeout(:long)
  @xbee_serialport.write("ATNI#{new_id}\r")
  if self.transmission_mode == :SYNC
    response = getresponse
    @xbee_serialport.read_timeout = tmp
    if ( response.nil? )
      return ""
    else
      response.strip.chomp
    end
  end
end

#pan_idObject

returns the PAN ID of the device. PAN ID is one of the 3 main identifiers used to communicate with the device from other XBees. All XBees which are meant to communicate must have the same PAN ID and channel number. The 3rd identifier is the address of the device itself represented by its serial number (High and Low) and/or it’s 16-bit MY source address.



300
301
302
# File 'lib/apimode/xbee_api.rb', line 300

def pan_id
  @pan_id ||= get_param("ID").unpack("n")
end

#pan_id!(new_id) ⇒ Object

sets the PAN ID of the device. Modules must have the same PAN ID in order to communicate with each other. The PAN ID value can range from 0 - 0xffff. The default from the factory is set to 0x3332.



308
309
310
311
# File 'lib/apimode/xbee_api.rb', line 308

def pan_id!(new_id)
  @xbee_serialport.write("ATID#{new_id}\r")
  getresponse if self.transmission_mode == :SYNC
end

#parityObject

returns the parity of the device as represented by a symbol: :None - for 8-bit none :Even - for 8-bit even :Odd - for 8-bit odd :Mark - for 8-bit mark :Space - for 8-bit space



348
349
350
351
352
353
354
# File 'lib/apimode/xbee_api.rb', line 348

def parity
  @xbee_serialport.write("ATNB\r")
  if self.transmission_mode == :SYNC
    response = getresponse().strip.chomp
    @paritycodes.index( response.to_i )
  end
end

#parity!(parity_type) ⇒ Object

sets the parity of the device to one represented by a symbol contained in the parity_type parameter :None - for 8-bit none :Even - for 8-bit even :Odd - for 8-bit odd :Mark - for 8-bit mark :Space - for 8-bit space



363
364
365
366
367
368
369
370
# File 'lib/apimode/xbee_api.rb', line 363

def parity!( parity_type )
  # validate symbol before writing parity param
  if !@paritycodes.include?(parity_type)
    return false
  end
  @xbee_serialport.write("ATNB#{@paritycodes[parity_type]}\r")
  getresponse if self.transmission_mode == :SYNC
end

#received_signal_strengthObject

returns the signal strength in dBm units of the last received packet. Expect a negative integer or 0 to be returned. If the XBee device has not received any neighboring packet data, the signal strength value will be 0



317
318
319
# File 'lib/apimode/xbee_api.rb', line 317

def received_signal_strength
  -(get_param("DB").hex)
end

#reset!Object

Resets the XBee module through software and simulates a power off/on. Any configuration changes that have not been saved with the save! method will be lost during reset.

The module responds immediately with “OK” then performs a reset ~2 seconds later. The reset is a required when the module’s SC or ID has been changes to take into affect.



529
530
531
# File 'lib/apimode/xbee_api.rb', line 529

def reset!
  @xbee_serialport.write("ATFR\r")
end

#restore!Object

Restores all the module parameters to factory defaults Restore (RE) command does not reset the ID parameter.



558
559
560
# File 'lib/apimode/xbee_api.rb', line 558

def restore!
  @xbee_serialport.write("ATRE\r")
end

#save!Object

writes the current XBee configuration to the XBee device’s flash. There is no undo for this operation



518
519
520
521
# File 'lib/apimode/xbee_api.rb', line 518

def save!
  @xbee_serialport.write("ATWR\r")
  getresponse if self.transmission_mode == :SYNC
end

#send!(message) ⇒ Object

just a straight pass through of data to the XBee. This can be used to send data when not in AT command mode, or if you want to control the XBee with raw commands, you can send them this way.



566
567
568
# File 'lib/apimode/xbee_api.rb', line 566

def send!(message)
  @xbee_serialport.write( message )
end

#serial_numObject

Returns the complete serialnumber of XBee device by quering the high and low parts.



235
236
237
# File 'lib/apimode/xbee_api.rb', line 235

def serial_num
  self.serial_num_high() << 32 | self.serial_num_low
end

#serial_num_highObject

Returns the high portion of the XBee device’s serial number. this value is factory set.



229
230
231
# File 'lib/apimode/xbee_api.rb', line 229

def serial_num_high
  @serial_high ||= get_param("SH","N")
end

#serial_num_lowObject

Returns the low portion of the XBee device’s serial number. this value is factory set.



223
224
225
# File 'lib/apimode/xbee_api.rb', line 223

def serial_num_low
  @serial_low ||= get_param("SL","N")
end

#set_param(at_param_name, param_value, at_param_unpack_string = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/apimode/xbee_api.rb', line 60

def set_param(at_param_name, param_value, at_param_unpack_string = nil)
  frame_id = self.next_frame_id
  at_command_frame = XBee::Frame::ATCommand.new(at_param_name,frame_id,param_value,at_param_unpack_string)
  # puts "Sending ... [#{at_command_frame._dump.unpack("C*").join(", ")}]"
  self.xbee_serialport.write(at_command_frame._dump)
  if self.transmission_mode == :SYNC
  r = XBee::Frame.new(self.xbee_serialport)
    if r.kind_of?(XBee::Frame::ATCommandResponse) && r.status == :OK && r.frame_id == frame_id
      if block_given?
        yield r
      else
        at_param_unpack_string.nil? ? r.retrieved_value : r.retrieved_value.unpack(at_param_unpack_string).first
      end
    else
      raise "Response did not indicate successful retrieval of that parameter: #{r.inspect}"
    end
  end
end

#set_remote_param(at_param_name, param_value, remote_address = 0x000000000000ffff, remote_network_address = 0xfffe, at_param_unpack_string = nil) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/apimode/xbee_api.rb', line 98

def set_remote_param(at_param_name, param_value, remote_address = 0x000000000000ffff, remote_network_address = 0xfffe, at_param_unpack_string = nil)
  frame_id = self.next_frame_id
  at_command_frame = XBee::Frame::RemoteCommandRequest.new(at_param_name, remote_address, remote_network_address, frame_id, param_value, at_param_unpack_string)
  puts "Sending ... [#{at_command_frame._dump.unpack("C*").join(", ")}]"
  self.xbee_serialport.write(at_command_frame._dump)
  if self.transmission_mode == :SYNC
    r = XBee::Frame.new(self.xbee_serialport)
    if r.kind_of?(XBee::Frame::RemoteCommandResponse) && r.status == :OK && r.frame_id == frame_id
      if block_given?
        yield r
      else
        at_param_unpack_string.nil? ? r.retrieved_value : r.retrieved_value.unpack(at_param_unpack_string).first
      end
    else
      raise "Response did not indicate successful retrieval of that parameter: #{r.inspect}"
    end
  end
end

#start_apimode_communicationObject

Switch to API mode - note that in Series 2 the Operation Mode is defined by the firmware flashed to the device. Only Series 1 can switch from AT (Transparent) to API Opearation and back seamlessly.



26
27
28
29
30
31
32
33
# File 'lib/apimode/xbee_api.rb', line 26

def start_apimode_communication
  in_command_mode do
    puts "Entering api mode"
    # Set API Mode 2 (include escaped characters)
    self.xbee_serialport.write("ATAP2\r")
    self.xbee_serialport.read(3)
  end
end

#versionObject

returns the version of this class



580
581
582
# File 'lib/apimode/xbee_api.rb', line 580

def version
  VERSION
end