How can I enumerate (list) serial ports?

Discussion in 'Python' started by Jason, Jun 18, 2009.

  1. Jason

    Jason Guest

    Hi,

    I'm developing an application to talk to a device over a serial port.
    I'm trying my hardest to keep it cross platform, so I was using
    pySerial for the serial communications. But I can't see a pythonic,
    cross-platform way to enumerate serial ports on a machine.

    Ideally I could show the user a list of "COM1","COM2", etc, or ttyS0,
    ttyS1, etc. At the moment I think they'll just have to type it into a
    box.

    Is there a known way to do this? Is there anyone who has a hack
    they're willing to share?

    Thanks,
    Jason
     
    Jason, Jun 18, 2009
    #1
    1. Advertising

  2. Jason

    Tim Golden Guest

    Jason wrote:
    > Hi,
    >
    > I'm developing an application to talk to a device over a serial port.
    > I'm trying my hardest to keep it cross platform, so I was using
    > pySerial for the serial communications. But I can't see a pythonic,
    > cross-platform way to enumerate serial ports on a machine.


    As with many other such issues, instant cross-platformability
    is likely to be rare. I admin I haven't looked at pySerial
    but I imagine that, behind the scenes, it's doing some sort
    of conditional imports according to platform. I imagine you'd
    have to do something similar to get a list of port names.

    On Windows, WMI can give you what you want. Look at the
    Win32_SerialPort class. Hopefully, someone else can help
    for other platforms.

    TJG
     
    Tim Golden, Jun 18, 2009
    #2
    1. Advertising

  3. Jason

    Jason Guest

    On Jun 18, 2:20 pm, Tim Golden <> wrote:
    > but I imagine that, behind the scenes, it's doing some sort
    > of conditional imports according to platform.


    I have, and yes indeed it does.

    > I imagine you'd
    > have to do something similar to get a list of port names.


    That's what I thought, although I might just defer to the user knowing
    what to type in (since they would have to identify the port allocated
    to the device in the first place).

    > On Windows, WMI can give you what you want. Look at the
    > Win32_SerialPort class. Hopefully, someone else can help
    > for other platforms.


    Thanks for this pointer :)

    Cheers,
    Jason
     
    Jason, Jun 18, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Hoag

    Can't locate serial ports

    Daniel Hoag, Feb 11, 2004, in forum: Java
    Replies:
    3
    Views:
    524
    Daniel Hoag
    Feb 13, 2004
  2. Replies:
    11
    Views:
    512
    Johan Bengtsson
    Jun 23, 2007
  3. Jörg Zieren
    Replies:
    3
    Views:
    380
    Andrew Thompson
    Nov 24, 2007
  4. Max Kotasek
    Replies:
    4
    Views:
    994
    Max Kotasek
    Apr 9, 2010
  5. mreister
    Replies:
    1
    Views:
    3,202
    mreister
    May 25, 2010
Loading...

Share This Page