MFC 使用hidapi打开设备获取信息,实际需求操作记录

C++USB通信。使用hidapi库与控制板通信。C++与hid设备通信。hidapi库的配置与使用。 提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言一、HID是什么?二、使用步骤1.引入库2.获取USB-HID设备3.打开和关闭USB-HID设备4.发送和接收报告5.发送和接收数据总结 前言 这篇文章主要是记录C++与USB-hid设备(即免驱动的usb设备,鼠标、键盘就是hid设备)进行通信,它也是一种USB设备,只不过不需要安装驱动,如果要与非USB-HID设备通信请参考libusb。 libusb首页 github地址 一、HID是什么? USB-HID是Uni 阅读详情

hidapi通过vid,pid打开设备,输出指令,读取信息

//开线程使用hidapi

AfxBeginThread(&USBHidTestThread, (LPVOID)this, THREAD_PRIORITY_NORMAL, 0);

根据实际需求写的方法USBHidTestThread:

UINT USBHidTestThread(LPVOID pParam) {
    Sleep(200);
    int Unplug = 0;//拔插状态
    USBTestDlg* pthis = (USBTestDlg*)pParam;
    int res = 0;
    unsigned char buf[64] = {};
    wchar_t wstr[MAX_STR] = {};
    hid_device* handle;
    CString tempStr = _T("");
    int i;
    char chstr[128] = {};
    struct hid_device_info* devs, * cur_dev;
    //有问题 从界面输入指令 而且指令要是0x01 界面输入的是01 这个切割的方式可能有问题
    string instruct1, instruct2, instruct3;
    instruct1 = (CStringA)Ins;
    instruct2 = (CStringA)Ins1;
    instruct3 = (CStringA)Ins2;
    debuglogpr(L"DebugUSB.log", _T("instruct string =") + Ins + Ins1 + Ins2);

    if (hid_init()) {
        return 0;//??
    }
    //将CSTRING转换为unsigned short
    //string strv,strp;
    //strv = (CStringA)Hid;//CString 转换为 string
    unsigned short vids, pids;
    string vv = (CStringA)Hid;
    const char* cv = vv.c_str();
    vids = strtol(cv, NULL, 16);
    string pp = (CStringA)Pid;
    const char* cp = pp.c_str();
    pids = strtol(cp, NULL, 16);

    devs = hid_enumerate(vids, pids);
    cur_dev = devs;

    vector<string> vpath;//装遍历出的每个地址
    while (cur_dev) {
        vpath.push_back(cur_dev->path);
        string str = cur_dev->path;//char* 转换为 string 可以直接赋值
        CA2T szr(str.c_str());
        tempStr = (LPCTSTR)szr;
        //tempStr.Format(_T("%s"), sss);//string 转换为 CString
        debuglogpr(L"DebugUSB.log", _T("--HID PATH:") + tempStr);

        //将unsigned short 转换为 string
        unsigned short us = cur_dev->product_id;
        char puf[20];
        itoa(us, puf, 16);
        string query = puf;
        CA2T szc(query.c_str());
        tempStr = (LPCTSTR)szc;

        debuglogpr(L"DebugUSB.log", _T("--PID:") + tempStr);

        cur_dev = cur_dev->next;
    }
    hid_free_enumeration(devs);
    ::memset(buf, 0x00, sizeof(buf));//报错:E0266    "memset" 不明确 加::表明调用全局函数

    CString log;//输出log用的
    for (int d = 0; d < vpath.size(); d++) {
        handle = hid_open_path(vpath.at(d).c_str());
        string path;
        if (!handle)
        {
            path = "this device path: ";
            path += vpath.at(d).c_str();
            CA2T szc(path.c_str());
            log = (LPCTSTR)szc;
            debuglogpr(L"DebugUSB.log", _T("Path:") + log);
            debuglogpr(L"DebugUSB.log", L"--------------------unable to open device ");
            continue;
        }
        debuglogpr(L"DebugUSB.log", L"open device Success !");

        // Read the Manufacturer String
        wstr[0] = 0x0000;
        res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
        if (res < 0)
        {
            debuglogpr(L"DebugUSB.log", L"Unable to read manufacturer string ***");
        }
        else
        {
            //QString test = QString::fromWCharArray(wstr);
            //tempStr = "manufacturer string =" + test.toStdString();
            debuglogpr(L"DebugUSB.log", L"read manufacturer string OK***");
            /*writeLog(tempStr);*/
        }


        hid_set_nonblocking(handle, 1);
        debuglogpr(L"DebugUSB.log", L"write ins:");


        unsigned short write1, write2, write3;
        string sw1 = (CStringA)Ins;
        const char* cw1 = sw1.c_str();
        write1 = strtol(cw1, NULL, 16);
        string sw2 = (CStringA)Ins1;
        const char* cw2 = sw2.c_str();
        write2 = strtol(cw2, NULL, 16);
        string sw3 = (CStringA)Ins2;
        const char* cw3 = sw3.c_str();
        write3 = strtol(cw3, NULL, 16);
        

        int p = 0;//p是typeCport口的标识,而不是配置界面portd的标识 从1开始
        if (write3 == 0x01) {
            p = 1;
        }
        else if (write3 == 0x02) {
            p = 2;
        }
        else if (write3 == 0x03) {
            p = 3;
        }
        else if (write3 == 0x04) {
            p = 4;
        }
        else if (write3 == 0x05) {
            p = 5;
        }
        else if (write3 == 0x06) {
            p = 6;
        }

        ::memset(buf, 0x00, sizeof(buf));
        buf[0] = 0xFF & write1;
        buf[1] = 0xFF & write2;
        buf[2] = 0xFF & write3;

        int write = 0;//write 是否写入数据成功的标记
        res = hid_write(handle, buf, 64);
        sprintf_s(chstr, "write info: %02x %02x %02x ...", buf[0], buf[1], buf[2]);
        CA2T szc(std::string(chstr).c_str());
        log = (LPCTSTR)szc;
        debuglogpr(L"DebugUSB.log", log);

        if (res < 0)
        {
            path = "this device path: ";
            path += vpath.at(d).c_str();
            CA2T szc(path.c_str());
            log = (LPCTSTR)szc;
            debuglogpr(L"DebugUSB.log", log);
            debuglogpr(L"DebugUSB.log", L"------------------------Unable to write()");
            continue;
        }
        else {
            path = "this device path: ";
            path += vpath.at(d).c_str();
            CA2T szc(path.c_str());
            log = (LPCTSTR)szc;
            debuglogpr(L"DebugUSB.log", log);
            debuglogpr(L"DebugUSB.log", L"write Success------------------------");
            write = 1;//能够写入成功说明打开设备地址正确 
        }
        res = 0;

        std::string result = "";

        int num = 0;

        
        CString port;//USBHidTestThread port标识 只针对TypeC
        debuglogpr(L"DebugUSB.log", L"read start:");

        


        while (1) {
            Sleep(100);
            if (aa && bb && !Unplug) {//当前port A/B面均check时 并且USB拔出 跳到下一个接口
                port.Format(L"port:%d ,check A+B OK!", p);
                debuglogpr(L"DebugUSB.log", port);
                p++;
                aa = 0;
                bb = 0;
                //port口从1开始
                if (p == 2) {
                    write3 = 0x02;
                }
                else if (p == 3) {
                    write3 = 0x03;
                }
                else if (p == 4) {
                    write3 = 0x04;
                }
                else if (p == 5) {
                    write3 = 0x05;
                }
                else if (p == 6) {
                    write3 = 0x06;
                }
            }
            port.Format(_T("port: %d"), p);
            debuglogpr(L"DebugUSB.log", port);

            Sleep(50);
        
            if (num > 0) {
                hid_set_nonblocking(handle, 1);
                debuglogpr(L"DebugUSB.log", L"write ins");
                ::memset(buf, 0x00, sizeof(buf));
                buf[0] = 0xFF & write1;
                buf[1] = 0xFF & write2;
                buf[2] = 0xFF & write3;

                res = hid_write(handle, buf, 64);
                sprintf_s(chstr, "write info: %02x %02x %02x ...", buf[0], buf[1], buf[2]);

                CA2T szc(std::string(chstr).c_str());
                log = (LPCTSTR)szc;
                debuglogpr(L"DebugUSB.log", log);
                if (res < 0)
                {

                    debuglogpr(L"DebugUSB.log", L" ...........................................write Fail");
                    continue;
                }
                else {

                    debuglogpr(L"DebugUSB.log", L"write Success ...........................................");

                }
            }
            num++;

            ::memset(buf, 0x00, sizeof(buf));
            res = hid_read(handle, buf, sizeof(buf));


            tempStr = "read come back =";
            result = "";
            CString str;
            str.Format(_T("%d"), p);
            if (res > 0) {
                debuglogpr(L"DebugUSB.log", L"  Get the returned data:res > 0");

                for (i = 0; i < res; i++)
                {
                    sprintf_s(chstr, "%02x", buf[i]);
                    result += std::string(chstr);
                    tempStr += std::string(chstr).c_str();
                }
                debuglogpr(L"DebugUSB.log", tempStr);

                string::size_type position;
                if ((position = result.find("ad0000")) != result.npos) {

                    debuglogpr(L"DebugUSB.log", L"Not detected USB,read continue-----");
                    pthis->SetDlgItemText(IDC_A, L"");
                    Unplug = 0;
                    res = 0;
                    continue;
                }
                else if ((position = result.find("ad0001")) != result.npos) {  
                    port = str + L"checkA";
                    debuglogpr(L"DebugUSB.log", port);
                    if (aa) {//a面已经check
                        continue;
                    }

                    pthis->SetDlgItemText(IDC_A, port);  

                    pthis->GetDlgItem(IDC_A)->ShowWindow(TRUE);

                    pthis->GetDlgItem(IDC_A)->Invalidate(0);
                    Unplug = 1;
                    aa = 1;
                    portNum++;
                


                }
                else if ((position = result.find("ad0002")) != result.npos) {
                    port = str + L"checkB";
                    debuglogpr(L"DebugUSB.log", port);
                    if (bb) {//b面已经check
                        continue;
                    }                

                    pthis->SetDlgItemText(IDC_A, port);
                    pthis->GetDlgItem(IDC_A)->ShowWindow(TRUE);
                    pthis->GetDlgItem(IDC_A)->Invalidate(0);
                    Unplug = 1;
                    bb = 1;
                    portNum++;
                
                }
            }
            if (res == 0)
                debuglogpr(L"DebugUSB.log", L"REM waiting...");

            if (res < 0) {
                debuglogpr(L"DebugUSB.log", L"SET ERR=Unable to read");
                break;

            }
        }
        if (write) {
            break;
        }


        debuglogpr(L"DebugUSB.log", L"This device write success!!");

    }


    return 1;

}

