No serial ports found

Source: Internet
Author: User

Http://www.systronix.com/book/tools/javaxcomm.html

Javaxcomm installation and configuration problems are common. Everytime I configure a new PC it seems there is some new problem waiting to bite -- for instance, these:

First, check your system environment

If the events you tried to set up didn't really take place, then of course nothing will work as intended. typos in system environment variables are a simple example of what can go wrong. so before you get too worried, check your
Settings. at a command prompt, type "set" to view all your environment settings and verify that java_home, etc are actually set to what you intended, and that your jsdk bin folder appears early in the system path. you shoshould see something like this (I 've deleted
A lot of irrelevant lines ):

D: \> set
Classpath = D: \ j2sdk14 \ Lib; D: \ j2sdk14 \ Lib \ comm. jar;
Java_home = D: \ j2sdk14
Java_lib = D: \ java_lib
Path = D: \ j2sdk14 \ bin; C: \ pvsw \ bin; c: \ windows \ system32; C: \ WINDOWS; c: \ windows \ system32 \ WBEM;

"No serial ports found" and errors in the javaxcomm docs

Or
"Where do those silly files * really * need to go "?

Recently, running this command line on a new notebook PC installation:
C: \ java_lib \ commapi \ samples \ blackbox> JAVA-verbose blackbox
Resulted in this eventual output:
[Loaded javax. Comm. comatrix ortenumerator from file:/C:/program % 20 files/Java/jdk1.5.0 _ 03/lib/COMM. jar]
No serial ports found!

What's going on here? Java is finding comm. jar but enumeration of serial ports is failing... after some trial and error, and with thanks to Peter Stewart
This linkWhich confirms others have had the same problem, here is the answer.

