2013年9月2日星期一

java serial communication , reported javax.comm.NoSuchPortExceptionerror

Reader through a Bluetooth connection , the normal connection , and its port is COM4, ​​then I use
System.out.println ("--- 0");
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier ("COM4");
System.out.println ("--- 1");
SerialPort Sport = (SerialPort) portId.open ("test", 2000);
System.out.println ("--- 2");
port 4 , in CommPortIdentifier.getPortIdentifier ("COM4"); here at javax.comm.NoSuchPortException error in my environment configuration is
javax.comm.properties on java_home \ jre \ lib \ under
comm.jar on java_home \ jre \ lib \ ext \ under
win32com.dll on java_home \ jre \ bin \ under

I use the above environment is configured to run code on the desktop
int i = 0;
Enumeration portEnum = javax.comm.CommPortIdentifier.getPortIdentifiers ();
System.out.println (portEnum.hasMoreElements ());
while (portEnum.hasMoreElements ()) {
javax.comm.CommPortIdentifier portId = (CommPortIdentifier) ​​portEnum. nextElement ();
String portName = portId.getName ();
int portType = portId.getPortType ();
i + +;
System.out.println (" Section [ " + ; i + "] port , name [" + portName + "], type [" + (portType == CommPortIdentifier.PORT_SERIAL? "RS -232 serial ":" IEEE 1284 parallel Port " ) + " ] " ) ;
}


/ * System.out.println ("--- 0");
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier ("COM4");
System.out.println ("--- 1");
SerialPort Sport = (SerialPort) portId.open ("test", 2000);
System.out.println ("--- 2");
* /
can print out two parallel , indicating that the environment is not my fault.
But in the notebook will not get a port.
I do not know the cause of the error in what ? Seek help, thank you.
------ Solution ---------------------------------------- ----
make sure your pc and this system is not all 32 , jre whether it is 32 , then confirm whether you are in the serial communication on those few dll files in the right place , in the program should be able to System.load () Gets the dll libraries.
exclude the above reasons , the general reported this anomaly represents the specified port can not be used , so the need to look at the hardware connected to the correct port , pc is com4, this not necessarily yes.
------ For reference only -------------------------------------- -
recommend a look at open source project RXTX, seemingly over comm handy
------ For reference only ---------------------- -----------------
open the serial port does not exist I also do this , with the exchange under the bar.

没有评论:

发表评论