-------------

if (Pid == L"0x0384") {//Pid是0x0584是spacex机种 usb2.0在3.0下面后缀也为3.  0x0384是DM usb后缀还是为2.
            debuglogpr(L"DebugUSB.log", L"DM-------");
            AfxBeginThread(&USBNewThread, (LPVOID)this, THREAD_PRIORITY_NORMAL, 0);
        }
        else {
            debuglogpr(L"DebugUSB.log", L"SPACEX-------");
            AfxBeginThread(&USBSpxThread, (LPVOID)this, THREAD_PRIORITY_NORMAL, 0);
        }

----------------

//spacex
UINT USBSpxThread(LPVOID pParam) {
    Sleep(300);
    CString porttype = L"", portpath = L"";
    CString u3btemp = L"", u2btemp = L"";
    int a = 0, b = 0, value = 0;
    typecValueTemp = 0;
    int TypecValue = 0;  //tool获取的TypeC正反面特征值
    USBTestDlg* pthis = (USBTestDlg*)pParam;
    CString log = _T("");
    int u3pass = 0;
    while (true) {
        Sleep(50);
        for (int j = 0; j < totalNum && j < 12; j++)   //遍历配置的path_Type
        {
            //if (j < (portNum * 2) && j >= (portNum - 1) * 2) {
                for (int i = 0; i < pthis->usbinfo->mUSBInfo.Index; i++)//遍历系统获取到的path_Type
                {
                    getPortTypeCValue.Format(_T("%s_%s"), pthis->usbinfo->mUSBInfo.PORTPATH[i], pthis->usbinfo->mUSBInfo.PORTTYPE[i]);//系统获取到的path_Type
                    if (readWriteTest[j].needTest)//需要测试读写速度
                    {
                        //!readWriteTest[j].isTest && readWriteTest[j].path == pthis->usbinfo->mUSBInfo.uPanReadWriteSpeed[i].UPANPATH && pthis->usbinfo->mUSBInfo.uPanReadWriteSpeed[i].speed > readWriteTest[j].speed
                        //现在不需要比较盘符
                        if (!readWriteTest[j].isTest && pthis->usbinfo->mUSBInfo.uPanReadWriteSpeed[i].speed > readWriteTest[j].speed)
                        {
                            readWriteTest[j].isTest = true;
                            log.Format(_T("ReadWriteSpeedTest:%s_%s,%c:%f m/s"), pthis->usbinfo->mUSBInfo.PORTPATH[i], pthis->usbinfo->mUSBInfo.PORTTYPE[i], pthis->usbinfo->mUSBInfo.uPanReadWriteSpeed[i].UPANPATH, pthis->usbinfo->mUSBInfo.uPanReadWriteSpeed[i].speed);
                            debuglogpr(L"DebugUSB.log", log);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    //2.0
                    if (((U2PathTest[j].Find(L"&")) != -1) && ((U2PathTest[j].Find(L"#")) != -1)) {
                        if (TcFlagTest[j]) {
                            log = _T("System TypeC 2.0 portPath: ") + getPortTypeCValue;
                            debuglogpr(L"DebugUSB.log", log);
                            u2btemp = U2PathTest[j] + _T("_") + _T("3.");//spacex 2.0 后缀也是3
                            debuglogpr(L"DebugUSB.log", L"u2bpath:" + u2btemp);

                            if (getPortTypeCValue.Find(u2btemp) != -1) {
                                debuglogpr(L"DebugUSB.log", L"compareUSB2flag");
                                if (compareUSB2flag[j] == 0) {
    
                                    if (aa || bb) {//当TypeC检测到一面时
                                        debuglogpr(L"DebugUSB.log", L"U2path:" + U2PathTest[j] + L"  U2path+1:" + U2PathTest[j + 1]);
                                        if (U2PathTest[j] == U2PathTest[j + 1]) {//保证当前TypeC是第一次检测
                                            pthis->SetDlgItemText(IDC_U2_1 + j, L"PASS");
                                            debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                                            u2find++;
                                            compareUSB2flag[j] = 1;
                                            pthis->GetDlgItem(IDC_U2_1 + j)->Invalidate(0);
                                            continue;
                                        }
        
                                    }
                                    if(aa && bb){//当TypeC检测到第二面时
                                        pthis->SetDlgItemText(IDC_U2_1 + j, L"PASS");
                                        debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                                        u2find++;
                                        compareUSB2flag[j] = 1;
                                        pthis->GetDlgItem(IDC_U2_1 + j)->Invalidate(0);
                                        continue;
                                    }
                                }
                            }
                        }
                        else//普通U盘(非typec转接)
                        {
                            log = _T("System normal USB2 portPath&portType: ") + getPortTypeCValue;

                            u2btemp = U2PathTest[j] + _T("_") + _T("3.");
                            if (getPortTypeCValue.Find(u2btemp) != -1)
                            {
                                if (compareUSB2flag[j] == 0)
                                {
                                    pthis->SetDlgItemText(IDC_U2_1 + j, L"PASS");
                                    debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                                    u2find++;
                                    compareUSB2flag[j] = 1;
                                    pthis->GetDlgItem(IDC_U2_1 + j)->Invalidate(0);
                                    continue;
                                }
                            }

                        }

                    }

                    //3.0或3.1
                    CString PN = _T("");
                    PN.Format(_T("%d"), portNum);
                    debuglogpr(L"DebugUSB.log", L"USB3ON:" + USB3ON + L";portNum:"+ PN);//USB3ON 此参数只针对是否测 不测哪个port的typec3.0,就配置对应port的数字 ——  不需要不配置就好,暂时未用到
                    if (USB3ON.Find(PN) !=-1) {//找到对应字符  该port不测3.0
                        debuglogpr(L"DebugUSB.log", PN+L" don't check 3.0");
                    }
                    else {
                        if (((U3PathTest[j].Find(L"&")) != -1) && ((U3PathTest[j].Find(L"#")) != -1))
                        {
                            if (TcFlagTest[j])//是typec转接
                            {
                                log = _T("System TypeC 3.0 portPath: ") + getPortTypeCValue;
                                debuglogpr(L"DebugUSB.log", log);
                                u3btemp = U3PathTest[j] + _T("_") + _T("3.");//spacex这个机种测出来两个地址是一样 通过系统查不出来标识
                                debuglogpr(L"DebugUSB.log", L"u3bpath:" + u3btemp);

                                if (getPortTypeCValue.Find(u3btemp) != -1)
                                {
                                    debuglogpr(L"DebugUSB.log", L"compareUSB3flag");
                                    if (compareUSB3flag[j] == 0)
                                    {
                                        if (aa || bb) {
                                            debuglogpr(L"DebugUSB.log", L"U3path:" + U3PathTest[j] + L" U3path+1:" + U3PathTest[j + 1]);
                                            if (U3PathTest[j] == U3PathTest[j + 1]) {

                                                pthis->SetDlgItemText(IDC_U3_1 + j, L"PASS");
                                                debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                                                u3find++;
                                                compareUSB3flag[j] = 1;
                                                pthis->GetDlgItem(IDC_U3_1 + j)->Invalidate(0);
                                                continue;
                                            }
                                        }
                                        if (aa && bb) {//当TypeC检测到第二面时
                                            pthis->SetDlgItemText(IDC_U3_1 + j, L"PASS");
                                            debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                                            u3find++;
                                            compareUSB3flag[j] = 1;
                                            pthis->GetDlgItem(IDC_U3_1 + j)->Invalidate(0);
                                            continue;
                                        }
                                    }
                                }
                                //}
                            }
                            else//普通U盘(非typec转接)
                            {
                                log = _T("System normal USB3 portPath&portType: ") + getPortTypeCValue;

                                u3btemp = U3PathTest[j] + _T("_") + _T("3.");
                                if (getPortTypeCValue.Find(u3btemp) != -1)
                                {
                                    if (compareUSB3flag[j] == 0)
                                    {
                                        pthis->SetDlgItemText(IDC_U3_1 + j, L"PASS");
                                        debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                                        u3find++;
                                        compareUSB3flag[j] = 1;
                                        pthis->GetDlgItem(IDC_U3_1 + j)->Invalidate(0);
                                        continue;
                                    }
                                }

                            }
                        }
                    }
                }

    /*        if (!TcFlagTest[j]) {
                log = _T("System normal USB3 portPath&portType: ") + getPortTypeCValue;

                u3btemp = U3PathTest[j] + _T("_") + _T("3.");
                if (getPortTypeCValue.Find(u3btemp) != -1)
                {
                    if (compareUSB3flag[j] == 0)
                    {
                        pthis->SetDlgItemText(IDC_U3_1 + j, L"PASS");
                        debuglogpr(L"DebugUSB.log", getPortTypeCValue + L":PASS");
                        u3find++;
                        compareUSB3flag[j] = 1;
                        pthis->GetDlgItem(IDC_U3_1 + j)->Invalidate(0);
                        continue;
                    }
                }
            }*/
            log.Format(_T("portNum:%d"), portNum);
            debuglogpr(L"DebugUSB.log", log);

        }
        a = _ttoi(U2NumTest[1]);//要测的USB 2.0个数
        b = _ttoi(U3NumTest[1]);//要测的USB 3.0个数
        if (a == 0)
        {
            u2p = true;
        }
        if (b == 0)
        {
            u3p = true;
        }
        if ((u2find == a) && (a > 0))
        {
            pthis->GetDlgItem(IDC_U2Result)->ShowWindow(TRUE);
            u2p = true;
            pthis->GetDlgItem(IDC_U2Result)->Invalidate(0);
        }
        if ((u3find == b) && (b > 0))
        {
            pthis->GetDlgItem(IDC_U3Result)->ShowWindow(TRUE);
            u3p = true;
            pthis->GetDlgItem(IDC_U2Result)->Invalidate(0);

        }
        if (u3p && u2p)
        {
            if (ReTest == 0)//复测功能开放至配置界面
            {
                CString updateStr = _T("");
                updateStr.Format(_T("Update Global set ResUSB = '1';"));
                dbUSE->UpdateDB(updateStr);
            }
            pthis->result_usb = 1;
            pthis->WriteXML_USB();
            debuglogpr(L"DebugUSB.log", L"USB ALL Test=PASS");
            return 1;
        }
    }


}

该需求USBHidTestThread和USBSpxThread是相辅相成的

libusb 和 hidapi 库编译和使用 阅读详情

相关推荐

我的CANFD数据盒(上位机软件实战:从QT-HID到数据回放)

本文详细介绍了使用QT开发CANFD上位机软件的实战经验,涵盖USB-HID通信、波特率配置、数据管理等核心技术。通过优化设备枚举、异步数据收发和智能波特率预设,实现了稳定高效的CANFD数据处理。文章还分享了多线程安全、内存管理等性能优化技巧,为嵌入式开发者提供了一套完整的QT开发解决方案。

weixin_30733003的博客 39

USB学习:hidapi库使用

hidapi是一个开源的操作 HID 设备的库,使用 C 语言实现,适用于 Windows、Linux 和 Mac OSX 平台。注意,这个库是针对 HID 设备的,其它 USB 设备(如 U 盘)不一定适合。

李迟的专栏 2万+

跨平台HID设备通信开发库hidapi详解

在现代计算机系统中,HID(Human Interface Device,人机接口设备)作为操作系统与用户之间交互的核心媒介,广泛应用于键盘、鼠标、游戏手柄等输入设备。HID协议基于USB规范设计,定义了设备与主机之间标准化的数据交换机制,使得设备无需安装专用驱动即可即插即用。HID设备是一种遵循HID类规范的输入设备,其核心功能是向主机发送或接收数据报告(Report)。

weixin_42610010的博客 1707

QT调用HIDAPI进行 USB-HID设备通信

QT 调用hidapi进行USBhid设备通信,例如STM32的HID和esp32的hid设备通信

weixin_68016945的博客 9522

基于MFC编写的读写USB_HID设备数据程序(供参考学习)

本文档给了一个基于MFC来编写读写USB-HID设备数据的参考程序,详细介绍了编写思路,从宏观的角度实现了HID枚举成的设备与PC机建立通信的过程,大家可以参考学习。

hidapi是一个开源的操作 HID 设备的库

hidapi是一个开源的操作 HID 设备的库

USB HID学习:一点开发记录

某天,曾经的前同事找我,说有个USB项目。因为知道我当时离职在找工作,于是转给我,然后介绍客户给我。

李迟的专栏 5319

MFC下HID设备读写

MFC下HID的上位机程序 包括打开设备、关闭设备和文件的读写操作 已经封装好DLL 修改VID和PID 可以直接使用 ,MFC包括IO操作,单通道读写和全部通道读写,波形显示AD数据,界面美观

编译错误LNK1104:无法打开文件“XXX.LIB”

今天遇到这样一个编译问题,程序报错 编译错误LNK1104:无法打开文件“XXX.LIB” 这个lib分明就在我设置的路径下,也没有正在使用,不知道为什么会报这个错误。 然后在网上搜索一番,找到了解决方案: 在工程属性的general中,将“user of MFC"选项设置为”use MFC in a shared dll“. 特此记录,以防止以后又遇到这个错误,但是为什

zero_226的专栏 4012

WINCC8.1工业组态软件安装与授权配置指南

SCADA系统作为工业自动化控制的核心平台,通过实时数据采集与监控实现生产流程可视化。WINCC作为西门子旗舰级组态软件,其8.1版本凭借稳定的运行时环境在汽车制造、流程工业等领域广泛应用。本文从工业控制系统软件安装规范切入,重点解析WINCC8.1与Automation License Manager的协同工作原理,详细说明包括系统环境检查、安装包校验、授权文件配置等关键技术环节。针对工程实施中常见的内存配置不足、授权管理器报错等典型问题,提供经过现场验证的解决方案,特别适用于需要进行产线监控系统升级维护

cqwf95925的博客 1671

Quartus ||———基于Verilog HDL的数字秒表设计实验

Quartus ||———基于Verilog HDL的数字秒表设计实验一、实验目的二、实验步骤(一)新建工程(二)添加设计文件(三)综合分析与功能仿真1、综合分析2、功能仿真 一、实验目的 用Verilog HDL设计一个数字跑表,所需引脚和功能如下: 二、实验步骤 (一)新建工程 在创建好工程名称后,选定芯片类型 (二)添加设计文件 新建Verilog文件,键入代码如下 module n_clk_top( input clk, input rese

TBMmagic的博客 5530

【QT】windows下QT使用HIDAPI进行简单读写

上期讲到QT添加HIDAPI的库,这次来讲一下如何使用HIDAPI库函数来进行HIDUSB设备的读取描述符和简单的读写。//非必要函数,调用hid_enumerate()和hid_open()都会自动调用它//释放hidapi/**hidapi信息结构*/structhid_device_info{/**设备路径*/char*path;/**序列号*/wchar_t*serial_number;以上就是简单的hidapi收发消息操作,若有错误,欢迎指出。......

weixin_45381001的博客 8446

Qt数据导出实战:从SQLite到CSV的完整流程(附内存优化技巧)

本文详细介绍了在Qt框架下,将SQLite数据库中的数据高效导出为CSV格式的完整流程。针对大数据量场景,重点分享了分块读取、流式写入等内存优化技巧,有效解决了嵌入式或资源受限环境中导出功能的内存占用与性能瓶颈问题,并提供了健壮的代码实现方案。

weixin_29313547的博客 346

HIDAPI:跨平台USB和蓝牙HID设备接口库

HIDAPI是一个跨平台的库,旨在帮助应用程序与Windows、Linux、FreeBSD和macOS上的USB和蓝牙HID类设备进行交互。HIDAPI不仅支持构建为共享库(如`.so`、`.dll`或`.dylib`),还可以通过添加单个源文件和头文件直接嵌入到目标应用程序中。这一灵活性使得HIDAPI成为开发者在多平台环境下处理HID设备的理想选择。 ## 项目技术分析 HIDAPI通过四...

gitblog_01010的博客 1607

TIMER-XL:突破长上下文限制的Transformer时序预测新范式

本文深入解析了清华大学提出的TIMER-XL模型,这是一种突破长上下文限制的Transformer时序预测新范式。它采用Decoder-only架构与补丁级生成技术,并创新性地引入TimeAttention机制,有效解决了传统模型在处理海量历史数据时面临的“上下文瓶颈”问题,显著提升了长序列预测的精度与稳定性。

weixin_28340315的博客 449

手把手教你用Copilot插件在Obsidian里免费接入DeepSeek-R1(附硅基流动API密钥获取)

本文详细介绍了如何通过Copilot插件在Obsidian中免费接入DeepSeek-R1模型,实现智能知识管理。从硅基流动API密钥获取到插件配置,再到高级功能调优和实战应用技巧,手把手教你打造AI驱动的个人知识库。

weixin_33686714的博客 2830

实践 C++ MFC界面读写USB HID设备数据程序

在开发了一个多线程USB烧写程序后,得到新的任务,要将HID的内容放到里面,没有人带着做细致的讲解,靠自己自生自灭:   1, 什么是HID? (项目要的急,没有什么了解就开始了!只知道,在Windows-&gt;DeviceManager下面有时候找COM端口的时候,会去人体输入学设备里面找,里面有鼠标键盘之类的HID,具体是啥还不知道。)HID: 猜想是 Hardware ID,用来标记...

Jackie_Kilby的博客 7206

Arduino ESP8266自定义配置分区表

ESP8266自定义分区表配置 随着项目的不断开发,项目文件也不断在增大,在没有考虑更换主硬件的条件下,最大开发利用有限资源势在必行,所以今天带来ESP8266自定义分区表的配置。 我这里以版本:2.7.4版本为例,后面的版本也是支持的。 注意:自定义分区表特别要注意和你的硬件相对应,flash芯片的大小决定这个分区是否有效,否则有意想不到的事情发现。 自定义分区表的几个重要参数 /* Flash Split for 4M chips */ /* sketch @0x40200000 (~1019K

perseverance51博客 1727

【QT】windows下QT使用HIDAPI

使用HIDAPI库函数来进行HID USB设备的读取描述符和简单的读写。

小曹的博客 6935

树冠体积计算之体元累加法

因为是自己之前研究的一个方向,就复现了一下论文中的这个方法,在此正好记录一下。 文章目录一、简介二、代码实现(MATLAB)三、小结 一、简介 简而言之,其实就是一句话,即以固定大小的体元模拟不规则的树冠形状。按照论文中的思路主要就是将树冠沿树高方向以 k 为步长进行等距离分段,把每一段树冠的点投影到垂直于树高方向的平面上,再对该平面划分成大小为 k × k 的像元,根据投影到各个像元内点的数量,判断该像元的有效性,统计有效像元的数量 T,则树冠体积为 T 个 k × k × k 的体元之和。如下图所示:

dayuhaitang1的博客 2612

Python学习第32天:Web前端入门

本文介绍了Web前端开发三大核心技术:HTML、CSS和JavaScript。首先概述了HTML的发展历程和HTML5新特性,详细讲解了常用HTML标签如文本、列表、链接、图像、表格、表单等。其次介绍了CSS的基础语法、选择器、颜色字体设置、盒子模型和布局定位方法。最后简要提及JavaScript为网页添加交互功能的作用。文章为Python开发者提供了前端技术的基础知识,帮助理解网页的结构、样式和行为实现原理。

tigerhhzz的博客 1919

C++ MFC界面读写USB HID设备数据程序

发一个简单易用的界面,用来对USB HID设备(比如说游戏手柄,控制面板等)读写数据,一般情况下面板上有一些LED,可以帮助我们测试读写是否正确。另外,需要可以修改vendorID和prodcutID,这样一个界面,可以用于测试多个HID设备。过程分成3步:1: 列举出所有的HID设备,2: 循环读取HID设备数据,3: 向HID设备写数据,下面我把三部分的程序单独分开,方便大家学习!在...

FLY_THINK2012的博客 1478

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

linux hid与标准key值关系,键盘驱动失效、代码32、被禁用(HID Keyboard Device、PS/2标准键盘)...

状态描述:某天下午win10更新后重启,突然无法输入PIN码解锁,后来发现整个键盘失灵。鼓弄了几个小时才找到解决方法,记录下来:1、解锁打开右下角屏幕键盘,输入密码(锁屏用手机拍照,见谅) 2、查看问题原因在左下角Windows键上鼠标右键,选择设备管理器,发现键盘下的HID Keyboard Device和PS/2标准键盘上都显示黄色感叹号(已经修好了 就不故意弄坏截图了),双击提示设备...

weixin_42452301的博客 3482

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

VC HID开发笔记

1、头文件包含,库文件链接  在VC中开发HID应用程序时,需要包含setupapi.h和hidsdi.h,包含方式必须为extern "C",如下所示: extern "C" { // Declare the C libraries used #include "set

1万+

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

上一篇: 生成指定名称的二维码图片
下一篇: CFileFind遍历文件
JamieLe
博客等级 码龄10年 3粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值