Re: URB Incorrect Device Address
"Wilhelmsen, Nils_christian" <[email protected]>
| Newsgroups | gmane.comp.lib.libusb.devel.windows |
|---|---|
| Message-ID | <[email protected]> |
This is the output from USB View:
Device Descriptor:
bcdUSB: 0x0200
bDeviceClass: 0x02
bDeviceSubClass: 0x00
bDeviceProtocol: 0x00
bMaxPacketSize0: 0x40 (64)
idVendor: 0x03EB (Atmel Corporation)
idProduct: 0x2404
bcdDevice: 0x0100
iManufacturer: 0x01
0x0409: "Atmel PST"
iProduct: 0x02
0x0409: "USART,SPI,i2c Bridge"
iSerialNumber: 0x03
0x0409: "15"
bNumConfigurations: 0x01
ConnectionStatus: DeviceConnected
Current Config Value: 0x01
Device Bus Speed: Full
Device Address: 0x05
Open Pipes: 3
Endpoint Descriptor:
bEndpointAddress: 0x83 IN
Transfer Type: Interrupt
wMaxPacketSize: 0x0040 (64)
bInterval: 0x10
Endpoint Descriptor:
bEndpointAddress: 0x81 IN
Transfer Type: Bulk
wMaxPacketSize: 0x0040 (64)
bInterval: 0x00
Endpoint Descriptor:
bEndpointAddress: 0x02 OUT
Transfer Type: Bulk
wMaxPacketSize: 0x0040 (64)
bInterval: 0x00
Configuration Descriptor:
wTotalLength: 0x0043
bNumInterfaces: 0x02
bConfigurationValue: 0x01
iConfiguration: 0x00
bmAttributes: 0x80 (Bus Powered )
MaxPower: 0x32 (100 Ma)
Interface Descriptor:
bInterfaceNumber: 0x00
bAlternateSetting: 0x00
bNumEndpoints: 0x01
bInterfaceClass: 0x02
bInterfaceSubClass: 0x02
bInterfaceProtocol: 0x01
iInterface: 0x00
Unknown Descriptor:
bDescriptorType: 0x24
bLength: 0x05
05 24 00 10 01
Unknown Descriptor:
bDescriptorType: 0x24
bLength: 0x04
04 24 02 02
Unknown Descriptor:
bDescriptorType: 0x24
bLength: 0x05
05 24 06 00 01
Unknown Descriptor:
bDescriptorType: 0x24
bLength: 0x05
05 24 01 03 01
Endpoint Descriptor:
bEndpointAddress: 0x83 IN
Transfer Type: Interrupt
wMaxPacketSize: 0x0040 (64)
bInterval: 0x10
Interface Descriptor:
bInterfaceNumber: 0x01
bAlternateSetting: 0x00
bNumEndpoints: 0x02
bInterfaceClass: 0x0A
bInterfaceSubClass: 0x00
bInterfaceProtocol: 0x00
iInterface: 0x00
Endpoint Descriptor:
bEndpointAddress: 0x81 IN
Transfer Type: Bulk
wMaxPacketSize: 0x0040 (64)
bInterval: 0x00
Endpoint Descriptor:
bEndpointAddress: 0x02 OUT
Transfer Type: Bulk
wMaxPacketSize: 0x0040 (64)
bInterval: 0x00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is the code. It is written in Python using ctypes:
####################################################################
from ctypes import *
c_libusb = CDLL(r'C:\WINDOWS\System32\libusb0.dll')
#Defines
LIBUSB_PATH_MAX = 512
#Datatypes
class usb_endpoint_descriptor(Structure):
pass
class usb_interface_descriptor(Structure):
pass
class usb_interface(Structure):
pass
class usb_config_descriptor(Structure):
pass
class usb_device_descriptor(Structure):
pass
class usb_device(Structure):
pass
class usb_dev_handle(Structure):
pass
class usb_bus(Structure):
pass
#Pointer types
c_ubyte_p = POINTER(c_ubyte)
usb_endpoint_descriptor_p = POINTER(usb_endpoint_descriptor)
usb_interface_descriptor_p = POINTER(usb_interface_descriptor)
usb_interface_p = POINTER(usb_interface)
usb_config_descriptor_p = POINTER(usb_config_descriptor)
usb_device_descriptor_p = POINTER(usb_device_descriptor)
usb_device_p = POINTER(usb_device)
usb_device_pp = POINTER(usb_device_p)
usb_dev_handle_p = POINTER(usb_dev_handle)
usb_bus_p = POINTER(usb_bus)
#Struct definitions
usb_endpoint_descriptor._fields_ = [('bLength', c_ubyte), ('bDescriptorType', c_ubyte),
('bEndpointAddress', c_ubyte), ('bmAttributes', c_ubyte),
('wMaxPacketSize', c_ushort), ('bInterval', c_ubyte),
('bRefresh', c_ubyte), ('bSyncAddress', c_ubyte),
('extra', c_ubyte_p), ('extralen', c_int)]
usb_interface_descriptor._fields_ = [('bLength', c_ubyte), ('bDescriptorType', c_ubyte),
('bInterfaceNumber', c_ubyte), ('bAlternateSetting', c_ubyte),
('bNumEndpoints', c_ubyte), ('bInterfaceClass', c_ubyte),
('bInterfaceSubClass', c_ubyte), ('bInterfaceProtocol', c_ubyte),
('iInterface', c_ubyte), ('endpoint', usb_endpoint_descriptor_p),
('extra', c_ubyte_p), ('extralen', c_int)]
usb_interface._fields_ = [('altsetting', usb_interface_descriptor_p), ('num_altsetting', c_int)]
usb_config_descriptor._fields_ = [('bLength', c_ubyte), ('bDescriptorType', c_ubyte),
('wTotalLength', c_ushort), ('bNumInterfaces', c_ubyte),
('bConfigurationValue', c_ubyte), ('iConfiguration', c_ubyte),
('bmAttributes', c_ubyte), ('MaxPower', c_ubyte),
('interface', usb_interface_p), ('extra', c_ubyte_p),
('extralen', c_int)]
usb_device_descriptor._fields_ = [('bLength', c_ubyte), ('bDescriptorType', c_ubyte),
('bcdUSB', c_ushort), ('bDeviceClass', c_ubyte),
('bDeviceSubClass', c_ubyte), ('bDeviceProtocol', c_ubyte),
('idVendor', c_ushort), ('idProduct', c_ushort), ('bcdDevice', c_ushort),
('iManufacturer', c_ubyte), ('iProduct', c_ubyte),
('iSerialNumber', c_ubyte), ('bNumConfigurations', c_ubyte)]
usb_device._fields_ = [('next', usb_device_p), ('prev', usb_device_p),
('filename', c_char*(LIBUSB_PATH_MAX)),
('bus', usb_bus_p), ('descriptor', usb_device_descriptor),
('config', usb_config_descriptor_p), ('devnum', c_ubyte),
('num_children', c_ubyte), ('children', usb_device_pp)]
usb_bus._fields_ = [('next', usb_bus_p), ('prev', usb_bus_p),
('dirname', c_char*(LIBUSB_PATH_MAX)),
('devices', usb_device_p), ('location', c_ulong),
('root_dev', usb_device_p)]
#Initialization
c_libusb.usb_init(None)
c_libusb.usb_find_busses(None)
c_libusb.usb_find_devices(None)
c_libusb.usb_get_busses.restype = usb_bus_p
busses = c_libusb.usb_get_busses(None)
c_libusb.usb_set_debug.argtypes = [c_int]
c_libusb.usb_set_debug(3)
#Opening up device
c_libusb.usb_open.argtypes = [usb_device_p]
c_libusb.usb_open.restype = usb_dev_handle_p
bussesObject = cast(busses, usb_bus_p).contents
theDevice = bussesObject.devices
#######################################################################
#This is just to double check that the correct device is being opened
deviceObject = cast(theDevice, usb_device_p).contents
theDescriptor = deviceObject.descriptor
print "idProduct: " + str(hex(theDescriptor.idProduct))
print "idVendor: " + str(hex(theDescriptor.idVendor))
########################################################################
theDeviceHandle = c_libusb.usb_open(theDevice)
c_libusb.usb_claim_interface.argtypes = [usb_dev_handle_p, c_int]
c_libusb.usb_claim_interface(theDeviceHandle, 1)
c_libusb.usb_set_configuration.argtypes = [usb_dev_handle_p, c_int]
c_libusb.usb_set_configuration(theDeviceHandle, 1)
#Data transfer
c_libusb.usb_bulk_write.argtypes = [usb_dev_handle_p, c_int, c_char_p, c_int, c_int]
data = c_char_p('test')
returnVal = c_libusb_bulk_write(theDeviceHandle, 2, data, 4, 100)
print returnVal
#Closing down device
c_libusb.usb_release_interface.argtypes = [usb_dev_handle_p, c_int]
c_libusb.usb_release_interface(theDeviceHandle, 1)
c_libusb.usb_close.argtypes = [usb_dev_handle_p]
c_libusb.usb_close.restype = c_int
c_libusb.usb_close(theDeviceHandle)
#############################################################################################################################################
-----Original Message-----
From: Xiaofan Chen [mailto:[email protected]]
Sent: 1. august 2014 16:21
To: [email protected]
Subject: Re: [Libusb-win32-devel] URB Incorrect Device Address
On Fri, Aug 1, 2014 at 7:00 PM, Wilhelmsen, Nils_christian <[email protected]> wrote:
>
> I am currently trying to get my USB device to work with libusb-win32.
> To do this I have set up a simple program that attempts to send a
> test string to a bulk endpoint. However, when I ran the program, no
> error messages came up but the device did not receive the test string,
> so I decided to intercept the URBs with USBPcap. In the URBs, the
> device address is set to 0xFF, whereas from USB view I found the
> device address to be 0x05, which implies the URB is supplying the incorrect device address.
>
>
> Does anyone know why this occurs? Any help will be appreciated.
>
Please post the output from USBView about your device.
And please post your codes.
--
Xiaofan
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Libusb-win32-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds