Serial connection with Vista problem

I ended up piecing together code to open a serial port on my machine for use with my X10 hardware. I have pasted the code below. When I run it, I get a error saying the port can't be opened because it is in use by windows (don't have the exact error handy) but it won't say what is using it. I think its Vista doing somthing to protect the system because I am not using COM1 or COM2 on my machine.

I took the exact same code and set it up on my work machine running XP, it worked fine, and even took the port over another program using it currently. Does anyone have any idea what could be done with Vista to allow me to use the port? or any ideas for what I could do, short of installing XP on a machine to write this code?

Thanks

import javax.swing.JOptionPane;//used for GUI

import java.util.Scanner;//used for scanner

import javax.comm.*;

import java.io.*;

import java.util.*;

//import com.micheldalal.x10

publicclass test

{

publicstaticvoid main(String[] args)

{

/*

try

{

String driverName = "com.sun.comm.Win32Driver"; // or get as a JNLP property

CommDriver commDriver = (CommDriver)Class.forName(driverName).newInstance();

commDriver.initialize();

}

catch (Exception e)

{}

*/

String wantedPortName ="COM3";

System.out.println("comm name");

//

// Get an enumeration of all ports known to JavaComm

//

Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();

System.out.println("comm name2");

//

// Check each port identifier if

//(a) it indicates a serial (not a parallel) port, and

//(b) matches the desired name.

//

CommPortIdentifier portId =null;// will be set if port found

System.out.println("null portID");

while (portIdentifiers.hasMoreElements())

{

System.out.println("Element");

CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();

if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&

pid.getName().equals(wantedPortName))

{

portId = pid;

System.out.println("Found Port " + portId);

System.out.println(portId.getCurrentOwner());

break;

}

System.out.println(pid.getName());

}

System.out.println("end while");

if(portId ==null)

{

System.err.println("Could not find serial port " + wantedPortName);

System.exit(1);

}

//

// Use port identifier for acquiring the port

//

//

// Use port identifier for acquiring the port

//

SerialPort port =null;

System.out.println("serial null");

try{

System.out.println("trying to open port");

port = (SerialPort) portId.open(

"name",// Name of the application asking for the port

10000// Wait max. 10 sec. to acquire port

);

}catch(Exception e){

System.err.println("Port already in use: " + e);

System.exit(1);

}

[4986 byte] By [marriott001a] at [2007-11-27 5:14:33]
# 1
There's a Sun java.comm implementation for Vista? I thought they skipped creating them for Windows because the specs changed or something...
CeciNEstPasUnProgrammeura at 2007-7-12 10:36:31 > top of Java-index,Java Essentials,Java Programming...
# 2

I didn't know of a new one no, i just used the one that was out already, don't get any errors from the code, its just the error that windows is using the port. I think it might throw a exxception, but I cant' remember if it is that, or if it just says it can't open the port because its in use

If you are talking about finding the comm.jar with the windows classes, yeh that was taken down i guess, but i found the link floating around when i was asking the same question.

Message was edited by:

marriott001

marriott001a at 2007-7-12 10:36:31 > top of Java-index,Java Essentials,Java Programming...