forked from qt-creator/qt-creator
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openmv: Pick the exact drive for cameras on windows.
- Loading branch information
Showing
6 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <QtCore> | ||
#include <QSerialPortInfo> | ||
|
||
#include <utils/hostosinfo.h> | ||
#include <utils/qtcprocess.h> | ||
|
||
namespace OpenMV { | ||
namespace Internal { | ||
|
||
QString serialPortDriveSerialNumber(const QString &portName) | ||
{ | ||
#if defined(Q_OS_WIN) | ||
Utils::Process process; | ||
std::chrono::seconds timeout(10); | ||
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine); | ||
process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine); | ||
process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("powershell")), | ||
QStringList() | ||
<< QStringLiteral("-Command") | ||
<< QString(QStringLiteral("(Get-PnpDeviceProperty -InstanceId (Get-WmiObject Win32_SerialPort | Where-Object { $_.DeviceID -eq '%1' }).PNPDeviceId | Where-Object { $_.KeyName -eq 'DEVPKEY_Device_Parent' }).Data")).arg(QString(portName)))); | ||
process.runBlocking(timeout, Utils::EventLoopMode::Off); | ||
|
||
if(process.result() == Utils::ProcessResult::FinishedWithSuccess) | ||
{ | ||
QRegularExpressionMatch match = QRegularExpression("\\\\(\\w+)$").match(process.stdOut().trimmed()); | ||
if (match.hasMatch()) return match.captured(1); | ||
} | ||
#elif defined(Q_OS_LINUX) | ||
#elif defined(Q_OS_MAC) | ||
#endif | ||
|
||
return QString(); | ||
} | ||
|
||
QString driveSerialNumber(const QString &drivePath) | ||
{ | ||
#if defined(Q_OS_WIN) | ||
Utils::Process process; | ||
std::chrono::seconds timeout(10); | ||
process.setTextChannelMode(Utils::Channel::Output, Utils::TextChannelMode::MultiLine); | ||
process.setTextChannelMode(Utils::Channel::Error, Utils::TextChannelMode::MultiLine); | ||
process.setCommand(Utils::CommandLine(Utils::FilePath::fromString(QStringLiteral("powershell")), | ||
QStringList() | ||
<< QStringLiteral("-Command") | ||
<< QString(QStringLiteral("(Get-Disk -Number (Get-Partition -DriveLetter '%1').DiskNumber).SerialNumber")).arg(QString(drivePath).remove(QStringLiteral(":")).remove(QStringLiteral("/"))))); | ||
process.runBlocking(timeout, Utils::EventLoopMode::Off); | ||
|
||
if(process.result() == Utils::ProcessResult::FinishedWithSuccess) | ||
{ | ||
QString serialNumber = process.stdOut().trimmed(); | ||
return serialNumber; | ||
} | ||
#elif defined(Q_OS_LINUX) | ||
#elif defined(Q_OS_MAC) | ||
#endif | ||
|
||
return QString(); | ||
} | ||
|
||
} // namespace Internal | ||
} // namespace OpenMV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef DRIVE_SERIAL_NUMBER_H | ||
#define DRIVE_SERIAL_NUMBER_H | ||
|
||
#include <QString> | ||
|
||
namespace OpenMV { | ||
namespace Internal { | ||
|
||
QString serialPortDriveSerialNumber(const QString &portName); | ||
QString driveSerialNumber(const QString &drivePath); | ||
|
||
} // namespace Internal | ||
} // namespace OpenMV | ||
|
||
#endif // DRIVE_SERIAL_NUMBER_H |