Python API
Loading...
Searching...
No Matches
plux.BaseDev Class Reference

Base class for all PLUX devices. More...

Inheritance diagram for plux.BaseDev:
plux.SignalsDev plux.BITalinoDev plux.MemoryDev

Public Member Functions

 __init__ (self, path)
 Connects to a PLUX device.
 
 getProperties (self)
 Returns the device properties.
 
 setParameter (self, port, index, data)
 Sets a system or sensor parameter value.
 
 getBattery (self)
 Returns a float number with the remaining battery charge as a percentage of full capacity.
 
 setTimeout (self, timeout=-1)
 Sets the receiving timeout value for loop().
 
 loop (self)
 Runs the device message loop.
 
 interrupt (self, param=None)
 Sends an interrupt signal to loop().
 
 onEvent (self, event)
 Event callback.
 
 onTimeout (self)
 Timeout callback.
 
 onInterrupt (self, param)
 Interrupt signal callback.
 
 close ()
 Disconnects from the device.
 

Static Public Member Functions

 findDevices (domain='')
 Finds PLUX devices within the given domain.
 

Detailed Description

Base class for all PLUX devices.

This class provides the basic functionality common to all PLUX devices. A BaseDev device can be instantiated if a specific device functionality is not required. A BaseDev instance can be promoted afterwards to a derived class instance, based of device properties. This promotion is done by passing the BaseDev instance to the constructor of the derived class.

Alternatively, a derived class can be directly instantiated from the path string if a specific device functionality is required.

It is not possible to demote a derived class instance to a BaseDev instance.

Constructor & Destructor Documentation

◆ __init__()

plux.BaseDev.__init__ (   self,
  path 
)

Connects to a PLUX device.

Parameters
pathA string with the path to the PLUX device. It can have one of the following formats:
Format Meaning Supported platforms
xx:xx:xx:xx:xx:xx Classic Bluetooth MAC address All platforms
BTHxx:xx:xx:xx:xx:xx Classic Bluetooth MAC address All platforms
BLExx:xx:xx:xx:xx:xx Bluetooth Low Energy MAC address Windows
COMn COM serial/virtual port Windows
/dev/... Serial device Mac OS and Linux
USB or USBn USB adapter connection Windows

Reimplemented in plux.SignalsDev, plux.MemoryDev, plux.BITalinoDev, plux.SignalsDev, plux.MemoryDev, and plux.BITalinoDev.

Member Function Documentation

◆ findDevices()

plux.BaseDev.findDevices (   domain = '')
static

Finds PLUX devices within the given domain.

Parameters
domainAn optional string with the domain of search. It can be "BTH" for a Classic Bluetooth search, "BLE" for a Bluetooth Low Energy search, or "USB" for an USB search. If it is not given (or if it is an empty string), a search is attempted in all domains.
Returns
A tuple of strings pairs. Each string pair is also a tuple and it represents a found device. The first string of each pair is the path of the device (the path to be passed to the device class constructor). The second string is the device description as returned in its description property.

◆ getProperties()

plux.BaseDev.getProperties (   self)

Returns the device properties.

The device properties are a dictionary of string keywords to associated values. The currently defined keywords are:

Keyword Meaning
description Device description string
fwVersion Device firmware version
hwVersion Device hardware version (not present in old devices)
memorySize Device internal memory size in kBytes (only on MemoryDev instances)
(zero if internal memory is not available)
path Device path string as passed to constructor
productID Device product identifier
uid Device unique identifier string

The fwVersion, hwVersion and productID properties are composed of two numbers (the major and minor numbers). These properties and are encoded as 2-byte integers where the higher byte is the major number and the lower byte is the minor number.

◆ setParameter()

plux.BaseDev.setParameter (   self,
  port,
  index,
  data 
)

Sets a system or sensor parameter value.

Parameters
portAn integer with the sensor port number for a sensor parameter, or zero for a system parameter.
indexAn integer with the index of the parameter to set within the sensor or system.
dataA string with the data to assign to the parameter
Remarks
The following parameters are currently supported on biosignalplux devices with firmware v3.7:
Port Index System / Sensor # of bytes Description Default value
0 0 System 1 Idle connection timeout in 32-second units 28 (~15 minutes)
9 3 SpO2/fNIRS sensor on ground port 2 LED current setting for red (1st byte) and IR (2nd byte) Read from redDefCurrent and irDefCurrent sensor characteristics
10 2 Digital output on digital port 1 Byte value 0: output low; value 1: output high; another value: ignored 0 (output low)

◆ getBattery()

plux.BaseDev.getBattery (   self)

Returns a float number with the remaining battery charge as a percentage of full capacity.

The returned value is -1 if the device is charging.

◆ setTimeout()

plux.BaseDev.setTimeout (   self,
  timeout = -1 
)

Sets the receiving timeout value for loop().

Parameters
timeoutAn optional integer with the timeout value in milliseconds. If timeout is 0, an immediate timeout condition occurs in loop() if there are no pending messages from device to dispatch. If timeout is not given or if it is -1, a timeout condition never occurs.
See also
onTimeout()

◆ loop()

plux.BaseDev.loop (   self)

Runs the device message loop.

The message loop receives and dispatches the messages from the device to the callbacks. This method returns when a callback returns True.

Remarks
This method cannot be called from a callback.

◆ interrupt()

plux.BaseDev.interrupt (   self,
  param = None 
)

Sends an interrupt signal to loop().

This method can be called from a thread while loop() is running on another thread. The onInterrupt() callback will be called from loop() (in the context of its thread).

Parameters
paramAn optional parameter to be passed to onInterrupt() callback.
Remarks
This method cannot be called from a callback, and it cannot be called if loop() is not running in another thread.

◆ onEvent()

plux.BaseDev.onEvent (   self,
  event 
)

Event callback.

This callback is called by message loop when an event is received from the device. In order to receive device events, an application must derive BaseDev class (or any of its derived classes) to a new class and override this method in the new class.

Parameters
eventThe received event. It can be a Event.DigInUpdate, Event.Disconnect, Event.SchedChange or Event.Sync object.
Returns
Return True to exit message loop or False otherwise. Default callback returns False.

◆ onTimeout()

plux.BaseDev.onTimeout (   self)

Timeout callback.

This callback is called by message loop when a timeout condition occurred. In order to receive timeout conditions, an application must derive BaseDev class (or any of its derived classes) to a new class and override this method in the new class.

Returns
Return True to exit message loop or False otherwise. Default callback returns False.
See also
setTimeout()

◆ onInterrupt()

plux.BaseDev.onInterrupt (   self,
  param 
)

Interrupt signal callback.

This callback is called by message loop after interrupt() is called from another thread. In order to receive interrupt signals, an application must derive BaseDev class (or any of its derived classes) to a new class and override this method in the new class.

Parameters
paramThe optional parameter passed to interrupt().
Returns
Return True to exit message loop or False otherwise. Default callback returns False.

◆ close()

plux.BaseDev.close ( )

Disconnects from the device.

If the device is in real-time acquisition (through SignalsDev.start()), it is automatically stopped.