visual studio code - Getting TIMEOUT ERROR using Libusb in Python - Stack Overflow

I am trying to read the data from my electronic board using Python.I am using the Libusb library on VS

I am trying to read the data from my electronic board using Python. I am using the Libusb library on VSCode platform in order to do that on Windows. However, I am getting an error related to the timeout.

I don't know how to solve it. Anyone would have an idea why this is happening? Should I download another librarry into the Python environment? The following is my code:

import usb.backend.libusb1, os, usb.core, numpy as np

# Needed variables for the sensor:
VENDOR_ID = 0x04d8
PRODUCT_ID = 0xf2a6
INTERFACE = 0
CONFIGURATION = 0
ENDPOINT_IN = 0
ENDPOINT_OUT = 1
INTEGRATION_TIMES = {"1ms": 0x00, "2ms": 0x01, "4ms": 0x02, "8ms": 0x03, "16ms": 0x04, "32ms": 0x05,
                "64ms": 0x06, "128ms": 0x07, "256ms": 0x08, "512ms": 0x09, "1024ms": 0x0A}
 REFERENCE_CURRENTS = {"20nA": 0x80, "80nA": 0x90,
                "320nA": 0xA0, "1280nA": 0xB0, "5120nA": 0xC0}

 def openPixelSensor():
"""
     Prepare USB libraries, locate Coher Sense KISA device, initialize device
"""
    cwd = os.getcwd()
    libpath = cwd + "\\libusb-1.0.dll"
    backend = usb.backend.libusb1.get_backend(find_library=lambda x: libpath)
    activeDev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)

    # If device was found do platform specific configuration
    if activeDev is not None:
        configuration = activeDev.get_active_configuration()
        interface = configuration[(INTERFACE, CONFIGURATION)]
        endpointIn = interface[ENDPOINT_IN]
        endpointOut = interface[ENDPOINT_OUT]
        return activeDev, endpointIn, endpointOut
    else:
        return None



def getReadings(pixelsensor):
    """
    Get the 8 sensor values from Coher Sense KISA device
    """
    data = pixelsensor[0].read(endpoint=pixelsensor[1].bEndpointAddress,
                               size_or_buffer= pixelsensor[1].wMaxPacketSize, timeout=1000
                               )

    values = []
    for i in range(0, 8):
        values.append(int.from_bytes(
            data[(4+2*i):(6+2*i)], byteorder='little'))
    print(values)
    return values
result = openPixelSensor()

getReadings(result)

The error is the following:

raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBTimeoutError: [Errno 10060] Operation timed out


 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744247736a4565019.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信