How to tell which USB Com port is which

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Make y'all a deal - I'll teach you English and you teach me Python...  cheeky

 

More seriously, thanks for the recommendations.  Will hunt a few of them down.  Online tutorials are good too, but I still like books on paper.  Among other things, you can throw them across the room in frustration, and they're often little the worse for it.  Can't say that for a PDF on a PC.  S.

 

PS - One thing I've not seen yet (I'm sure there's a way) is hunting down exactly which COM port the USB<->RS232 gadget winds up at.  I've seen some seriously silly numbers, and they're not that hard to hunt down in something like the Device Manager, but a program to do so automatically might have to ramble through lots of them sending some query and expecting some unique response.  Easily done, but more hassle...  S.

Last Edited: Mon. Sep 4, 2017 - 01:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:

jgmdesign wrote:
I find Bob's comment rather funny.....I am asking a question about a programming language named after a snake.
It's name after Monty Python: good movies, not so much the TV series.

 

Furthermore PS - Some of the TV shows weren't that special.  Some were hilarious - Spam, The Argument Clinic, the Cheese Shop, How Not To Be Seen, and others.  Ask the Simpsons - They can't all be as good as the best.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:
PS - One thing I've not seen yet (I'm sure there's a way) is hunting down exactly which COM port the USB<->RS232 gadget winds up at.  I've seen some seriously silly numbers, and they're not that hard to hunt down in something like the Device Manager, but a program to do so automatically might have to ramble through lots of them sending some query and expecting some unique response.  Easily done, but more hassle...  S.
I've never done it automatically.

Under both Linux and Windows I've always just checked for the new device.

To make matters worse, not closing a port properly can make it unavailable for a while.

Unplugging and plugging can cause a name/number change.

 

On Linux, I think that the output from lsusb can be used to find the right entry under /dev .

The line

Bus 002 Device 003: ID 03f0:5611 Hewlett-Packard PhotoSmart C3180

is for one of my printers

'Tain't a virtual serial port.  I don't have any at the moment.

Its VID:PID pair is 03f0:5611 .

Its device node is /dev/bus/usb/002/003 .

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Almost nothing you can think of doing in python is new. If I Google "python enumerate serial ports" top hit is.... 

 

https://stackoverflow.com/questi...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Almost nothing you can think of doing in python is new. If I Google "python enumerate serial ports" top hit is.... 

 

https://stackoverflow.com/questi...

I hadn't thought of enumeration as a search term.

The contained link to pyserial documentation is better:

https://pythonhosted.org/pyseria... wrote:
Tools
serial.tools.list_ports

This module can be executed to get a list of ports (python -m serial.tools.list_ports). It also contains the following functions.

serial.tools.list_ports.comports()
    Returns:    an iterable that yields ListPortInfo objects.

A ListPortInfo object normally contains the information needed to select the right virtual serial port.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

Last Edited: Mon. Sep 4, 2017 - 03:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:
 to ramble through lots of them sending some query and expecting some unique response.  

Really - do not do that!!

 

Sooner or later, you are bound to upset something with that query!

 

surprise

 

The microsoft mouse driver used to do this - and cause havoc!

 

angry

 

There was a startup option somewhere to disable it.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:
PS - One thing I've not seen yet (I'm sure there's a way) is hunting down exactly which COM port the USB<->RS232 gadget winds up at.  I've seen some seriously silly numbers, and they're not that hard to hunt down in something like the Device Manager, but a program to do so automatically might have to ramble through lots of them sending some query and expecting some unique response.  Easily done, but more hassle...  S.

 

I've been battling with this for a while now, not with python but in general,  i got my custom board with ftdi usb-uart chip and have named it with their own tool, sadly windows does not want to give this information easily.(Sure it still displays the name i'm looking for from settings -> other devices, but nowhere else)

 

if you only ever going to have one usb gadget with same device descriptor + vid/pid on your system, then you can find it many ways.

 

awneil wrote:
Really - do not do that!!

 

Do you hate me if i tell i do that also? :P 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JoniS wrote:
Do you hate me if i tell i do that 

Yes!

 

It really is a pain when you have something connected to a COM port, then some other totally unrelated app starts squirting stuff at it!!

 

angry

 

It can also mess-up the app which is supposed to be using the port if your "scanner" happens to to be using it at the point that it tries to open it ...

 

 

EDIT

 

This has nothing specifically to do with Python - dunno if it's possible to split out to a separate thread?

 

EDIT 2

 

It has now been split - from this: https://www.avrfreaks.net/forum/two-snakes-one-python

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Sep 4, 2017 - 01:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Scroungre wrote:
 to ramble through lots of them sending some query and expecting some unique response.  

Really - do not do that!!

 

Sooner or later, you are bound to upset something with that query!

 

surprise

 

 

 

Yeah, I was thinking about that when I wrote it, and decided that while it's easy enough to enforce among all MY gizmos, I often have plugged in things that are not mine.

 

Enumeration sounds like a better idea, although I believe it'll only tell you what ports exist, not what's plugged into them.

 

