BaseDevice(QObject)

Base Device class for real-time interfaces to hardware devices. Developer: Dominik I. Braun Contact: dome.braun@fau.de Last Update: 2024-06-05

class biosignal_device_interface.devices.core.base_device.BaseDevice(self, parent: PySide6.QtCore.QObject | None = None)[source]

Bases: QObject

Initialize self. See help(type(self)) for accurate signature.

Parameters:

parent (Union[QMainWindow, QWidget])

abstract _connect_to_device()[source]

Function to attempt a connection to the devices.

Returns:

Success of the connection attempt.

Return type:

bool

abstract _disconnect_from_device()[source]

Closes the connection to the device.

self.interface closes and is set to None. Device state is_connected is set to False. Signal connected_signal emits False.

Returns:

Success of the disconnection attempt.

Return type:

bool

_extract_auxiliary_data(data, milli_volts=True)[source]

Extract auxiliary channels from the transmitted data.

Parameters:
  • data (np.ndarray) – Raw data that got transmitted.

  • milli_volts (bool, optional) – If True, the auxiliary data is converted to milli volts. Defaults to True.

Returns:

Extracted auxiliary channel data.

Return type:

np.ndarray

_extract_biosignal_data(data, milli_volts=True)[source]

Extracts the biosignals from the transmitted data.

Parameters:
  • data (np.ndarray) – Raw data that got transmitted.

  • milli_volts (bool, optional) – If True, the biosignal data is converted to milli volts. Defaults to True.

Returns:

Extracted biosignal channels.

Return type:

np.ndarray

abstract _make_request()[source]

Requests a connection or checks if someone connected to the server. After connection is successful, the Signal connected_signal emits True and sets the current state is_connected to True.

Returns:

Returns True if request was successfully. False if not.

Return type:

bool

abstract _process_data(input)[source]

Decodes the transmitted bytes and convert them to respective output format (e.g., mV).

Emits the processed data through the Signal data_available_signal which can be connected to a function using: {self.device}.data_available_signal.connect(your_custom_function).

This works perfectly fine outside of this class.

Your custom function your_custom_function needs to have a parameter “data” which is of type np.ndarray.

In case that the current configuration of the device was requested, the configuration is provided through the Signal configuration_available_signal that emits the current parameters in a dictionary.

Parameters:

input (bytearray) – Bytearray of the transmitted raw data.

Return type:

None

abstract _read_data()[source]

This function is called when bytes are ready to be read in the buffer. After reading the bytes from the buffer, _process_data is called to decode and process the raw data.

Return type:

None

abstract _start_streaming()[source]

Sends the command to start the streaming to the device.

if successful:

Device state is_streaming is set to True. Signal streaming_signal emits True.

Return type:

None

abstract _stop_streaming()[source]

Sends the command to stop the streaing to the device

if successful:

Device state is_streaming is set to False. Signal streaming_signal emits False.

Return type:

None

_update_configuration_parameters(params)[source]

Updates the device attributes with the new configuration parameters.

Parameters:

params (Dict[str, Union[Enum, Dict[str, Enum]]]) –

Dictionary that holds the configuration settings to which the device should be configured to.

The first one should be the attributes (configuration mode) name, and the second its respective value. Orient yourself on the enums of the device to choose the correct configuration settings.

Return type:

None

check_valid_ip(ip_address)[source]

Checks if the provided IP is valid.

Parameters:
  • ip (str) – IP to be checked.

  • ip_address (str)

Returns:

True if IP is valid. False if not.

Return type:

bool

check_valid_port(port)[source]

Checks if the provided port is valid.

Parameters:

port (str) – Port to be checked.

Returns:

True if port is valid. False if not.

Return type:

bool

abstract clear_socket()[source]

Reads all the bytes from the buffer.

Return type:

None

abstract configure_device(params)[source]

Sends a configuration byte sequence based on selected params to the device. An overview of possible configurations can be seen in biosignal_device_interface/constants/{device}.py.

E.g., enums/sessantaquattro.py

Parameters:

params (Dict[str, Union[Enum, Dict[str, Enum]]]) –

Dictionary that holds the configuration settings to which the device should be configured to.

The first one should be the attributes (configuration mode) name, and the second its respective value. Orient yourself on the enums of the device to choose the correct configuration settings.

Return type:

None

get_device_information()[source]

Gets the current configuration of the device.

Returns:

Dictionary that holds information about the current device configuration and status.

Return type:

Dict[str, Enum | int | float | str]

get_server_wifi_ip_address()[source]

Returns the IP address of the host server.

Return type:

list[str]

toggle_connection(settings=None)[source]

Toggles the connection to the device.

Parameters:

settings (Tuple[str, int], optional) –

If CommunicationProtocol.TCPIP: Tuple[0] = IP -> string Tuple[1] = Port -> int

If CommunicationProtocol.SERIAL pr CommunicationProtocol.USB: Tuple[0] = COM Port -> string Tuple[1] = Baudrate -> int

Defaults to None.

Returns:

True if connection attempt was successfully. False if not.

Return type:

bool

toggle_streaming()[source]

Toggles the current state of the streaming. If device is streaming, the streaming is stopped and vice versa.

Return type:

None