It seems login ze JDK is hardcoded to look for properties in <java_home> \ JRE \ Lib (without regard to where the comm. jar file is located! -You 'd think Java wocould look for the. properties file in the same folder containing comm. Jar). The javax. Comm. Properties
File is nothing mysterious-it just lists "driver = com. sun. comm. win32driver ". so as long as that win32driver class can be found some/Any/where in your classpath, javaxcomm is happy. win32com. dll can go in <java_home> \ JRE \ bin too, in spite of what the javaxcomm
Docs tell you.

2006 July 18: So, bottom line:

  1. Install comm. jar and javax. Comm. properties in <java_home> \ JRE \ Lib
  2. Install win32com. DLL in <java_home> \ JRE \ bin or in <java_home> \ bin and be sure whichever folder you use is in your path environment variable. the second choice is maybe best because you need the <java_home> \ bin in your path anyway to enable java.exe, javac.exe,
    Javadoc.exe, etc, and you don't need the \ JRE \ bin folder in your path.
  3. Add the comm. jar location to your classpath-preferably as a system environment variable. also be sure the classpath contains ". "so that the current directory (such as when you run the blackbox test below) is already ded.
  4. Ignore the javaxcomm javadocs in platformspecific.html, regarding locations of the files mentioned above.

2006 May 04: On a new notebook PC, after doing all the above, blackbox still fails with
No serial ports found! Error. Urk. What now? I decided to try to get a clean and simple installation.

  1. I installed the comm. jar and javax. comm. properties in the JRE/lib folder and win32com. DLL in the JRE/bin folder. then added the JRE/lib. comm. jar to the classpath followed by the JDK/bin folder, and the JRE/bin to the path. blackbox fails

    Exception in thread "Main" Java. Lang. noclassdeffounderror: javax/comm/portinuseexception
  2. Oops, it was a typo in my classpath variable. Fixed that and now things work as expected.

Then to test it, open a command prompt in the blackbox samples folder (the one containing blackbox. Class) and type "Java blackbox"

Using javaxcomm on a PC with USB but no serial ports

USB to serial adapters are cheap and plentiful. I 've personally used a Belkin model sold as a PDA synchronization accessory, since they were available cheap at a local office supply store. follow the USB serial adapter installation instructions
Provided by that hardware vendor, and blackbox shocould report the new device as simply another serial port. this has worked for me on notebook PCs without any serial ports, and on notebook and desktop PCs to add another serial port.

You can verify the proper serial port operation and get or set the COM port number in Windows Device Manager on the Advanced tab.

USB serial adapters will function as a "normal serial port" with at least one difference-there is more software latency since the USB driver software adds another intermediate layer to the code which access the UART in the adapter. so
You may need to increase timeout values in javaxcomm code which may use a USB serial adapter.

Java finds javaxcomm files in an unexpected place
Exception in thread "Main" Java. Lang. nullpointerexception
At com. ajile. Drivers. SerialPort. ajilecommdriver. registerwithjavaxcomm (ajilecommdriver. Java: 42)
At javax. Comm. comatrix ortidentifier. getportidentifiers (unknown source)
At blackbox. Main (blackbox. Java: 222)

This looks strange because you wonder "what does an ajile driver have to do with blackbox? "How is the ajile library getting mixed up with blackbox? The answer is in the classpath order. In this case on my system it was:

Classpath = D: \ java_lib \ commapi \ samples \ blackbox. jar; D: \ ajile \ runtime_cldc \ RTS; D: \ j2sdk14 \ Lib \ comm. jar; D: \ tini1.11 \ bin;

Here the problem is in the order of the classpath folders.Blackbox. JarIs listed first, but then the ajile
Runtime_cldc \ RTSFolder is next. Since the ajile runtime runner des j2-cldc support for javaxcomm, the blackbox example is trying to use that to run on the PC, and this won't work. Reordering
The paths so that the order is blackbox. jar, then comm. jar, then others fixes this problem:

Classpath = D: \ java_lib \ commapi \ samples \ blackbox. jar; D: \ j2sdk14 \ Lib \ comm. jar; D: \ ajile \ runtime_cldc \ RTS; D: \ tini1.11 \ bin;

This points up a weakness in trying to have all your classpaths set up in your system environment. one ordering may not be what you want all the time. fortunately there is a solution: the Java-CP (classpath) option. for example, instead of adding blackbox. jar
And comm. jar to the environment, add paths to them on the command line:

Java-cp d: \ java_lib \ commapi \ samples \ blackbox. jar; D: \ j2sdk14 \ Lib \ comm. jar; blackbox

Or, even better, by using our environment variables:

Java-CP % java_lib % \ commapi \ samples \ blackbox. jar; % java_home % \ Lib \ comm. jar; blackbox

Default install puts the JDK in c: \ Program Files

Growth gh! On my new notebook I let the JDK install itself where it wanted to-under C: \ Program Files-note the whitespace. so now (some) Java command line tools fail because "Program Files" contains white space! How inane. For example:
C: \ java_lib \ commapi \ samples> JAVA-CP % java_lib % \ commapi \ samples \ blackbox. jar; % java_home % \ Lib \ comm. jar; blackbox

Exception in thread "Main" Java. Lang. noclassdeffounderror: files \ Java \ jdk1/5/0_03 \ Lib \ comm/jar;
This appears to fail because java_home expands
Java_home = c: \ Program Files \ Java \ jdk1.5.0 _ 03
And "Program Files \ Java \..." gets delimited to "files \ Java \..."

However, not all is broken:
C: \ java_lib \ commapi \ samples \ blackbox> JAVA-verbose blackbox

Successfully Loads files in the classpath such:
[Loaded javax. Comm. comatrix ortenumerator from file:/C:/program % 20 files/Java/jdk1.5.0 _ 03/lib/COMM. jar]

So frankly I don't understand what's going on here...

Javax/comm/portinuseexception

While writing this tutorial, I installed javaxcomm and received this-new to me-error:

D: \> JAVA blackbox
Exception in thread "Main" Java. Lang. noclassdeffounderror: javax/comm/portinuseexception

I was not using any of the serial ports, So What cocould this mean? I started by using the-verbose switch. However this was not terribly heplful:

D: \> JAVA-verbose blackbox
[Opened D: \ j2sdk14 \ JRE \ Lib \ RT. jar]
[Opened D: \ j2sdk14 \ JRE \ Lib \ sunrsasign. jar]
[Opened D: \ j2sdk14 \ JRE \ Lib \ JSSE. jar]
[Opened D: \ j2sdk14 \ JRE \ Lib \ JCE. jar]
<Snipped out a hundred lines or so>
[Loaded java. AWT. event. windowlistener from D: \ j2sdk14 \ JRE \ Lib \ RT. jar]
[Loaded blackbox]
Exception in thread "Main" Java. Lang. noclassdeffounderror: javax/comm/portinuseexception
[Loaded java. Lang. stacktraceelement from D: \ j2sdk14 \ JRE \ Lib \ RT. jar]
[Loaded java. util. hashmap $ keyset from D: \ j2sdk14 \ JRE \ Lib \ RT. jar]
[Loaded java. util. hashmap $ keyiterator from D: \ j2sdk14 \ JRE \ Lib \ RT. jar]

This seems to indicate that the portinuseexception class can't be found. This class is located in the comm. jar file. One solution is to add the javaxcomm JAR file explicitly to my environment classpath:

% Java_lib % \ commapi \ comm. Jar <Note: This is incorrect; the reason why is explained below, so keep reading...

Then execution generated this error:

D: \> JAVA blackbox
No serial ports found!

From past experience I knew that this results when javaxcomm can't find the javax. Comm. properties file, which causes the serial port enumeration to fail.

Hmm, I think I really wanted the comm. jar reference to be the java_home \ Lib \ comm. jar folder, not the java_lib location. OK, change that in my system variables. that does it:

D: \> set
Classpath = D: \ j2sdk14 \ Lib; D: \ j2sdk14 \ Lib \ comm. jar;
Java_home = D: \ j2sdk14
Java_lib = D: \ java_lib
Path = D: \ j2sdk14 \ bin; C: \ pvsw \ bin; c: \ windows \ system32; C: \ WINDOWS; c: \ windows \ system32 \ WBEM;

D: \> set classpath = % java_lib % \ commapi \ samples \ blackbox. jar; % classpath %

D: \> JAVA blackbox
COM1: port_owned

... And now I can see the blackbox GUI starting up as expcted.

Applications can't enumerate serial ports (COM1, com2,... don't appear to exist)

The javax. comm. properties must be in the correct directory. failure to do this will result in javaxcomm application's inability to enumerate your PC serial ports. instead of COM1, com2 etc, you will see 'serial0' which are just the name
Placeholders, not real serial ports. (You can't actually access 'serial0' on the PC .)

Blackbox example can't find serial ports even though you 'd followed the instructions

You may have another "java.exe" being executed in spite of the path settings, typically in a Windows system folder. I think in brief ze some system registry settings overrule those in the environment settings, though I 've never seen documentation on this
(If you have, please let me know). I 've observed this issue on our PCs here, more than once.

Try executing with the-verbose switch and with an explicit path to your desired Java EXE, from within the blackbox folder in the commapi:

D: \ j2sdk14 \ bin \ Java-verbose blackbox

This shoshould tell you exactly why it can't find the serial ports. Then you can usually proceed from there to solve the problem.

**************************************** **************************************** **************************************** *******************************

Below are the images

**************************************** **************************************** **************************************** *******************************

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.