Hi John Nagle...

> Is there some way to get the USB ID of a serial port through pyserial on 
> Linux and/or
> Windows?

I`m surprised that the big guns on here haven`t helped...

Short answer no.

> USB serial port devices have device names determined by when they were 
> plugged in.

Yep and they are easy to find in 32 bit Windows, *nix, AmigaOS and Mac OSX...

> So, if you have more than one USB serial device, you need the USB device's 
> built-in
> ID to figure out what's out there. Is there a way to get that info portably?

No not your way, but let`s see if I can help...
It is difficult to detect USB-Serial that is" p-n-p" and able to be put into 
any USB port.

In Windows it will be given a COMx: device, in *.nix /dev/ttyUSBx, in AmigaOS 
SER: and
I don`t know for sure but in Mac OSX /dev/ttyUSBx too

OK, I`m NO coder by any stretch of the imagination; but I have vast experience 
on getting
things like this to work. watch for wordwrapping etc, etc...

Let`s think laterally; how would a 10 year old think?
Assumptions will be made but not necessarily written here.
For this to work there will need to be user intervention at some point.

To make your needs platform independent requires the sys module, the 
sys.platform part
of it. Also the os module is needed, (and maybe the time module), to create 
your own custom
module. NOTE:- Pyserial is NOT needed for this AT ALL!

Righto, assume that the computer is powered down. This is a crude example, 
without error
checking.

Plug in your USB-Serial adaptor into any random USB port.

Power up the computer to Windows 32 bit or Linux in your case.

# Linux first...

import os
import sys
global myportnumber
myportnumber = "0"
if sys.platform == linux2:
        # To see if ttyUSBx exists.
        os.system("ls /dev/ttyUSB*")
        # If only one does then this will be yours.
        # If more than one exists, remove your unit from the USB port.
        raw_input("Remove the USB-Serial adaptor from the port then press 
ENTER:- ")
        os.system("ls /dev/ttyUSB*")
        # Now find out which number does not exist and that is yours also.
        # Replace the adaptor back into the same port as it came out of.
        # myportnumber = raw_input("ENTER the number ONLY of your adaptor and 
press RETURN:- ")
        # Now set up the port to RAW and say 1200 bps.
        # NOTE:- The whitespaces must be adhered to.
        os.system("stty -F /dev/ttyUSB"+myportnumber+" 1200")
        os.system("stty -F /dev/ttyUSB"+myportnumber+" raw")

# You are now ready to roll and use your USB-Serial port.

# Windows second.

import os
import sys
global myportnumber
myportnumber = "0"
if sys.platform == win32:
        # To see if COMx exists.
        os.system("MODE.COM")
        # If only one does then this will be yours.
        # If more than one exists, remove your unit from the USB port.
        raw_input("Remove the USB-Serial adaptor from the port then press 
ENTER:- ")
        os.system("MODE.COM")
        # Now find out which number does not exist and that is yours also.
        # Replace the adaptor back into the same port as it came out of.
        # myportnumber = raw_input("ENTER the number ONLY of your adaptor and 
press RETURN:- ")
        # Now set up the port to RAW and say 1200 bps.
        # NOTE:- The whitespaces must be adhered to.
        os.system("MODE COM"+myportnumber+": BAUD=1200 PARITY=N DATA=8 STOP=1 
to=on")

This is a starter and no doubt the Pros on here will take th p**s out of it...



--
73...

Bazza, G0LCU...

Team AMIGA...

http://homepages.tesco.net/wisecracker/

http://main.aminet.net/search?readme=wisecracker

http://mikeos.berlios.de/

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to