QSerialPortInfo Class
提供有关现有串行端口的信息。
Note
之前的博文简要介绍了QSerialPort类,完成串口的发送,接受,通信参数如波特率设置是足够了,但总觉得有点不足吧,我希望知道此时能够连接的端口有哪些,那个端口是连着我的设备的,因为可能大部分时间我都不知道我连接的是哪一个端口号。
Public Functions
QSerialPortInfo() //构造一个空的QSerialPortInfo对象。
QSerialPortInfo(const QSerialPort &port) //从串行端口构造QSerialPortInfo对象。
QSerialPortInfo(const QString &name) //从串行端口构造QSerialPortInfo对象。
QSerialPortInfo(const QSerialPortInfo &other) //从串行端口名称构造一个QSerialPortInfo对象。
//该构造函数根据端口名称在可用端口中找到相关的串行端口,并为该端口构造串行端口信息实例。
~QSerialPortInfo()
销毁QSerialPortInfo对象。 对对象中值的引用无效。
QString description() const
返回串行端口的描述字符串(如果有); 否则返回一个空字符串。
bool hasProductIdentifier() const //如果存在有效的16位product number,则返回true;
bool hasVendorIdentifier() const //如果存在有效的16位vendor number,则返回true;否则,返回true。
bool isBusy() const // 如果串行端口繁忙,则返回true; 否则返回false。
bool isNull() const // 返回此QSerialPortInfo对象是否包含串行端口定义。
QString manufacturer() const //返回串口的 manufacturer 字符串(如果有); 否则返回一个空字符串。
QString portName() const //返回串行端口的名称。
quint16 productIdentifier() const //Returns the 16-bit product number for the serial port, if available; otherwise returns zero.
QString serialNumber() const //Returns the 16-bit product number for the serial port, if available; otherwise returns zero.
void swap(QSerialPortInfo &other) // Swaps QSerialPortInfo other with this QSerialPortInfo. This operation is very fast and never fails.
QString systemLocation() const //返回串行端口的系统位置。
quint16 vendorIdentifier() const // Returns the 16-bit vendor number for the serial port, if available; otherwise returns zero.
QSerialPortInfo & operator=(const QSerialPortInfo &other) //Sets the QSerialPortInfo object to be equal to other.
在使用QSerialPort进行串口通信前,预先使用此类了解设备的端口情况,或者专门开一个线程检测这个状态,或者实时更新这个数值,用法会灵活很多吧,应该。