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-exchang
Main Topics
Browse All TopicsUnfortunately, 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("lookin
CommPortIdentifier portId;
m_portList = CommPortIdentifier.getPort
System.out.println(m_portL
while (m_portList.hasMoreElement
portId = (CommPortIdentifier)m_port
System.out.println(portId.
}
}
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.getPort
} catch (NoSuchPortException e) {
System.err.println("Nosuch
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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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-exchang
Business Accounts
Answer for Membership
by: krakatoaPosted on 2004-03-24 at 00:59:41ID: 10665397
This is Sun's own port tester code:
ner; ;
ier; tion; ion;
t event)
ent event)
t event)
ent event)
ay);
ly mode");
Reciever");
e();
e delay = "
Identifier (args[idx] );
g port "
n option "
Identifier s();
(portDisp[ 1],
portId)
RIAL)
) ed "
getName()
panel)
BlackBox [-h] | [-f] [-l] [-m] [-n] [-s] [-d receive_delay] [-p ports]");
");
);
g port "
ort();
/*
* @(#)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.WindowListe
import java.awt.event.WindowEvent
import java.util.Enumeration;
import javax.comm.CommPort;
import javax.comm.CommPortIdentif
import javax.comm.SerialPort;
import javax.comm.NoSuchPortExcep
import javax.comm.PortInUseExcept
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(WindowEven
{
}
public void windowDeiconified(WindowEv
{
}
public void windowOpened(WindowEvent event)
{
}
public void windowClosed(WindowEvent event)
{
}
public void windowActivated(WindowEven
{
}
public void windowDeactivated(WindowEv
{
}
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.gr
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("Friend
}
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
}
else if (args[idx].equals("-d"))
{
idx++;
rcvDelay = new Integer(args[idx]).intValu
System.out.println("Receiv
+ rcvDelay + " msecs");
}
else if (args[idx].equals("-p"))
{
idx++;
while (args.length > idx)
{
/*
* Get the specific port
*/
try
{
portId =
CommPortIdentifier.getPort
System.out.println("Openin
+ portId.getName());
win.addPort(portId);
}
catch (NoSuchPortException e)
{
System.out.println("Port "
+ args[idx]
+ " not found!");
}
idx++;
}
allPorts = false;
break;
}
else
{
System.out.println("Unknow
+ args[idx]);
printUsage();
}
idx++;
}
if (allPorts)
{
/*
* Get an enumeration of all of the comm ports
* on the machine
*/
ports = CommPortIdentifier.getPort
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
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
{
/*
* Is this a serial port?
*/
if (portId.getPortType()
== CommPortIdentifier.PORT_SE
{
// Is the port in use?
if (portId.isCurrentlyOwned()
{
System.out.println("Detect
+ 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.
+ " in use by "
+ e.currentOwner);
}
}
}
public void addPanel(SerialPortDisplay
{
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:
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("Closin
+ portNum
+ " ("
+ p.getName()
+ ")");
portDisp[portNum].closeBBP
}
}
}
}
Hope it helps! k.