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 configurations 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 should see something like this (I've deleted a lot of irrelevant lines): D:\>set |
"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: 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 for this link which confirms others have had the same problem, here is the answer. It seems Windoze 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 would 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:
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 should 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.CommPortIdentifier.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\BlackBox.jar;D:\aJile\Runtime_cldc\Rts;D:\j2sdk14\lib\comm.jar;D:\tini1.11\bin; CLASSPATH=d:\java_lib\commapi\samples\BlackBox\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\BlackBox.jar;D:\j2sdk14\lib\comm.jar; BlackBox or, even better, by using our environment variables: java -cp %JAVA_LIB%\commapi\samples\BlackBox\BlackBox.jar;%JAVA_HOME%\lib\comm.jar; BlackBox |
Default install puts the JDK in C:\Program Files |
Aargh! 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: Exception in thread "main" java.lang.NoClassDefFoundError: Files\Java\jdk1/5/0_03\lib\comm/jar; However, not all is broken: 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 I was not using any of the serial ports, so what could this mean? I started by using the -verbose switch. However this was not terribly heplful: D:\>java -verbose BlackBox 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 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 D:\>set CLASSPATH=%JAVA_LIB%\commapi\samples\BlackBox\BlackBox.jar;%CLASSPATH% D:\>java BlackBox ... 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 Windoze 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 should tell you exactly why it can't find the serial ports. Then you can usually proceed from there to solve the problem. |
*******************************************************************************************************************************************************
以下是图片
*******************************************************************************************************************************************************