Pessoal,
Estou lendo uma porta serial e mandando dados constantes…
Queria ficar atualizando a tela com os campos recebidos da porta serial sem mexer na estrutura da tela, mas não estou conseguindo, pq ele fica criando novas telas e nem atualiza os campos.
Monto tela após chamar a classe que seta os valores dos campos:
public void serialEvent(SerialPortEvent event)
{
Tela tela = new Tela();
StringBuffer bufferLeitura = new StringBuffer();
int novoDado = 0;
switch (event.getEventType())
{
case 1:
while (novoDado != -1) {
try
{
novoDado = inputStream.read();
if (novoDado == -1) {
break;
}
if ('\r' != (char)novoDado) {
bufferLeitura.append((char)novoDado);
}
}
catch (IOException ioe)
{
System.out.println("ERRO - Erro de leitura serial: " + ioe);
}
}
inicio.validaDados(new String(bufferLeitura)); // SETA OS VALORES PARA ENVIAR PARA A TELA
// System.out.println(bufferLeitura + "\n");
tela.rdc(); // TELA DE SWING
}
}
Tela que seta os campos:
public void validaNumSerie(String input) {
Pattern pattern;
Matcher matcher;
pattern = Pattern.compile(".*N_S=([0-9A-Fa-f]+).*", 32);
matcher = pattern.matcher(input);
if (matcher.matches()) {
// Converte hexa
String numero = String.valueOf(Integer.parseInt(
matcher.replaceAll("$1"), 16));
while (numero.length() < 9) {
numero = "0" + numero;
}
dispositivos.setNumSerie(numero);
Tela.getTextField_NumSerie().setText(dispositivos.getNumSerie()); // SETO O CAMPO DA TELA DE SWING - Tentativa
System.out.println("Número de Série: " + dispositivos.getNumSerie());
}
}