Java Communications API

Hi
I've written a program to communicate with a circuit with JCA throught LPT Port. I have done this:
import java.io.*;
import java.util.*;
import javax.comm.*;
public class test65{
static Enumeration portList;
static CommPortIdentifier portId;
static int num = 8;
static ParallelPort parPort;
static OutputStream outputStream;
public static void main(String arg[]){
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
System.out.println ("Found Parralel Port :"+portId.getName());
if (portId.getName().equals("LPT1")) {
try {
parPort = (ParallelPort)portId.open("Robotics", 2000);
} catch (PortInUseException e) {
System.out.println("ERROR: This port is in use by: "+e.currentOwner+".");
try {
outputStream = parPort.getOutputStream();
} catch (IOException e) {
System.out.println ("ERROR: IO Exception.");
parPort.close();
} catch (NullPointerException e){
System.out.println ("ERROR: OutPutStream could not be Created.");
parPort.close();
try {
System.out.println ("Number "+num+" is about to be sent ....");
System.out.println ("Mode : "+parPort.getMode());
outputStream.write(num); //(1)
System.out.println ("Number "+num+" was Sent.");
} catch (IOException e) {
System.out.println ("ERROR: Could not Write Output");
parPort.close();
in the line that writes num to the stream,(1), program stops and doesn't send anything. If i install a printer then the num is sent to the printer driver to be PRINTED. i don't want to print anything. I've think if there is any driver that sends to the port whatever it recieves. What should i do to send numbers to LPT port like outp and out commands in basic and c ?

When using java communications api you need to simulate a centronics printer circuit in order to get output to the pins all this requires is that you pull pin11 (Busy) low, pin12 (Paper Out) low, and pin15 (Printer Error) High, although I've only had success thus far using spp mode which of course only supports output. Good luck all.

Similar Messages

  • About Java Communication API for Windows

    hi
    I'm studying Serial Communication in university.
    I'd like to know the reason why we can't downlaod Java Communication API for Windows.
    I confirmed Comm for Linux and Soralis, but I can't find Comm for Win.
    Please tell me the reason if someone know.

    For no particular reason Sun stopped supporting the windows version
    of that package. I use rxtx which happens to allow for much faster
    communication too.
    The interface is identical to Sun's version, just the package differs: "gnu.io".
    kind regards,
    Jos

  • Problem with Java Communication API

    hi
    I installed the Java Communication API on win32 platform (as per the guidelines)
    Now when I try to run the sample program 'Blackbox' for the serial port, I get an error (in fact an exception is generated inside main function in BlackBox.class file)
    I tried the SimpleRead.java example but that too generated the same exception
    Can anybody help me out.... I am a novice with Java Comm API

    I tried running the sample BlackBox program provided for serial port and now it says
    No Serial Ports Found!
    I verified that both comm.jar and javax.comm.properties are in the <JDK>\lib directory.
    Actually, I am using netBeans IDE 1.4 and I used the C:\J2SDK folder installed with netBeans for the Java Communicaion API
    plz help.

  • Java Communications API and Java SDK 1.4.2

    I just installed the Java Communications API 2.0 on my Windows XP system, with JDK 1.4.2. As per the install instructions, I copied files from the zip into my /lib and /bin directories and set the classpath. However, when I attempt to compile any of the samples, the compiler displays a large number of errors. I know the API documentation only references JDK1.2 -- are there any special tricks to installing on newer JDKs, or will I need to acquire an older JDK to develop?

    My path variable is still not being set! Here is the content of my autoexec.bat located on the root directory of C:\
    rem - By Groove Setup
    PATH=%PATH%;"C:\Program Files\Groove Networks\Groove\Bin"
    PATH=%PATH%;C:\PROGRAM FILES\J2SDK1.4.2_07\BIN
    /code]
    When I type 'path' at the MSDOS C:\ prompt, I receive the following in the get the following:C:\WINDOWS;C:\WINDOWS\COMMAND;\C:\PROGRAM FILES\GROOVE NETWORKS\GROOVE\BIN
    As an aside, I noticed that when I perform a search of the my hard drive (c:\), I find two autoexec.bat files. One at the root, and the other in C:\Windows\Command\EBD.
    I believe the instructions stated to modify the autoexec.bat at the root directory.
    TIA for any assistance. This is really becoming a nusance and taking up quite a bit of my time trying to resolve this problem.

  • Problem with java communication api for gsm modem port

    Hi,every body
        Am using gsm modem in my project previously my linux is 32bit with 32 bit jvm of sun that time there was no problem at the time of working with gsm modem port .But now am using 64bit linux then 32bit files are not supporting to communicate with gsm modem port .How can i get java communication api for unix 64bit ,64bit jvm of sun.please any body help me ...i am searching in sun/oracle also for downloading java communication files of 64bit jvm but i didn't get the link... i need bellow java communication api files.
           ex:1)libLinuxSerialParallel.so
                2)javax.comm.properties
                3)comm.jar
                4)commtest.jar

