Beispiel #1
0
/************************************************************************//**
 * \brief Connects this instance to a Manta
 * \param connectionSerial The serial number of the manta to search for.
 *
 * If connectionSerial is left out or given as 0 then any connected Manta will
 * match. If a serial number is given then libmanta will attempt to connect to
 * that Manta. If no matching manta is found then Connect will throw a
 * MantaNotFoundException. If no exception is thrown then the connection can be
 * assumed to have been successful.
 *
 ****************************************************************************/
void MantaUSB::Connect(int connectionSerial)
{
#define SERIAL_STRING_SIZE 32
   wchar_t serialString[SERIAL_STRING_SIZE];

   if(IsConnected())
   {
      return;
   }

   DebugPrint("%s-%d: Attempting to Connect to Manta %d...",
         __FILE__, __LINE__, connectionSerial);
   if(connectionSerial)
   {
      swprintf(serialString, SERIAL_STRING_SIZE, L"%d", connectionSerial);
      DeviceHandle = hid_open(VendorID, ProductID, serialString);
   }
   else
   {
      DeviceHandle = hid_open(VendorID, ProductID, NULL);
   }
   if(NULL == DeviceHandle)
      throw(MantaNotFoundException());
   hid_get_serial_number_string(DeviceHandle, serialString, SERIAL_STRING_SIZE);
   SerialNumber = wcstol(serialString, NULL, 10);
   hid_set_nonblocking(DeviceHandle, 1);
}
Beispiel #2
0
int HidController::open() {
    if (isOpen()) {
        qDebug() << "HID device" << getName() << "already open";
        return -1;
    }

    // Open device by path
    if (debugging()) {
        qDebug() << "Opening HID device"
                 << getName() << "by HID path" << hid_path;
    }
    m_pHidDevice = hid_open_path(hid_path);

    // If that fails, try to open device with vendor/product/serial #
    if (m_pHidDevice == NULL) {
        if (debugging())
            qDebug() << "Failed. Trying to open with make, model & serial no:"
                << hid_vendor_id << hid_product_id << hid_serial;
        m_pHidDevice = hid_open(hid_vendor_id, hid_product_id, hid_serial_raw);
    }

    // If it does fail, try without serial number WARNING: This will only open
    // one of multiple identical devices
    if (m_pHidDevice == NULL) {
        qWarning() << "Unable to open specific HID device" << getName()
                   << "Trying now with just make and model."
                   << "(This may only open the first of multiple identical devices.)";
        m_pHidDevice = hid_open(hid_vendor_id, hid_product_id, NULL);
    }

    // If that fails, we give up!
    if (m_pHidDevice == NULL) {
        qWarning()  << "Unable to open HID device" << getName();
        return -1;
    }

    setOpen(true);
    startEngine();

    if (m_pReader != NULL) {
        qWarning() << "HidReader already present for" << getName();
    } else {
        m_pReader = new HidReader(m_pHidDevice);
        m_pReader->setObjectName(QString("HidReader %1").arg(getName()));

        connect(m_pReader, SIGNAL(incomingData(QByteArray)),
                this, SLOT(receive(QByteArray)));

        // Controller input needs to be prioritized since it can affect the
        // audio directly, like when scratching
        m_pReader->start(QThread::HighPriority);
    }

    return 0;
}
Beispiel #3
0
/**
 * @brief tries to open the MSI gaming notebook's SteelSeries keyboard
 * @returns a corresponding hid_device, null if the keyboard was not detected
 */
