Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stdio.h>
00010 #include <wchar.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013 #include <hidapi.h>
00014
00015
00016 #include <unistd.h>
00017
00018
00019 int main(int argc, char* argv[])
00020 {
00021 int res;
00022 unsigned char buf[256];
00023 #define MAX_STR 255
00024 wchar_t wstr[MAX_STR];
00025 hid_device *handle;
00026 int i;
00027
00028 struct hid_device_info *devs, *cur_dev;
00029
00030 devs = hid_enumerate(0x0, 0x0);
00031 cur_dev = devs;
00032 while (cur_dev) {
00033 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);
00034 printf("\n");
00035 printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
00036 printf(" Product: %ls\n", cur_dev->product_string);
00037 printf(" Release: %hx\n", cur_dev->release_number);
00038 printf(" Interface: %d\n", cur_dev->interface_number);
00039 printf("\n");
00040 cur_dev = cur_dev->next;
00041 }
00042 hid_free_enumeration(devs);
00043
00044
00045 memset(buf,0x00,sizeof(buf));
00046 buf[0] = 0x01;
00047 buf[1] = 0x81;
00048
00049
00050
00051
00053 handle = hid_open(0x054c, 0x0268, NULL);
00054 if (!handle) {
00055 printf("unable to open device\n");
00056 return 1;
00057 }
00058
00059
00060 wstr[0] = 0x0000;
00061 res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
00062 if (res < 0)
00063 printf("Unable to read manufacturer string\n");
00064 printf("Manufacturer String: %ls\n", wstr);
00065
00066
00067 wstr[0] = 0x0000;
00068 res = hid_get_product_string(handle, wstr, MAX_STR);
00069 if (res < 0)
00070 printf("Unable to read product string\n");
00071 printf("Product String: %ls\n", wstr);
00072
00073
00074 wstr[0] = 0x0000;
00075 res = hid_get_serial_number_string(handle, wstr, MAX_STR);
00076 if (res < 0)
00077 printf("Unable to read serial number string\n");
00078 printf("Serial Number String: (%d) %ls", wstr[0], wstr);
00079 printf("\n");
00080
00081
00082 wstr[0] = 0x0000;
00083 res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
00084 if (res < 0)
00085 printf("Unable to read indexed string 1\n");
00086 printf("Indexed String 1: %ls\n", wstr);
00087
00088
00089 hid_set_nonblocking(handle, 1);
00090
00091
00092
00093 res = hid_read(handle, buf, 17);
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 memset(buf,0,sizeof(buf));
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 res = 0;
00146 while (true) {
00147 res = hid_read(handle, buf, sizeof(buf));
00148 if (res == 0)
00149 printf("waiting...\n");
00150 if (res < 0)
00151 printf("Unable to read()\n");
00152 if (res > 0) {
00153 printf("Data read:\n ");
00154
00155 for (i = 0; i < res; i++)
00156 printf("%02hhx ", buf[i]);
00157 printf("\n");
00158 }
00159
00160 usleep(50*1000);
00161 }
00162
00163
00164
00165
00166 return 0;
00167 }
00168
00169