Search code examples
pythonpyusb

usb.core.USBError: [Errno 75] Overflow


I am very new to USB. I need to communicate with a laser controller and I want to use Python for this. I am now working in an Ubuntu 20.04 machine. I have this code:

import usb.core
import usb.util

device = usb.core.find(idVendor=0xC251, idProduct=0x2201)
if device is None:
    raise RuntimeError('Device not found')
interface = device[0].interfaces()[0]
if device.is_kernel_driver_active(interface.bInterfaceNumber):
    device.detach_kernel_driver(interface.bInterfaceNumber)

endpoint = device[0].interfaces()[0].endpoints()[0]
endpoint.write(b'\x00\x90\x04')

but I always get usb.core.USBError: [Errno 75] Overflow when trying to write. However, I am able to read data from the device using endpoint.read(64) and this seems to be working fine. I cannot find information about this overflow error.

In case it is of any help, this is what print(device) shows:

DEVICE ID c251:2201 on Bus 002 Address 010 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0xc251
 idProduct              : 0x2201
 bcdDevice              :  0x100 Device 1.0
 iManufacturer          :    0x1 LASER Driver 
 iProduct               :    0x2 LASER Driver IJS
 iSerialNumber          :    0x3 0001A0000000
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 100 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x22 (34 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0 
   bmAttributes         :   0xc0 Self Powered
   bMaxPower            :   0x32 (100 mA)
    INTERFACE 0: Human Interface Device ====================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x3 Human Interface Device
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 HID
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1

Solution

  • I have exactly the same problem, but with other USB device, not the laser controller. What helped in my case, is writing exactly 64-byte long data packets to the endpoint, with the appropriate amount of zeros appended.

    What I mean -- in your write code, instead of sending three bytes:

    endpoint.write(b'\x00\x90\x04')
    

    try out sending 64-byte long packet:

    cmd = b'\x00\x90\x04'
    packet_to_send = cmd + b'\x00' * (64 - len(cmd))
    endpoint.write(packet_to_send)