bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
Q_UNUSED(result);
Q_UNUSED(eventType);
MSG* pMsg = reinterpret_cast<MSG*>(message);
if (pMsg->message == WM_KEYUP)
{
ushort key = pMsg->wParam;
if (key == '\r')
{
ui->sn_lineEdit->setText(m_scanSN);
m_scanSN = "";
}
else
{
//可见字符
if (key >= 32 && key < 127)
{
m_scanSN = m_scanSN + QChar(key);
}
}
}
if(pMsg->message == WM_DEVICECHANGE){
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)pMsg->lParam;
switch (pMsg->wParam) {
case DBT_DEVICEARRIVAL:
if(lpdb->dbch_devicetype == DBT_DEVTYP_PORT){
qDebug()<<"插入串口设备!";
emit signalUpdataSerialPort();
}
break;
case DBT_DEVICEREMOVECOMPLETE:
if(lpdb->dbch_devicetype == DBT_DEVTYP_PORT){
qDebug()<<"串口设备离开";
m_SerialPort.closeSerialPort();
ui->openSerialport_Btn->setText("打开串口");
m_serialPortStatus = false;
logMessage("关闭串口");
emit signalUpdataSerialPort();
}
}
}
return false;
}