File tree Expand file tree Collapse file tree
src/Studio/Devices/OpenBCI Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -271,6 +271,10 @@ void OpenBCIAutoDetection::DetectDevices()
271271 if (mBreak == true )
272272 break ;
273273
274+ // Before attempting to initialize a port, check if it is already in use
275+ if (IsPortInUse (portNames[i]))
276+ continue ;
277+
274278 //
275279 // Init Serial connection
276280 //
@@ -434,6 +438,21 @@ void OpenBCIAutoDetection::DetectDevices()
434438 mIsSearching = false ;
435439}
436440
441+ bool OpenBCIAutoDetection::IsPortInUse (const String& portName)
442+ {
443+ const uint32 numDevices = mDriver ->mDevices .Size ();
444+ for (uint32 i = 0 ; i < numDevices; ++i)
445+ {
446+ OpenBCIDeviceBase* device = mDriver ->mDevices [i];
447+ if (device->GetSerialPortName () == portName)
448+ {
449+ LogDetailedInfo (" OpenBCIAutoDetection: skipping port %s (already in use)" , portName.AsChar ());
450+ return true ;
451+ }
452+ }
453+ return false ;
454+ }
455+
437456
438457void OpenBCISerialThread::run ()
439458{
You can’t perform that action at this time.
0 commit comments