Created
July 9, 2013 20:55
-
-
Save anonymous/5961223 to your computer and use it in GitHub Desktop.
Sample Code from terminal28.blogspot.com showing how to write a Qt 5.1.0 application that uses Signal11's HIDAPI library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
qDebug() << "Hi"; | |
int res; | |
unsigned char buf[256]; | |
#define MAX_STR 255 | |
wchar_t wstr[MAX_STR]; | |
hid_device *handle; | |
int i; | |
#ifdef WIN32 | |
UNREFERENCED_PARAMETER(argc); | |
UNREFERENCED_PARAMETER(argv); | |
#endif | |
struct hid_device_info *devs, *cur_dev; | |
if (hid_init()) | |
return -1; | |
devs = hid_enumerate(0x0, 0x0); | |
cur_dev = devs; | |
while (cur_dev) { | |
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number); | |
printf("\n"); | |
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string); | |
printf(" Product: %ls\n", cur_dev->product_string); | |
printf(" Release: %hx\n", cur_dev->release_number); | |
printf(" Interface: %d\n", cur_dev->interface_number); | |
printf("\n"); | |
cur_dev = cur_dev->next; | |
} | |
hid_free_enumeration(devs); | |
// Set up the command buffer. | |
memset(buf,0x00,sizeof(buf)); | |
buf[0] = 0x01; | |
buf[1] = 0x81; | |
// Open the device using the VID, PID, | |
// and optionally the Serial number. | |
////handle = hid_open(0x4d8, 0x3f, L"12345"); | |
handle = hid_open(0x4d8, 0x3f, NULL); | |
if (!handle) { | |
printf("unable to open device\n"); | |
return 1; | |
} | |
hid_close(handle); | |
/* Free static HIDAPI objects. */ | |
hid_exit(); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment