//*****************************************************************************
//COMUNICAÇÃO SERIAL UTILIZANDO A API DA SUN
//*****************************************************************************
// CLASSE SerialCom.java É PARTE DO PACKAGE SrCom
//*****************************************************************************
//AUTOR : Daniel V. Gomes
//EMAIL: dansovg@ig.com.br
//DATA INICIAL: 29/04/04
//DATA ATUAL: 03/05/04
//*****************************************************************************
//NOTA: Você pode utilizar este código a vontade mas não me responsabilizo por
//erros durante sua execução. Quaisquer dúvidas ou sugestões,
//envie-me por email.
//*****************************************************************************
package SrCom;
import javax.comm.*;
import java.io.*;
import java.util.*;
public class SerialCom {
//*********************************
//Variáveis
//*********************************
//variáveis para identificar portas
protected String[] portas;
protected Enumeration listaDePortas;
//construtor
public SerialCom(){
listaDePortas = CommPortIdentifier.getPortIdentifiers();
}
//retorna as portas disponíveis
public String[] ObterPortas(){
return portas;
}
//Copia portas para um Array
protected void ListarPortas(){
int i = 0;
portas = new String[10];
while (listaDePortas.hasMoreElements()) {
CommPortIdentifier ips =
(CommPortIdentifier)listaDePortas.nextElement();
portas[i] = ips.getName();
i++;
}
}
//pesquisa se a Porta existe
public boolean PortaExiste(String COMp){
String temp;
boolean e = false;
while (listaDePortas.hasMoreElements()) {
CommPortIdentifier ips =
(CommPortIdentifier)listaDePortas.nextElement();
temp = ips.getName();
if (temp.equals(COMp)== true) {
e = true;
};
}
return e;
}
//imprime as portas disponíveis
protected void ImprimePortas(){
for (int i = 0 ; i < portas.length ; i ++ ) {
if (portas[i] != null ) {
System.out.print(portas[i] + " ");
}
}
System.out.println(" ");
}
}//FIM DA CLASSE