Skip to content

Commit 9f79f6f

Browse files
author
jef
committedOct 5, 2010
fix com port detection on windows
git-svn-id: http://svn.osgeo.org/qgis/trunk@14339 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 50bdfb3 commit 9f79f6f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎src/app/gps/qgsgpsinformationwidget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,9 @@ void QgsGPSInformationWidget::populateDevices()
889889
QList< QPair<QString, QString> > ports = QgsGPSDetector::availablePorts();
890890

891891
mCboDevices->clear();
892-
for ( int i = 0; i < ports.size(); i++ )
892+
893+
// add devices to combobox, but skip gpsd which is first.
894+
for ( int i = 1; i < ports.size(); i++ )
893895
{
894896
mCboDevices->addItem( ports[i].second, ports[i].first );
895897
}

‎src/core/gps/qextserialport/qextserialenumerator.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,27 @@ QextSerialEnumerator::~QextSerialEnumerator( )
8585
//static
8686
void QextSerialEnumerator::setupAPIScan(QList<QextPortInfo> & infoList)
8787
{
88+
#if 0
8889
enumerateDevicesWin(GUID_DEVCLASS_PORTS, &infoList);
90+
#else
91+
// just iterate the com ports.
92+
// looks like GUID_DEVCLASS_PORTS doesn't find them all.
93+
for( unsigned int i = 0 ; i < 256; i++ )
94+
{
95+
QString port = "\\\\.\\COM" + QString::number(i);
96+
97+
HANDLE hPort = ::CreateFile(port.toAscii(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
98+
if( hPort == INVALID_HANDLE_VALUE )
99+
continue;
100+
101+
QextPortInfo info;
102+
info.friendName = QString("COM%1:").arg( i );
103+
info.portName = port;
104+
infoList.append(info);
105+
106+
CloseHandle( hPort );
107+
}
108+
#endif
89109
}
90110

91111
void QextSerialEnumerator::enumerateDevicesWin( const GUID & guid, QList<QextPortInfo>* infoList )

0 commit comments

Comments
 (0)
Please sign in to comment.