示例#1
0
def __pollDevice(latch):

  # wait for data from the device using the asynchronous API. See
  # http://libusb.sourceforge.net/api-1.0/
  pollobj = select.poll()
  pollfds = LibUSB.get_pollfds()
  LOGGER.debug("retreived poll file descriptors: %s" % pollfds)
  for (fd, events) in pollfds:
    pollobj.register(fd, events)

  while True:
    latch.open()
    try:
      timeoutInMillis = None
      t0 = datetime.datetime.now()
      nextTimeout = LibUSB.get_next_timeout()
      if nextTimeout is not None:
        (secs, usecs) = nextTimeout
        timeoutInMillis = secs * 1000.0 + usecs * 0.001
        if LOGGER.isEnabledFor(logging.DEBUG):
          LOGGER.debug("next timeout: %(timeoutInMillis)f" % locals())
      pollresult = pollobj.poll(timeoutInMillis) # milliseconds
      t1 = datetime.datetime.now()
      dt = t1 - t0
      elapsedTimeInMillis = dt.seconds * 1000.0 + dt.microseconds * 0.001
      if LOGGER.isEnabledFor(logging.DEBUG):
        LOGGER.debug("poll result: %(pollresult)s, timeout: %(timeoutInMillis)s, elapsed: %(elapsedTimeInMillis)f" % locals())
      if (len(pollresult) > 0) or (timeoutInMillis is None) or (elapsedTimeInMillis > timeoutInMillis):
        LibUSB.handle_events_timeout()
    except Exception,e:
      exc_type, exc_value, exc_traceback = sys.exc_info()
#        msg = traceback.format_exception_only(exc_type, exc_value);
      msg = traceback.format_exception(exc_type, exc_value, exc_traceback);
      LOGGER.error("\n".join(msg))
示例#2
0
def createInterruptTransfer(dh, endpoint, bufferSize, callback, timeoutInMillis):
  th = LibUSB.transfer(0)
  th.fill_interrupt_transfer(dh, endpoint, "", callback, timeoutInMillis)
  th.zero_transfer_buffer(bufferSize)
  return th
示例#3
0
def transferStatusToString(status):
  return LibUSB.transfer_status_str(status)
示例#4
-1
def getHandleToLowSpeedDevice(vencor_id, device_id):

  # find the device
  device = LibUSB.get_device_with_vid_pid(vendor_id, device_id)
  if device is None:
    raise Exception("unable to find X10 device")
  LOGGER.debug("found X10 device")

  # the cm15 is a low speed device (1.5MBit/s) which means that its
  # maximum data payload is 8 bytes per transfer
  assert(device.device_speed() == LibUSB.SPEED_LOW)

  # open the device:
  dh = device.open()
  LOGGER.debug("opened a handle to the device")

  return dh