Fix serial port autodetect issues for Mac (similar to fixes for Linux).

This commit is contained in:
Stephen Anthony 2020-10-19 19:16:49 -02:30
parent 89c6b847e7
commit 949e6aa915
2 changed files with 22 additions and 1 deletions

View File

@ -111,8 +111,20 @@ StringList SerialPortMACOS::portNames()
// Add only those that can be opened
for(const auto& port: portList)
if(openPort(port.getPath()))
if(isValid(port.getPath()))
ports.emplace_back(port.getPath());
return ports;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SerialPortMACOS::isValid(const string& port) const
{
// For now, we can only detect whether the port could be opened
// Eventually we may extend this to do more intensive checks
int handle = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
if(handle > 0)
close(handle);
return handle > 0;
}

View File

@ -69,6 +69,15 @@ class SerialPortMACOS : public SerialPort
*/
StringList portNames() override;
private:
/**
Tests whether this port can be opened, and is a valid
serial port.
@return True if valid, else false
*/
bool isValid(const string& port) const;
private:
// File descriptor for serial connection
int myHandle{0};