    Moderator Action:
    This duplicate cross-post is locked.
    Stay with your original post.
    https://forums.oracle.com/thread/2602063
    (... and your hijack reply to a third thread has been removed.)

  • Identifying a comm port using java communication API

    HI ALL,
    i'm using the communication API to detect the comm port to which my modem is attached.
    i say CommPortIdentifier c = CommPortIdentifier.getPortIdentifier("COM3");
    then i SOP(c.getName())
    i get an exception saying noSuchPortException
    i've put the javax.comm.properties file in jdk/lib but to no avail.
    i also have a win32com.dll file that is there inside lib.
    but this hasn't helped. Now the properties file has a driver mentioned. do i have 2 download that driver or does it come with the OS (i've no idea)
    i would be helpful if anybody could help me out with this problem.

    Try putting tha javax.comm.properties file in you <java>/jre/lib folder as well... It worked for me !

  • Java communication api for windows 64 bit

    Hi,
    I need communication api for windows 64 bit. Are these api's in developement?
    Thanks,
    Andrea Todeschini

    If you use version 2.0 of the rxtx library then it provides a complete implementation of the javax.comm package.
    Version 2.1 does not (its in the gnu.io namespace)
    // Try the following url
    http://users.frii.com/jarvi/rxtx/download.html
    matfud

  • Newbie question on the Java communications API

    Hi All,
    I found the javax.comm extension package that lets me listen to the serial port of the PC, but am unsure as to how to use it. Well, I've tried running the SimpleRead.java program and I get an error message that says the package is missing in the import (which I assume means that I havent downloaded it and added it to one of the folders in my Java directory). Where can I find the package from? And am I missing anything else?
    In case you're all wondering, I've got a microcontroller attached to the serial port that sends data periodically. I would like to use the Java comm API to read the incoming data (and if possible store it in the form of a text file or something). Any suggestions would be great as I'm still new to Java. More of a C/C++ person (^_^) Thanks in advance.....

    Did you try using that little search field in the upper right hand corner of your browser?

  • How to distrubute java communication api ?

    hi , I have a java project using java comm api (comm.jar) I need to distrubute it to clients (because it is an applet based app) without any user interactivity.
    First I remember Webstart but somewhere I read some bugs about comm.api and webstart so I want to ask first Is there any people here used to developed and distrubute comm.api before ? What did you used ?
    My clients has no knowledge about computers,so It should be some automatic process.

    What about my suggestion in your original post regarding the same question?
    http://forum.java.sun.com/thread.jsp?thread=412320&forum=31&message=1814508

  • Java Communications API (JCA) is really that difficult???

    Hi everyone, I am an advanced developer for some years in Microsoft Platforms (.NET, VS6, etc.). I have used Microsoft Programs for a while and I can certainly say that I can develop serious programs.
    The reason I am posting this is that I am doing some reaserac in the usability of other programmer platforms for windows and linux.
    I turned towards Java about a month ago. I kno very well the structure of the language but I came across something very silly:
    I tried to install the javax.comm package! Ha ha ha...
    I thought SUN is a serious company (one o the largest) and I keep wondering why this package is so difficult to install. I tried every single post on the forums and nothing worked for me. I am using sdk1.4.1
    with SUN Studio One update 1 (formerly Forte, ha ha).
    IS THERE ANYONE OUT THERE THAT HAS THE API WORKING ON A WINDOWS 2000 PLATFORM (language doesn't matter but the answer -please- must be in english...) THAT CAN GIVE ME THE MAP OF FILES LIKE:
    c:\j2sdk1.4.1\bin\win32comm.dl
    c:\j2sdk1.4.1\lib\javax.comm.properties
    c:\j2sdk1.4.1\lib\ext\javax.comm
    c:\program files\java\j2re1.4.1\lib\javax.comm
    Classpath = <somthing>
    etc.
    Please, I can't get this working. I need to see the damn package in the Studio so that I can work properly..
    CAN THIS API ORK WITH THE STANDARD EDITION OF JAVA AND THE COMMUNITY EDITION OF FORTE???

    Hi,
    Acneto, the jar file must be mounted and the
    the parser must be updated. If the api is installed
    correctly (finally i have it running) then the ide is
    able to compile and run programs that are associated
    with the api.That's what I've told you before...I've installed the commAPI in windows 98, Me, 2000 and XP...
    The problem with installing the API (I haven't told you before because I thought you already done it...) is with the "java home". Lots of people think that their java home is the jdk\lib and may be the c:\windows\java\lib...or other. And other people think that their java home is c:\windows\java\lib and then discover that is \jdk\lib.
    So what I always advice is to make a little problem:
    class JavaHome
    System.out.println("My java home is:"+System.getProperty("java.home"));
    }And so copy the files in the wrong place...
    (I don't know if there is a different way to update
    the parser database without adding the jar to the
    filesystem).I don't think so...anyway, you can mount the jar, update the database, and then unmount!
    I will make a post today that indicates a way of
    installing the api succesfully under win2K pro with
    j2sdk1.4.1 and Sun Studio One update 1 IDE.
    By the way, I believe that a special forum regarding
    serial and parallel port communications should be
    launced by SUN. There are just too many ppl out there
    that make such applications.I agree with you!
    Best regards,
    ANeto

  • Having problem with Java Communication API

    I am using this code to list the port that i have but it does not return any thing. when i compile and run nothing is printed out. i think either its not going in while loop but if i remove while loop it returns NULL. so i think its not recognizing any PORTS. i want to detect a modem port as i want to make a voice mail software. I am jsut starting by listing, opening and listening to the ports. Please help me ASAP. Thank you.
    import javax.comm.*;
    import java.util.*;
    public class PortLister {
    public static void main(String[] args) {
    Enumeration e = CommPortIdentifier.getPortIdentifiers();
    while (e.hasMoreElements()) {
    System.out.println((CommPortIdentifier) e.nextElement());
    }

    Go back where you downloaded the API and read the FAQ. I think it's the question number 2.

  • Problem in sending SMS via using java communication API

    I need to send SMS via my sony ericsson Z530i. It is connected to the com5 port of my system. I got the following code.
    import java.io.*;
    import java.util.BitSet;
    import javax.comm.*;
    import java.lang.*;
    public class SerialToGsm {
        InputStream in;
        OutputStream out;
        String lastIndexRead;
        String senderNum;
        String smsMsg;
        SerialToGsm(String porta) {
            try {
    //            CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("com5");
                CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(porta);
                SerialPort sp = (SerialPort)portId.open("Sms_GSM", 0);
                sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
                in = sp.getInputStream();
                out = sp.getOutputStream();
                // modem reset
                sendAndRecv("+++AT", 30);       // delay for 20 sec/10
                sendAndRecv("AT&F", 30);
                sendAndRecv("ATE0", 30);        // echo off
                sendAndRecv("AT +CMEE=1", 30);  // verbose error messages
                sendAndRecv("AT+CMGF=0", 70);   // set pdu mode
    //            sendAndRecv("AT V1E0S0=0&D2&C1", 1000000);
            catch (Exception e) {
                System.out.println("Exception " + e);
             System.exit(1);
        private String sendAndRecv(String s, int timeout) {
            try {
                // clean serial port input buffer
                in.skip(in.available());
                System.out.println("=> " + s);
                s = s + "\r";         // add CR
                out.write(s.getBytes());
                out.flush();           
                String strIn = new String();
                for (int i = 0; i < timeout; i++){
                    int numChars = in.available();
                    if (numChars > 0) {
                        byte[] bb = new byte[numChars];
                        in.read(bb,0,numChars);
                        strIn += new String(bb);
                    // start exit conditions
                    if (strIn.indexOf(">\r\n") != -1) {
                        break;
                    if (strIn.indexOf("OK\r\n") != -1){
                        break;
                    if (strIn.indexOf("ERROR") != -1) { // if find 'error' wait for CR+LF
                        if (strIn.indexOf("\r\n",strIn.indexOf("ERROR") + 1) != -1) {
                            break;                                            
              Thread.sleep(100); // delay 1/10 sec
                System.out.println("<= " + strIn);
                if (strIn.length() == 0) {
                    return "ERROR: len 0";
                return strIn;
            catch (Exception e) {                 
                System.out.println("send e recv Exception " + e);
                return "ERROR: send e recv Exception";
        public String sendSms (String numToSend, String whatToSend) {
            ComputeSmsData sms = new ComputeSmsData();
            sms.setAsciiTxt(whatToSend);
            sms.setTelNum(numToSend);
    //        sms.setSMSCTelNum("+393359609600");  // SC fixed
            String s = new String();
            s = sendAndRecv("AT+CMGS=" + (sms.getCompletePduData().length() / 2) + "\r", 30);
    //        System.out.println("==> AT+CMGS=" + (sms.getCompletePduData().length() / 2));
    //        System.out.println("<== " + s);
            if (s.indexOf(">") != -1) {
    //            s = sendAndRecv(sms.getSMSCPduData() + sms.getCompletePduData() + "\u001A"); // usefull one day?
    //            System.out.println("Inviero questo >>>> " + sms.getCompletePduData());
                   // if this sintax won't work try remove 00 prefix
                s = sendAndRecv("00" + sms.getCompletePduData() + "\u001A", 150);
    //            System.out.println("<== " + s);
                return s;
            else {
                return "ERROR";
        // used to reset message data
        private void resetGsmObj() {
            lastIndexRead = null;
            senderNum = null;
            smsMsg = null;
        public String checkSms (){
            String str = new String();
            String strGsm = new String();                         
            strGsm = sendAndRecv("AT+CMGL=0", 30);  // list unread msg and sign them as read
            // if answer contain ERROR then ERROR
            if (strGsm.indexOf("ERROR") != -1) {
                resetGsmObj();
                return strGsm; // error
            strGsm = sendAndRecv("AT+CMGL=1", 30);  // list read msg
            // if answer contain ERROR then ERROR
            if (strGsm.indexOf("ERROR") != -1) {
                resetGsmObj();
                return strGsm; // error
            // evaluate message index
            if (strGsm.indexOf(':') <= 0) {
                resetGsmObj();
                return ("ERROR unexpected answer");
            str = strGsm.substring(strGsm.indexOf(':') + 1,strGsm.indexOf(','));
            str = str.trim(); // remove white spaces
    //        System.out.println("Index: " + str);
            lastIndexRead = str;
            // find message string
            // look for start point (search \r, then skip \n, add and one more for right char
            int startPoint = strGsm.indexOf("\r",(strGsm.indexOf(":") + 1)) + 2;
            int endPoint = strGsm.indexOf("\r",startPoint + 1);
            if (endPoint == -1) {
                // only one message
                endPoint = strGsm.length();
            // extract string
            str = strGsm.substring(startPoint, endPoint);
            System.out.println("String to be decoded :" + str);
            ComputeSmsData sms = new ComputeSmsData();
            sms.setRcvdPdu(str);
    //        SMSCNum = new String(sms.getRcvdPduSMSC());
            senderNum = new String(sms.getRcvdSenderNumber());
            smsMsg = new String(sms.getRcvdPduTxt());
            System.out.println("SMSC number:   " + sms.getRcvdPduSMSC());
            System.out.println("Sender number: " + sms.getRcvdSenderNumber());
            System.out.println("Message: " + sms.getRcvdPduTxt());
            return "OK";
        public String readSmsSender() {
            return senderNum;
        public String readSms() {
            return smsMsg;
        public String delSms() {  
            if (lastIndexRead != "") {               
                return sendAndRecv("AT+CMGD=" + lastIndexRead, 30);
            return ("ERROR");
    }When i compile, there is no error. But when i execute it, the following error comes:
    E:\java\JavaSmsApi>javac SerialToGsm.java
    E:\java\JavaSmsApi>java SerialToGsm
    Exception in thread "main" java.lang.NoSuchMethodError: main
    What might be the error? Somebody help me. Thanks in advance.

    You are probably trying to run this as a CLDC application instead of a MIDP application (aka a MIDLet). Since CLDC apps start with a main(....) your runtime looks for one but does not find it, hence the error. Please recheck the project configuration.

  • Need API for Java communicating with RS232

    Dear All,
    I am a newbie to Java. I have a sensor connected to a microcontroller, and this microcontroller is also connected to a PC through the RS232 (COM 1). I have installed the Java Communications API "Javax.comm" on my PC and was able to run the "BlackBox" sample program. What I require is a simple Java program that will read and show the bytes comming through the COM1 port. If anyone has done anything similar or has an idea of how to go about it, could they please send me some example code, I would be very grateful. Or if anyone knows about any website with such similar examples i would be very grateful.
    Thank you very much.
    FREDERIC

    Cross posted numerous times...
    http://forum.java.sun.com/thread.jspa?threadID=634826

  • Java Communications Package

    I have download the commapi file and load the files to the place in my current version. I am running J2SE 1.5.0_04. I have run the blackbox program and have found no serial ports. I have also tired running the SimpleRead.java. This comes up with this error message:
    Exception in thread "main" java.lang.NoClassDefFoundError; SimpleRead
    What does this mean?
    Why do I find no serial ports with the black box program?
    thanks

    Go to www.java.sun.com and type commapi on the search text box. You will find the Java Communication API for dowload.

  • Help! How to get the Java Communication Package work in JDK1.3.1?

    I downloaded a Java Communications API Win32 ver 2.0 from java.sun.com, and try to use it to do some programming to communication ports with JDK1.3.1.
    I failed. When I tested with the samples (BlackBox, SimpleRead) coming with the javax.comm. It showed "no serial port found", something like that. I check the installation Instructions of the comm. package, it only described the installation under JDK1.1 and the pre-release version of JDK1.2. (and the installation of the same package in JDK1.1 and JDK1.2 are totally different.)I tried the specification with my JDK1.3, but it doesn't work.
    Who knows how to install the Javax.comm package in JDK1.3.1? Please let me know as soon as possible. Thanks a lot.

    This comes straight out of the FAQ that you got with your download:
    Q: My application does not find any ports when it enumerates available ports.
    Q: BlackBox gives me a message that says "No serial ports found!"
    A: In order for the Java communications API to find ports the file
    javax.comm.properties must be in the correct place. The preferred location
    is in <jdk>/lib. See the installation instructions for alternate locations
    and further information.
    Installation is very simple. Comm is a standard extension, so copy comm.jar to %JAVA_HOME%\jre\lib\ext
    This is all in the docs....

Maybe you are looking for

  • Vertical Mixed Line Chart - How to make the lines Bold

    Hi,   I am using a Vertical Mixed Line Chart in a report and user want the lines in the chart to be made bold. Is there an option to make them bold?   I checked in the Properties but unable to find.   Could you please reply <REMOVED_BY_MODERATOR> Nan

  • Using IUserAccountFactory for BAPI fetch

    Hi All, I need to get these details from the ECC system using SAP JCA. Portal User Locked Portal User Validity Portal User Language Portal User Country Portal User Last Logged On Date Portal Group Assigned We are using SAP Middleware -Java to fetch t

  • Weblogic Server 9.2 MP 3 for Solaris x86

    Does anyone know where I can download weblogic server 9.2 mp 3 for Solarix x86. I have spent my entire day looking for it in support.oracle.com (metalink) and oracle download pages but nothing has turned up so far.

  • N97 New Firmware Version 3

    I was reading some blogs and noticed that Version 3 for N97 is available, is this true? Some blog were stating that Nokia is planning to release Anna for N97... What's going on? The last I know was nokia released Version 2 software well over a year a

  • CSS Questions :: Renaming Class Styles & Replacing Styles Globally

    1) Renaming Class Styles I have a large website that I redesigned over a year ago and now manage. I've been doing some housekeeping and attempting to rename some of the class styles I've applied to different parts of each page. Problem: When I change