Re: [pyusb-users] Need Help Please

2020-11-16 Thread Nicolas Pinault via pyusb-users
Hi,
 
 On Windows, for HID devices, I use a dedicated HID library : 
https://github.com/rene-aguirre/pywinusb
 
 Nicolas
 
 
 Le 13/11/2020 à 07:50, John Beamish a écrit :
 
 
Hi 

 
 
I am trying to use a USB port to talk to a 18F46K20 pic controller. The 
project, which is in the early stages, will communicate simple commands to the 
controller,  to get temperature and humidity data from a sensor attached to the 
controller.
 
I want to use Python to manipulate the results in graphic form.
 
I have read some articles about using PyUSB for interacting with the USB port 
so I thought I would do some preliminary tests to trial it before I get into 
the more complex parts.
 
I copied a small program to test it 
(https://github.com/pyusb/pyusb/blob/master/docs/tutorial.rst)
 
 
import usb.core
import usb.util
dev = usb.core.find(idVendor=0x04B3, idProduct=0x310C)
if dev is None:
raise ValueError('Device not found')
print (dev.idProduct,dev.idVendor) 
dev.set_configuration()
 
 
The device is an USB optical mouse. Info from USB Device Viewer is at the end 
of this email.
 
Line 6 outputs 12556 1203 ( which is in decimal).
 
Line 7 produces the following
 
Exception has occurred: USBError
 [Errno 40] Operation not supported or unimplemented on this platform
   File "C:\Users\John Beamish\test\usbtest.py", line 7, in 
     dev.set_configuration()
 
 
I loaded pyusb 1.1.0 with pip install pyusb and libusb1 1.8 with pip install 
libusb1
 
I am running Python 3.9 0n Windows 10 Home Version 2004.
 

 
 
I know I have/ or am doing something wrong but if anyone is able to advise me I 
would really appreciate this.
 

 
 
This was supposed to be the easy bit!!!
 
Regards
 

 
 
John Beamish
 

 
 
       ---===>Device Information<===---
 English product name: "USB Optical Mouse"
 
 ConnectionStatus:                  
 Current Config Value:              0x01  -> Device Bus Speed: Low
 Device Address:                    0x27
 Open Pipes:                           1
 
           ===>Device Descriptor<===
 bLength:                           0x12
 bDescriptorType:                   0x01
 bcdUSB:                          0x0200
 bDeviceClass:                      0x00  -> This is an Interface Class Defined 
Device

 bDeviceSubClass:                   0x00
 bDeviceProtocol:                   0x00
 bMaxPacketSize0:                   0x08 = (8) Bytes
 idVendor:                        0x04B3 = IBM Corporation
 idProduct:                       0x310C
 
 

 
 

 
 

 
 
 
 
 

___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


 
 ___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Writing and reading hexadecimal command

2019-11-21 Thread Nicolas Pinault via pyusb-users

Raphaël,

To convert numerical values to byte strings, and vice versa, please use 
the struct API :

import struct
s = struct.pack("

 Bonjour,

Thank you for your answer,

The DP5_Programmer's guide can be found here:

http://experimentationlab.berkeley.edu/sites/default/files/images/DP5_Programmers_Guide_A4.pdf

And the entire code is here (Python_SDK\pyDppUSB):

https://www.amptek.com/-/media/ametekamptek/documents/softwares/Python_SDK.zip?la=en

I run the pyDP5.py module (Python_SDK\pyDppUSB\pyDP5.py), and here is 
a selected part (from Python_SDK\pyDppUSB\DppLibusb.py) that I'm 
interested in. As I said, this code was provide by Amptek when I 
contacted them, but it's for demo only in python 2, and not offically 
supported (that's the reason why it's pretty "dirty", with the few 
correction I already added):


from vbfunctions import *
from vbclasses import *
import usb
import sys
import time
from dppStatus import *
import codecs

decode_hex = codecs.getdecoder("hex_codec")

LIBUSB_TIMEOUT = 500

#REQUEST_STATUS_PACKET = 
decode_hex('F5FA0101FE0F')  # Request Status Packet

REQUEST_STATUS_PACKET = '\xf5\xfa\x01\x01\x00\x00\xfe\x0f'


#---
# DppLibusb Class
#---

class DppLibusb():
    def __init__(self):
    self.VENDOR = 0x10C4
    self.PRODUCT = 0x842A
    self.CONFIGURATION = 1
    self.INTERFACE = 0
    self.ENDPOINT_IN = 0x81
    self.ENDPOINT_OUT = 0x02

    self.device = None
    self.handle = None

    self.device = usb.core.find(idVendor=0x10c4, idProduct=0x842a)

    #for bus in usb.busses():
    #   for dev in bus.devices:
    #  if dev.idVendor == self.VENDOR and dev.idProduct == 
self.PRODUCT:

    # self.device = dev

    self.strStatus = str()
    self.bArrStatusIn = bytes()
    self.bArrBuffer = bytes()
    self.AckPid2 = bytes()
    self.AckMsg = str()
    #self.STATUS = STATUS
    self.DataRaw = bytes()
    self.Channels = int()
    self.Data = int()
    self.Header = bytes()

    self.bArrArrBuffer = bytearray()

    if self.open() == None:
    print (sys.stderr, "Unable to open DppLibusb device!")
    sys.exit()
    return None

    def isConnected(self):
    _ret = False
    iNumBytes = 0
    print("Get Status")

*try:*
*    iNumBytes = self.write(REQUEST_STATUS_PACKET, 
LIBUSB_TIMEOUT)*

**
*    except usb.USBError as err:*
*    pass*
*    if iNumBytes  > 0:*
*    print ('Bytes Out =',iNumBytes) # debug*
*    try:*
**
*    self.bArrArrBuffer = self.read(128, LIBUSB_TIMEOUT)*
*    self.bArrStatusIn = bytearray(self.bArrArrBuffer)*
**
*    except usb.USBError as err:*
*    pass*


    if len(self.bArrStatusIn) > 0:
    print ("STATUS.RAW type ", type(self.STATUS.RAW))
    self.STATUS.RAW = bytearray(self.bArrStatusIn[6:70])
    if len(self.STATUS.RAW) > 0:
    Process_Status(self.STATUS)
    if (self.STATUS.SerialNumber > 0):
    _ret = True
    return _ret

While the iNumbytes get a value from the *iNumBytes = 
self.write(REQUEST_STATUS_PACKET, LIBUSB_TIMEOUT)* (which might be a 
wrong value), the *self.bArrArrBuffer = self.read(128, 
LIBUSB_TIMEOUT)* is never reached. So my guess is that the 
REQUEST_STATUS_PACKET is in the wrong format, thus my original 
question : how do I write and read instruction in hexadecimal ? Is 
converting the whole instruction in string via REQUEST_STATUS_PACKET = 
'\xf5\xfa\x01\x01\x00\x00\xfe\x0f' correct ? (I doubt it is). Again, 
sorry for the "messy" code, and thanks for any answer provided.


Best regards

Raphaël

    > Message du 21/11/19 10:11
> De : "Nicolas Pinault via pyusb-users"

> A : pyusb-users@lists.sourceforge.net
> Copie à : "Nicolas Pinault" 
> Objet : Re: [pyusb-users] Writing and reading hexadecimal command
>
>
Bonjour Raphaël,
>
> You do not provide enought information.
> Can you provide a link to the DP5 documentation ?
> Can you provide a small code sample ?
>
> Bonne journée,
> Nicolas
>
>
> Le 21/11/2019 à 09:43, raphael moreau a écrit :
>

> Good morning pyusb users,

>

> I'm writing you this emial because I'm facing an issue that
I did not succed to resolve until now, and I'm sure you will.

>

> I'm currently working on a Python project which involve t

Re: [pyusb-users] Writing and reading hexadecimal command

2019-11-21 Thread Nicolas Pinault via pyusb-users

Bonjour Raphaël,

You do not provide enought information.
Can you provide a link to the DP5 documentation ?
Can you provide a small code sample ?

Bonne journée,
Nicolas


Le 21/11/2019 à 09:43, raphael moreau a écrit :


Good morning pyusb users,

I'm writing you this emial because I'm facing an issue that I did not 
succed to resolve until now, and I'm sure you will.


I'm currently working on a Python project which involve the 
communication witn an USB Device (DP5 Amptek SDD Detector, an x-ray 
detector), and after a few test it seems that my device dont 
understand what I'm telling him to do.


I started with the basic, a Device Status request, which is the 
following (.jgp screenshot, I hope you'll be able to see it):


I tried the classic dev.write(x,test,x), with test = 
'\xf5\xfa\x01\x01\x00\x00\xfe\x0f', or test = '\xf5\xfa1100\xfe\x0f' 
but the expected result, which is the following(same here, .jpg 
screenshot):


does not seems to be return with res = dev.read(x, length, x) with 
length = 128 or length = 64 (seems odd to me for the 128 but i guess 
it's for the array format?)


My question is therefore quit simple, how do I pass and read thoses 
command ?


I'm using python 3, and I have no problem in term of identification of 
the device, configuration, interface and endpoint IN and OUT, with pyusb.


The program I'm using is an old python 2 demo supplied by the 
manufacturer which is not supported by them.


I precise that I'm rather new to USB and programming in general, so I 
apologize if this question seems basic, or had already been answered to.


Thank you for any response,

Best regards,

Raphaël Moreau



___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] UNICODE ERROR while writing text in endpoint

2016-12-22 Thread Nicolas Pinault

Hi,
Le 21/12/2016 à 18:18, Mayur Vijaywargi a écrit :

Hi,

I am getting this kind of error "'ascii' codec can't encode character 
u'\u010c' in position 6: ordinal not in range(128)"


This the code I am using to search endpoint to write:

def get_device(vid, pid, backend_driver=None):
if backend_driver is not None:
return core.find(idVendor=vid, idProduct=pid, 
backend=backend_driver)

else:
return core.find(idVendor=vid, idProduct=pid)

def searhDevices():
backend = None
if os.name  == "nt":
backend = libusb1.get_backend(find_library=lambda x: 
"dll/libusb0_x86.dll")


device = None
for each_device in supported_devices:
device = get_device(each_device.get('vid'), 
each_device.get('pid'), backend)

if device is not None:
response['line_size'] = each_device.get("line_size")
break

if device is None:
raise ValueError('Device not found')
device.set_configuration()
config = device.get_active_configuration()
for intf in config:
for each_endpoint in intf:
global end_point
end_point = util.find_descriptor(
intf, custom_match=lambda e: 
util.endpoint_direction(e.bEndpointAddress) == util.ENDPOINT_OUT)

if end_point is not None:
break

if end_point is None:
raise ValueError('End point not found')


end_point.write('¥À')

This is not a pyusb problem.
Since you wrote '¥À' and not u'¥À' , I assume you use Python3.
Even with Python3, you have to specify the source encoding at the first 
line of the file like the following.

# -*- coding: UTF-8 -*-
When not specified, Python3 considers you use UTF8 encoding.



--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel


___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


--
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Can't still not read Digital Multimeter USB output

2016-09-15 Thread Nicolas Pinault
Le 16/09/2016 à 01:21, Joe a écrit :
> Am 15.09.2016 um 12:11 schrieb Joe:
 What's the best method to install it?
>> Solved: pip install hidapi
>>
> This is now working with the usb hid interface of the UT61B DMM:
> hid.device.get_manufacturer_string,
> hid.device.get_product_string,
> hid.device.get_serial_number_string and
> hid.enumerate.
>
> But I could not find descriptions or documentation or samples of the
> following methods and properties of hid.device:
> error, close, open, open_path, read, write, send_feature_report.
> Unfortunetaly I see no source in the package, only a pyd file.
>
> Any hint, any idea?
> Thanx -- Joe
>
Even if it is not the right place (PyUSB mailing list) here is an example :

class MyDevice(object):
 def __init__(self, vendor_id=0x, product_id=0x, path=None):

 self.vendor_id = vendor_id
 self.product_id = product_id
 self.path = path

 if path :
 self.__dev = hid.Device(path=path)
 else :
 self.__dev = hid.Device(self.vendor_id, self.product_id)

 self.manufacturer = self.__dev.manufacturer
 self.product = self.__dev.product

 def GetFeature1(self):
 return struct.unpack("B", 
self.__dev.get_feature_report(HID_FEATURE_1, 5)[4])[0]

 def SetFeature2(self, value):
 self.__dev.send_feature_report(struct.pack("https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Can't still not read Digital Multimeter USB output

2016-09-15 Thread Nicolas Pinault

Le 15/09/2016 à 11:48, Joe a écrit :

Am 15.09.2016 um 09:01 schrieb Nicolas Pinault:

Under Windows, USB HID devices have to be accessed through the HID API,
not the USB API. This means you can't use PyUSB with HID devices under
Windows.

Try this package : https://pypi.python.org/pypi/hid/0.1.1

Nicolas

--
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

What's the best method to install it? My test machine runs under Win 10
Version 1607 (64 Bit) with Python. Didn't get it running with the infos
from https://pypi.python.org/pypi/hid/0.1.1
Regards - Joe


I don't install it. I just copy __init__.py in my sources folder and 
rename it hid.py.

As this module uses ctypes to work, you also need hidapi.dll.



--
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users
.




--
*Nicolas PINAULT
R&D electronics engineer
*** nico...@aaton.com <mailto:nico...@aaton.com>

*AATON-Digital*
38000 Grenoble - France
Tel +33 4 7642 9550

http://www.aaton.com
http://www.transvideo.eu
French Technologies for Film and Digital Cinematography

Follow us on Twitter
@Aaton_Digital
@Transvideo_HD

Like us on Facebook
https://www.facebook.com/AatonDigital

--
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Can't still not read Digital Multimeter USB output

2016-09-15 Thread Nicolas Pinault
Under Windows, USB HID devices have to be accessed through the HID API, 
not the USB API. This means you can't use PyUSB with HID devices under 
Windows.

Try this package : https://pypi.python.org/pypi/hid/0.1.1

Nicolas

--
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Digital Multimeter Output

2016-09-02 Thread Nicolas Pinault

Le 02/09/2016 à 11:33, Joe a écrit :

Am 02.09.2016 um 11:22 schrieb Xiaofan Chen:

On Thu, Sep 1, 2016 at 10:30 PM, Joe  wrote:

We use two DMMs UNI-T UT61B. They have two interfaces each, a RS232C
Interface and a USB interface.
The RS232C interfaces work well. Without any command before, the DMMs
continuously send 2 .. 3 packages of 14 Bytes per second. We get them with a
little Python 3.52 script, using PySerial. It's ok.

But the younger of our computers have no RS232C comports, and I don't want
to use virtual comports. So I try to use the USB interfaces of the DMMs with
PyUSB 1.0, but somethin is wrong with this test script (using Win10 Version
1607, 64 bit):

You need to check what kind of USB protocol the USB interface uses.
Maybe it is also a USB Serial Port and you can use the PySerial. If it
is not a USB serial port and you do not know the communication protocol,
then you have to carry out reverse engineering.

Google seems to say that sigrok supports it. You can try ask there
for the protocol.
https://sigrok.org/wiki/UNI-T_UT61B


Thank you, Xiaofan, I'll look at sigrok.
In the mean time I tried another attempt:

import usb.util
import usb.backend.libusb1

def Gosub():
  failures = 0
  failuresmaximum = 48
  dev = usb.core.find (idVendor = 0x1a86, idProduct = 0xe008) #
Multimeter UT61B
  if dev == None:
  print ('Multimeter UT61B not found')
  else:
  print ('Multimeter UT61B was found')
  print ('dev:\n' + str (dev) + '\n')
  dev.set_configuration ()
  ep = dev [0] [0,0] [0]
  if ep == None:
  print ('ep is None')
  else:
  data = None
  while failures < failuresmaximum:
  try:
  data = dev.read (ep.bEndpointAddress, ep.wMaxPackeSize)
  print ('Success. len (date): ' + len (date))
  except:
  failures += 1
  print ('Failures: ' + str (failures))
  if data == None:
  print ('No data read')
  else:
  for ss in data:
  print (str (ss))

print ('Starting')
Gosub ()
print ('Ready.-')

Output:

Starting
Multimeter UT61B was found
dev:
DEVICE ID 1a86:e008 on Bus 003 Address 003 =
   bLength:   0x12 (18 bytes)
   bDescriptorType:0x1 Device
   bcdUSB :  0x100 USB 1.0
   bDeviceClass   :0x0 Specified at interface
   bDeviceSubClass:0x0
   bDeviceProtocol:0x0
   bMaxPacketSize0:0x8 (8 bytes)
   idVendor   : 0x1a86
   idProduct  : 0xe008
   bcdDevice  : 0x1200 Device 18.0
   iManufacturer  :0x1 WCH.CN 
   iProduct   :0x2 USB to Serial
   iSerialNumber  :0x0
   bNumConfigurations :0x1
CONFIGURATION 1: 100 mA ==
 bLength  :0x9 (9 bytes)
 bDescriptorType  :0x2 Configuration
 wTotalLength :   0x29 (41 bytes)
 bNumInterfaces   :0x1
 bConfigurationValue  :0x1
 iConfiguration   :0x4 Error Accessing String
 bmAttributes :   0x80 Bus Powered
 bMaxPower:   0x32 (100 mA)
  INTERFACE 0: Human Interface Device 
   bLength:0x9 (9 bytes)
   bDescriptorType:0x4 Interface
   bInterfaceNumber   :0x0
   bAlternateSetting  :0x0
   bNumEndpoints  :0x2
   bInterfaceClass:0x3 Human Interface Device
   bInterfaceSubClass :0x0
   bInterfaceProtocol :0x0
   iInterface :0x0
ENDPOINT 0x82: Interrupt IN ==
 bLength  :0x7 (7 bytes)
 bDescriptorType  :0x5 Endpoint
 bEndpointAddress :   0x82 IN
 bmAttributes :0x3 Interrupt
 wMaxPacketSize   :0x8 (8 bytes)
 bInterval:0x5
ENDPOINT 0x2: Interrupt OUT ==
 bLength  :0x7 (7 bytes)
 bDescriptorType  :0x5 Endpoint
 bEndpointAddress :0x2 OUT
 bmAttributes :0x3 Interrupt
 wMaxPacketSize   :0x8 (8 bytes)
 bInterval:0x5

Failures: 48
No data read
Ready.-

Does anybody see the mistake?

Your device is a HID device.
You can't use PyUSB with HID devices under Windows.
For HID devices I use this : https://pypi.python.org/pypi/hid/0.1.1

Nicolas



Thank you - Joe


--
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Re: [pyusb-users] USB topology

2016-05-16 Thread Nicolas Pinault
Le 13/05/2016 à 17:36, Jeffrey Nichols a écrit :
> On 5/13/2016 10:39 AM, Nicolas Pinault wrote:
>> Le 13/05/2016 à 15:10, Jeffrey Nichols a écrit :
>> I already tried to use "port_numbers" but this field was always blank.
>> After updating libusb-1.0, this field is not blank anymore.
>>
>> What  I don't understand is that bus/port_number numbers are not unique.
>> On my system :
>>   IdVendor8086 IdProduct=1E26 bus=1 Address=1 port=0
>>   IdVendor8086 IdProduct=1E2D bus=2 Address=1 port=0
>> * IdVendor0204 IdProduct=6025 bus=1 Address=6 port=1 ports = (1, 6, 1)
>>   IdVendor0424 IdProduct=2513 bus=1 Address=2 port=6 ports = (1, 6)
>> + IdVendor046D IdProduct=C061 bus=2 Address=5 port=1 ports = (1, 1)
>>   IdVendor0529 IdProduct=0001 bus=1 Address=4 port=5 ports = (1, 5)
>>   IdVendor2CFF IdProduct=0002 bus=1 Address=5 port=2 ports = (1, 6, 2)
>>   IdVendor413C IdProduct=2107 bus=2 Address=2 port=2 ports = (1, 2)
>> + IdVendor8087 IdProduct=0024 bus=2 Address=4 port=1 ports = (1,)
>> * IdVendor8087 IdProduct=0024 bus=1 Address=3 port=1 ports = (1,)
>>   IdVendor8564 IdProduct=4000 bus=3 Address=20 port=8 ports = (8,)
>>   IdVendor8086 IdProduct=1E31 bus=3 Address=1 port=0
>>
>> The lines marked with a + or a * contains same bus/port_number numbers.
>> Only port_numbers field is different.
>> What does this mean ?
> When the bus is different, they're on totally different USB buses 
> (presumably this corresponds internally to USB root hubs, I'm not sure 
> of the technical details). That's always the first level of 
> differentiation.
>
Sure. It's so obvious I didn't mentioned it.
> The port always corresponds to the final number in the ports tuple. 
> It's the port number on the last hub in the hierarchy. It's not unique 
> enough to use to distinguish positions in the hierarchy (even when 
> combined with bus), and not terribly useful in my opinion.
That's what I discovered. Only port_numbers is useful.
>
> I use the tuple (bus, port_numbers) in my application to determine a 
> device's physical location, so when I tell a device to reboot into 
> bootloader mode I can find the new device in the same location (as a 
> device anywhere else could not be the one I'm looking for).
My use case is different but the idea is the same.

Nicolas

--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] USB topology

2016-05-13 Thread Nicolas Pinault

Le 13/05/2016 à 16:39, Nicolas Pinault a écrit :

Le 13/05/2016 à 15:10, Jeffrey Nichols a écrit :

On 5/13/2016 9:03 AM, Nicolas Pinault wrote:

Le 12/05/2016 à 17:15, Wander Lairson Costa a écrit :

2016-05-12 11:40 GMT-03:00 Nicolas Pinault:

Hi,

Is it possible to retrieve USB bus topology with PyUSB ?


Yes, you will need to use the Device object "port_number" and "bus" properties.
While it is enough for my application, I don't see how to 
reconstruct the USB tree with just "port_number".
There's also "port_numbers", assuming you're using a somewhat recent 
libusb-1.0 version as your backend. Combine that with the bus 
attribute, and you can get a representation of the physical 
attachment point of the device.

I already tried to use "port_numbers" but this field was always blank.
After updating libusb-1.0, this field is not blank anymore.

What  I don't understand is that bus/port_number numbers are not unique.
On my system :
  IdVendor8086 IdProduct=1E26 bus=1 Address=1 port=0
  IdVendor8086 IdProduct=1E2D bus=2 Address=1 port=0
* IdVendor0204 IdProduct=6025 bus=1 Address=6 port=1 ports = (1, 6, 1)
  IdVendor0424 IdProduct=2513 bus=1 Address=2 port=6 ports = (1, 6)
+ IdVendor046D IdProduct=C061 bus=2 Address=5 port=1 ports = (1, 1)
  IdVendor0529 IdProduct=0001 bus=1 Address=4 port=5 ports = (1, 5)
  IdVendor2CFF IdProduct=0002 bus=1 Address=5 port=2 ports = (1, 6, 2)
  IdVendor413C IdProduct=2107 bus=2 Address=2 port=2 ports = (1, 2)
+ IdVendor8087 IdProduct=0024 bus=2 Address=4 port=1 ports = (1,)
* IdVendor8087 IdProduct=0024 bus=1 Address=3 port=1 ports = (1,)
  IdVendor8564 IdProduct=4000 bus=3 Address=20 port=8 ports = (8,)
  IdVendor8086 IdProduct=1E31 bus=3 Address=1 port=0

The lines marked with a + or a * contains same bus/port_number numbers.
Only port_numbers field is different.
What does this mean ?


After sorting results and analysing further, I understand the whole picture.
port_numbers like (1,) references a hub
port_numbers like (1, 6, 2) indicate the full path to reach the device 
(root/hub/device)
port_number references the port number of the last hub the device is 
connected on..


Nicolas
--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] USB topology

2016-05-13 Thread Nicolas Pinault

Le 13/05/2016 à 15:10, Jeffrey Nichols a écrit :

On 5/13/2016 9:03 AM, Nicolas Pinault wrote:

Le 12/05/2016 à 17:15, Wander Lairson Costa a écrit :

2016-05-12 11:40 GMT-03:00 Nicolas Pinault:

Hi,

Is it possible to retrieve USB bus topology with PyUSB ?


Yes, you will need to use the Device object "port_number" and "bus" properties.
While it is enough for my application, I don't see how to reconstruct 
the USB tree with just "port_number".
There's also "port_numbers", assuming you're using a somewhat recent 
libusb-1.0 version as your backend. Combine that with the bus 
attribute, and you can get a representation of the physical attachment 
point of the device.

I already tried to use "port_numbers" but this field was always blank.
After updating libusb-1.0, this field is not blank anymore.

What  I don't understand is that bus/port_number numbers are not unique.
On my system :
  IdVendor8086 IdProduct=1E26 bus=1 Address=1 port=0
  IdVendor8086 IdProduct=1E2D bus=2 Address=1 port=0
* IdVendor0204 IdProduct=6025 bus=1 Address=6 port=1 ports = (1, 6, 1)
  IdVendor0424 IdProduct=2513 bus=1 Address=2 port=6 ports = (1, 6)
+ IdVendor046D IdProduct=C061 bus=2 Address=5 port=1 ports = (1, 1)
  IdVendor0529 IdProduct=0001 bus=1 Address=4 port=5 ports = (1, 5)
  IdVendor2CFF IdProduct=0002 bus=1 Address=5 port=2 ports = (1, 6, 2)
  IdVendor413C IdProduct=2107 bus=2 Address=2 port=2 ports = (1, 2)
+ IdVendor8087 IdProduct=0024 bus=2 Address=4 port=1 ports = (1,)
* IdVendor8087 IdProduct=0024 bus=1 Address=3 port=1 ports = (1,)
  IdVendor8564 IdProduct=4000 bus=3 Address=20 port=8 ports = (8,)
  IdVendor8086 IdProduct=1E31 bus=3 Address=1 port=0

The lines marked with a + or a * contains same bus/port_number numbers.
Only port_numbers field is different.
What does this mean ?

Regards,
Nicolas





Jeff


--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j


___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users



--
*Nicolas PINAULT
R&D electronics engineer
*** nico...@aaton.com <mailto:nico...@aaton.com>

*AATON-Digital*
38000 Grenoble - France
Tel +33 4 7642 9550

http://www.aaton.com
http://www.transvideo.eu
French Technologies for Film and Digital Cinematography

Follow us on Twitter
@Aaton_Digital
@Transvideo_HD

Like us on Facebook
https://www.facebook.com/AatonDigital

--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] USB topology

2016-05-13 Thread Nicolas Pinault

Le 12/05/2016 à 17:15, Wander Lairson Costa a écrit :

2016-05-12 11:40 GMT-03:00 Nicolas Pinault :

Hi,

Is it possible to retrieve USB bus topology with PyUSB ?


Yes, you will need to use the Device object "port_number" and "bus" properties.
While it is enough for my application, I don't see how to reconstruct 
the USB tree with just "port_number".



Regards,
Nicolas

--
Nicolas PINAULT
R&D electronics engineer
nico...@aaton.com

AATON-Digital
38000 Grenoble - France
Tel +33 4 7642 9550

http://www.aaton.com
http://www.transvideo.eu
French Technologies for Film and Digital Cinematography

Follow us on Twitter
@Aaton_Digital
@Transvideo_HD

Like us on Facebook
https://www.facebook.com/AatonDigital


--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users







--
*Nicolas PINAULT
R&D electronics engineer
*** nico...@aaton.com <mailto:nico...@aaton.com>

*AATON-Digital*
38000 Grenoble - France
Tel +33 4 7642 9550

http://www.aaton.com
http://www.transvideo.eu
French Technologies for Film and Digital Cinematography

Follow us on Twitter
@Aaton_Digital
@Transvideo_HD

Like us on Facebook
https://www.facebook.com/AatonDigital

--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


[pyusb-users] USB topology

2016-05-12 Thread Nicolas Pinault

Hi,

Is it possible to retrieve USB bus topology with PyUSB ?


Regards,
Nicolas

--
*Nicolas PINAULT
R&D electronics engineer
*** nico...@aaton.com <mailto:nico...@aaton.com>

*AATON-Digital*
38000 Grenoble - France
Tel +33 4 7642 9550

http://www.aaton.com
http://www.transvideo.eu
French Technologies for Film and Digital Cinematography

Follow us on Twitter
@Aaton_Digital
@Transvideo_HD

Like us on Facebook
https://www.facebook.com/AatonDigital

--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Problem accessing USB device

2016-01-28 Thread Nicolas Pinault

Looks like I found the answer to my problem.
On this page http://www.libusb.org/wiki/APIs, I've read :
"libusb is not suited for HID class devices. While it is possible to use 
libusb with HID class devices it requires the original HID class driver 
to be replaced by a driver which supports libusb, and this leads to a 
quite poor user experience on any platform other than Linux. It is 
recommended to use ​HIDAPI <http://www.signal11.us/oss/hidapi/> instead. 
HIDAPI provides convenient cross-platform access to HID class devices 
and can do so without any kernel driver concerns across all supported 
platforms."


Nicolas

Le 28/01/2016 08:21, Nicolas Pinault a écrit :

Hi,

I'm trying to use a USB device under Windows7x64.
The device is HID like with custom protocol.
The USB device is recognised by Windows as a HID device (without error 
nor warning shown is device manager).

It works perfectly with a host running QNX OS.

With PyUSB :
Discovery of the device is OK.
Configuration of the device seems to be OK.
Reading/writing the device fails.

Here is the code I use :

import usb.core
import usb.util

class Test(object):
def __init__(self):
self.VendorId = 0x15A2
self.ProductId = 0x0073
self.dev = usb.core.find(idVendor=self.VendorId, 
idProduct=self.ProductId)

if not self.dev :
raise ValueError("Device not found")
print self.dev

self.dev.set_configuration()

cfg = self.dev.get_active_configuration()
intf = cfg[(0,0)]
self.interface = cfg[(0,0)].bInterfaceNumber

self.dev.set_interface_altsetting(interface = self.interface, 
alternate_setting = self.interface)


print "Interface :", self.interface
self.DeviceSetIdle()

def DeviceSetIdle(self):
self.dev.ctrl_transfer(bmRequestType = 
usb.util.build_request_type(usb.util.CTRL_OUT,

usb.util.CTRL_TYPE_CLASS,
usb.util.CTRL_RECIPIENT_INTERFACE),
   bRequest = USB_HID_SET_IDLE_REQUEST,
# 0x0A

   wValue   = 0,#8 << 8,
   wIndex   = self.interface,
   data_or_wLength = None,
   timeout  = 0)

if __name__ == '__main__':
t = Test()

I get the following output :
DEVICE ID 15a2:0073 on Bus 003 Address 023 =
 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   : 0x15a2
 idProduct  : 0x0073
 bcdDevice  :0x2 Device 0.02
 iManufacturer  :0x1 Freescale Semiconductor Inc.
 iProduct   :0x2 Kinetis Bootloader
 iSerialNumber  :0x0
 bNumConfigurations :0x1
  CONFIGURATION 1: 100 mA ==
   bLength  :0x9 (9 bytes)
   bDescriptorType  :0x2 Configuration
   wTotalLength :   0x29 (41 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  :0x2
 bInterfaceClass:0x3 Human Interface Device
 bInterfaceSubClass :0x0
 bInterfaceProtocol :0x0
 iInterface :0x0
  ENDPOINT 0x81: Interrupt IN ==
   bLength  :0x7 (7 bytes)
   bDescriptorType  :0x5 Endpoint
   bEndpointAddress :   0x81 IN
   bmAttributes :0x3 Interrupt
   wMaxPacketSize   :   0x40 (64 bytes)
   bInterval:0xa
  ENDPOINT 0x2: Interrupt OUT ==
   bLength  :0x7 (7 bytes)
   bDescriptorType  :0x5 Endpoint
   bEndpointAddress :0x2 OUT
   bmAttributes :0x3 Interrupt
   wMaxPacketSize   :   0x40 (64 bytes)
   bInterval:0xa
Interface : 0
Traceback (most recent call last):
  File 
"Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", 
line 244, in 

t = Test()
  File 
"Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", 
line 154, in __init__

self.DeviceSetIdle()
  File 
"Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", 
line 174, in DeviceSetIdle

timeout  = 0)
  File "C:\Python27\lib\site-packages\usb\core.py", line 1043, in 
ctrl_transfer

self.__get_timeout(timeout))
  File "

[pyusb-users] Problem accessing USB device

2016-01-27 Thread Nicolas Pinault

Hi,

I'm trying to use a USB device under Windows7x64.
The device is HID like with custom protocol.
The USB device is recognised by Windows as a HID device (without error 
nor warning shown is device manager).

It works perfectly with a host running QNX OS.

With PyUSB :
Discovery of the device is OK.
Configuration of the device seems to be OK.
Reading/writing the device fails.

Here is the code I use :

import usb.core
import usb.util

class Test(object):
def __init__(self):
self.VendorId = 0x15A2
self.ProductId = 0x0073
self.dev = usb.core.find(idVendor=self.VendorId, 
idProduct=self.ProductId)

if not self.dev :
raise ValueError("Device not found")
print self.dev

self.dev.set_configuration()

cfg = self.dev.get_active_configuration()
intf = cfg[(0,0)]
self.interface = cfg[(0,0)].bInterfaceNumber

self.dev.set_interface_altsetting(interface = self.interface, 
alternate_setting = self.interface)


print "Interface :", self.interface
self.DeviceSetIdle()

def DeviceSetIdle(self):
self.dev.ctrl_transfer(bmRequestType = 
usb.util.build_request_type(usb.util.CTRL_OUT,

usb.util.CTRL_TYPE_CLASS,
usb.util.CTRL_RECIPIENT_INTERFACE),
   bRequest = USB_HID_SET_IDLE_REQUEST,
# 0x0A

   wValue   = 0,#8 << 8,
   wIndex   = self.interface,
   data_or_wLength = None,
   timeout  = 0)

if __name__ == '__main__':
t = Test()

I get the following output :
DEVICE ID 15a2:0073 on Bus 003 Address 023 =
 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   : 0x15a2
 idProduct  : 0x0073
 bcdDevice  :0x2 Device 0.02
 iManufacturer  :0x1 Freescale Semiconductor Inc.
 iProduct   :0x2 Kinetis Bootloader
 iSerialNumber  :0x0
 bNumConfigurations :0x1
  CONFIGURATION 1: 100 mA ==
   bLength  :0x9 (9 bytes)
   bDescriptorType  :0x2 Configuration
   wTotalLength :   0x29 (41 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  :0x2
 bInterfaceClass:0x3 Human Interface Device
 bInterfaceSubClass :0x0
 bInterfaceProtocol :0x0
 iInterface :0x0
  ENDPOINT 0x81: Interrupt IN ==
   bLength  :0x7 (7 bytes)
   bDescriptorType  :0x5 Endpoint
   bEndpointAddress :   0x81 IN
   bmAttributes :0x3 Interrupt
   wMaxPacketSize   :   0x40 (64 bytes)
   bInterval:0xa
  ENDPOINT 0x2: Interrupt OUT ==
   bLength  :0x7 (7 bytes)
   bDescriptorType  :0x5 Endpoint
   bEndpointAddress :0x2 OUT
   bmAttributes :0x3 Interrupt
   wMaxPacketSize   :   0x40 (64 bytes)
   bInterval:0xa
Interface : 0
Traceback (most recent call last):
  File 
"Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", 
line 244, in 

t = Test()
  File 
"Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", 
line 154, in __init__

self.DeviceSetIdle()
  File 
"Z:\Cantar2\Processeur\Apps_2\PyCantarem2Update\src\PyCantarem2Update.py", 
line 174, in DeviceSetIdle

timeout  = 0)
  File "C:\Python27\lib\site-packages\usb\core.py", line 1043, in 
ctrl_transfer

self.__get_timeout(timeout))
  File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 
883, in ctrl_transfer

timeout))
  File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 
595, in _check

raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 22] Invalid parameter

As I am far from a USB ninja, I spent days documenting myself and 
searching the Internet for a solution without success.


What's wrong with my code ?

Nicolas

--
*Nicolas PINAULT
R&D electronics engineer
*** nico...@aaton.com <mailto:nico...@aaton.com>

*AATON-Digital*
38000 Grenoble - France
Tel +33 4 7642 9550

http://www.aaton.com
http://www.transvideo.eu
French Techn