Skip to content

Latest commit

 

History

History
158 lines (106 loc) · 4.36 KB

File metadata and controls

158 lines (106 loc) · 4.36 KB

XBee Serial API

Constructor

__init__(port=None, baudrate=115200, status=False, logger=None)

Configure the serial port

Note

Serial ports are not opened on object creation.


Parameters
  • port (str or None) - Port of serial device.
  • baudrate (int) - Baudrate of serial device.
  • status (bool) - Automatically receive status packets after a transmission.
  • logger (Logger) - Logger object from Logger.Logger used to record data such as sent and received data.

See Serial Port for details on finding the correct serial port name.

baudrate should be the same for both device (XBee RF module) and serial port. XBees will be configured to 115200 by default.

See Frame Details for details regarding the XBee status packet (Frame type 0x89).

A Logger instance will be created if it is not provided. You should only create your own instance of Logger if you want to log data that is not already logged by the XBee library.

Example:

from Communication.XBee.XBee import XBee

PORT = "/dev/cu.usbserial-D30DWZKT"
BAUD_RATE = 115200
xbee = XBee(PORT, BAUD_RATE) # status and logger will be set to False and None respectively

Methods

open()

Open a connection over the serial port. This method does not return anything if a port is successfully opened.


Returns True if success, False if failure (There is already an open port)
Raises: SerialException if there is an error opening the serial port.

A SerialException typically occurs if:

  • The XBee module is not plugged in
  • The port/device name is incorrect
  • The port is in use (e.g. There is another program accessing the same port )
close()

Close a connection over the serial port.


Returns True if success, False if failure.
Return type bool

transmit_data(data, address="0000000000000000")

Send data to another XBee module(s)


Parameters
  • data (str) - String data to transmit.
  • address (str) - Address of destination XBee module. "0000000000000000" if no value is provided.
Returns Status of transmit request. See 0x89 Tx (Transmit) Status for more details.
Return type x89 or None
Raises SerialException if serial port is not open

data can be at most 100 bytes (100 characters)

address can be set to 000000000000FFFF in order to broadcast a message

0x89: (frame_type, frame_id, status)

Returns None if no status frame is received


retrieve_data()

Check for incomming data


Returns str if there is incomming data. None otherwise.
Return type 0x81 or None

0x81: (frame_type, source_address, rssi, options, data)


Note

The below methods are used by GCS for testing.

request_at_command_data(self, id)

Request and retrieve configuration detail of XBee device.

Parameters id (str) - Identifier of AT command
Returns AT command response. See 0x88 AT Command Response for more details.
Return type 0x88
Raises SerialException if serial port is not open
read_config(self, filename)

Warning

This method will be completely rewritten.

This method reads a config file and executes AT commands to retrieve configuration data of an XBee module. All returned data is written to a log file.

Parameters filename (str) - Filename of AT Commands to execute.
Raises SerialException if serial port is not open