Problem Getting the Serial Port.

Discussion in 'Java' started by Malik Asif Joyia, Jun 25, 2005.

  1. Hello
    I m writing the following code but it is not working can any bod tell
    that what is the problem with it?
    <code>
    public void OpenSerialPort() throws java.io.IOException {
    try {
    Enumeration en = CommPortIdentifier.getPortIdentifiers();
    CPI1 = CommPortIdentifier.getPortIdentifier("COM1");
    try
    {
    sm = (SerialPort) CPI1.open("UARTTesting", 3000);
    }catch(PortInUseException ee)
    {
    System.out.println(ee.getMessage());
    }

    } catch (NoSuchPortException e) {
    System.out.println(e.getMessage());
    }


    }
    </code>
    but when i run the code it throws exception no such port exists, My OS
    is Windows 2003 Server Enterpirze Edition.

    Thanks
     
    Malik Asif Joyia, Jun 25, 2005
    #1
    1. Advertising

  2. "Malik Asif Joyia" <> writes:

    > I m writing the following code but it is not working can any bod tell
    > that what is the problem with it?


    The comm API will silently "fail" to detect any ports if it cannot
    load the native component. Are you sure javacomm.dll is on the library
    path?
     
    Tor Iver Wilhelmsen, Jun 25, 2005
    #2
    1. Advertising

  3. Malik Asif Joyia

    Dale King Guest

    Tor Iver Wilhelmsen wrote:
    > "Malik Asif Joyia" <> writes:
    >
    >
    >>I m writing the following code but it is not working can any bod tell
    >>that what is the problem with it?

    >
    >
    > The comm API will silently "fail" to detect any ports if it cannot
    > load the native component. Are you sure javacomm.dll is on the library
    > path?


    Actually, I believe it usually occurs because of not having that stupid
    properties file as well.

    I recommend against using the Java Comm Api and going with RXTX
    (www.rxtx.org). It at least has had active development in the past 7 years.

    --
    Dale King
     
    Dale King, Jun 25, 2005
    #3
  4. Malik Asif Joyia wrote:

    > Hello
    > I m writing the following code but it is not working can any bod tell
    > that what is the problem with it?
    > <code>
    > public void OpenSerialPort() throws java.io.IOException {
    > try {
    > Enumeration en = CommPortIdentifier.getPortIdentifiers();
    > CPI1 = CommPortIdentifier.getPortIdentifier("COM1");
    > try
    > {
    > sm = (SerialPort) CPI1.open("UARTTesting", 3000);
    > }catch(PortInUseException ee)
    > {
    > System.out.println(ee.getMessage());
    > }
    >
    > } catch (NoSuchPortException e) {
    > System.out.println(e.getMessage());
    > }
    >
    >
    > }
    > </code>
    > but when i run the code it throws exception no such port exists, My OS
    > is Windows 2003 Server Enterpirze Edition.
    >
    > Thanks
    >


    The installation is tricky and all of the parts have to be in the right
    places. Here is the little class I wrote to identify the serial ports
    and also to tell me that the JavaComm API was installed correctly. My
    Windows XP installation requires the:

    comm.jar file to be in the Program Files/Java/jdk1.5.0_03/jre/lib/ext
    and the Program Files/Java/jre1.5.0_03/lib/ext directories.

    javax.comm.properties file to be in the
    Program Files/Java/jre1.5.0_03/jre/lib directory.

    win32com.dll file to be in the Program Files/Java/jre1.5.0_03/bin directory.

    import java.io.*;
    import java.util.*;
    import javax.comm.*;

    public class Ports {
    public Ports() {
    CommPortIdentifier cpi = null;

    Enumeration e = CommPortIdentifier.getPortIdentifiers();

    while (e.hasMoreElements()) {
    try {
    cpi = (CommPortIdentifier) e.nextElement();
    } catch (NoSuchElementException n) {}
    System.out.println(cpi.getName());
    }
    }
    public static void main(String[] args) { new Ports(); }
    }

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Jun 27, 2005
    #4
  5. Malik Asif Joyia

    Dale King Guest

    Knute Johnson wrote:
    > Malik Asif Joyia wrote:
    >
    >> Hello
    >> I m writing the following code but it is not working can any bod tell
    >> that what is the problem with it?
    >> <code>
    >> public void OpenSerialPort() throws java.io.IOException {
    >> try {
    >> Enumeration en = CommPortIdentifier.getPortIdentifiers();
    >> CPI1 = CommPortIdentifier.getPortIdentifier("COM1");
    >> try
    >> {
    >> sm = (SerialPort) CPI1.open("UARTTesting", 3000);
    >> }catch(PortInUseException ee)
    >> {
    >> System.out.println(ee.getMessage());
    >> }
    >>
    >> } catch (NoSuchPortException e) {
    >> System.out.println(e.getMessage());
    >> }
    >>
    >>
    >> }
    >> </code>
    >> but when i run the code it throws exception no such port exists, My OS
    >> is Windows 2003 Server Enterpirze Edition.
    >>
    >> Thanks
    >>

    >
    > The installation is tricky and all of the parts have to be in the right
    > places. Here is the little class I wrote to identify the serial ports
    > and also to tell me that the JavaComm API was installed correctly. My
    > Windows XP installation requires the:
    >
    > comm.jar file to be in the Program Files/Java/jdk1.5.0_03/jre/lib/ext
    > and the Program Files/Java/jre1.5.0_03/lib/ext directories.
    >
    > javax.comm.properties file to be in the
    > Program Files/Java/jre1.5.0_03/jre/lib directory.
    >
    > win32com.dll file to be in the Program Files/Java/jre1.5.0_03/bin
    > directory.


    I recommend putting all 3 files in both the JDK and the JRE to make sure
    it works. Depending on your setup you may end up invoking the java
    runtime that is in the JDK instead of the JRE.

    --
    Dale King
     
    Dale King, Jun 29, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Serial Port problem

    Guest, Sep 2, 2004, in forum: Java
    Replies:
    13
    Views:
    18,326
    zg2pro
    Sep 16, 2010
  2. Sonoman
    Replies:
    2
    Views:
    870
  3. Pom
    Replies:
    2
    Views:
    1,667
    Bas-i
    Jan 31, 2007
  4. Max Kotasek
    Replies:
    4
    Views:
    989
    Max Kotasek
    Apr 9, 2010
  5. msalerno
    Replies:
    3
    Views:
    412
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page