Skip to content

Commit 24b00f8

Browse files
committed
don't open ports already in use by devices
1 parent 2a3c2f1 commit 24b00f8

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/Studio/Devices/OpenBCI/OpenBCIDriver.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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

438457
void OpenBCISerialThread::run()
439458
{

0 commit comments

Comments
 (0)