pluxbiosignals / python-samples

Python programming examples using PLUX's API.
https://pluxbiosignals.com
Apache License 2.0
13 stars 4 forks source link

Detect sensor type #8

Closed mesca closed 3 years ago

mesca commented 3 years ago

Opensignals is able to detect the sensor type for each channel (EDA, ECG, etc.) I do not see anything in the API documentation that would allow me to do the same. Is this possible with the Python API?

DFNOsorio commented 3 years ago

Hey,

To get the sensors connected, you simply have to call the .getSensors() on your instance. For example if you use the sample code provided, your instance should be something like this: device = NewDevice(address), and to get the sensors just call device.getSensors() (P.S. This method only works with devices that have the biosignals 3.7 and up firmware)

Best regards

mesca commented 3 years ago

Hi Daniel, Thanks for the pointer. Unfortunately, .getSensors() segfaults on my machine (macOS 11.5). I tried with Python 3.7, 3.8, and 3.9. Firmware version: 3.7. Hardware version: 17.0.

mesca commented 3 years ago

Here is the output of lddb:

Process 10840 launched: '/Users/mesca/opt/miniconda3/envs/timeflux/bin/python' (x86_64)
2021-08-09 16:04:00.898988+0200 python[10840:101182] instantiateOnDevice for regular
Process 10840 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x141)
    frame #0: 0x0000000101e3c66f _datetime.cpython-39-darwin.so`new_date_ex + 95
_datetime.cpython-39-darwin.so`new_date_ex:
->  0x101e3c66f <+95>:  callq  *0x130(%rcx)
    0x101e3c675 <+101>: testq  %rax, %rax
    0x101e3c678 <+104>: je     0x101e3c696               ; <+134>
    0x101e3c67a <+106>: movq   $-0x1, 0x10(%rax)
Target 0: (python) stopped.
DFNOsorio commented 3 years ago

The API in this rep for macOS is for the 3.7 Python, but we tested using the built in (non Anaconda) version (sometimes there are weird behaviors when using it). What sensors do you have attached to the device?

mesca commented 3 years ago

The built-in version I have is 3.8.2, and it does not work with it either. I tried with an EDA sensor, then ECG, then both.

DFNOsorio commented 3 years ago

I've just updated the compiled API for version 3.8 and 3.9, and also performed a quick test. Screenshot 2021-08-09 at 16 22 35

mesca commented 3 years ago

Eager to test, but the macOS lib has disappeared from the repo ;)

DFNOsorio commented 3 years ago

Done. I changed the folder structure and forgot to do the add command

mesca commented 3 years ago

Thanks, it works! I can see the following properties: ['characteristics', 'clas', 'color', 'hwVersion', 'measurCalib', 'productionTime', 'serialNum', 'type', 'uid'] Can you tell me how to map these to the actual sensor type? The only API documentation I have is here, but it is clearly outdated.

DFNOsorio commented 3 years ago

Glad to hear it works.

The key in the return dictionary is the port to which the sensor is connected.

The properties you listed are as follow: uid - Sensor 48-bit unique identifier clas - Sensor class serialNum - Sensor serial number within its class hwVersion - Sensor hardware version number type - Sensor interface type bitmask productionTime - Sensor production timestamp color - Sensor sleeve color characteristics - Sensor characteristics measurCalib - Sensor measurements or calibration data

The clas is what I think you want. You can implement the following list to convert the number to the sensor type sensorClasses = ['UNKNOWN', 'EMG', 'ECG', 'LUX', 'EDA', 'BVP', 'RESP', 'XYZ', 'SYNC', 'EEG', 'SYNC_ADAP', 'SYNC_LED', 'SYNC_SW', 'USB', 'FORCE', 'TEMP', 'VPROBE', 'BREAKOUT', 'SpO2', 'GONI', 'ACT', 'EOG', 'EGG']

To map the color (the colored sleeve on the sensor), sensorColors = ['unknown', 'black', 'gray', 'white', 'dark_blue', 'light_blue', 'red', 'green', 'yellow', 'orange', 'light_green', 'brown']

The characteristics and measurCalib (measured calibration) are sensor specific.

Some sensors have variants (present in the characteristics dict) and can be mapped using sensorVariants = { 'SpO2': {'H': 'hSpO2', 'F': 'fSpO2', 'L': 'SpO2'}, 'FORCE': {'1': 'FSRI', '2': 'FSRII', '3': 'FSRIII', '4': 'FSRIV', '5': 'LOADCELL', '6': 'FORCEPLATFORM'} }

mesca commented 3 years ago

Perfect, thanks a lot. I think I have everything I need. I am closing this issue. It would be great to update the documentation.