Question

CommPortIdentifier doesn't find any ports

Asked by: kender_a

Unfortunately, CommPortIdentifier doesn't find the ports. I had copied win32com.dll into every bin directory, and comm.jar + javax.comm.properties  into every lib directory, but it didn't help. The device manager shows that I have all the ports, and HyperTermonal works properly too.

Here's the code, which I use to find the ports.
   private Enumeration m_portList;

    public CTesaComm() {
        initComponents();
       
        // initialize the CommPortIdentifier
        System.out.println("looking for ports...");
        CommPortIdentifier portId;
        m_portList = CommPortIdentifier.getPortIdentifiers();
        System.out.println(m_portList.toString());
        while (m_portList.hasMoreElements()){
            portId = (CommPortIdentifier)m_portList.nextElement();
            System.out.println(portId.getName());
        }
   
    }


I also tried forcing the connection on COM1, COM2 and COM3 with the following code (where _X is the number of the port)

        try
        {
            portID = CommPortIdentifier.getPortIdentifier("COM2");
        } catch (NoSuchPortException e) {
            System.err.println("Nosuch port");
            return;
        }

I'm getting the NoSuchPortException .

Please suggest.

Thanks,
Nick

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-03-24 at 00:21:09ID20929966
Tags

commportidentifier

,

return

Topic

Java Programming Language

Participating Experts
2
Points
250
Comments
3

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Switching Modem From com3 to com2
    I use win95 along with an Award Modular Bios v4.5 and a Maxtech XPV2881 28,000bps Voice Fax Modem. The modem is on com3 where it works with Juno and my ISP. However it doesn't work with dial-up networking, AT&T Worldnet, Aol or any software that requires dial-up networkin...
  2. Com1, Com2, Com3, Com4
    How do I know which Com is which? I am trying to install a PalmIII. I can't figur out which Com port I am plugged into. I know Com3 is my mouse. What are 1,2 and4?
  3. change modem from com3 to com1
    I've got an internal modem which has installed on Com3, but I use a piece of software that needs it on Com1. How do I change it? PC is Compaq EP Series and the modem is Diamond SupraExpress 56iPRO.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: krakatoaPosted on 2004-03-24 at 00:59:41ID: 10665397

This is Sun's own port tester code:

/*
 * @(#)BlackBox.java      1.13 98/10/20 SMI
 *
 * Author: Tom Corson
 *
 * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license
 * to use, modify and redistribute this software in source and binary
 * code form, provided that i) this copyright notice and license appear
 * on all copies of the software; and ii) Licensee does not utilize the
 * software in a manner which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind.
 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
 * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
 * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
 * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
 * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control
 * of aircraft, air traffic, aircraft navigation or aircraft
 * communications; or in the design, construction, operation or
 * maintenance of any nuclear facility. Licensee represents and
 * warrants that it will not use or redistribute the Software for such
 * purposes.
 */

import java.io.*;

import java.awt.Frame;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;

import java.util.Enumeration;

import javax.comm.CommPort;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
import javax.comm.NoSuchPortException;
import javax.comm.PortInUseException;

public class BlackBox extends Frame implements WindowListener
{
      static int                  portNum = 0,
                              panelNum = 0,
                              rcvDelay = 0;
      static SerialPortDisplay[]      portDisp;
      static BlackBox             win;
      static boolean                  threaded = true,
                              silentReceive = false,
                              modemMode = false,
                              friendly = false;

      public BlackBox()
      {
            super("Serial Port Black Box Tester");
            addNotify();

            addWindowListener(this);
      }

      public void windowIconified(WindowEvent event)
      {
      }

      public void windowDeiconified(WindowEvent event)
      {
      }

      public void windowOpened(WindowEvent event)
      {
      }

      public void windowClosed(WindowEvent event)
      {
      }

      public void windowActivated(WindowEvent event)
      {
      }

      public void windowDeactivated(WindowEvent event)
      {
      }

      public void windowClosing(WindowEvent event)
      {
            cleanup();
            dispose();
            System.exit(0);
      }

