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

Unity freezes until a successful connection has been established and various errors #5

Closed jdevoldere closed 4 years ago

jdevoldere commented 4 years ago

PluxDeviceManager.cs Line 475: string[] tempListDevices = Marshal.PtrToStringAnsi(listDevicesByType[k]).Split('&');

Results in the following error sometimes: System.ExecutionEngineException: String conversion error: Partial byte sequence encountered in the input.

However, even when I put this bit of code into a try-catch block, Unity still freezes up until a successful connection has been established with the Plux and in order to do so I have to turn the Plux off and back on again, sometimes even twice, which is quite inconvenient.

Here is the script I'm using to interface with the PluxDeviceManager: https://pastebin.com/tjie4mRJ

jdevoldere commented 4 years ago

Edited the post because the issues also happen in a non-VR project.

GRamosPlux commented 4 years ago

Dear jdevoldere,

Thank you very much for sharing with us your experience while coupling PLUX API with VR functionalities, our team is delightful for being aware about the innovative solutions prepared by each member of our community!

Regarding the identified error (System.ExecutionEngineException: String conversion error: Partial byte sequence encountered in the input.) your assumption seems very reasonable, in fact, when this error is raised, PLUX .dll sent a nonconvertible message to PluxDeviceManager, raising the exception.

Your approach through the try-catch block is very appropriate to overtake this undesirable event.

Regarding the freezing problem, our team is truly grateful for alerting us about your personal experience and I need to apologize for the less positive behaviour. The freezing state is mainly due to the execution of a Bluetooth scan in the main thread (which takes near 10 seconds to conclude).

Indeed, this is not an appropriate behaviour and in order to correct it we did a new commit a few minutes ago. We truly hope that it could be helpful!

In this new release you will need to specify two callbacks while initialising PluxDeviceManager object. The callbacks should present the following format:

The first method will be called once the scan process is completed, providing you the necessary list of devices.

You should call PluxDevManager.PluxDev(detectedDevices[0]); inside this callback and only start the acquisition PluxDevManager.StartAcquisitionByNbrUnity(SamplingRate, NumberOfChannel, Resolution); when second callback is invoked flagging that a Bluetooth connection between the computer and PLUX device have been estabalished with success, giving you the opportunity to start the acquisition in a secure way!

I truly hope that this new release could be helpful, however, if you still facing some undesirable behaviours, please, do not hesitate to alert our team and we will reopen this issue immediately.

NOTE: We also update the README.md file ;-)

My best and sincere regards, GRamosPlux