qextserialenumerator.h 2.05 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5
/*!
 * \file qextserialenumerator.h
 * \author Michal Policht
 * \see QextSerialEnumerator
 */
6

pixhawk's avatar
pixhawk committed
7 8 9 10 11 12 13 14
#ifndef _QEXTSERIALENUMERATOR_H_
#define _QEXTSERIALENUMERATOR_H_


#include <QString>
#include <QList>

#ifdef _TTY_WIN_
15 16
#include <windows.h>
#include <setupapi.h>
pixhawk's avatar
pixhawk committed
17 18 19 20 21 22 23
#endif /*_TTY_WIN_*/


/*!
 * Structure containing port information.
 */
struct QextPortInfo {
24 25 26 27
    QString portName;		///< Port name.
    QString physName;		///< Physical name.
    QString friendName;		///< Friendly name.
    QString enumName;		///< Enumerator name.
pixhawk's avatar
pixhawk committed
28 29 30 31 32
};


/*!
 * Serial port enumerator. This class provides list of ports available in the system.
33 34
 *
 * Windows implementation is based on Zach Gorman's work from
pixhawk's avatar
pixhawk committed
35 36 37 38
 * <a href="http://www.codeproject.com">The Code Project</a> (http://www.codeproject.com/system/setupdi.asp).
 */
class QextSerialEnumerator
{
39 40 41 42 43 44 45 46 47
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);
pixhawk's avatar
pixhawk committed
48

49 50 51 52 53 54 55 56 57 58
    /*!
     * 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);
pixhawk's avatar
pixhawk committed
59

60 61 62 63 64 65
    /*!
     * Search for serial ports using setupapi.
     * 	\param infoList list with result.
     */
    static void setupAPIScan(QList<QextPortInfo> & infoList);
#endif /*_TTY_WIN_*/
pixhawk's avatar
pixhawk committed
66

67 68 69 70 71 72
public:
    /*!
     * Get list of ports.
     * 	\return list of ports currently available in the system.
     */
    static QList<QextPortInfo> getPorts();
pixhawk's avatar
pixhawk committed
73 74 75
};

#endif /*_QEXTSERIALENUMERATOR_H_*/