串口设备信息扫描工具技术详解

项目概述

本项目是一个基于 Electron + React + C++ 技术栈的跨平台串口设备信息扫描工具(SerialPortScanner),专门用于检测、分析和展示系统中的串口设备信息。该工具能够扫描物理串口、虚拟串口和USB转串口设备,并提供详细的设备信息展示。

核心特性

  • 🔍 全面扫描:支持物理串口、虚拟串口、USB设备三种类型
  • 📊 详细信息:提供设备制造商、驱动信息、硬件ID等详细信息
  • 🎨 现代界面:基于React的响应式用户界面
  • 高性能:C++后端提供高效的设备扫描能力
  • 🔧 跨平台:基于Electron的跨平台桌面应用
  • 📱 无边框设计:自定义标题栏和窗口控制

快速开始

环境准备:

  1. 安装 Visual Studio 2022 和 Windows SDK
  2. 安装 Node.js 16+ 和 npm/yarn
  3. 克隆项目代码

编译运行:

# 1. 编译后端C++库
cd code/backend
mkdir build && cd build
cmake .. && cmake --build .

# 2. 启动前端开发服务器
cd ../../frontend
npm install
npm run dev

生产部署:

# 构建完整应用程序
cd code/frontend
npm run build

技术架构

整体架构图

┌─────────────────────────────────────────────────────────────┐
│                    前端层 (Frontend)                        │
├─────────────────────────────────────────────────────────────┤
│  React Components  │  Electron Main Process  │  DLL Bridge  │
│  - MainPage        │  - Window Management    │  - API Layer │
│  - Sidebar         │  - IPC Handlers         │  - Memory Mgmt│
│  - ContentArea     │  - DLL Loading          │              │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                    后端层 (Backend)                         │
├─────────────────────────────────────────────────────────────┤
│  C++ DLL Library   │  Device Scanning       │  Data Models  │
│  - SerialDevice    │  - Physical Ports      │  - Device Info│
│  - LibGlobal       │  - Virtual Ports       │  - Capabilities│
│  - MemoryManager   │  - USB Devices         │  - JSON Export│
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                   系统层 (System)                           │
├─────────────────────────────────────────────────────────────┤
│  Windows API       │  Device Manager        │  Registry     │
│  - SetupAPI        │  - Hardware Detection  │  - Device Info│
│  - Registry Access │  - Driver Information  │  - System Data│
└─────────────────────────────────────────────────────────────┘

技术栈详解

前端技术栈
  • Electron 28.0.0:跨平台桌面应用框架
  • React 18.2.0:用户界面库
  • TypeScript 5.3.0:类型安全的JavaScript
  • Tailwind CSS:实用优先的CSS框架
  • FontAwesome:图标库
  • Vite:快速构建工具
后端技术栈
  • C++17:高性能系统编程语言
  • Visual Studio 2022:集成开发环境
  • Poco C++ Libraries:跨平台C++库
  • Windows SetupAPI:设备管理API
  • CMake:跨平台构建系统
  • Google Test:单元测试框架

核心模块分析

1. 后端C++模块

1.1 设备扫描器 (SerialDeviceScanner)
// 核心扫描函数
std::vector<SerialDeviceModel> ScanPhysicalSerialDevices();
std::vector<SerialDeviceModel> ScanUSBDevices();
std::vector<SerialDeviceModel> ScanVirtualSerialDevices();

功能特点:

  • 使用Windows SetupAPI进行设备枚举
  • 通过硬件ID识别设备类型
  • 支持多种设备类型的检测和分类
  • 提供详细的设备属性信息

设备类型识别逻辑:

bool IsPhysicalSerialPort(HDEVINFO hDevInfo, SP_DEVINFO_DATA& deviceInfoData) {
   
   
    // 排除虚拟设备标识
    if (hwId.find("EVSERIAL") != std::string::npos ||
        hwId.find("VIRTUAL") != std::string::npos ||
        hwId.find("SOFTWARE") != std::string::npos) {
   
   
        return false;
    }
    
    // 识别物理串口模式
    if (hwId.find("ACPI\\") == 0 ||
        hwId.find("PCI\\") == 0 ||
        hwId.find("ROOT\\") == 0) {
   
   
        return true;
    }
}
1.2 设备管理器 (SerialDeviceManager)

核心功能:

  • 统一管理所有设备扫描操作
  • 解析JSON输入参数
  • 生成标准化的设备信息JSON
  • 内存管理和资源清理

函数设计模式:

const char* SerialDeviceManager::scanSerialDevices(const char* jsonIn) {
   
   
    // 局部变量声明
    std::vector<SerialDeviceModel> allDevices;
    std::string response;
    Poco::LogStream log(getLogger());
    
    // 业务处理
    if (!parseScanOptions(jsonIn)) {
   
   
        response = createErrorResponse("Invalid JSON input");
        goto exit;
    }
    
    // 执行扫描逻辑...
    
exit:
    // 清理动作
    return result;
}
1.3 设备数据模型 (SerialDeviceModel)

包含的完整设备信息:

  • 基本信息:设备名称、端口号、描述
  • 硬件信息:制造商、硬件ID、兼容ID
  • 驱动信息:驱动版本、服务名称、安装日期
  • 技术规格:最大波特率、支持的数据位、停止位、校验位
  • USB信息:厂商ID、产品ID、芯片类型
  • 虚拟设备:配对端口、虚拟类型

2. 前端React模块

2.1 主页面组件 (MainPage)

核心功能:

  • 设备扫描控制
  • 扫描结果展示
  • 设备选择管理
  • 窗口状态控制

状态管理:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值