Feature #777 » find.cpp
| 1 |
#include <QSerialPortInfo>
|
|---|---|
| 2 |
#include <QString>
|
| 3 |
#include <QList>
|
| 4 |
|
| 5 |
QString findStlinkPort() |
| 6 |
{
|
| 7 |
// Bekannte ST-Link VID/PID-Kombinationen
|
| 8 |
const QList<QPair<int,int>> stlinkIds = { |
| 9 |
{0x0483, 0x374B}, // ST-Link V2 |
| 10 |
{0x0483, 0x374D}, // ST-Link V3 |
| 11 |
{0x0483, 0x3748}, // ältere Varianten |
| 12 |
};
|
| 13 |
|
| 14 |
for (const QSerialPortInfo &info : QSerialPortInfo::availablePorts()) { |
| 15 |
|
| 16 |
// VID/PID prüfen
|
| 17 |
for (const auto &id : stlinkIds) { |
| 18 |
if (info.vendorIdentifier() == id.first && |
| 19 |
info.productIdentifier() == id.second) { |
| 20 |
return info.systemLocation(); // z.B. "/dev/ttyACM0" |
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
// Fallback: Produktname prüfen
|
| 25 |
if (info.description().contains("STLink", Qt::CaseInsensitive) || |
| 26 |
info.manufacturer().contains("STMicro", Qt::CaseInsensitive)) { |
| 27 |
return info.systemLocation(); |
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
return QString(); // nichts gefunden |
| 32 |
}
|