digi.xbee.serial module

class digi.xbee.serial.FlowControl[source]

Bases: enum.Enum

This class represents all available flow controls.

class digi.xbee.serial.XBeeSerialPort(baud_rate, port, data_bits=<sphinx.ext.autodoc.importer._MockObject object>, stop_bits=<sphinx.ext.autodoc.importer._MockObject object>, parity=<sphinx.ext.autodoc.importer._MockObject object>, flow_control=<FlowControl.NONE: None>, timeout=0.1)[source]

Bases: sphinx.ext.autodoc.importer._MockObject, digi.xbee.comm_interface.XBeeCommunicationInterface

This class extends the functionality of Serial class (PySerial).

It also introduces a minor change in its behaviour: the serial port is not automatically open when an object is instantiated, only when calling open().

Class constructor. Instantiates a new XBeeSerialPort object with the given port parameters.

Parameters:
  • baud_rate (Integer) – serial port baud rate.
  • port (String) – serial port name to use.
  • data_bits (Integer, optional) – serial data bits. Default to 8.
  • stop_bits (Float, optional) – serial stop bits. Default to 1.
  • parity (Char, optional) – serial parity. Default to ‘N’ (None).
  • flow_control (Integer, optional) – serial flow control. Default to None.
  • timeout (Integer, optional) – read timeout. Default to 0.1 seconds.
open()[source]

Opens port with current settings. This may throw a SerialException if the port cannot be opened.

is_interface_open

Returns whether the underlying hardware communication interface is active or not.

Returns:Boolean. True if the interface is active, False otherwise.
write_frame(frame)[source]

Writes an XBee frame to the underlying hardware interface.

Subclasses may throw specific exceptions to signal implementation specific hardware errors.

Parameters:frame (Bytearray) – The XBee API frame packet to write. If the bytearray does not correctly represent an XBee frame, the behaviour is undefined.
read_byte()[source]

Synchronous. Reads one byte from serial port.

Returns:the read byte.
Return type:Integer
Raises:TimeoutException – if there is no bytes ins serial port buffer.
read_bytes(num_bytes)[source]

Synchronous. Reads the specified number of bytes from the serial port.

Parameters:num_bytes (Integer) – the number of bytes to read.
Returns:the read bytes.
Return type:Bytearray
Raises:TimeoutException – if the number of bytes read is less than num_bytes.
quit_reading()[source]

Makes the thread (if any) blocking on wait_for_frame return.

If a thread was blocked on wait_for_frame, this method blocks (for a maximum of ‘timeout’ seconds) until the blocked thread is resumed.

wait_for_frame(operating_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]

Reads the next packet. Starts to read when finds the start delimiter. The last byte read is the checksum.

If there is something in the COM buffer after the start delimiter, this method discards it.

If the method can’t read a complete and correct packet, it will return None.

Parameters:operating_mode (OperatingMode) – the operating mode in which the packet should be read.
Returns:the read packet as bytearray if a packet is read, None otherwise.
Return type:Bytearray
read_existing()[source]

Asynchronous. Reads all bytes in the serial port buffer. May read 0 bytes.

Returns:the bytes read.
Return type:Bytearray
get_read_timeout()[source]

Returns the serial port read timeout.

Returns:read timeout in seconds.
Return type:Integer
set_read_timeout(read_timeout)[source]

Sets the serial port read timeout in seconds.

Parameters:read_timeout (Integer) – the new serial port read timeout in seconds.
set_baudrate(new_baudrate)[source]

Changes the serial port baudrate.

Parameters:new_baudrate (Integer) – the new baudrate to set.
purge_port()[source]

Purges the serial port by cleaning the input and output buffers.

close()

Terminates the underlying hardware communication interface.

Subclasses may throw specific exceptions to signal implementation specific hardware errors.

timeout

Returns the read timeout.

Returns:read timeout in seconds.
Return type:Integer