public void enviarDados(String dados) { try { output.write(dados.getBytes()); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Algo deu errado", "ERRO", JOptionPane.ERROR_MESSAGE); } } ----------------------------------------------------------------------------------------------------------------- static void delay (int t) throws InterruptedException{ Thread.sleep(t); } ----------------------------------------------------------------------------------------------------------------- private void enviar (int freqpin, int ciclopin, String a, String b) throws InterruptedException{ for(int ciclo=0; ciclo< ciclopin; ciclo++){ enviarDados(a); delay(freqpin); enviarDados(b); delay(freqpin); } } ----------------------------------------------------------------------------------------------------------------- private void enviarciclos () throws InterruptedException{ for(int i=0; i < Integer.valueOf(tfBinary.getText()); i++){ //Loop de ciclos por pino enviar(Integer.valueOf(tfFreqP8.getText()),Integer.valueOf(tfCyclesP8.getText()), "8ON", "8OFF"); enviar(Integer.valueOf(tfFreqP9.getText()),Integer.valueOf(tfCyclesP9.getText()), "9ON", "9OFF"); enviar(Integer.valueOf(tfFreqP10.getText()),Integer.valueOf(tfCyclesP10.getText()), "10ON", "10OFF"); } } ----------------------------------------------------------------------------------------------------------------- private void enviarcar () throws InterruptedException{ int x = Integer.valueOf(tfCyclesCar1.getText()); for(int i=0; i < x; i++){ //Loop do 1º ciclos carreador enviarDados("11ON"); delay(Integer.valueOf(tfFreqP11.getText())); enviarDados("11OFF"); delay(Integer.valueOf(tfFreqP11.getText())); } delay(Integer.valueOf(tfStopCar.getText())*1000); for(int i=0; i < Integer.valueOf(tfCyclesCar2.getText()); i++){ //Loop do 2º ciclos carreador enviarDados("11ON"); delay(Integer.valueOf(tfFreqP11.getText())); enviarDados("11OFF"); delay(Integer.valueOf(tfFreqP11.getText())); } } ----------------------------------------------------------------------------------------------------------------- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { for(int i=0; i< Integer.valueOf(tfReplicate.getText());i++){ try { enviarciclos(); enviarcar(); } catch (InterruptedException ex) { } } } ----------------------------------------------------------------------------------------------------------------- public synchronized void serialEvent(SerialPortEvent oEvent) { if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) { try { int a = input.read(); int temp = Integer.parseInt(tfTemp.getText()); float t = (float) ((5.0 * a * 100.0) / 1024.0); DecimalFormat decimal = new DecimalFormat( "0.00" ); jLTemp.setText(String.valueOf(decimal.format(t))); if (t <= temp){ enviarDados("TON"); } else { enviarDados("TOFF"); } //System.out.println(a); } catch (Exception e) { System.err.println(e.toString()); } } // Ignore all the other eventTypes, but you should consider the other ones. }