Exemplo n.º 1
0
int CorsairTemp::SetTempLimit(int limit)
{//2
	memset(cl->buf,0x00,sizeof(cl->buf));
	// Read fan Mode
	cl->buf[0] = 0x05; // Length
	cl->buf[1] = cl->CommandId++; // Command ID
	cl->buf[2] = WriteTwoBytes; // Command Opcode
	cl->buf[3] = TEMP_Limit; // Command data...
	cl->buf[4] = limit & 0x00FF;
	cl->buf[5] = limit >> 8;

	int res = hid_write(cl->handle, cl->buf, 11);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to write() %s\n", (char*)hid_error(cl->handle) );
		return -1;
	}

	res = cl->hid_read_wrapper(cl->handle, cl->buf);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to read() %s\n", (char*)hid_error(cl->handle) );
		return -1;
	}

	return 0;
}
Exemplo n.º 2
0
int mcp_panel_open() {
	int res = 0;

	mcpHandle = hid_open(VENDOR_ID, MCP_PROD_ID, NULL);

	if (!mcpHandle) {
		XPLMDebugString("-> CP: mcp_driver.panel_open: unable to open device.\n");
		return -1;
	}
	wchar_t wstr[MAX_STR];
	res = hid_get_manufacturer_string(mcpHandle, wstr, MAX_STR);
    sprintf(tmp, "-> CP: mcp_driver.panel_open: Manufacturer String %ls\n", wstr);
	XPLMDebugString(tmp);

	hid_set_nonblocking(mcpHandle, 1);
	res = hid_read(mcpHandle, mcp_in_buf, MCP_IN_BUF_SIZE);
	if (res < 0) {
	    sprintf(tmp, "-> CP: mcp_driver.panel_open: Error: %ls\n", hid_error(mcpHandle));
		XPLMDebugString(tmp);
	}
	res = hid_send_feature_report(mcpHandle, mcp_all_on_panel, sizeof(mcp_all_on_panel));
	res = hid_send_feature_report(mcpHandle, mcp_course_left, sizeof(mcp_course_left));
	res = hid_send_feature_report(mcpHandle, mcp_course_right, sizeof(mcp_course_right));
	res = hid_send_feature_report(mcpHandle, mcp_ias_mach, sizeof(mcp_ias_mach));
	res = hid_send_feature_report(mcpHandle, mcp_heading, sizeof(mcp_heading));
	res = hid_send_feature_report(mcpHandle, mcp_altitude, sizeof(mcp_altitude));
	res = hid_send_feature_report(mcpHandle, mcp_vert_speed, sizeof(mcp_vert_speed));
	if (res < 0) {
	    sprintf(tmp, "-> CP: mcp_driver.panel_open: Error: %ls\n", hid_error(mcpHandle));
		XPLMDebugString(tmp);
	}
	return 0;
}
Exemplo n.º 3
0
int CorsairTemp::GetTempLimit()
{//2
	memset(cl->buf,0x00,sizeof(cl->buf));
	// Read fan Mode
	cl->buf[0] = 0x03; // Length
	cl->buf[1] = cl->CommandId++; // Command ID
	cl->buf[2] = ReadTwoBytes; // Command Opcode
	cl->buf[3] = TEMP_Limit; // Command data...

	int res = hid_write(cl->handle, cl->buf, 11);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to write() %s\n", (char*)hid_error(cl->handle) );
		//return -1;
	}

	res = cl->hid_read_wrapper(cl->handle, cl->buf);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to read() %s\n", (char*)hid_error(cl->handle) );
		//return -1;
	}

	int limit = cl->buf[5]<<8;
	limit += cl->buf[4];

	return limit;
}
Exemplo n.º 4
0
Arquivo: dbg_mac.c Projeto: arv3/edbg
//-----------------------------------------------------------------------------
int dbg_dap_cmd(uint8_t *data, int size, int rsize)
{
  char cmd = data[0];
  int res;

  memset(hid_buffer, 0xff, report_size + 1);

  hid_buffer[0] = 0x00; // Report ID
  memcpy(&hid_buffer[1], data, rsize);

  res = hid_write(handle, hid_buffer, report_size + 1);
  if (res < 0)
  {
    printf("Error: %ls\n", hid_error(handle));
    perror_exit("debugger write()");
  }

  res = hid_read(handle, hid_buffer, report_size + 1);
  if (res < 0)
    perror_exit("debugger read()");

  check(res, "empty response received");

  check(hid_buffer[0] == cmd, "invalid response received");

  res--;
  memcpy(data, &hid_buffer[1], (size < res) ? size : res);

  return res;
}
Exemplo n.º 5
0
void print_string(unsigned char data[]) {
    int r = 0, tr = 0, ind = 2;
    int len = data[0] - 2;
    const char *str = NULL;

    while (len > 0) {
        if (ind == 8) {
            r = hid_read(dev, data, 8);
            if (r < 0) {
                fatal("error reading data (%ls)", hid_error(dev));
            }
            if (tr != 8) {
                fatal("expected 8 bytes, received: %d", tr);
            }
            ind = 0;
        }
        str = decode_byte(data[ind]);
        if (strlen(str) > 1) {
            printf("<%s>", str);
        } else {
            printf("%s", str);
        }
        len--;
        ind++;
    }
}
Exemplo n.º 6
0
void usb_write(unsigned char data[8]) {
    int r = hid_write(dev, data, 8);
    if (r < 0) {
        fatal("error writing data (%ls)", hid_error(dev));
    }
    usleep(30 * 1000);
}
Exemplo n.º 7
0
int boca_hid_write(boca_hid_printer_t *self, char *data, size_t byte_to_write) {
    if (!self->device)
        return 0;
    int byte_written = 0;
    while ((*data) != '\0') {
        char *buf;
        size_t byte_to_copy = self->output_length;
        byte_to_copy--;
        buf = calloc(self->output_length, sizeof(char));
        byte_to_copy = byte_to_copy > strlen(data) ? strlen(data) : byte_to_copy;
        if (byte_to_copy == 0)break;
        memcpy(buf + 1, data, byte_to_copy);
        int ret = hid_write(self->device, (const unsigned char *) buf, self->output_length);
        if (ret == -1) {
            zsys_warning("hid printer: can not write code: %d msg: %ls", GetLastError(),
                         hid_error(self->device));
            free(buf);
            break;
        }
        data += byte_to_copy;
        byte_written += ret;
        free(buf);
    }
    return byte_written;
}
Exemplo n.º 8
0
int cb_panel_open() {
	printf("\n\n\n\n\n\n\n\n\n\n\n");
	int res = 0;

	cbHandle = hid_open(CB_VENDOR_ID, CB_PROD_ID, NULL);

	if (!cbHandle) {
		printf("-> CP: cb_driver.panel_open: unable to open device.\n");
		return -1;
	}
	wchar_t wstr[MAX_STR];
	res = hid_get_manufacturer_string(cbHandle, wstr, MAX_STR);
	sprintf(tmp, "-> CP: cb_driver.panel_open: Manufacturer String %ls\n", wstr);
    printf(tmp);

	cb_panel_read_non_blocking(tempInbuf);
	cb_panel_read_non_blocking(tempInbuf);
	cb_panel_read_non_blocking(tempInbuf);
	res = cb_panel_write(cb_blank_panel);
//		res = hid_send_feature_report(cbHandle, cb_blank_panel, CB_OUT_BUF_SIZE);
	if (res < 0) {
		sprintf(tmp, "-> CP: cb_driver.panel_open: Error: %ls\n", hid_error(
				cbHandle));
		printf(tmp);
	}
	return 0;
}
void HidDevice::sendFeatureReport(uint8_t reportId, const ByteString& data)
{
    ByteString reportBuf = ByteString(1, reportId) + data;
    int r = hid_send_feature_report(devHandle, reportBuf.data(), reportBuf.size());
    if(r<0)
    {
        std::string errorString;
        utf16BufferToUtf8String(errorString, hid_error(devHandle));
        throw HidDeviceError(errorString);
    }
}
Exemplo n.º 10
0
int mcp_panel_read_non_blocking(unsigned char *buf) {
	int res = 0;
	if (mcpHandle) {
		hid_set_nonblocking(mcpHandle, 1);
		res = hid_read(mcpHandle, buf, MCP_IN_BUF_SIZE);
		if (res < 0) {
		    sprintf(tmp, "-> CP: mcp_driver.panel_read_non_blocking: Error: %ls\n", hid_error(mcpHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Exemplo n.º 11
0
int cb_panel_write(unsigned char buf[]) {
	int res = 0;
	if (cbHandle) {
		res = hid_write(cbHandle, buf, CB_OUT_BUF_SIZE);
		if (res < 0) {
			sprintf(tmp, "-> CP: cb_driver.panel_write: Error: %ls\n",
					hid_error(cbHandle));
			printf(tmp);
		}
	}
	return res;
}
Exemplo n.º 12
0
int cb_panel_write_empty() {
	int res = 0;
	unsigned char cb_empty_buf[0];
	if (cbHandle) {
		res = hid_send_feature_report(cbHandle, cb_empty_buf, 0);
		if (res < 0) {
			sprintf(tmp, "-> CP: cb_driver.panel_write_empty: Error: %ls\n",
					hid_error(cbHandle));
			printf(tmp);
		}
	}
	return res;
}
Exemplo n.º 13
0
int cb_panel_read_blocking(unsigned char *buf) {
	int res = 0;
	if (cbHandle) {
		hid_set_nonblocking(cbHandle, 0);
		res = hid_read_timeout(cbHandle, buf, CB_IN_BUF_SIZE, 100);
		if (res < 0) {
			sprintf(tmp, "-> CP: cb_driver.panel_read_blocking: Error: %ls\n",
					hid_error(cbHandle));
			printf(tmp);
		}
	}
	return res;
}
ByteString HidDevice::getFeatureReport(uint8_t reportId)
{
    uint8_t buf[MAX_REPORT_LEN+1];
    buf[0] = reportId;
    int r = hid_get_feature_report(devHandle, buf, sizeof(buf));
    if(r<0)
    {
        std::string errorString;
        utf16BufferToUtf8String(errorString, hid_error(devHandle));
        throw HidDeviceError(errorString);
    }
    return ByteString(buf+1, r-1);
}
Exemplo n.º 15
0
int CorsairTemp::GetTempSensors()
{//1
	memset(cl->buf,0x00,sizeof(cl->buf));
	// Read fan Mode
	cl->buf[0] = 0x03; // Length
	cl->buf[1] = cl->CommandId++; // Command ID
	cl->buf[2] = ReadOneByte; // Command Opcode
	cl->buf[3] = TEMP_CountSensors; // Command data...

	int res = hid_write(cl->handle, cl->buf, 11);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to write() %s\n", (char*)hid_error(cl->handle) );
		//return -1;
	}

	res = cl->hid_read_wrapper(cl->handle, cl->buf);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to read() %s\n", (char*)hid_error(cl->handle) );
		//return -1;
	}

	return cl->buf[2];
}
Exemplo n.º 16
0
LPCUSBSIO_API const wchar_t *I2C_Error(LPC_HANDLE handle, int32_t status)
{
    LPCUSBSIO_I2C_Ctrl_t *dev = (LPCUSBSIO_I2C_Ctrl_t *) handle;
    const wchar_t *retStr = NULL;
    
    if (validHandle(handle) != 0) 
    {
        if ((status == LPCUSBSIO_OK) || (LPCUSBSIO_ERR_HID_LIB == status)) 
        {
            retStr = hid_error(dev->hidDev);
        }
        else 
        {
            retStr = GetErrorString(status);
        }
    }
    else 
    {
        retStr = hid_error(NULL);
    }
    
    return retStr;
}
Exemplo n.º 17
0
int mcp_panel_close() {
	int res = 0;
	if (mcpHandle) {
		res = hid_send_feature_report(mcpHandle, mcp_blank_panel, sizeof(mcp_blank_panel));
		if (res < 0) {
		    sprintf(tmp, "-> CP: mcp_driver.panel_close: Error: %ls\n", hid_error(mcpHandle));
			XPLMDebugString(tmp);
		}
		hid_close(mcpHandle);
		XPLMDebugString("-> CP: mcp_driver.panel_close: panel closed.\n");
		mcpHandle = NULL;
	}
	return res;
}
Exemplo n.º 18
0
int CorsairTemp::SelectSensor(int index)
{
	memset(cl->buf,0x00,sizeof(cl->buf));

	cl->buf[0] = 0x04; // Length
	cl->buf[1] = cl->CommandId++; // Command ID
	cl->buf[2] = WriteOneByte; // Command Opcode
	cl->buf[3] = TEMP_SelectActiveSensor; // Command data...
	cl->buf[4] = index;

	int res = hid_write(cl->handle, cl->buf, 11);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to write() %s\n", (char*)hid_error(cl->handle) );
		//return -1;
	}

	res = cl->hid_read_wrapper(cl->handle, cl->buf);
	if (res < 0) {
		fprintf(stderr, "Error: Unable to read() %s\n", (char*)hid_error(cl->handle) );
		//return -1;
	}

	return cl->buf[2];
}
Exemplo n.º 19
0
void vrpn_HidInterface::send_feature_report(size_t bytes, const vrpn_uint8 *buffer) {
	if (!_working) {
		fprintf(stderr,"vrpn_HidInterface::send_feature_report(): Interface not currently working\n");
		return;
	}

	int ret = hid_send_feature_report(_device, buffer, bytes);
	if (ret == -1) {
		fprintf(stderr, "vrpn_HidInterface::send_feature_report(): failed to send feature report\n");
		const wchar_t * errmsg = hid_error(_device);
		if (errmsg) {
			fprintf(stderr, "vrpn_HidInterface::send_feature_report(): error message: %ls\n", errmsg);
		}
	} else {
		//fprintf(stderr, "vrpn_HidInterface::send_feature_report(): sent feature report, %d bytes\n", static_cast<int>(bytes));
	}
}
Exemplo n.º 20
0
int mcp_panel_write(unsigned char buf[]) {
	int res = 0;
	int i = 0;
	unsigned char tmpBuffer[MCP_OUT_BUF_SIZE];
	for (i = 0; i < MCP_OUT_BUF_SIZE; i++) {
		tmpBuffer[i] = buf[i];
	}
	if (mcpHandle) {
		res = hid_send_feature_report(mcpHandle, tmpBuffer,
				sizeof(tmpBuffer));
		if (res < 0) {
		    sprintf(tmp, "-> CP: mcp_driver.panel_write: Error: %ls\n", hid_error(mcpHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Exemplo n.º 21
0
bool CDevice::Selftest()
{
	int ret;

	hidbuf[0] = ID_SELFTEST;
	hidbuf[1] = 0;
	ret = hid_send_feature_report(handle, hidbuf, 2);
	if (ret == -1) {
		wprintf(L"error: %s\n", hid_error(handle));
	}
	uint32_t start = getTicks();
	do {
	} while ((getTicks() - start) < 1000);

	hidbuf[1] = 0xFF;
	ret = hid_get_feature_report(handle, hidbuf, 2);
	printf("self-test code $%02X\n", hidbuf[1]);
	return(hidbuf[1] == 0 ? true : false);
}
Exemplo n.º 22
0
int operate_relay(hid_device *handle,unsigned char relay, unsigned char state){
   unsigned char buf[9];// 1 extra byte for the report ID
   int res;

   buf[0] = 0x0; //report number
   buf[1] = state;
   buf[2] = relay;
   buf[3] = 0x00;
   buf[4] = 0x00;
   buf[5] = 0x00;
   buf[6] = 0x00;
   buf[7] = 0x00;
   buf[8] = 0x00;
   res = hid_write(handle, buf, sizeof(buf));
   if (res < 0) {
      fprintf(stderr,"Unable to write()\n");
      fprintf(stderr,"Error: %ls\n", hid_error(handle));
   }
   return(res);
}
Exemplo n.º 23
0
bool CDevice::GenericWrite(int reportid, uint8_t *buf, int size, bool initCS, bool holdCS)
{
	int ret;

	if (size > SPI_WRITEMAX) {
		printf("Write too big.\n");
		return(false);
	}
	hidbuf[0] = reportid;
	hidbuf[1] = size;
	hidbuf[2] = initCS,
	hidbuf[3] = holdCS;
	if (size)
		memcpy(hidbuf + 4, buf, size);
	ret = hid_send_feature_report(handle, hidbuf, 4 + size);
	if (ret == -1) {
		wprintf(L"error: %s\n", hid_error(handle));
	}
	return(ret >= 0);
}
Exemplo n.º 24
0
int mp_panel_open() {
	int res = 0;

	mpHandle = hid_open(VENDOR_ID, MP_PROD_ID, NULL);

	if (!mpHandle) {
		XPLMDebugString("-> CP: mp_driver.panel_open: unable to open device.\n");
		return -1;
	}
	wchar_t wstr[MAX_STR];
	res = hid_get_manufacturer_string(mpHandle, wstr, MAX_STR);
    sprintf(tmp, "-> CP: mp_driver.panel_open: Manufacturer String %ls\n", wstr);
	XPLMDebugString(tmp);

	res = hid_send_feature_report(mpHandle, mp_blank_panel, MP_OUT_BUF_SIZE);
	if (res < 0) {
	    sprintf(tmp, "-> CP: mp_driver.panel_open: Error: %ls\n", hid_error(mpHandle));
		XPLMDebugString(tmp);
	}
	return 0;
}
Exemplo n.º 25
0
void read_pedals() {
    int r = 0, i = 0;
    unsigned char query[8] = {0x01, 0x82, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00};
    unsigned char response[8];

    for (i = 0 ; i < 3 ; i++) {
        query[3] = i + 1;
        usb_write(query);
        r = hid_read(dev, response, 8);
        if (r < 0) {
            fatal("error reading data (%ls)", hid_error(dev));
        }
        printf("[switch %d]: ", i + 1);
        switch (response[1]) {
            case 0:
                printf("unconfigured");
                break;
            case 1:
            case 0x81:
                print_key(response);
                break;
            case 2:
                print_mouse(response);
                break;
            case 3:
                print_key(response);
                printf(" ");
                print_mouse(response);
                break;
            case 4:
                print_string(response);
                break;
            default:
                fprintf(stderr, "Unknown response:\n");
                debug_arr(response, 8);
                return;
        }
        printf("\n");
    }
}
Exemplo n.º 26
0
enum BOCA_FEATURE_REPORT_STATUS boca_hid_status_feature(boca_hid_printer_t *self) {
    enum BOCA_FEATURE_REPORT_STATUS ret = BOCA_REPORT_UNKNOWN;
    if (!self->device)
        return ret;
    unsigned char *buf = (unsigned char *) calloc(PACKET_SIZE, sizeof(byte));
    buf[0] = 0x0;
    int byte_read = hid_get_feature_report(self->device, buf, sizeof(byte) * PACKET_SIZE);
    if(self->verbose)
        zsys_debug("hid printer: read %d bytes from feature port", byte_read);
    if (byte_read > 0) {
        if (byte_read == 2)
            ret = (enum BOCA_FEATURE_REPORT_STATUS) (int) buf[1];
        else
            ret = (enum BOCA_FEATURE_REPORT_STATUS) (int) buf[0];
        if (self->verbose) {
            zsys_debug("hid printer: BOCA status %s", boca_feature_report_display(ret));
        }

    } else {
        zsys_warning("hid printer: could not read from BOCA %ls", hid_error(self->device));
    }
    return ret;
}
Exemplo n.º 27
0
int main(int argc, const char * argv[])
{
    // handle command line args
    char *cvalue = NULL;
    int index;
    char *command;

    // buffer for TX command to device
    static unsigned char buf[16];
    
    // references to device
    int res;
    hid_device *handle;
	struct hid_device_info *devs, *cur_dev;
	
    // find all devices matching Vendor ID and Product ID
	devs = hid_enumerate(0x0fc5, 0xb080);
	cur_dev = devs;	

    // display all matching devices
	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("\n");
		cur_dev = cur_dev->next;
	}
	
    hid_free_enumeration(devs);
    
    
    /* Open the device using the VID, PID,
       and optionally the Serial number.
       
     // handle = hid_open(0x4d8, 0x3f, "12345");
        OR
     // handle = hid_open(0x4d8, 0x3f, NULL);
    
     My Delcom device is 0fc5 b080
	 */
    
    handle = hid_open(0x0fc5, 0xb080, NULL);
	
    if (!handle) {
		printf("unable to open device\n");
 		return 1;
	}

    // Begin parsing the command line options
    if (argc != 2)
		fprintf(stderr, "Usage: %s <color>\n", argv[0]);
	else {
    
        // Toggle LED 
        if (strcmp(argv[1],"green") == 0) {
            // turn others off 
            res = hid_write(handle, red_off, 16);
            res = hid_write(handle, yellow_off, 16);
            //set green
            res = hid_write(handle, green, 16);
            printf("setting Green LED...\n");
        }
        if (strcmp(argv[1],"yellow") == 0) {
            // turn others off 
            res = hid_write(handle, green_off, 16);
            res = hid_write(handle, red_off, 16);
            //set yellow
            res = hid_write(handle, yellow, 16);
            printf("setting Yellow LED...\n");
        }
        if (strcmp(argv[1],"red") == 0) {    
            // turn others off 
            res = hid_write(handle, green_off, 16);
            res = hid_write(handle, yellow_off, 16);
            //set red
            res = hid_write(handle, red, 16);
            printf("setting Red LED...\n");
        }
        if (strcmp(argv[1],"off") == 0) {    
            // all off
            res = hid_write(handle, green_off, 16);
            res = hid_write(handle, yellow_off, 16);
            res = hid_write(handle, red_off, 16);
            printf("setting all LED off...\n");
        }    
        
        if (res < 0) {
            printf("Unable to set LED\n");
            printf("Error: %ls\n", hid_error(handle));
        }
    }         
    return 0;
}
Exemplo n.º 28
0
int main(int argc, char* argv[])
{
	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;
	}

	// Read the Manufacturer String
	wstr[0] = 0x0000;
	res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
	if (res < 0)
		printf("Unable to read manufacturer string\n");
	printf("Manufacturer String: %ls\n", wstr);

	// Read the Product String
	wstr[0] = 0x0000;
	res = hid_get_product_string(handle, wstr, MAX_STR);
	if (res < 0)
		printf("Unable to read product string\n");
	printf("Product String: %ls\n", wstr);

	// Read the Serial Number String
	wstr[0] = 0x0000;
	res = hid_get_serial_number_string(handle, wstr, MAX_STR);
	if (res < 0)
		printf("Unable to read serial number string\n");
	printf("Serial Number String: (%d) %ls", wstr[0], wstr);
	printf("\n");

	// Read Indexed String 1
	wstr[0] = 0x0000;
	res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
	if (res < 0)
		printf("Unable to read indexed string 1\n");
	printf("Indexed String 1: %ls\n", wstr);

	// Set the hid_read() function to be non-blocking.
	hid_set_nonblocking(handle, 1);
	
	// Try to read from the device. There shoud be no
	// data here, but execution should not block.
	res = hid_read(handle, buf, 17);

	// Send a Feature Report to the device
	buf[0] = 0x2;
	buf[1] = 0xa0;
	buf[2] = 0x0a;
	buf[3] = 0x00;
	buf[4] = 0x00;
	res = hid_send_feature_report(handle, buf, 17);
	if (res < 0) {
		printf("Unable to send a feature report.\n");
	}

	memset(buf,0,sizeof(buf));

	// Read a Feature Report from the device
	buf[0] = 0x2;
	res = hid_get_feature_report(handle, buf, sizeof(buf));
	if (res < 0) {
		printf("Unable to get a feature report.\n");
		printf("%ls", hid_error(handle));
	}
	else {
		// Print out the returned buffer.
		printf("Feature Report\n   ");
		for (i = 0; i < res; i++)
			printf("%02hhx ", buf[i]);
		printf("\n");
	}

	memset(buf,0,sizeof(buf));

	// Toggle LED (cmd 0x80). The first byte is the report number (0x1).
	buf[0] = 0x1;
	buf[1] = 0x80;
	res = hid_write(handle, buf, 17);
	if (res < 0) {
		printf("Unable to write()\n");
		printf("Error: %ls\n", hid_error(handle));
	}
	

	// Request state (cmd 0x81). The first byte is the report number (0x1).
	buf[0] = 0x1;
	buf[1] = 0x81;
	hid_write(handle, buf, 17);
	if (res < 0)
		printf("Unable to write() (2)\n");

	// Read requested state. hid_read() has been set to be
	// non-blocking by the call to hid_set_nonblocking() above.
	// This loop demonstrates the non-blocking nature of hid_read().
	res = 0;
	while (res == 0) {
		res = hid_read(handle, buf, sizeof(buf));
		if (res == 0)
			printf("waiting...\n");
		if (res < 0)
			printf("Unable to read()\n");
		#ifdef WIN32
		Sleep(500);
		#else
		usleep(500*1000);
		#endif
	}

	printf("Data read:\n   ");
	// Print out the returned buffer.
	for (i = 0; i < res; i++)
		printf("%02hhx ", buf[i]);
	printf("\n");

	hid_close(handle);

	/* Free static HIDAPI objects. */
	hid_exit();

#ifdef WIN32
	system("pause");
#endif

	return 0;
}
Exemplo n.º 29
0
bool FocusMaster::sendCommand(const uint8_t *command, char *response)
{
    INDI_UNUSED(response);

    int rc = hid_write(handle, command, 2);

    LOGF_DEBUG("CMD <%#02X %#02X>", command[0], command[1]);

    if (rc < 0)
    {
        LOGF_ERROR("<%#02X %#02X>: Error writing to device %s", command[0], command[1], hid_error(handle));
        return false;
    }

    return true;
}
inline bool hid_error_mbs(hid_device *dev, char *out_mb_error, size_t mb_buffer_size)
{
    return ServerUtility::convert_wcs_to_mbs(hid_error(dev), out_mb_error, mb_buffer_size);
}