Updating the list of the system's serial ports

J

Jörg Zieren

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
 
A

Andrew Thompson

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
 
J

Jörg Zieren

Andrew said:
Jörg Zieren wrote:
..

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
 
A

Andrew Thompson

Jörg Zieren said:
[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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top