Qt通讯类型 - USB

前言

usb也是目前常出现的设备接口类型。本篇是从需求的接口出发,目前分如下三类

  1. hidapi
  2. win32
  3. libusb

需求方面,基本功能是连接和读写数据,进阶需求例如热插拔

 本文不详细介绍测试示例,仅列举一些开发过程中的笔记

HIDAPI

source

https://github.com/signal11/hidapi

LIBUSB

//待更新

Win32

文档

doc - CM_Register_Notification function

doc - RegisterDeviceNotificationA function (winuser.h)

 

Use  RegisterDeviceNotificationA instead of CM_Register_Notification if your code targets Windows 7 or earlier versions of Windows. 

You can use  CM_Register_Notification instead of RegisterDeviceNotification if your code targets Windows 8 or newer versions of Windows. The advantage of CM_Register_Notification is that it does not require a window handle to work.

Note

        对USB的支持,换而言之是在检测硬件设备的改变。Windows操作系统会对上层程序发送WM_DEVICECHANGE消息来通知设备的改变,对应的,要实现一个数据处理的事件。

LRESULT CALLBACK DevPluginInterface::windowMessageProcess(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if (message == WM_DEVICECHANGE)
    {
        //do something
    }
}

        使用接口 RegisterDeviceNotification 要注意创建一个窗口句柄(另一个不用,但我还没测试)

 hwnd = ::CreateWindowW(wc.lpszClassName, // classname
                           wc.lpszClassName, // window name
                           0,  // style
                           0,  // x
                           0,  // y
                           0,  // width
                           0,  // height
                           0,  // parent
                           0,  // menu handle
                           hi, // application
                           0); // windows creation data.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值