[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

device identification

Omer Ihsan

3/21/2010 8:45:00 PM

i have installed pyusb now and run the sample usbenum.py....i have 3
usb ports on my PC but the results show 6 outputs to
dev.filename..they are numbers like 001 or 005 etc.... and they
changed when i plugged in devices...(i am no good with the usb
standards)....i just want to identify each device/port... what
parameter in the example would help me....

3 Answers

Tim Roberts

3/23/2010 4:22:00 AM

0

Omer Ihsan <omrihsan@gmail.com> wrote:
>
>i have installed pyusb now and run the sample usbenum.py....i have 3
>usb ports on my PC but the results show 6 outputs to
>dev.filename..they are numbers like 001 or 005 etc.... and they
>changed when i plugged in devices...(i am no good with the usb
>standards)....i just want to identify each device/port... what
>parameter in the example would help me....

You can't identify the ports.[1] What good would it do you? The ports on
your PC are not numbered.

You certainly CAN identify the devices, by their VID and PID (or idVendor
and idProduct). You identify by function, not by location. When you plug
in a USB drive, you don't want to worry about where it's plugged in.
===
[1]: OK, technically, it is not impossible to identify the port numbers,
but it is quite tedious. You need to chase through the sysfs expansion of
your buses hub/port tree and find a match for your device. It's not worth
the trouble.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Omer Ihsan

3/23/2010 2:49:00 PM

0

On Mar 23, 9:22 am, Tim Roberts <t...@probo.com> wrote:
> Omer Ihsan <omrih...@gmail.com> wrote:
>
> >i have installed pyusb now and run the sample usbenum.py....i have 3
> >usb ports on my PC but the results show 6 outputs to
> >dev.filename..they are numbers like 001 or 005 etc.... and they
> >changed when i plugged in devices...(i am no good with the usb
> >standards)....i just want to identify each device/port... what
> >parameter in the example would help me....
>
> You can't identify the ports.[1]  What good would it do you?  The ports on
> your PC are not numbered.
>
> You certainly CAN identify the devices, by their VID and PID (or idVendor
> and idProduct).  You identify by function, not by location.  When you plug
> in a USB drive, you don't want to worry about where it's plugged in.
> ===
> [1]: OK, technically, it is not impossible to identify the port numbers,
> but it is quite tedious.  You need to chase through the sysfs expansion of
> your buses hub/port tree and find a match for your device.  It's not worth
> the trouble.
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

VID and PID is fair enough. now what i want is that i have a threaded
code that threads two functions to run at the same time. i want each
function to run seperate devices. the problem is if it doesnt identify
the attached devices it might run the code on a single device which
isnt what is required.
how will i be able to run a code on a device of my choice???....you
can leave away the threading part for now.

Tim Roberts

3/25/2010 3:41:00 AM

0

Omer Ihsan <omrihsan@gmail.com> wrote:
>
>VID and PID is fair enough. now what i want is that i have a threaded
>code that threads two functions to run at the same time. i want each
>function to run seperate devices. the problem is if it doesnt identify
>the attached devices it might run the code on a single device which
>isnt what is required.

Some of the libraries that pyusb uses are not thread-safe, like libusb 0.1.

>how will i be able to run a code on a device of my choice???....you
>can leave away the threading part for now.

You can return all of the devices with a particular VID and PID:

collection = usb.core.find( find_all=True, idVendor=0x1234,
idProduct=0x5678 )

Then you can dish those out to threads using something like the queue
module.

Or, usb.core.find accepts a predicate function that allows you to use any
criteria you wish.

What kind of device are you trying to manipulate? I have a lot of USB
experience -- perhaps I can offer advice.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.