Ideally, we here at AVR Freaks could standardize on something! [Obligatory XKCD  https://www.xkcd.com/927/

 

This is what the USB-IF organization does, passing out vid/pid pairs, but they want a thousand bucks ($US, when I last checked) each to register, and to confirm they're unique.  Not really practical for hobbyist gizmos.

 

My thoughts were more along the Hayes AT command set, ie. a guard time (say at least one second of quiet), a sequence of three characters (say ===, where Hayes uses +++) followed by another guard time (one more second).  Then the device returns a string (say up to 255 chars, null terminated, with 'probably unique' descriptive bits in it (author's name?  device name?  64-bit hash of the .hex file?).  It's then up to the software to agree, "Yep, that's who I want to talk to" or "Sorry, wrong COM number."

 

Might be more complicated than it has to be, but would work on multidrop buses and such because the guard times prevent the sequence from accidentally showing up in a bitstream (yeah, technically a sensor could report exactly === as data after more than a second idle and then have nothing more to transmit, but the chance of that is akin to the chance of a hash collision in our 64-bit space.  So there.  cheeky)

 

S.

 

PS - Note that the hash of the hex could be calculated offline, if you exclude the hash itself from what's being hashed.  Else, when you try to program it into the PROGMEM as the hash of everything else the resulting hex file will hash to something else...  Whee!  Or stick it into EEprom.  S.

 

Edited to add PPS:  If you wanted to be snotty, you need merely calculate the hash once, of revision 1.0, then always deliver that hash value to the software, and it'll act as if it's the same thing.  This might simplify distribution (the software can always be the same) but cause trouble when the software is trying to use a feature that isn't in that revision...  S.

 

PPPS: If you really wanted to be snotty, set the hash to all zeros and increment it when you feel like it.  Saves hashing, I guess, and sounds like good fun until you realize that someone else had exactly the same idea, and lo - hash collisions!  (not really).  S.

 

Last Edited: Mon. Sep 4, 2017 - 10:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:
 it's easy enough to enforce among all MY gizmos, I often have plugged in things that are not mine.

Yes - that is my point.

 

So long as it all stays on your own machine, it remains your problem - so that's fine.

 

The Big Issue is when someone ships this kind of thing in an app to be installed on other people's machines...

 

angry

 

Enumeration sounds like a better idea, although I believe it'll only tell you what ports exist, not what's plugged into them.

Indeed.

 

Although the Windows Device Manager often displays extra info; eg,

 

 

so that could possibly help ...

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Although the Windows Device Manager often displays extra info; eg,

 

Brother paid a thousand bucks for that.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:

awneil wrote:

Although the Windows Device Manager often displays extra info; eg,

 

Brother paid a thousand bucks for that.  S.

Yup, othervice it would show the standard name from driver manufactor which comes from driver files, ie. Ftdi let's people change the descriptor name of the chip, but in the device manager it still shows the standard "USB serial stuff" because that's what the driver's report. Anyway, at the late night yesterday, I found a way to get the name which the chip itself reports and not the driver's, with help of D2XX driver instead of VCP driver, this obviously only helps aslong as I use ftdi devices for the USB comms.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:
Brother paid a thousand bucks for that. S.
But if you program an AVR-USB with LUFA you can achieve the same.

 

So if you want "identifiable" interfaces don't buy ebay USB-TTL/RS232 devices but make up boards with something like a mega8U2 and program them to do CDC-ACM with LUFA and set the string in each to something unique ;-)

 

Now you can enumerate and look for the right unique string.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you're saying it's not directly tied to the VID/PID - it can be changed without having to fork-out for a VID/PID ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well Atmel have done Dean a HUGE favour and given him some of their VID space.

 

From:

 

http://www.linux-usb.org/usb.ids

 

03eb  Atmel Corp.
	0902  4-Port Hub
	2002  Mass Storage Device
	2015  at90usbkey sample firmware (HID keyboard)
	2018  at90usbkey sample firmware (CDC ACM)
	2019  stk525 sample firmware (microphone)
	201c  at90usbkey sample firmware (HID mouse)
	201d  at90usbkey sample firmware (HID generic)
	2022  at90usbkey sample firmware (composite device)
	2040  LUFA Test PID
	2041  LUFA Mouse Demo Application
	2042  LUFA Keyboard Demo Application
	2043  LUFA Joystick Demo Application
	2044  LUFA CDC Demo Application
	2045  LUFA Mass Storage Demo Application
	2046  LUFA Audio Output Demo Application
	2047  LUFA Audio Input Demo Application
	2048  LUFA MIDI Demo Application
	2049  Stripe Snoop Magnetic Stripe Reader
	204a  LUFA CDC Class Bootloader
	204b  LUFA USB to Serial Adapter Project
	204c  LUFA RNDIS Demo Application
	204d  LUFA Combined Mouse and Keyboard Demo Application
	204e  LUFA Dual CDC Demo Application
	204f  LUFA Generic HID Demo Application
	2060  Benito Programmer Project
	2061  LUFA Combined Mass Storage and Keyboard Demo Application
	2062  LUFA Combined CDC and Mouse Demo Application
	2063  LUFA Datalogger Device
	2064  Interfaceless Control-Only LUFA Devices
	2065  LUFA Test and Measurement Demo Application
	2066  LUFA Multiple Report HID Demo
	2068  LUFA Virtual Serial/Mass Storage Demo
	2069  LUFA Webserver Project
etc.

So if you use AVR you get access to a ready made VID/PID to use anyway. After that it's just a question of  editing a string in the config.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Scroungre wrote:
Brother paid a thousand bucks for that. S.
But if you program an AVR-USB with LUFA you can achieve the same.

 

So if you want "identifiable" interfaces don't buy ebay USB-TTL/RS232 devices but make up boards with something like a mega8U2 and program them to do CDC-ACM with LUFA and set the string in each to something unique ;-)

 

Now you can enumerate and look for the right unique string.

 

You can also identify atleast FTDI chips since string descriptor can be changed with FT_Prog.

Proplem is while from setting's you can actually see that the descriptor got changed, for god knows why device manager is only showing info which the driver .inf files provide without a clue about the change in descriptor, neithed does "managementObjectSearcher" or registry know anything about the name shown in settings.(Well registry can show it if lucky, but its not reliable way of identification since noone guarantines that the info is in there).

 

But yeah, by using D2XX driver instead of VCP, i managed to get the name i'm looking for from FTDI set of apis, which makes it possible to identify the one you look for programatically for autoconnect feature.(which is kinda needed for backround service)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If one was going the LUFA route then line 194 here...

 

https://github.com/abcminiuser/l...

 

As you can see that example project would currently show "LUFA USB-RS232 Adapter" there. Could just as easily be "Fred Bloggs adapter 0037" to make it easily findable.

 

BTW above in the file you see:

 

https://github.com/abcminiuser/l...

 

so it's a 0x204B from the list above.

Last Edited: Mon. Sep 4, 2017 - 02:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Well Atmel have done Dean a HUGE favour and given him some of their VID space.

 

Nice of them.  Before LUFA existed I tried to get a u2 chip working, and Atmel's sample code wouldn't even compile.

 

Hopefully Dean is now on a sailboat drinking from skinny glasses with little umbrellas in them, because Atmel couldn't get their own code working.  They owe him, in a big way.

 

S.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:
Hopefully Dean is now on a sailboat drinking from skinny glasses with little umbrellas in them
I follow him on twitter. I don't think he's quite there yet (got a bit "burned" by a light bulb company in fact!).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it possible the ebay thingies have unique serial numbers?  You can run a program to find out.  I use USBDeview.

 

I make the serial numbers different the lazy way.  I use the "unique name" stuff in the xmega chips.  Wafer number, batch number, location on wafer, etc.  I don't know if other chips have this.

 

With winusb, and probably libusb too, I find VID and PID irrelevant.  I pick numbers out of the air.

Last Edited: Mon. Sep 4, 2017 - 07:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Windows can generate a GUID and GUID is mentioned in WCID.

 

https://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.110).aspx

https://github.com/pbatard/libwdi/wiki/WCID-Devices#defining-a-device-interface-guid-or-other-device-specific-properties

...

(second paragraph)

... and especially the provision of the Device Interface GUID that you want your device to be accessed with.

...

ref. https://www.avrfreaks.net/forum/anybody-use-winusb-wcid-win10-1703

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I think I found the problem with the Win10-1703.  The OS was apparently clobbered by my Hauppauge tv tuner PCI card driver. It clobbered another Win10 install, with different symptoms, also.  

 

I do mix up winusb and WCID.  I don't know where one stops and the other starts.  I got it working 8 or so months ago, but I forget what I've done yesterday.

 

I apparently find my winusb devices by telling Microsoft's SetupDiGet..... to look for the class interface GUID.

 

I didn't have Windows generate one.   I made my own.   "{42314231-4231-4231-4231-423142314231}\0"

 

I guess I should mention I copy it into the descriptor with my patented Copy_to_wide() function that inserts the nulls.

 

Last Edited: Mon. Sep 4, 2017 - 08:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dmesg|grep tty

This will give you a list (among which) are the initialisation of al tty devices and the time they were discovered.

paul@dualcore ~ $ dmesg |grep tty
[    0.000000] console [tty0] enabled
[    6.077348] 0000:01:00.0: ttyS4 at I/O 0xcc00 (irq = 17, base_baud = 115200) is a 16550A
[    6.169646] 0000:01:00.0: ttyS5 at I/O 0xc880 (irq = 17, base_baud = 115200) is a 16550A
[ 5633.361708] usb 2-8.2.1: pl2303 converter now attached to ttyUSB0
[ 5637.939270] usb 2-8.2.4: pl2303 converter now attached to ttyUSB1
[ 5689.102430] pl2303 ttyUSB1: pl2303 converter now disconnected from ttyUSB1
[ 5692.773799] usb 2-8.2.4: FTDI USB Serial Device converter now attached to ttyUSB1
[ 5697.038412] ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1
[ 5700.915165] usb 2-8.2.4: pl2303 converter now attached to ttyUSB1

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com