pluxbiosignals / unity-sample

Unity Sample APP intended to show a practical integration of PLUX devices with the Unity environment, encompassing functionalities such as: the search of compatible Bluetooth devices and also the start/stop of a real-time acquisition.
18 stars 3 forks source link

Have all eight channel output data #14

Closed C1wan closed 2 years ago

C1wan commented 2 years ago

Dear PluxBiosignals team,

Is there a way to aquire data fro all eight channels (Hybrid8) and if yes how or is it only limited to tow channels ?I tried to modify the Hybrid8Test.cs but it still will give out data only from to channels.

Thanks in advance

GRamosPlux commented 2 years ago

Dear @C1wan,

Thank you very much for opening this valuable discussion! The PLUX team strongly hopes that this message finds you well.

Concerning the simultaneous acquisition of data from 8 channels, using the biosignalsplux Hybrid-8 hub, the following changes should be able to ensure the data streaming from 8 Analog channels:

On the other hand, if one specific channel has a digital sensor attached (fNIRS, SpO2,...), for example, in channel 1, the pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x01)); instruction should be replaced by pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x03));

I will carefully wait for your important feedback regarding the effectiveness of the previous changes or any further question that you would like to explore.

My best and sincere regards, @GRamosPlux

C1wan commented 2 years ago

Dear PluxBiosignals team,

first of all thanks for the answer. I already tried your solution but I dont get any data shown in the method OnDataReceived() and in the outputString from the other channels besides CH1 and CH8. How can I fix this issue because I want to have all channels shown in the output string and not just two channels.

Thanks in advance

GRamosPlux commented 2 years ago

Dear @C1wan,

We are truly grateful for your important feedback!

This is a really curious event, our sincere apologies for the undesirable setback. In order to deeply evaluate the source of this peculiar behaviour, would it be possible to share with us a copy of the Hybrid8Test.cs file or a code snippet containing the channel initialization instructions being currently used?

My best and sincere regards, @GRamosPlux

C1wan commented 2 years ago

Dear BiosignalsPlux Team, here are some code snippets:

Here I applied the advice from your previoius code snippets:

    public void StartButtonFunction()
    {
        // Get the Sampling Rate and Resolution values.
        samplingRate = int.Parse(SamplingRateDropdown.options[SamplingRateDropdown.value].text);
        int resolution = int.Parse(ResolutionDropdown.options[ResolutionDropdown.value].text);

        // Initializing the sources array.
        List<PluxDeviceManager.PluxSource> pluxSources = new List<PluxDeviceManager.PluxSource>();

        // biosignalsplux Hybrid-8 device (3 sensors >>> 1 Analog + 2 Digital SpO2/fNIRS)
        if (pluxDevManager.GetProductIdUnity() == Hybrid8PID)
        {
            // Add the sources of the digital channels (CH1 and CH2).
            // Mehr digitale Channels hinzufügen
            //  pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x03));
            //pluxSources.Add(new PluxDeviceManager.PluxSource(2, 1, resolution, 0x03));
            // Define the LED Intensities of both sensors (CH1 and CH2) as: {RED, INFRARED}
            //  int redLedIntensity = (int) (int.Parse(RedIntensityDropdown.options[RedIntensityDropdown.value].text) * (MaxLedIntensity / 100f)); // A 8-bit value (0-255)
            // int infraredLedIntensity = (int)(int.Parse(InfraredIntensityDropdown.options[InfraredIntensityDropdown.value].text) * (MaxLedIntensity / 100f)); // A 8-bit value (0-255)
            //int[] ledIntensities = new int[2] { redLedIntensity, infraredLedIntensity };
            //pluxDevManager.SetParameter(1, 0x03, ledIntensities);

            // Add the source of the analog channel (CH8).
            // Add the source of the analog channel (CH1-CH8).
            pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(2, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(3, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(4, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(5, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(6, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(7, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(8, 1, resolution, 0x01));

            // Add the sources of the internal IMU channels (CH11 with 9 derivations [3xACC | 3xGYRO | 3xMAG] defined by the 0x01FF chMask).
            // int imuPort = 11;
            //   pluxSources.Add(new PluxDeviceManager.PluxSource(imuPort, 1, resolution, 0x01FF));

            // Alternatively only some of the derivations can be activated.
            // >>> 3xACC (channel mask 0x0007)
            // pluxSources.Add(new PluxDeviceManager.PluxSource(imuPort, 1, resolution, 0x0007));
            // >>> 3xGYR (channel mask 0x0038)
            // pluxSources.Add(new PluxDeviceManager.PluxSource(imuPort, 1, resolution, 0x0038));
            // >>> 3xMAG (channel mask 0x01C0)
            // pluxSources.Add(new PluxDeviceManager.PluxSource(imuPort, 1, resolution, 0x01C0));
        }
        // biosignalsplux (2 Analog sensors)
        else if (pluxDevManager.GetProductIdUnity() == BiosignalspluxPID)
        {
            // Starting a real-time acquisition from:
            // >>> biosignalsplux [CH1 and CH8 active]
            pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x01));
            pluxSources.Add(new PluxDeviceManager.PluxSource(8, 1, resolution, 0x01));
        }
        // muscleBAN (7 Analog sensors)
        else if (pluxDevManager.GetProductIdUnity() == MuscleBanPID)
        {
            // Starting a real-time acquisition from:
            // >>> muscleBAN [CH1 > EMG]
            pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x01));
            // >>> muscleBAN [CH2-CH4 > ACC | CH5-CH7 > MAG active]
            pluxSources.Add(new PluxDeviceManager.PluxSource(2, 1, resolution, 0x3F));
        }
        // muscleBAN v2 (7 Analog sensors)
        else if (pluxDevManager.GetProductIdUnity() == MuscleBanNewPID)
        {
            // Starting a real-time acquisition from:
            // >>> muscleBAN [CH1 > EMG]
            pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x01));
            // >>> muscleBAN Virtual Port [CH2-CH4 > ACC | CH5-CH7 > MAG active]
            pluxSources.Add(new PluxDeviceManager.PluxSource(11, 1, resolution, 0x3F));
        }
        // biosignalsplux Solo (8 Analog sensors)
        else if (pluxDevManager.GetProductIdUnity() == BiosignalspluxSoloPID)
        {
            // Starting a real-time acquisition from:
            // >>> biosignalsplux Solo [CH1 > MICRO]
            pluxSources.Add(new PluxDeviceManager.PluxSource(1, 1, resolution, 0x01));
            // >>> biosignalsplux Solo [CH2 > CUSTOM]
            pluxSources.Add(new PluxDeviceManager.PluxSource(2, 1, resolution, 0x01));
            // >>> biosignalsplux Solo Virtual Port [CH3-CH5 > ACC | CH6-CH8 > MAG]
            pluxSources.Add(new PluxDeviceManager.PluxSource(11, 1, resolution, 0x3F));
        }

        // BITalino (2 Analog sensors)
        if (pluxDevManager.GetProductIdUnity() == BitalinoPID)
        {
            // Starting a real-time acquisition from:
            // >>> BITalino [Channels A2 and A5 active]
            pluxDevManager.StartAcquisitionUnity(samplingRate, new List<int> { 2, 5 }, 10);
        }
        else
        {
            // Start a real-time acquisition with the created sources.
            pluxDevManager.StartAcquisitionBySourcesUnity(samplingRate, pluxSources.ToArray());
        }
    }

