Updating the list of the system's serial ports

  • Follow


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
0
Reply ISO 11/23/2007 9:28:22 AM

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 Thompsonhttp://www.physci.org/Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200711/1
0
Reply Andrew 11/23/2007 12:00:45 PM


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
0
Reply UTF 11/23/2007 9:32:38 PM

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 Thompsonhttp://www.physci.org/Message posted via http://www.javakb.com
0
Reply Andrew 11/24/2007 4:52:09 AM

3 Replies
105 Views

(page loaded in 0.067 seconds)

Similiar Articles:













7/25/2012 7:16:32 PM


Reply: