How to install The Java Communications API in a Windows Environment
Posted by Circuit Negma on February 7, 2007
Fix to the previous Port on :: ” How to install The Java Communications API “.
————————————————————————————-
There is a trick to install the Java Communications API correctly on a Windows system Machine. The following files are the core of JAVA Communiccation API, and they are very important to have them installed on your system for a proper operation:
- comm.jar
- win32com.dll
- javax.comm.properties
For the jdk (Java Developnment Kit) to recognize the serial ports on your machine, it is important to properly place these files in the right folders on your local machine :
%Java_HOME% = the location of your jdk directory.
To Find your JDK directory, Use the Following steps:
1. Click on Start
2. Click on Search
3. Click on For Files or Folders …
4. In the Left hand Side, Click on All Files and Folders
5. Type in jdk* in the textbox under All or part of the file name:
6. Click Search
7. Look for yellow icon that looks like a folder
8. Double Clikc on the folder to open the jdk folder
comm.jar should be placed in:
%JAVA_HOME%/lib %JAVA_HOME%/jre/lib/ext
win32com.dll should be placed in:
%JAVA_HOME%/bin %JAVA_HOME%/jre/bin %windir%System32
javax.comm.properties should be placed in:
%JAVA_HOME%/lib %JAVA_HOME%/jre/lib
Download Link:
coming soon
hamed said
Thanks.
aser hasan said
I dont know what to say,But realy Very Very thank to you professional
Billy said
This was exactly what I needed, Thank-you.
a said
many thanx man
pegah said
wow it was great.
thanks
Five said
*thumps up*
thx!! =)
satyam said
i did they same but the program is throwing compile time exception
its
java.lang.noclassdiffounderror: javax/comm/commportidentifier
i think my javax.comm is not installed properly plz suggest some thing.
satyam
Circuit Negma said
please verify the following:
1. is java jdk is instsalled
2. replace the following files in the following directories:
[-win32com.dll-] should be copied to the following directories:
%JAVA_HOME%/bin == C:\Program Files\Java\jdk1.5.0_10\bin
%JAVA_HOME%/jre/bin == C:\Program Files\Java\jdk1.5.0_10\jre\bin
%windir%/System32 == C:\windows\system32
Here is how to copy the file to the above directories:
a. click start
b. click run
c. type in one of the above directories in the textfield and hit ENTER, this will pop-up a window directed to the specified directory. if this does not work, this means that your windows system environmental variables for java is missing.
d. copy the file to that directory.
[-comm.jar-] should be copied to the following directories:
%JAVA_HOME%/lib == C:\Program Files\Java\jdk1.5.0_10\lib
%JAVA_HOME%/jre/lib/ext == C:\Program Files\Java\jdk1.5.0_10\jre\lib\ext
[-javax.comm.properties-] should be copied to the following directories:
%JAVA_HOME%/lib == C:\Program Files\Java\jdk1.5.0_10\lib
%JAVA_HOME%/jre/lib == C:\Program Files\Java\jdk1.5.0_10\jre\lib
3. you need to include comm.jar in your project settings or properties
this is an example, I use netbeans for my java developments:
Here is a sample code:
//Sun’s serial port driver
import javax.comm.*;
import java.io.*;
import java.util.*;
public class com implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId1;
static CommPortIdentifier portId2;
InputStream inputStream;
OutputStream outputStream;
SerialPort serialPort1, serialPort2;
Thread readThread;
protected String divertCode = “10”;
static String TimeStamp;
public com()
{
try
{
TimeStamp = new java.util.Date().toString();
serialPort1 = (SerialPort) portId1.open(“portId1(” + portId1.getName().toString() + “)”, 1000);
System.out.println(TimeStamp + “: ” + portId1.getName() + ” opened for scanner input”);
}
catch (PortInUseException e)
{}
try
{
inputStream = serialPort1.getInputStream();
}
catch (IOException e)
{}
try
{
serialPort1.addEventListener(this);
}
catch (TooManyListenersException e)
{}
serialPort1.notifyOnDataAvailable(true);
try
{
serialPort1.setSerialPortParams(38400,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort1.setDTR(false);
serialPort1.setRTS(true);
}
catch (UnsupportedCommOperationException e)
{}
readThread = new Thread(this);
readThread.start();
}
public void run()
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e) {}
}
public static void main(String[] args) {
try
{
// Scan for available ports on local host machine.
CommPortIdentifier cpi = null;
for (Enumeration e = CommPortIdentifier.getPortIdentifiers() ; e.hasMoreElements() 😉
{
CommPortIdentifier tmp = (CommPortIdentifier)e.nextElement();
System.out.println(“COM = ” + tmp.getName().toString() + ” mem = ” + tmp.toString());
System.out.println(“e = ” + e.toString());
if (tmp.getName().equals(“COM1”))
{
cpi = tmp;
System.out.println(“this is COM1: string”);
break;
}
}
// Defien a port manually
portId1 = CommPortIdentifier.getPortIdentifier(“COM1”);
// Create new COM thread and start listening to the port.
com reader = new com();
}
catch
(Exception e) {
TimeStamp = new java.util.Date().toString();
System.out.println(TimeStamp + portId1.getName().toString() + portId1);
System.out.println(TimeStamp + “: msg1 – ” + e);
}
}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
StringBuffer readBuffer = new StringBuffer();
int c;
try
{
c=inputStream.read();
while ( (c != 1) || (c != 2) || (c != 3) || (c != 4))
{
//readBuffer.append((char) c);
System.out.print(c);
}
String scannedInput = readBuffer.toString();
TimeStamp = new java.util.Date().toString();
System.out.println(TimeStamp + “: scanned input received:” + scannedInput);
inputStream.close();
readBuffer = new StringBuffer(0);
/* if(scannedInput.substring(0,1).equals(“F”)){
outputStream = serialPort1.getOutputStream();
outputStream.write(divertCode.getBytes());
System.out.println(TimeStamp + “: diverter fired”);
outputStream.close();
}
else
{
System.out.println(TimeStamp + “: diverter not diverted”);
}
*/
} catch (IOException e) {}
break;
}
}
}
neha said
he thanx,it helped me alot,i waz not able to solve this problem from last 1 week,thanx,now i can very well proceed with my project,thanx again
Vlatko said
Hi, I've done the previous but it is not working. import javax.comm.*; can't pass.
I have no idea why?
Vlatko
fisseha said
pleace give me a presice answer
Vlatko said
actually, I found it. In some of the previous comments was said that you should place files in ...jdk... folder. But when you open a project, check for the path of the already added libraries(below the package folder in solution explorer).
In my project that folder was ...jre... instead of ...jdk...
greetings
Circuit Negma said
I am glad to hear that.
thanks for your comments Vlatko
Vlatko said
I was happy when found your explanation. I still am. :)
Thank you.
Vlatko said
And can someone tell me how to do the same under Unix platform?
Tnaks,
Vlatko
Circuit Negma said
I found the following links on installing API on a linux system:
1. http://www.agaveblue.org/howtos/Comm_How-To.shtml
2. http://www.toolsforteams.com/roller/blog/entry/java_communications_api_notes
I also found the following question and answer on sun.com website:
“…
Q: Is there a linux version of the Java communications API?
A: We do not provide a linux implementation. But Kevin Hester has written Java communications API drivers for linux and uses our CommPort driver loading scheme to load his own gnu.io.RXTXCommDriver class. He gave us permission to disclose his web page:
http://www.geeksville.com/~kevinh/linuxcomm.html
http://wass.homelinux.net/howtos/Comm_How-To.shtml
…”
I did not try any of the mentioned solutions above since i do not have a linux machine.
so you have to fool around with this to get it working on your linux machine.
good luck
Vlatko said
I've tried and worked that with rxtxComm.
http://www.captain.at/howto-java-serial-port-javax-comm-rxtx.php
I am trying to do it with comm.jar(your win version but for linux).
You know, that gnu.io.* got the same functions as your javax.comm. Is it posible to find
it for linux. Just that properties.
In properties, there is a win32 and so...
But, it is not so important for me to work with javax.comm, I am a biginner. :)
I am a recent linux user. You know, it is not so bad and scary.
Greetings,
Circuit Negma said
Linux is not so hard to learn. as long as you understand the system ext., system folders and some basic commands, you will be surprised how easy it is.
I used Linux long time ago for my school. but I stopped using it since I finished schools and turned back to windows because most of my design softwares run on windows only.
As much as I would like to help every one with the Comm api, I am no longer have a linux machine for experiments.
If you do find the solution would you be so kind to post it here so that every one could learn from your help.
thank you so much Vlatko
smn_007 said
hai…
I have a java program to poll a sensor device every 2 min…. The program uses java comm to read and write data to it. I have java servlet program that has to access the serial port at the same time as the polling program to read/write data from it….. I.It works individually….it is not possible to access the serial port at the same time….. Can any time slice help….. or anything which could get it done
plz can anyone help with it….
the project has to completed within a week
Thanks in advance
smn
smn_007 said
hai…
Can 2 threads access the serial port through wait and notify…. can anyone help me with the code…. using java comm package
smn
Shaswat said
Thnks…..
Jecelyn said
Cool man, u really help me out!! Thanks lot!
Caesar said
hi all
I’m seeking this guide to properly install the javax.comm extension.
I don’t know well how it works…
I really need to map COM ports using the JAVA ICA Client through Adito Open VLS, by the time i ‘ve “drive and printer mapping” working great but unfortunately in a citrix troubleshooting guide says that COM port MAPPING is not supported by de JICA Client Applet. =(
I really need it working cuz my App works with Epson Fiscal Printers that only can communicate through that annoying COM port
BTW Thanks a lot to all of you. My apollogies, my english sucks…
César
Circuit Negma said
so, do you need a sample code of using javax.comm?
if you do, just let me know. I have it somewhere, it is going to take some time to locate the sample code I have.
Circuit Negma said
I have posted a sample code before on this page somewhere. please refer to sample code above.
smn_07 said
Hey the how to install java comm api can be found on this page which was posted earlier in this website…
this will definetly help u out
Dan said
Hi,
I installed as per your instruction. But it is not working for me. What OS you are using?
I am on Windows Vista. Is it possible to access direct IO from the user-mode? as per my knowledge, from windows XP onwards we need a SYS file to access the IO directly. Can you help me out?
Regards,
Dan
Circuit Negma said
Hi Dan,
I was using Windows XP. Then I moved to xp once I was done with my project.
Sorry, I do not know to to get the API working on XP.
However, I knew that to obtain a COM (port) you need to obtain an ownership of the targeted port. Under XP this is very trivial as XP will let you take over the ownership, where as the Vista OS would not let to do until you identify your self as the administrator to gain ownership of that port, thu I could be wrong.
Also, I do not know if this API is compatible with Vista.
try thin one : GiovynetSerialPort1.3
Try to sear google such keywords as : java communication api for vista
hopefully this will help you
DINESH Rajapaksha said
Thnx a Lot…!! now its wokring !
this will help a lot in my Final year project :))
thnx again
tuansoibk said
thanks a lot, it’s really helpful!
jiggy360 said
Im not able to run sample program in windows…
Exception in thread “main” java.lang.NoClassDefFoundError: javax/comm/CommPortIdentifier
I have installed everything exactly stated above.. still im getting this error
please help!!!
Circuit Negma said
Hi Jiggy360,
I am sorry but it is going to be a while before I try to figure out what is going on with your port identifier problem. it is the end of the year and I am swamped with work.
However, from the error you posted, it seems that you java compiler can not access the library to identify the ports on your machine. I suggest doing the following:
1. search Google, use keyword: java.lang.NoClassDefFoundError: javax/comm/CommPortIdentifier
link1 : http://www.google.com/#hl=en&source=hp&q=java.lang.NoClassDefFoundError%3A+javax%2Fcomm%2FCommPortIdentifier&btnG=Google+Search&aq=f&aqi=&oq=&fp=5483bb45bcb244db
I also found the following web page on java.lang.NoClassDefFoundError:
link2 : http://www.practicalembeddedjava.com/tools/javaxcomm.html
sundarrajan said
hi sir
i need a help urgent … help me for my project
I just need to list the comm ports available in windows. i have successfully the javax.comm package as you have mentioned earlier in this blog.
I m having this program
import javax.comm.*;
import java.util.Enumeration;
public class ListPorts {
public static void main(String args[]) {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier)ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "Parallel";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
}
}
}
The above program is compiling well and good in my system.. but when i try to run it its shows me the error as
Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading
driver com.sun.comm.Win32Driver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialPar
allel in java.library.path
Caught java.lang.UnsatisfiedLinkError: com.sun.comm.SolarisDriver.readRegistrySe
rial(Ljava/util/Vector;Ljava/lang/String;)I while loading driver com.sun.comm.So
larisDriver
I have done all the things clear.. but i m ambiguous where the problem is .
Thanks in advance
Please try to run this program in your system and then reply for me
Circuit Negma said
I love to help out, but there is one small problem. My new computer does not have any COM ports, However, I am going to try to compile you code. Also, I am going to look for my old code that did utilize COM ports on my old machine and post it here.
Circuit Negma said
Ok, so I compiled you code on my machine, and as you said it does compile, but I cannot run it on my machine because it is Vista 64-bit machine.
Netbeans IDE shoes the following error every time I try to run the code:
I am going to look for the old codes and post them here.
Vijay said
Dear Circuit Negma,
Thank you very very much. It is what exactly I was looking for and I did not find any exact solution in this clear way till I visited your post here.
Thanks a lot,
Vijay
Ryan said
Hi,
I can’t thank you enough!!
This really helped!!
>>Ryan
Commenter said
Extra Ordinary Tutorial!
Dean Shah said
Very great writing. Honest!
David said
Thank you!
Works like a charm!!
Thank you very much, I had been searching for this the entire morning!!
David
BALAJI said
Hai all,
This is the error i am getting.
pls help me on that issue if some one already gone through this issues.advance thaks to you
Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading driver com.sun.comm.Win32Driver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver
Circuit Negma said
the above mentioned serial driver is for windows 32-bit system. It is not for Linux or anyother operating system.
BALAJI said
Hai all,
I have already placed the required jar,properties and dll files in the correct directories.
Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading driver com.sun.comm.Win32Driver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver
Pls help me on that above issue.
Circuit Negma said
what operating system are you using? I tried this on my 64bit Vista machine and it did not work, however, this did work previously on a 32bit windows XP. I think these drivers are only for 32bit systems.
I will try to look for an answer for you on this one.
Circuit Negma said
@Balaji:: did you add the jar to your project library? For example, in netbeans under project window, there is a library or Jar folder that shows all the libraries utilized by the project.
I will try to look for an answer to your error code, however, I am currently tied up with loads of work. I would suggest searching google for the error code.
example:
google keyword search: Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading driver com.sun.comm.Win32Driver
Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading driver com.sun.comm.Win32Driver
Darren said
Oh my god!
you saved my life! thank you thank you thank you thank you!
I couldn’t have figured this out without you. My app now finds the javax.comm package and complies no problems 🙂
prajee said
Thank you 🙂
You really helped me.
Circuit Negma said
glad to hear it.
Deji Balogun said
While running my program, the following error came up: Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_15\jre\bin\win32com.dll: Can’t load IA 32-bit .dll on a AMD 64-bit platform. Please, what can I do to correct this as I need it for my project to work today?
Circuit Negma said
Last time I did this on a 64bit machine, I got the same results. it seems that the driver is built for a 32bit machine only. Since this driver is no longer under development there is not much to do about it. I would suggest that you get hold of a 32bit machine and finish your project on that one.
I tried to make this version of driver to support 64bit machine but I was not successful.
If you search google for ‘java communication api 64?bit’, you might find someone who is already done it.
charts said
I want to install java in wondows.
Circuit Negma said
you need to things to start programming in java language.
1. an IDE (editor) you could use the notepad in windows as long as you give your file the .java ext. I personally use Netbeans IDE from http://www.netbeans.com or you could use Eclipse from http://www.eclipse.org/
2. you need Java JDK. you can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html
Shakti Panda said
hi,we have installed the seril communication packages i.e jar,dll and properties in the maneer suggested by you in the above posts. the code is as given
package Serial_Communication;
import java.io.*;
import java.util.*;
import javax.comm.*; // for SUN’s serial/parallel port libraries
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.FileWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class nulltest implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static CommPortIdentifier saveportId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
Writer writer = null;
static String messageString = “Hello, world!”;
static OutputStream outputStream;
static boolean outputBufferEmptyFlag = false;
public static void main(String[] args) {
boolean portFound = false;
String defaultPort;
// determine the name of the serial port on several operating systems
String osname = System.getProperty(“os.name”,””).toLowerCase();
if ( osname.startsWith(“windows”) ) {
// windows
defaultPort = “COM1”;
} else if (osname.startsWith(“linux”)) {
// linux
defaultPort = “/dev/ttyS0”;
} else if ( osname.startsWith(“mac”) ) {
// mac
defaultPort = “????”;
} else {
System.out.println(“Sorry, your operating system is not supported”);
return;
}
if (args.length > 0) {
defaultPort = args[0];
}
System.out.println(“Set default port to “+defaultPort);
// parse ports and if the default port is found, initialized the reader
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
System.out.println(portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) {
System.out.println(“Found port: “+defaultPort);
portFound = true;
// init reader thread
nulltest reader = new nulltest();
}
}
}
if (!portFound) {
System.out.println(“port ” + defaultPort + ” not found.”);
}
}
public nulltest() {
// initalize serial port
try {
serialPort = (SerialPort) portId.open(“SimpleReadApp”, 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
// activate the DATA_AVAILABLE notifier
serialPort.notifyOnDataAvailable(true);
try {
// set port parameters
serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
// start the read thread
readThread = new Thread(this);
readThread.start();
}
public void run() {
// first thing in the thread, we initialize the write operation
// initwritetoport();
try {
while (true) {
// write string to port, the serialEvent will read it
// writetoport();
Thread.sleep(1000);
}
} catch (InterruptedException e) {}
}
public void delay(){
try {
Thread.sleep(3000L);
}
catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
// we get here if data has been received
byte[] readBuffer = new byte[20];
try {
// read data
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
File file = new File(“D://Serial_Comm.text”) ;//Adress where the file(here text file) to be made
/* print data*/
String result = new String(readBuffer);
System.out.println(“Read: “+result);
try{
writer = new BufferedWriter(new FileWriter(file,true));
writer.write(result+”\n”);
writer.flush();
}catch(FileNotFoundException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
} finally{
try
{
if (writer != null){
writer.close();
}
} catch (IOException e){
e.printStackTrace();
}
}
}catch (IOException e) {}
delay(); // This is used to sense data within a particular instant,here,3 seconds
break;
}
}
}
However we are facing an error in the line
public class nulltest implements Runnable, SerialPortEventListener
and the error is reported as class nulltest is public, should be declared in a file named nulltest.java
please help us out
Circuit Negma said
I will try to locate the project folder and files and post them online for you to download.
kishor said
Go Here You’ll get Installer to Do that
http://kishor15389.blogspot.com/2011/05/how-to-install-java-communications.html
Techie said
Could you pls send a link from where I can download win32com.dll
Circuit Negma said
the download link is mentioned in this post.
here is the link again: http://www.megaupload.com/?d=XSPXW2PY
Vivek Mishra said
This is really 1 great post.
Darren said
You sir are a fooking genius
If ever meet you at a bar, I will buy you several drinks
You saved me 🙂
arun said
I downloaded java communication API but it doesnot contain all three files that you mentioned where i can get this
thank you
Circuit Negma said
I downloaded the API (zipped file) using the above download link and there it was all 3 files. you need winzip to extract the 3 files from the download javaxcomm.zip
khan said
Could you guyes please help me to set up Java Comm Api for window 7 64 bit
Brian said
Hi,
Thanks for all the information as I’ve been trying to set this up for awhile.
I’ve followed your instructions above but i still seem to be having some trouble
I’m getting the error:
Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_26\jre\bin\win32com.dll: Can’t find dependent libraries
I’ve placed win32com.dll is all the places mentioned above as well as the properties file and the jar file.
Any help would be appreciated.
Thanks
Running on NetBeans 7 IDE on a Windows 7 Machine.
Brian said
I found that i’m running Windows 7 64bit which cannot find the win32com.dll… need win64com.dll i think. i’ve switched to RxTx 64bit and everything is working find now.
Thanks
Circuit Negma said
Thanks for updating and contributing to the post so that everyone could benefit.
derxen Blog » Relaiskarte mit JAVA steuern said
[…] RXTXcomm Installationsanweisung | Alternative Anleitung […]
Rkumar said
Hi, it was very helpful. im trying out for a sample application to send sms from my Micromax Q2 mobile. It is throwing NoSuchPortException. can u send me a sample java code to send sms?
Circuit Negma said
sorry friend, but I do not have a sample code to send sms.
1. you could search google for sample code. use the following search word: java code: sms -> http://www.google.com/search?q=java+code%3A+sms&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a
2. you could tweak the rs232 java code by adding the correct format of sms protocol.
3. the error NoSuchPortException means that the port identifier such as COM1 or COM4 does not exist in your system or it is not accessible. you could try to use the following command:CommPortIdentifier.getPortIdentifiers() to get the ports registered in your system.
again you could search google using the search word: NoSuchPortException.
Good luck
uniqueijts: thankyou v much... said
thank you v much, .
jhon said
Hi, Thank you for your code. i kept all the files in jdk folder whatever you mentioned like that, but it is giving exception like–” Exception in thread “main” java.lang.NoSuchMethodError: main”
pls tell me what can i do.
Circuit Negma said
1. is the jdk folder path defined in the windows env. path
2. did you add jdk or comm library to your project
omkar said
I cant find the java comm api..the link you gave is nothing but a fedaral notice..
Circuit Negma said
This is because the FBI has shutdown the site. I will try to relocate the file on my machine and reupload it again soon.
vamsi said
when i am using CommPortIdentifier.getPortIdentifier(“COM4”); i get the exception javax.comm.NoSuchPortException
at javax.comm.CommPortIdentifier.getPortIdentifier
i phone is also connected to the com4..
when i am using Enumeration enu = CommPortIdentifier.getCommPortIdentifiers();
no exception and no output
i want solution for that
vinayaka said
can any one let me know procedure for installing comm api in netbeans
please
thank you.
Circuit Negma said
1. you need to install API on your system.
2. you need to add the comm.jar to your project. If I remember correctly, you add the jar file under libraries in the Project workspace/explorer.
Paiker said
I will be really very thankfull for ur support.
I have made and appplet which is reading the data from the machine attached to the serial port.
And it is working fine when i am running it from the Eclipse..
But when i am trying to add this applet in the HTML page it is not running and in the console this error is coming .
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/comm/PortInUseException
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/comm/PortInUseException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.comm.PortInUseException
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 20 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/comm/PortInUseException
Circuit Negma said
1. Since the API works in a stand alone applet, then the API is installed correctly.
2. I never worked with embedded applet for HTML. I do not think the problem is coming from the COM API, because we know it works on your machine. I would suggest that you build a simple applet that shows a “hello” message and then try to embed it in HTML. if your steps of embedding java is correct then try again with your serial port applet
3. I wonder if windows allows a remote access of serial port through HTML!!!!!!!
hopefully this will put you on the right direction
Raj said
Before u execute an applet, make sure all the ports are stopped. Also u can add RXTXComm.jar to the classpath.. Regards, Raj..
Anand said
Thanx This is what I m needed.
Its really help me….
DS said
i m facing this exception when i run my java app..i cant undstnd wats happng cz at one instance it runs perfectly but nxt time it dsnt..and den after it dsnt run for a long period of time..i hvnt found ne solution yet pls provide one.
Trying to open COM4…
Apr 7, 2012 10:54:49 PM ManagerInterface initSerial
SEVERE: null
javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:337)
at ManagerInterface.initSerial(ManagerInterface.java:536)
at ManagerInterface.initCommunication(ManagerInterface.java:518)
at PortSelector.startButtonMouseClicked(PortSelector.java:237)
at PortSelector.access$0(PortSelector.java:231)
at PortSelector$1.mouseClicked(PortSelector.java:63)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Circuit Negma said
1. first line of errors says that COM4 is being used by Unknow windows Application. before you run your java appley, you need to close any software that uses COM4
2. if you look through the comments on this post you will notice couple of codes samples. you should be able to tailor them to your needs.
prajwal said
thumbs up!! thanks a lot..
Andres said
where can I find this files? I mean, download the comm.jar, win32com.dll and javax.comm.properties files.
Circuit Negma said
I am still looking for the file. I really have not done any work in java for a while now and I do not know where I placed my java projects on my machine.
Andres said
ok thanks
lconceic said
http://llk.media.mit.edu/projects/cricket/doc/serial.shtml
Mustafa said
Thaaaaaaaaaank u v.much
stephenmwongela said
Reblogged this on Computer World.
abraham ks said
hi in my project i did’nt get seriel communication properly so pls give a code for that.
Circuit Negma said
the API mentioned in this article does not work on Windows 7 64-bit and any 64-bit machines. you need to search google for what is new on talking with serial ports in Java
also, in the commments, I have posted a code for serial communication.
sagar said
Very very helpfull thanks alot
best explanation i saw
thank you
god bless you 🙂
migz said
It took me two days to figure out why my code wasn’t working, it as because I didn’t have the comm library properly installed, and your way was the only way that worked!
sathish kumar khammam said
thank you very much……
matpyam said
hye..can i ask something..
i already downloaded all the thing that need here http://smslib.org/download/
but, me can’t fing the file comm.jar, javax.comm.properties and win32com.dll..
realy2 need help..:(
Circuit Negma said
it is right there on the site you gave me http://smslib.org/download/.
download the following “SUN JavaComm v2 (Win32)” from the above site.
Software said
Wow that was odd. I just wrote an extremely long comment but after I clicked
submit my comment didn’t show up. Grrrr… well I’m not writing all that over again.
Regardless, just wanted to say superb blog!
Circuit Negma said
thanks
chintan said
Thank you , it’s really helpful