questo è il mio codice:

codice:
	public void SetSerialPort(Properties prop) throws Exception {
		
		OutputStream out = null; 
		InputStream in = null;
		dev_serial = "com7";
		portList = CommPortIdentifier.getPortIdentifiers();
		boolean portFound = false;

		String driverName = "com.sun.comm.Win32Driver";
		try {
			CommDriver commdriver = (CommDriver)Class.forName(driverName).newInstance();
			commdriver.initialize();
		} catch (Exception e2) {
			e2.printStackTrace();
		}
		
		while (portList.hasMoreElements()) {

			portId = (CommPortIdentifier) portList.nextElement();
			
			System.out.println("portId name: " + portId.getName() + ", type: " + portId.getPortType() + ", owner: " + portId.getCurrentOwner());
			
			if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

				String [] array = prop.getProperty("port.list").split(" ");
				
//				for (int i=0; i <= array.length; i++ ) {
//					dev_serial = array [i];
//				}
				
				if (portId.getName().equalsIgnoreCase(dev_serial)) {
				
					System.out.println("Found port " + dev_serial);
					portFound = true;
            
					try {
						serialPort = (SerialPort) portId.open("SimpleWrite", 2000);
					} catch (PortInUseException e) {
						System.out.println("Port in use.");
						continue;
						
					}
					try {
						out = serialPort.getOutputStream();
						in = serialPort.getInputStream();
						
					} catch (IOException e) {
						e.printStackTrace();
						System.out.println("Error: " + e.getMessage());
						continue;
					}
					try {
						serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
					} catch (UnsupportedCommOperationException e) {
						e.printStackTrace();
						System.out.println("Error: " + e.getMessage());
						continue;
					}
					try {
						serialPort.notifyOnOutputEmpty(true);
					} catch (Exception e) {
						e.printStackTrace();
						System.out.println("Error setting event notification");
						System.out.println(e.toString());
					}
					try {
					/// COMANDI CSQ

//					out.write (("AT+COPS?" + String.valueOf(this.invio)).getBytes());
					out.write (("AT+CSQ" + String.valueOf(this.invio)).getBytes());