Updating the list of the system's serial ports

Discussion in 'Java' started by Jörg Zieren, Nov 23, 2007.

  1. Jörg Zieren

    Jörg Zieren Guest

    Hi,

    I use javax.comm.CommPortIdentifier.getPortIdentifiers() to get a list
    of the system's serial ports. This works fine, but the list is only
    updated upon loading of the class CommPortIdentifier (through static code).

    However, the Java application needs to detect a USB-to-serial converter
    which is plugged in at runtime. This converter shows up as an additional
    COM port (we're on WinXP). If it is plugged in before the app starts, it
    is detected, but not if it is plugged in during runtime.

    The said static code in CommPortIdentifier is:

    CommDriver commdriver =
    (CommDriver)Class.forName("javax.comm.RXTXCommDriver").newInstance();
    commdriver.initialize();

    This can be repeated, which does detect the newly appeared COM port, but
    it only adds to the list of available ports that getPortIdentifiers()
    returns, so I assume it's not meant to be done.

    Is there some way to properly refresh the list of system COM ports
    dynamically?

    Thanx in advance,
    Jörg
     
    Jörg Zieren, Nov 23, 2007
    #1
    1. Advertising

  2. Jörg Zieren wrote:
    ...
    >This can be repeated, which does detect the newly appeared COM port, but
    >it only adds to the list of available ports that getPortIdentifiers()
    >returns, so I assume it's not meant to be done.


    Huh? That paragraph seemed entirely logical up till
    the point "..so I assume it's not meant to be done."

    Why would you assume it is inappropriate to (for example)
    start a thread that regularly checks for new COM connections,
    and update a list(?/whatever) accordingly?

    --
    Andrew Thompson
    http://www.physci.org/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200711/1
     
    Andrew Thompson, Nov 23, 2007
    #2
    1. Advertising

  3. Andrew Thompson wrote:
    > Jörg Zieren wrote:
    > ..
    >> This can be repeated, which does detect the newly appeared COM port, but
    >> it only adds to the list of available ports that getPortIdentifiers()
    >> returns, so I assume it's not meant to be done.

    >
    > Huh? That paragraph seemed entirely logical up till
    > the point "..so I assume it's not meant to be done."
    >
    > Why would you assume it is inappropriate to (for example)
    > start a thread that regularly checks for new COM connections,
    > and update a list(?/whatever) accordingly?


    You're right, I was being unclear - sorry. The problem is that each
    reinitialization *adds* *all* ports to the list of available ports. So at
    first there's, say, "COM1 COM2 LPT1". After calling initialize()
    "manually" for the first time (i.e. for the second time in total), there's
    "COM1 COM2 LPT1 COM1 COM2 LPT1". And so on, so after n calls to
    initialize, each port is listed n+1 times.

    -Jörg
     
    Jörg Zieren, Nov 23, 2007
    #3
  4. Jörg Zieren wrote:
    >> ..
    >>> This can be repeated, which does detect the newly appeared COM port, but

    >[quoted text clipped - 7 lines]
    >> start a thread that regularly checks for new COM connections,
    >> and update a list(?/whatever) accordingly?

    >
    >You're right, I was being unclear - sorry. The problem is that each
    >reinitialization *adds* *all* ports to the list of available ports.


    Oh right - I get you now. That is less optimal.

    >...So at
    >first there's, say, "COM1 COM2 LPT1". After calling initialize()
    >"manually" for the first time (i.e. for the second time in total), there's
    >"COM1 COM2 LPT1 COM1 COM2 LPT1". And so on, so after n calls to
    >initialize, each port is listed n+1 times.


    ..mmm. That suggestion of mine just does not sound 'right'
    anymore. I better bow out of this thread and hope one of the
    'Java comm' experts can identify the best strategy.

    --
    Andrew Thompson
    http://www.physci.org/

    Message posted via http://www.javakb.com
     
    Andrew Thompson, Nov 24, 2007
    #4
    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:
    526
    Daniel Hoag
    Feb 13, 2004
  2. Replies:
    11
    Views:
    515
    Johan Bengtsson
    Jun 23, 2007
  3. Jason
    Replies:
    2
    Views:
    473
    Jason
    Jun 18, 2009
  4. Max Kotasek
    Replies:
    4
    Views:
    1,005
    Max Kotasek
    Apr 9, 2010
  5. mreister
    Replies:
    1
    Views:
    3,233
    mreister
    May 25, 2010
Loading...

Share This Page