mirror of https://github.com/stella-emu/stella.git
Fix serial port autodetect issues for Mac (similar to fixes for Linux).
This commit is contained in:
parent
89c6b847e7
commit
949e6aa915
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in New Issue