rxtx problem, please help!

Discussion in 'Java' started by joshua, Jul 1, 2007.

  1. joshua

    joshua Guest

    Hello!

    So I am trying to access a virtual serial port using the rxtx
    library. I enumerate the ports, and loop through them attempting to
    open each one. Although the portId.isCurrentlyOwned() returns false,
    portId.open() still throws a PortInUseException, and when I call
    portId.getCurrentOwner(), it returns null.

    Here is relevant code:

    portList = CommPortIdentifier.getPortIdentifiers();

    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier)portList.nextElement();

    /* only iterate through serial ports */
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

    /* attempt to open the port */
    try {
    if (portId.isCurrentlyOwned()) {
    System.out.println(portId.getName() + " is owned");
    } else {
    System.out.println(portId.getName() + " is not
    owned");
    }
    serialPort = (SerialPort)portId.open("Square2Plus",
    2000);
    } catch (PortInUseException e) {
    //if the port is unavailable, move to the next one
    System.out.println(portId.getName() + " is owned by " +
    portId.getCurrentOwner());
    continue;
    }
    }
    }

    if(portOpen) {
    System.out.println(portId.getName() + "is open!");
    serialPort.close();
    } else {
    System.out.println("port not found");
    }


    Running this code produces:

    COM3 is not owned
    COM3 is owned by null
    COM5 is not owned
    COM5 is owned by null
    port not found

    So if the ports aren't owned, why is it throwing this exception, and
    what can I do about it?

    Please and thank you all so much!
    Joshua
     
    joshua, Jul 1, 2007
    #1
    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. Alex Bitkiller

    Java rxtx libs

    Alex Bitkiller, Feb 17, 2004, in forum: Java
    Replies:
    2
    Views:
    4,326
    Alex Bitkiller
    Feb 18, 2004
  2. bimbo

    rxtx 2.1.6

    bimbo, Apr 8, 2004, in forum: Java
    Replies:
    0
    Views:
    784
    bimbo
    Apr 8, 2004
  3. Brzezi
    Replies:
    0
    Views:
    707
    Brzezi
    Jun 27, 2004
  4. Nanou

    URGENT RXTX SERIAL PORT

    Nanou, May 31, 2005, in forum: Java
    Replies:
    0
    Views:
    463
    Nanou
    May 31, 2005
  5. Nanou

    URGENT RXTX SERIAL PORT

    Nanou, May 31, 2005, in forum: Java
    Replies:
    11
    Views:
    5,891
    Nanou
    Jun 2, 2005
Loading...

Share This Page