| |

serialport communication using Java

Reading Time: < 1 minute

before going to execute this program read how to install comport api for windows

In java there is no inbuilt support to access serial or parallel ports, to over come this we are taking support of  Java communication API.

after downloading the java communication api extract the folder then you can get the following…
in Commapi folder we require
comm.jar

javax.comm.properties

win32com.dll

after getting these files perform following operations….

  • Copy file comm.jar in <JAVA_HOME>\jre\lib\ext
  • Copy file javax.comm.properties in <JAVA_HOME>\jre\lib
  • Copy file win32com.dll in <JAVA_HOME>\lib

now you can able to access the commport by Java programm.

The following example displays the available ports(serial and parallel ports) and their type:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package keyboardreader;

/**
*
* @author vijay
*/

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);
}
}
}

output is like this :

COM1: Serial
COM2: Serial
LPT1: Parallel
LPT2: Parallel

Similar Posts

4 Comments

  1. hai vijay
    now i am successfully send messages for more numbers at time from database, i have one query regarding deliverying status , while sending sms how we have to check sms is delivered or not , i have studied At+cnmi command but i cant get clear idea, how to check whether message is deliverying or we have to check the ok response while giving at+cmgs=”996584435″, can u give any sample code regarding this , expecting a quick reply id arunram.prf@gmail.com

  2. hai vijay
    now i am successfully send messages for more numbers at time from database, i have one query regarding deliverying status , while sending sms how we have to check sms is delivered or not , i have studied At+cnmi command but i cant get clear idea, how to check whether message is deliverying or we have to check the ok response while giving at+cmgs=”996584435″, can u give any sample code regarding this , expecting a quick reply id arunram.prf@gmail.com

Comments are closed.