qextserialenumerator.h 2.02 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/*!
 * \file qextserialenumerator.h
 * \author Michal Policht
 * \see QextSerialEnumerator
 */
 
#ifndef _QEXTSERIALENUMERATOR_H_
#define _QEXTSERIALENUMERATOR_H_


#include <QString>
#include <QList>

#ifdef _TTY_WIN_
	#include <windows.h>
	#include <setupapi.h>
#endif /*_TTY_WIN_*/


/*!
 * Structure containing port information.
 */
struct QextPortInfo {
	QString portName;		///< Port name.
	QString physName;		///< Physical name.
	QString friendName;		///< Friendly name.
	QString enumName;		///< Enumerator name.
};


/*!
 * Serial port enumerator. This class provides list of ports available in the system.
 * 
 * Windows implementation is based on Zach Gorman's work from 
 * <a href="http://www.codeproject.com">The Code Project</a> (http://www.codeproject.com/system/setupdi.asp).
 */
class QextSerialEnumerator
{
	private:
		#ifdef _TTY_WIN_
			/*!
			 * Get value of specified property from the registry.
			 * 	\param key handle to an open key.
			 * 	\param property property name.
			 * 	\return property value.
			 */
			static QString getRegKeyValue(HKEY key, LPCTSTR property);

			/*!
			 * Get specific property from registry.
			 * 	\param devInfo pointer to the device information set that contains the interface 
			 * 		and its underlying device. Returned by SetupDiGetClassDevs() function.
			 * 	\param devData pointer to an SP_DEVINFO_DATA structure that defines the device instance.
			 * 		this is returned by SetupDiGetDeviceInterfaceDetail() function. 
			 * 	\param property registry property. One of defined SPDRP_* constants. 
			 * 	\return property string.
			 */
			static QString getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property);

			/*!
			 * Search for serial ports using setupapi.
			 * 	\param infoList list with result.
			 */
			static void setupAPIScan(QList<QextPortInfo> & infoList);
		#endif /*_TTY_WIN_*/

	public:
		/*!
		 * Get list of ports.
		 * 	\return list of ports currently available in the system.
		 */
		static QList<QextPortInfo> getPorts();
};

#endif /*_QEXTSERIALENUMERATOR_H_*/