MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / refreshSerialDevices

Method refreshSerialDevices

app/src/IO/Drivers/UART.cpp:728–773  ·  view source on GitHub ↗

* @brief Scans for available serial ports and rebuilds the device list. */

Source from the content-addressed store, hash-verified

726 * @brief Scans for available serial ports and rebuilds the device list.
727 */
728void IO::Drivers::UART::refreshSerialDevices()
729{
730 QStringList names;
731 QStringList locations;
732 locations.append("/dev/null");
733 names.append(tr("Select Port"));
734
735 auto validPortList = validPorts();
736 for (const auto& info : std::as_const(validPortList)) {
737 if (!info.isNull()) {
738#ifdef Q_OS_WIN
739 names.append(info.portName() + " " + info.description());
740#else
741 names.append(info.portName());
742#endif
743
744 locations.append(info.systemLocation());
745 }
746 }
747
748 if (m_deviceNames != names) {
749 m_deviceNames = names;
750 m_deviceLocations = locations;
751
752 const bool indexChanged = relocateOpenPortIndex(validPortList);
753
754 const bool uart_active = ConnectionManager::instance().busType() == SerialStudio::BusType::UART;
755 if (uart_active && autoReconnect() && m_lastSerialDeviceIndex > 0
756 && m_lastSerialDeviceIndex < portList().count()) {
757 setPortIndex(m_lastSerialDeviceIndex);
758 ConnectionManager::instance().connectDevice();
759 }
760
761 Q_EMIT availablePortsChanged();
762
763 if (indexChanged)
764 Q_EMIT portIndexChanged();
765 }
766
767 if (m_portIndex == 0) {
768 const auto ports = portList();
769 auto lastPort = m_settings.value("IO_Serial_SelectedDevice", "").toString();
770 if (!lastPort.isEmpty() && ports.contains(lastPort))
771 setPortIndex(ports.indexOf(lastPort));
772 }
773}
774
775/**
776 * @brief Handles a serial port error by disconnecting and showing a message box.

Callers

nothing calls this directly

Calls 9

busTypeMethod · 0.80
connectDeviceMethod · 0.80
isEmptyMethod · 0.80
appendMethod · 0.45
descriptionMethod · 0.45
countMethod · 0.45
valueMethod · 0.45
containsMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected