访问Hid设备,并进行读写操作
目前这个代码可以读取到设备,但是貌似对设备创建读写的时候回发生报错,希望知道如何处理的读者能告知。
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include "hidapi.h"
// Headers needed for sleeping.
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
int get_error();
int main(int argc, char* argv[]){
myUsbDeviceOpen(&handle, &hReader, &hWriter, 0x0461, 0x010);
get_error();
for (size_t i = 0; i < 100; i++)
{
myUsbDeviceRead(handle, buf, 10);
if (get_error() != 0)
break;
for (size_t j = 0; j < 10; j++)
{
printf("read 0x%x\t", buf[j]);
}
printf("\n");
}