Then I tried to output data from all channels but I got an IndexOutOfBoundsException because the channels were not recorded:

  public void OnDataReceived(int nSeq, int[] data)
    {
        // Show samples with a 0.3s interval.
        // if (nSeq % samplingRate == 0)

        int subsamplingFactor = (int)(0.3 * samplingRate);
        if (nSeq % subsamplingFactor == 0)
        {
            // Show the current package of data.
            string outputString = "Acquired Data:\n";
            for (int j = 0; j < data.Length; j++)
            {
                outputString += data[j] + "\t";
            }
            UnityEngine.Debug.Log(outputString);
            // Show the values in the GUI.

            valueCH1 = data[0];
            /*
             valueCH2 = data[1];
             valueCH3 = data[2];
             valueCH4 = data[3];
             valueCH5 = data[4];
             valueCH6 = data[5];
             valueCH7 = data[6];
             valueCH8 = data[7];
 */

        }
    }

Thanks in advance

GRamosPlux commented 2 years ago

Dear @C1wan,

Thank you very much for sharing this valuable set of code snippets. From a code point-of-view, your actions seem perfect.

There is another possibility that may be triggering this peculiar behaviour. Due to its similar appearance, it is possible that we are interacting with a standard biosignalsplux hub (auxiliary link) instead of the Hybrid-8 model (auxiliary link).

If this hypothesis is adequate, the code is probably entering in another if clause. In order to evaluate this hypothesis, we can try to apply the following changes:

I will carefully wait for your always important feedback concerning this experience.

My best and sincere regards, @GRamosPlux

C1wan commented 2 years ago

Dear @GRamosPlux ,

your assumption was correct and with your changes it finally worked. Thank you for the help .

Thankfully, @C1wan

GRamosPlux commented 2 years ago

Dear @C1wan,

These are excellent news, the team is really glad for understanding that you were able to overtake the current issue!

I strongly wish you a continuation of excellent researches in the Biosignals world and, please, do not hesitate to open a new discussion if any problem or question arises in the future.

My best and sincere regards, @GRamosPlux