hid_device* open_keyboard()
{
    if (hid_init() == 0)
        return hid_open(0x1770, 0xff00, 0);
    else
        return NULL;
}
Beispiel #4
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;
}
Beispiel #5
0
SwitchPanel::SwitchPanel()
{
	handle = hid_open(0x06a3, 0x0d67, NULL);
	oapiWriteLog("Device opened");
	// Set the hid_read() function to be non-blocking.
	hid_set_nonblocking(handle, 1);
}
int main( int argc, char* argv[] )
{
  unsigned char buf[2];
  hid_device *handle;
  int res;

  // Space Navigator: 046d c626
  handle = hid_open( 0x046d, 0xc626, NULL );

  if ( handle == NULL ) {
    printf( "spacenav-rezero: Could not open HID device (got sudo?)\n" );
    exit( EXIT_FAILURE );
  }

  buf[0] = 0x07; // This proprietary(?) feature report will rezero the device.
  buf[1] = 0x00;
  res = hid_send_feature_report( handle, buf, sizeof(buf) );

  if ( res != sizeof(buf) ) {
    printf( "spacenav-rezero: Write failed\n" );
    exit( EXIT_FAILURE );
  }

  hid_close( handle );

  return EXIT_SUCCESS;
}
Beispiel #7
0
//-----------------------------------------------------------------------------
void dbg_open(debugger_t *debugger)
{
  handle = hid_open(debugger->vid, debugger->pid, debugger->wserial);

  if (!handle)
    perror_exit("unable to open device");
}
Beispiel #8
0
bool RawHID::open(OpenMode mode)
{
    QMutexLocker locker(m_mutex);

    int res;
    hid_device *handle;

    // Initialize the hidapi library (safe to call multiple times)
    res = hid_init();

    // Open the device using the VID, PID
    handle = hid_open(m_deviceInfo->getVendorID(), m_deviceInfo->getProductID(), NULL);

    if (handle) {
        m_handle = handle;

        m_writeThread = new RawHIDWriteThread(this);
        m_readThread = new RawHIDReadThread(this);

        m_readThread->start();
        m_writeThread->start();
    } else {
        qDebug() << "Failed to open USB device";
    }

    return QIODevice::open(mode);
}
hid_device* get_inkling_device()
{
	const int wacomVendorID = 0x056a;
	const int wacomInclingID = 0x0221;

	//Find device using hidapi
	#define MAX_STR 255
	hid_device *found = NULL;

	// Enumerate and print the HID devices on the system
	struct hid_device_info *devs, *cur_dev;

	devs = hid_enumerate(0x0, 0x0);
	cur_dev = devs;
	while (cur_dev) {
	  if(cur_dev->vendor_id == wacomVendorID && cur_dev->product_id == wacomInclingID){
	    found = hid_open(cur_dev->vendor_id, cur_dev->product_id, NULL);
	    if(found == NULL)
	      puts("Failed to open hid to Inkling");
	    break;
	  }
	  cur_dev = cur_dev->next;
	}
	hid_free_enumeration(devs);

    if(found == NULL){
	  puts("Inkling device not found");
    }
	return found;
}
Beispiel #10
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;
}
void Sbs2EmocapDataReader::resetHandle()
{
#ifdef Q_OS_MAC
    hid_close(handle);
    hid_exit();
    handle = hid_open(0x1234, 0xed02, NULL);
#endif
}
void USBInterface::HIDOpen(const unsigned short VendorID, const unsigned short ProductID)
{
    if(!HIDisOpen)
    {
        DeviceHandle = hid_open(VendorID, ProductID, NULL);
        if(DeviceHandle)HIDisOpen= true;
    }
}
int main(int argc, char* argv[])
{
	int res;
	int i;

	// Initialize the hidapi library
	printf("Starting to initialize HID library...\n");
	res = hid_init();
	printf("Initialized HID library.\n");

	// Open the device using the VID, PID,
	// and optionally the Serial number.
	printf("Trying to open device...\n");
	handle = hid_open(0x04d8, 0x003f, NULL);
	if(handle != NULL) {
		printf("Opened device successfully.\n");
	} else {
		printf("Could not open device.\n");
		exit(EXIT_FAILURE);
	}
	read_device_info();

	toggle_led1();

	printf("Button is %spressed.\n", get_push1_state() ? "" : "not ");

	printf("The decimal result is %d\n", get_pot1_val());

	// Register signal handler
	if (signal(SIGINT, sig_handler) == SIG_ERR) {
        printf("\nCan't catch SIGINT\n");
        exit(EXIT_FAILURE);
	}

	// Enter ncurses mode
	initialize_display();

	// Main loop
	while(1) {
		int a;
		a = (int)((100 / 1023.0) * get_pot1_val()); 
		print_percent_bar(2, a);
		refresh();
		sleep(0.1);
	}

	// Leave ncurses mode
	end_display();

	// Unregister signal handler
	signal(SIGINT, SIG_DFL);

	// Finalize the hidapi library
	res = hid_exit();

	return 0;
}
Beispiel #14
0
int main(int argc, char* argv[])
{
	int res;
	unsigned char buf[RELAY_COMMAND_SIZE];
	hid_device *handle;
	unsigned char command;

	if (argc != 2) {
		fprintf(stderr, "usage: %s [on|off]\n", argv[0]);
		exit(1);
	}
	if (strcmp(argv[1], "on") == 0) {
		command = RELAY_STATE_ON;
	} else if (strcmp(argv[1], "off") == 0) {
		command = RELAY_STAT_OFF;
	} else if (strcmp(argv[1], "scan") == 0) {
		return doScan();
	} else {
		fprintf(stderr, "usage: %s [on|off]\n", argv[0]);
		exit(1);
	}

	if (hid_init()) {
		fprintf(stderr, "can't init hid lib\n");
		exit(1);
	}

	// Set up the command buffer.
	memset(buf,0x00,sizeof(buf));
	buf[1] = command;
	buf[2] = RELAY_NUMBER;
	

	// Open the device using the VID, PID,
	// and optionally the Serial number.
	////handle = hid_open(0x4d8, 0x3f, L"12345");
	handle = hid_open(RELAY_VENDOR_ID, RELAY_PRODUCT_ID,  NULL);
	if (!handle) {
		printf("unable to open device\n");
 		return 1;
	}

	res = hid_write(handle, buf, sizeof(buf));

	if (res < 0) {
		printf("Unable to send command\n");
	}


	hid_close(handle);

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

	exit(0);
}
int
open_dev(dldev_t *dev)
{
	dev->usb.handle = hid_open(VENDOR_ID, PRODUCT_ID, NULL);
	if(dev->usb.handle == NULL) {
		ERROR("could not open device in open_dev()");
		return -1;
	}
	return 0;
}
glowproxy_device* Open(void)
{
    glowproxy_device* handle;
    handle = hid_open(VENDOR_ID, PRODUCT_ID, NULL);
    if (!handle) {
        //printf("unable to open device\n");
        return NULL;
    }
    return handle;
}
Beispiel #17
0
Keyboard::Keyboard() :
  m_dev(NULL)
{
  m_dev = hid_open(0x1770, 0xff00, 0);

  if(!m_dev) {
    std::cout << "cannot open usb device" << std::endl;
    QTimer::singleShot(0, qApp, SLOT(quit()));
    return;
  }
}
Beispiel #18
0
void HID_PnP::PollUSB()
{
    buf[0] = 0x00;
    memset((void*)&buf[2], 0x00, sizeof(buf) - 2);

    if (isConnected == false) {
        device = hid_open(0x04d8, 0x003f, NULL);

        if (device) {
            isConnected = true;
            hid_set_nonblocking(device, true);
            timer->start(15);
        }
    }
    else {
        if(toggleLeds == true) {
            toggleLeds = false;

            buf[1] = 0x80;

            if (hid_write(device, buf, sizeof(buf)) == -1)
            {
                CloseDevice();
                return;
            }

            buf[0] = 0x00;
            buf[1] = 0x37;
            memset((void*)&buf[2], 0x00, sizeof(buf) - 2);
        }

        if (hid_write(device, buf, sizeof(buf)) == -1)
        {
            CloseDevice();
            return;
        }
        if(hid_read(device, buf, sizeof(buf)) == -1)
        {
            CloseDevice();
            return;
        }
        if(buf[0] == 0x37) {
            potentiometerValue = (buf[2]<<8) + buf[1];
            buf[1] = 0x81;
        }
        else if(buf[0] == 0x81) {
            pushbuttonStatus = (buf[1] == 0x00);
            buf[1] = 0x37;
        }
    }

    hid_comm_update(isConnected, pushbuttonStatus, potentiometerValue);
}
Beispiel #19
0
void TaquitoClient::connect(){
  std::cerr << "connecting" << std::endl;
  if(USBHandle) 
    disconnect();
  USBHandle = hid_open(VENDOR_ID, DEVICE_ID, NULL);    // attempt to open device
  if(USBHandle) {
    // if handle is set, then connection has been made
    hid_set_nonblocking(USBHandle, 1);                // set hid_read() in non-blocking mode
  }else{
    std::cerr << "connection failure" << std::endl;
    throw TaquitoError();
  }
}
Beispiel #20
0
int main(int argc, char const *argv[])
{
	unsigned short vendor_id = 1027;
	unsigned short product_id = 65448;
	wchar_t *serial_number = NULL;
	hid_device *dev = hid_open(vendor_id, product_id, serial_number);

	if (hid_device != NULL)
	{
	}

	return 0;
}
Beispiel #21
0
Comm::ErrorCode Comm::open(void)
{
    boot_device = hid_open(VID, PID, NULL);
    if(boot_device)
    {
        connected = true;
        hid_set_nonblocking(boot_device, true);
        qWarning("Device successfully connected to.");
        return Success;
    }

    qWarning("Unable to open device.");
    return NotConnected;
}
Beispiel #22
0
//--------------------------------------------------------------
void ofxPowerMate::conecta(){
    
    // Open the device using the VID, PID,
    // and optionally the Serial number.
    handle = hid_open(0x077d, 0x0410, NULL);
    
    // Read the Manufacturer String
    res = hid_get_manufacturer_string(handle, wstr, 6);
    printf("Manufacturer String: %ls\n", wstr);
    
    // Set the hid_read() function to be non-blocking.
    hid_set_nonblocking(handle, 1);

}
/*---------------------------------------------------------------------------*/
int t100::connectBasic()
{
  this->t100_handle = hid_open(VID, PID, NULL);
  
  if(!(this->t100_handle))
  {   
    this->problem = true;
    return -1;
  } 
  else
  {
    return 0;
  }
}
Beispiel #24
0
int USB_Open()
{
    // Open the device using the VID, PID,
    // and optionally the Serial number.
    DeviceHandle = hid_open(MY_VID, MY_PID, NULL);

    if(DeviceHandle == NULL)
    {
        USBConnected = false;
        return -1;
    }
    USBConnected = true;
    return 0;
}
Beispiel #25
0
bool UsbHid::open(unsigned short vendorId, unsigned short productId, QString serialNumberString)
{
	close();

	bool res = false;
	hid_device *h;
	wchar_t *serial = (serialNumberString.size() > 0) ? const_cast<wchar_t*>(serialNumberString.toStdWString().c_str()) : 0;

	if ((h = hid_open(vendorId, productId, serial)) != 0)
	{
		hidDevice = h;
		res = true;
	}

	return res;
}
Beispiel #26
0
int initializeUSB1208(){
    ret = hid_init();
    if (ret < 0) {
        fprintf(stderr, "hid_init failed with return code %d\n", ret);
        return -1;
    }

    if ((hid = hid_open(MCC_VID, USB1208LS_PID, NULL)) >  0) {
        //printf("USB-1208LS Device is found!\n");
    } else {
        fprintf(stderr, "USB-1208LS not found.\n");
        exit(1);
    }

    return 0;
}
/*---------------------------------------------------------------------------*/
int t100::connectBySerial(uint64_t serial)
{
  wchar_t buf[16];
  swprintf(buf, sizeof(buf) / sizeof(*buf), L"%llu", serial);

  this->t100_handle = hid_open(VID, PID, buf);

  if(!(this->t100_handle))
  {   
    this->problem = true;
    return -1;
  } 
  else
  {
    this->mySerialNumber = serial;
    return 0;
  }
}
Beispiel #28
0
void init_pid(unsigned short vid, unsigned short pid) {
#ifdef OSX
    hid_init();
    dev = hid_open(vid, pid, NULL);
#else
    struct hid_device_info *info = NULL, *ptr = NULL;
    hid_init();
    info = hid_enumerate(vid, pid);
    ptr = info;
    while (ptr != NULL) {
        if (ptr->interface_number == 1) {
            dev = hid_open_path(ptr->path);
            break;
        }
        ptr = ptr->next;
    }
    hid_free_enumeration(info);
#endif
}
Beispiel #29
0
int initializeDevice() {

  struct hid_device_info *devs, *cur_dev;
  const wchar_t targetManufacturer[] = L"Wincor Nixdorf";

  hid_init();
  /* Auto-detection du périphérique */
  //Wincor Nixdorf

	devs = hid_enumerate(0x0, 0x0);
	cur_dev = devs;

	while (cur_dev) {
    if (DEBUG) fprintf(stdout, "<Debug> Périphérique trouvé: %04hx %04hx - %ls - %s\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->manufacturer_string ,cur_dev->path);

    #if defined(__APPLE__)
      if (!wcscmp(targetManufacturer, cur_dev->manufacturer_string) ) {
        fprintf(stdout, "<Pilote> Afficheur USB %04hx %04hx en cours d\'ouverture sur %s..\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path);
        display = hid_open(cur_dev->vendor_id, cur_dev->product_id, NULL);
        break;
      }
    #elif defined(linux)
      if (!wcscmp(targetManufacturer, cur_dev->manufacturer_string) &&  !strcmp(cur_dev->path+(strlen(cur_dev->path)-2), "01")) {
        fprintf(stdout, "<Pilote> Afficheur USB %04hx %04hx en cours d\'ouverture sur %s..\n", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path);
        display = hid_open_path(cur_dev->path);
        break;
      }
    #else
      fprintf(stderr, "<Fatal> Ce système n'est pas (encore) supporté pour l'instant!\n");
      exit(-1);
    #endif

		cur_dev = cur_dev->next;
	}

	hid_free_enumeration(devs);
  if (!display) return 0;

  hid_get_product_string(display, moduleName, MAX_STR);
  if (DEBUG) fprintf(stdout, "<Info> Connected to \"%ls\" display.\n", moduleName);
  return display!=NULL;
}
Beispiel #30
0
int main(int argc, char* argv[]){
	hid_device *handle;
	unsigned char resbuf[8];

	if(argc < 3){
		usage();
		return 1;
	}
	host = argv[1];
	port = atoi(argv[2]);

	printf("Opening ONTRAK device...\n");
	handle = hid_open(VENDOR_ID, DEVICE_ID, NULL);
	hid_set_nonblocking(handle, 0);	//blocking mode ftw
	printf("Device opened and set to blocking mode.");

	UdpTransmitSocket transmitSocket( IpEndpointName( host, port ) );

	while(true){
		send_ontrak_command(handle);
		int res = hid_read(handle, resbuf, 8);
		if(res <= 0){
			printf("ERROR reading\n");
		}
		else{
			fprintf(stdout, ".");
			fflush(stdout);
			if(++dots > 80){
				printf("\n");
				dots = 0;
			}
			int state = atoi((const char*)resbuf+1);
			// printf("%d\n", state);
			if(state != last_state){
				last_state = state;
				send_osc(transmitSocket, state);
			}
		}
		usleep(POLL_SLEEP_MS * 1000);
	}
}