serial_dashboard.SerialConnection

class serial_dashboard.SerialConnection(port=None, baudrate=115200, daq_delay=20, port_search_delay=1000, bytesize=8, parity='N', stopbits=1)

Class containing details about a serial connection.

ser

Serial connection to a device.

Type

serial.Serial instance

port

Name of the port of the connection. This is not the device name, but a descriptive name.

Type

str

baudrate

Baud rate of the connection

Type

int

bytesize

Number of data bits. Possible values: serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS, serial.EIGHTBITS

Type

int

parity

Enable parity checking. Possible values: serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD, serial.PARITY_MARK, serial.PARITY_SPACE.

Type

int

stopbits

Number of stop bits. Possible values: serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE, serial.STOPBITS_TWO

Type

int

ports

List of ports that are available. Each entry is a serial.tools.list_ports_common.ListPortInfo instance.

Type

list

available_ports

A dictionary with the descriptive port names as keys and strings with the name of the ports such that they can be opened with serial.Serial() as values.

Type

dict

reverse_available_ports

A dictionary with the descriptive port names as values and strings with the name of the ports such that they can be opened with serial.Serial() as keys.

Type

dict

port_status

The status of the port. Either “disconnected”, “establishing”, “connected”, or “failed”.

Type

str

daq_task

Task for data acquisition.

Type

async task

daq_delay

Approximate time, in milliseconds, between data acquisitions.

Type

float

port_search_task

Task for checking for available ports.

Type

async task

port_search_delay

Approximate time, in milliseconds, between checks of available ports.

Type

float

kill_app

If True, kill the connect/app.

Type

bool

__init__(port=None, baudrate=115200, daq_delay=20, port_search_delay=1000, bytesize=8, parity='N', stopbits=1)

Create an instance storing information about a serial connection.

Parameters
  • port (str, default None) – If given, name of the port to connect to. If None, no device is connected.

  • baudrate (int) – Baud rate of the connection

  • daq_delay (float) – Approximate time, in milliseconds, between data acquisitions.

  • bytesize (int) – Number of data bits. Possible values: serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS, serial.EIGHTBITS

  • parity (int) – Enable parity checking. Possible values: serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD, serial.PARITY_MARK, serial.PARITY_SPACE.

  • stopbits (int) – Number of stop bits. Possible values: serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE, serial.STOPBITS_TWO

Methods

__init__([port, baudrate, daq_delay, …])

Create an instance storing information about a serial connection.

connect(port[, allow_disconnect, handshake])

Connect to a port.

disconnect()

Disconnect port.

portsearch([on_change])

Search for ports and update port information.

connect(port, allow_disconnect=False, handshake=True)

Connect to a port.

Parameters
  • port (str, int, or serial.tools.list_ports_common.ListPortInfo instance) – Port to which to connect. If an int, connect to port given by self.ports[port].

  • allow_disconnect (bool, default True) – If already connected to a port, allow disconnection. If False, raise an exception if already connected.

  • handshake (bool, default True) – If True, “handshake” with the connected device by closing, reopening connection waiting a second, and then clearing the input buffer.

disconnect()

Disconnect port.

portsearch(on_change=True)

Search for ports and update port information.

Parameters

on_change (bool, default True) – If True, only update ports, available_ports, and reverse_available_ports attributes if there was a change in the available ports.