mirror of https://github.com/stella-emu/stella.git
Change serial port autodetection in Unix to not re-configure the ports, only test if they can be opened.
If this fixes the recently reported bug, we will extend this to other systems.
This commit is contained in:
parent
c462cc4680
commit
858e79e7d3
|
@ -105,7 +105,6 @@ StringList SerialPortUNIX::portNames()
|
||||||
// Get all possible devices in the '/dev' directory
|
// Get all possible devices in the '/dev' directory
|
||||||
FilesystemNode::NameFilter filter = [](const FilesystemNode& node) {
|
FilesystemNode::NameFilter filter = [](const FilesystemNode& node) {
|
||||||
return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyACM") ||
|
return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyACM") ||
|
||||||
BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyS") ||
|
|
||||||
BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyUSB");
|
BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyUSB");
|
||||||
};
|
};
|
||||||
FSList portList;
|
FSList portList;
|
||||||
|
@ -116,8 +115,20 @@ StringList SerialPortUNIX::portNames()
|
||||||
|
|
||||||
// Add only those that can be opened
|
// Add only those that can be opened
|
||||||
for(const auto& port: portList)
|
for(const auto& port: portList)
|
||||||
if(openPort(port.getPath()))
|
if(isValid(port.getPath()))
|
||||||
ports.emplace_back(port.getPath());
|
ports.emplace_back(port.getPath());
|
||||||
|
|
||||||
return ports;
|
return ports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool SerialPortUNIX::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;
|
||||||
|
}
|
||||||
|
|
|
@ -70,6 +70,15 @@ class SerialPortUNIX : public SerialPort
|
||||||
*/
|
*/
|
||||||
StringList portNames() override;
|
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:
|
private:
|
||||||
// File descriptor for serial connection
|
// File descriptor for serial connection
|
||||||
int myHandle{0};
|
int myHandle{0};
|
||||||
|
|
Loading…
Reference in New Issue