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.
15 stars 3 forks source link

About a device connection and a function "StartAcquisitionUnity" #8

Closed yukih00 closed 3 years ago

yukih00 commented 4 years ago

In order to measure pulse and EDA data, I wrote a C# script. But the script provided errors such as Null reference exception. I guest that the connection between Unity and the device (PsychoBIT) failed or a function “StartAcquisitionUnity” was incorrectly used. The script was found in https://1drv.ms/u/s!AlgXmeFIkeV9tvFiblDQWhOsjnbFug?e=0rwRcJ.

Could you provide some advices to me?

best, yukih00

GRamosPlux commented 4 years ago

Dear yukih00,

I am very glad for understanding that you continue the exploration of our API, it will be a pleasure to support you regarding this issue! Thank you very much for opening a new discussion, it is very helpful for us and will certainly be for other members of the community.

A few moments ago I had the opportunity to test your script and to replicate the issue. Your perception is totally correct, the connection with the device fails, it seems that the API has a small limitation but fortunately it can be easily overtaken.

Before clicking on X key (to establish a connection with PLUX device) you should always execute a Bluetooth scan and connect to one of the found devices instead of having a fixed configuration (a constant macAddress.

If you follow the Scan >> Connection workflow the NullReferenceException will probably disappear. Note that sometimes the connection is not established with success at the first try, so, it could be necessary to try to connect more than once.

After a successful connection (flagged by the call of ConnectionDone() callback) you will be able to start a real-time acquisition by pressing C. However, you should change the PDM.StartAcquisitionUnity(100, new List<int>() { 1,2,3,4}, 16); call, replacing 16 by 10, because BITalino only supports acquisitions using 10 bits resolution (when 4 or less channels are active) or 6 bits (if more than 4 channels are active).

In addition, if you want to manually stop the acquisition, it will probably be necessary to apply a very simple edit in the phase == 1 if clause:

[...]
else if (phase == 1)
{
    //Sampling
    data = PDM.GetPackageOfData(true);
    TS = TS + Time.deltaTime;
    //Output
    Output();
    if (Input.GetKeyDown(KeyCode.V))
    {
        PDM.StopAcquisitionUnity();
     }
}

I truly hope that the previous information could be helpful, however, if you don't consider them totally enlightening or if further questions/issues arise, please, do not hesitate to alert us!

My best and sincere regards, GRamosPlux