Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2293

Re: Get USB ID of a serial port through pyserial?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <wisecracker@tesco.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'sys': 0.04; 'roll': 0.07; 'checking.': 0.09; 'etc...': 0.09; 'received:81.103': 0.09; 'received:81.103.221': 0.09; 'received:81.103.221.35': 0.09; 'received:81.103.221.58': 0.09; 'received:ispmail.ntl.com': 0.09; 'received:ntl.com': 0.09; 'received:queueout04-winn.ispmail.ntl.com': 0.09; 'second.': 0.09; 'starter': 0.09; 'sys.platform': 0.09; 'whitespaces': 0.09; 'linux': 0.11; 'written': 0.12; '"0"': 0.16; 'coder': 0.16; 'is"': 0.16; 'it...': 0.16; 'osx': 0.16; 'pyserial': 0.16; 'received:aamtaout04-winn.ispmail.ntl.com': 0.16; 'think?': 0.16; 'windows?': 0.16; 'case.': 0.16; 'figure': 0.18; 'of.': 0.19; 'device': 0.20; 'maybe': 0.21; '(and': 0.22; 'etc,': 0.23; 'exists.': 0.23; 'module,': 0.23; "what's": 0.24; 'detect': 0.25; 'determined': 0.25; 'assume': 0.25; 'windows': 0.26; 'there.': 0.26; 'work.': 0.27; 'error': 0.29; 'subject:?': 0.29; 'needed,': 0.29; 'also.': 0.31; 'exists,': 0.31; 'port.': 0.31; 'subject:through': 0.31; 'vast': 0.31; 'does': 0.31; 'it.': 0.31; 'random': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'example,': 0.33; 'things': 0.33; 'bit': 0.33; 'module': 0.33; 'requires': 0.35; 'there': 0.35; 'difficult': 0.35; 'put': 0.35; 'module.': 0.35; 'surprised': 0.35; 'too': 0.36; 'getting': 0.36; 'think': 0.36; 'platform': 0.36; 'some': 0.37; 'skip:o 20': 0.37; 'raw': 0.37; 'user': 0.38; 'but': 0.38; 'no.': 0.38; 'port': 0.38; 'so,': 0.38; 'to.': 0.39; '1200': 0.39; 'ok,': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'how': 0.39; 'would': 0.40; 'necessarily': 0.40; 'from:no real name:2**0': 0.60; 'back': 0.61; 'url:net': 0.62; 'ready': 0.63; 'year': 0.63; 'devices': 0.64; 'url:search': 0.64; 'here': 0.65; 'here.': 0.68; 'press': 0.71; 'subject:Get': 0.74; 'serial': 0.77; 'yours': 0.84; 'crude': 0.84; 'don`t': 0.84; 'win32:': 0.84; 'stretch': 0.91; 'yours.': 0.93; 'usb': 0.95
Date Thu, 31 Mar 2011 18:59:49 +0100
From <wisecracker@tesco.net>
To Python <python-list@python.org>
Subject Re: Get USB ID of a serial port through pyserial?
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Priority 3 (Normal)
Sensitivity Normal
X-Originating-IP from 86.143.162.194 by mail.tesco.net; Thu, 31 Mar 2011 18:59:49 +0100
X-Mailer 4.2.7
X-Cloudmark-Analysis v=1.1 cv=R50lirqlHffDPPkwUlkuVa99MrvKdVWo//yz83qex8g= c=1 sm=0 a=7hlicc0NwKgA:10 a=IkcTkHD0fZMA:10 a=UVwo0EfeAAAA:8 a=uVhb0EPuAAAA:8 a=nWwrNhkoAAAA:8 a=6bQkU-fnAAAA:8 a=ZCGR1grB8ASzq61wZ6cA:9 a=YZvvLk3BzbpLhwmzV9kA:7 a=QEXdDO2ut3YA:10 a=4-eX4snyH10A:10 a=b-W18Ad88IKKZmUS:21 a=zhy2HWEJ3q066I54:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.38.1301597172.2990.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 82.94.164.166
X-Trace 1301597172 news.xs4all.nl 81483 [::ffff:82.94.164.166]:33701
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2293

Show key headers only | View raw


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/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Get USB ID of a serial port through pyserial? <wisecracker@tesco.net> - 2011-03-31 18:59 +0100

csiph-web