      public static void main(String[] args)
      {
            Enumeration             ports;
            CommPortIdentifier      portId;
            boolean                  allPorts = true,
                              lineMonitor = false;
            int                  idx = 0;

            win = new BlackBox();
            win.setLayout(new FlowLayout());
            win.setBackground(Color.gray);

            portDisp = new SerialPortDisplay[4];

            while (args.length > idx)
            {
                  if (args[idx].equals("-h"))
                  {
                        printUsage();
                  }

                  else if (args[idx].equals("-f"))
                  {
                        friendly = true;
      
                        System.out.println("Friendly mode");
                  }

                  else if (args[idx].equals("-n"))
                  {
                        threaded = false;
      
                        System.out.println("No threads");
                  }

                  else if (args[idx].equals("-l"))
                  {
                        lineMonitor = true;
      
                        System.out.println("Line Monitor mode");
                  }

                  else if (args[idx].equals("-m"))
                  {
                        modemMode = true;
      
                        System.out.println("Modem mode");
                  }

                  else if (args[idx].equals("-s"))
                  {
                        silentReceive = true;
      
                        System.out.println("Silent Reciever");
                  }

                  else if (args[idx].equals("-d"))
                  {
                        idx++;
                        rcvDelay = new Integer(args[idx]).intValue();
      
                        System.out.println("Receive delay = "
                                      + rcvDelay + " msecs");
                  }

                  else if (args[idx].equals("-p"))
                  {
                        idx++;

                        while (args.length > idx)
                        {
                              /*
                               *  Get the specific port
                               */
            
                              try
                              {
                                    portId =
                                       CommPortIdentifier.getPortIdentifier(args[idx]);

                                    System.out.println("Opening port "
                                              + portId.getName());
      
                                    win.addPort(portId);
                              }
      
                              catch (NoSuchPortException e)
                              {
                                    System.out.println("Port "
                                                  + args[idx]
                                                  + " not found!");
                              }

                              idx++;
                        }

                        allPorts = false;

                        break;
                  }

                  else
                  {
                        System.out.println("Unknown option "
                                      + args[idx]);
                        printUsage();
                  }

                  idx++;
            }

            if (allPorts)
            {
                  /*
                   *  Get an enumeration of all of the comm ports
                   *  on the machine
                   */
      
                  ports = CommPortIdentifier.getPortIdentifiers();
      
                  if (ports == null)
                  {
                        System.out.println("No comm ports found!");
      
                        return;
                  }

                  while (ports.hasMoreElements())
                  {
                        /*
                         *  Get the specific port
                         */
      
                        portId = (CommPortIdentifier)
                                          ports.nextElement();

                        win.addPort(portId);
                  }
            }

            if (portNum > 0)
            {
                  if (lineMonitor)
                  {
                        if (portNum >= 2)
                        {
                              portDisp[0].setLineMonitor(portDisp[1],
                                                   true);
                        }

                        else
                        {
                              System.out.println("Need 2 ports for line monitor!");
                              System.exit(0);
                        }
                  }
            }

            else
            {
                  System.out.println("No serial ports found!");
                  System.exit(0);
            }
          }

      private void addPort(CommPortIdentifier      portId)
      {
            /*
             *  Is this a serial port?
             */

            if (portId.getPortType()
             == CommPortIdentifier.PORT_SERIAL)
            {
                  //  Is the port in use?      

                  if (portId.isCurrentlyOwned())
                  {
                        System.out.println("Detected "
                                       + portId.getName()
                                       + " in use by "
                                       + portId.getCurrentOwner());
                  }

                  /*
                   *  Open the port and add it to our GUI
                   */

                  try
                  {
                        portDisp[portNum] = new
                              SerialPortDisplay(portId,
                                            threaded,
                                            friendly,
                                            silentReceive,
                                            modemMode,
                                            rcvDelay,
                                            win);

                        this.portNum++;
                  }

                  catch (PortInUseException e)
                  {
                        System.out.println(portId.getName()
                                       + " in use by "
                                       + e.currentOwner);
                  }
            }
      }

      public void addPanel(SerialPortDisplay      panel)
      {
            Dimension      dim;
            Insets            ins;

            win.add(panel);

            win.validate();

            dim = panel.getSize();

            ins = win.getInsets();

            dim.height = ((this.panelNum + 1) * (dim.height + ins.top
                                          + ins.bottom)) + 10;

            dim.width = dim.width + ins.left + ins.right + 20;

            win.setSize(dim);

            win.show();

            panelNum++;
      }

      static void printUsage()
      {
            System.out.println("Usage: BlackBox [-h] | [-f] [-l] [-m] [-n] [-s] [-d receive_delay] [-p ports]");

            System.out.println("Where:");

            System.out.println("\t-h      this usage message");

            System.out.println("\t-f      friendly - relinquish port if requested");

            System.out.println("\t-l      run as a line monitor");

            System.out.println("\t-m      newline is \\n\\r (modem mode)");

            System.out.println("\t-n      do not use receiver threads");

            System.out.println("\t-s      don't display received data");

            System.out.println("\t-d      sleep for receive_delay msecs after each read");

            System.out.println("\t-p      list of ports to open (separated by spaces)");

            System.exit(0);
      }

      private void cleanup()
      {
            SerialPort      p;

            while (portNum > 0)
            {
                  portNum--;
                  panelNum--;

                  /*
                   *  Close the port
                   */

                  p = portDisp[portNum].getPort();

                  if (p != null)
                  {
                        System.out.println("Closing port "
                                       + portNum
                                       + " ("
                                       + p.getName()
                                       + ")");

                        portDisp[portNum].closeBBPort();
                  }
            }
      }
}


Hope it helps! k.

 

by: oraelbisPosted on 2004-03-24 at 03:38:01ID: 10666705

On jdk1.4, you need copy files into another places:

Copy comm.jar to   %JAVA_HOME%\jre\lib\ext
Copy javax.comm.properties to  %JAVA_HOME%\jre\lib
Copy win32com.dll to  %JAVA_HOME%\bin

see:
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20661635.html#8810978

 

by: kender_aPosted on 2004-03-24 at 07:40:50ID: 10668698

DIRECT HIT!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...