コード例 #1
0
ファイル: usbbutton.c プロジェクト: OzFalcon/Ultimarc-linux
bool writeUSBButton(unsigned char* barray, int autoconnect, bool transfer)
{
  libusb_context *ctx = NULL;
  struct libusb_device_handle *handle = NULL;
  unsigned char mesg[USBBTN_MESG_LENGTH] = {0,0,0,0};

  bool result = true;

  int pos = 0;
  int ret = 0;

  if (transfer)
  {
    handle = openUSB(ctx, USBBTN_VENDOR, USBBTN_PRODUCT, USBBTN_INTERFACE, autoconnect);

    if (!handle)
    {
      result = false;
      goto error;
    }
  }

  while (pos < USBBTN_SIZE)
  {
    memcpy(&mesg[0], &barray[pos], 4);

    debug ("Writing (%i): %x, %x, %x, %x", pos, mesg[0], mesg[1], mesg[2], mesg[3]);
    if (transfer)
    {
      ret = libusb_control_transfer(handle,
                                    UM_REQUEST_TYPE,
                                    UM_REQUEST,
                                    USBBTN_VALUE,
                                    USBBTN_INTERFACE,
                                    mesg,
                                    USBBTN_MESG_LENGTH,
                                    UM_TIMEOUT);
      debug ("Write result: %i", ret);
    }
    pos+=USBBTN_MESG_LENGTH;
  }

exit:
  if (transfer)
  {
    closeUSB(ctx, handle, USBBTN_INTERFACE);
  }
  else
  {
    log_info ("board array was not written out!!!");
  }
  return result;

error:
  return result;
}
コード例 #2
0
ファイル: IntanThread.cpp プロジェクト: malfatti/GUI
bool IntanThread::startAcquisition()
{

    if (!simulateDataStream)
    {
        closeUSB();
        initializeUSB(false);
        ftdi_write_data(&ftdic, &startCode, 1);  
    }
    
    startThread();

    isTransmitting = true;

    return true;
}
コード例 #3
0
ファイル: common.c プロジェクト: katie-snow/Ultimarc-linux
struct libusb_device_handle*
openUSB(libusb_context *ctx, uint16_t vendor, uint16_t product, int interface, int autoconnect)
{
  int ret = 0;

  struct libusb_device_handle *handle = NULL;

  /* Open USB communication */
  ret = libusb_init(&ctx);
  if (ret < 0)
  {
    log_err("libusb_init failed: %i.", ret);
    goto error;
  }
  libusb_set_debug(ctx, 3);

  handle = libusb_open_device_with_vid_pid(ctx, vendor, product);
  if (!handle)
  {
    log_err("Unable to open device.");
    goto error;
  }

  if (interface != -1)
  {
    if (!claimInterface(handle, interface, autoconnect))
    {
      goto error;
    }
  }

  exit:
  return handle;

  error:
  closeUSB(ctx, handle, interface);
  return NULL;
}