Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:50:13+00:00 2026-05-22T20:50:13+00:00

I have usb mass stroage with led I am trying to light on and

  • 0

I have usb mass stroage with led

I am trying to light on and off the led

using usb packet sniffing tool USBlyzer,

I can get the raw data

55 53 42 43 58 66 93 88 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

whose Request info is Bulk or Interrupt Transfer and I/O is out

and in the USB properties section

I can get the info such as

Endpoint Descriptor 81 1 In, bulk, 512 bytes

bDescriptorType 05h Endpoint

bEndpointAddress 81h 1 In

Endpoint Descriptor 02 2 In, bulk, 512 bytes

bDescriptorType 05h Endpoint

bEndpointAddress 02h 2 Out

I made a python code with python 2.7, libusb-win32-bin-1.2.4.0, pyusb-1.0.0-a1

the full source is here

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0x1516, idProduct=0x8628)

# was it found?
if dev is None:
    raise ValueError('Device not found')

dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
interface_number = cfg[0].bInterfaceNumber
alternate_setting = usb.control.get_interface(interface_number)
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = \
                                ineterface_number, bAlternateSetting = alternate_setting)
ep = usb.util.find_descriptor(intf,custom_match = \
                                  lambda e: \
                                      usb.util.endpoint_direction(e.bEndpointAddress) == \
                                      usb.util.ENDPOINT_OUT)
# set the active configuration. With no arguments, the first
# configuration will be the active one


assert ep is not None

ep.write(0x2,0x55)
ep.write(0x2,0x53)
ep.write(0x2,0x42)
ep.write(0x2,0x43)
ep.write(0x2,0x58)
ep.write(0x2,0x66)
ep.write(0x2,0x93)
ep.write(0x2,0x88)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x06)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)
ep.write(0x2,0x00)

but when I try to execute it,

Traceback (most recent call last):
  File "C:\Documents and Settings\kty1104\Desktop\usb2.py", line 14, in <module>
    interface_number = cfg[0].bInterfaceNumber
  File "C:\Python27\lib\site-packages\usb\core.py", line 447, in __getitem__
    return Interface(self.device, index[0], index[1], self.index)
TypeError: 'int' object is not subscriptable

arise

what’s wrong with my code?

any if anything wrong concept is there, please let me know

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:50:13+00:00Added an answer on May 22, 2026 at 8:50 pm

    I don’t know anything about pyusb, but my interpretation of the error message is that, contra others’ opinions, cfg is not an integer, but that it requires a non-integral index. I say this because the exception is thrown in a __getitem__ function, which could only be cfg‘s __getitem__, because that’s the only place a __getitem__ call would be made in the line

    interface_number = cfg[0].bInterfaceNumber
    

    Now if cfg were an int, it wouldn’t have a __getitem__. The problem is that cfg‘s __getitem__ seems to expect to be able to subscript the index that it receives, as illustrated by the middle two arguments, index[0], index[1]. Since you passed cfg an integer, that’s impossible.


    From the tutorial:

    You can also use the subscript
    operator to access the descriptors
    randomly, like that:

    >>> # access the second configuration
    >>> cfg = dev[1]
    >>> # access the first interface
    >>> intf = cfg[(0,0)]
    >>> # third endpoint
    >>> ep = intf[2] 
    

    As you can see, the index is zero based. But wait! There
    is something weird in the way I access
    an interface… Yes, you are right,
    the subscript operator in the
    Configuration accepts a sequence of
    two items, with the first one being
    the index of the Interface and the
    second one, the alternate setting. So,
    to access the first interface, but its
    second alternate setting, we write
    cfg[(0,1)].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get USB Mass Storage activity to turn on or off
I have a USB token contain certificate, public/private key pair, how can i get
I am trying to modify a mass storage driver using the composite usb framework
We have a usb device and the drivers (.inf, libusb.dll, libusb.sys) and can install
I have a USB device I'm trying to communicate with over a virtual serial
Many LCD televisions nowadays have USB ports so you can plug in your camera
I have installed usb driver, selected the android device's debugging mode but i can't
I need to disable cdrom and the usb mass storage drivers using c# windows
I have USB IR module in connected to a tty port, and I can
I have a USB camera pluged in my PC (using windows 7) and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.