Guest User

temperaturajavafxarduino

a guest
May 26th, 2022
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.81 KB | None | 0 0
  1. Medir temperatura ambiente com JavaFX e Arduino
  2.  
  3.  */
  4. package tempinofxb10;
  5.  
  6.  
  7. /**
  8.  *
  9.  * @author kml tina
  10.  
  11.  bem10jfx.blogspot.com
  12.  */
  13. import java.util.Date;
  14. import javafx.application.Application;
  15. import javafx.application.Platform;
  16. import javafx.collections.FXCollections;
  17. import javafx.collections.ObservableList;
  18. import javafx.event.ActionEvent;
  19. import javafx.event.Event;
  20. import javafx.event.EventHandler;
  21. import javafx.geometry.Orientation;
  22. import javafx.geometry.Pos;
  23. import javafx.geometry.Side;
  24. import javafx.scene.Group;
  25. import javafx.scene.Scene;
  26. import javafx.scene.chart.CategoryAxis;
  27. import javafx.scene.chart.LineChart;
  28. import javafx.scene.chart.NumberAxis;
  29. import javafx.scene.chart.PieChart;
  30. import javafx.scene.chart.XYChart;
  31. import javafx.scene.control.Accordion;
  32. import javafx.scene.control.Button;
  33. import javafx.scene.control.CheckBox;
  34. import javafx.scene.control.ChoiceBox;
  35. import javafx.scene.control.ListView;
  36. import javafx.scene.control.Separator;
  37. import javafx.scene.control.Slider;
  38. import javafx.scene.control.TextArea;
  39. import javafx.scene.control.TextField;
  40. import javafx.scene.control.TitledPane;
  41. import javafx.scene.control.Tooltip;
  42. import javafx.scene.effect.Blend;
  43. import javafx.scene.effect.BlendMode;
  44. import javafx.scene.effect.Effect;
  45. import javafx.scene.input.MouseEvent;
  46. import javafx.scene.layout.Background;
  47. import javafx.scene.layout.Border;
  48. import javafx.scene.layout.HBox;
  49. import javafx.scene.layout.VBox;
  50. import javafx.scene.paint.Color;
  51. import javafx.scene.text.Text;
  52. import javafx.stage.Stage;
  53. import javafx.stage.WindowEvent;
  54. import jssc.SerialPort;
  55. import jssc.SerialPortEvent;
  56. import jssc.SerialPortEventListener;
  57. import jssc.SerialPortException;
  58. import jssc.SerialPortList;
  59.  
  60. /**
  61.  
  62.  */
  63. public class TempInoFXb10 extends Application {
  64.  
  65.     String vlCode;
  66.     String vlactions;
  67.     Text lbaction = new Text("Ação: " + vlactions);
  68.     Text lbcode = new Text("Temperatura" + vlCode);
  69.     SerialPort serialport;
  70.     String input;
  71.     ChoiceBox cbport = new ChoiceBox();
  72.     Scene scene;
  73.      final  NumberAxis axisY=new NumberAxis();
  74.         final CategoryAxis axisX=new CategoryAxis();
  75.        final LineChart <String,Number> lc =new LineChart<String,Number> (axisX, axisY);
  76.        
  77.    Button btsendposi=new Button("+");
  78.    Button btsendnegativo=new Button("-");
  79.      int vlsendPos=29;
  80.      int vlsendNeg=1;
  81.       TextArea taTerminalJFX=new TextArea();
  82.       //new stagest
  83.          Stage stageesta=new Stage();
  84.     Group gpesta=new Group();
  85.     Scene sceneesta =new Scene(gpesta, 300, 400,Color.ALICEBLUE);
  86.       Button btest1=new Button("Estatisticas");
  87.        String strdatas;
  88.        
  89.          //?
  90.         XYChart.Series xychtdia=new XYChart.Series ();
  91.        int contpieOne=0;
  92.        
  93.        //horas e logs
  94.        
  95.         Date dt=new Date();
  96.          int odatas=dt.getHours()-1;
  97.        
  98.        
  99.       Text txtimeini=new Text("Horario de Inicio "+""+odatas+":"+dt.getMinutes()+":"+dt.getSeconds()) ;
  100.        Text txtimeatu=new Text("Atual "+odatas+":"+dt.getMinutes()+":"+dt.getSeconds());
  101.         int contfrio=0;                                  
  102.        
  103.        
  104.     ObservableList<PieChart.Data>pieChartDatas1=
  105.             FXCollections.observableArrayList(
  106.                     new PieChart.Data("Frio", 15),
  107.                     new PieChart.Data("Quente", 15)
  108.            
  109.             );
  110.      PieChart pieChart1=new PieChart(pieChartDatas1);
  111.        ObservableList<PieChart.Data>pieChartDatas2=
  112.             FXCollections.observableArrayList(
  113.                     new PieChart.Data("1", 15)
  114.                    
  115.            
  116.             );
  117.      PieChart pieChart2=new PieChart(pieChartDatas2);
  118.        
  119.     public void arranqdeconexao() {
  120.  
  121.         final String[] serialPortasNomes = SerialPortList.getPortNames();
  122.         for (String nomeportas : serialPortasNomes) {
  123.             cbport.getItems().addAll(nomeportas);
  124.             System.out.println("iniciando comunicaçao de portas\n" + nomeportas);
  125.         taTerminalJFX.appendText("iniciando comunicaçao de portas" + nomeportas+"\n" );
  126.         }
  127.  
  128.     }
  129.  
  130.     @Override
  131.     public void start(Stage stage) {
  132.         Group gp = new Group();
  133.         scene = new Scene(gp, 600, 500, Color.BLACK);
  134.         stage.setTitle("sensor para medir temperaturas");
  135.         stage.setScene(scene);
  136.  
  137.          String str_Carro_line="theme";
  138.        // gp.getStylesheets().addAll("" + getClass().getResource(str_Carro_line+".css"));
  139.         arranqdeconexao();
  140.  
  141.         lbaction.setText("Action : " + vlactions);
  142.         lbcode.setText("Temperatura: " + vlCode);
  143.        
  144.        
  145.        lc.setTitle("Temperatura Atual");
  146.          
  147.          
  148.        
  149.          
  150.        
  151.         xychtdia.setName("Diagrama");
  152.          
  153.         lc.setAnimated(true);
  154.          
  155.         lc.getData().addAll(xychtdia);
  156.        
  157.         lc.setPrefSize(300, 200);
  158.         lc.setStyle("-fx-padding: 10;" +
  159. "-fx-border-style: solid inside;" +
  160. "-fx-border-width: 2;" +
  161. "-fx-border-insets: 0.5;" +
  162. "-fx-border-radius: 5;" +
  163. "-fx-border-color: orange;"+
  164.                 "-fx-background-color: White;");
  165.        lc.setAlternativeRowFillVisible(true);
  166.      
  167.        
  168.        
  169.         Button btport = new Button("conectar");
  170.           btport.setStyle(
  171.                  
  172.                   "-fx-background-color: #4682B4;"+
  173.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  174.                           "-fx-font: bold italic 10pt \"Arial\";");
  175.           btport.setOnMouseEntered(new EventHandler<MouseEvent>() {
  176.             @Override
  177.             public void handle(MouseEvent event) {
  178.           btport.setStyle(
  179.                
  180.                   "-fx-background-color: #7652B4;"+
  181.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  182.                           "-fx-font: bold italic 10pt \"Arial\";");
  183.          
  184.             }
  185.         });
  186.            btport.setOnMouseExited(new EventHandler<MouseEvent>() {
  187.             @Override
  188.             public void handle(MouseEvent event) {
  189.           btport.setStyle(
  190.                    
  191.                   "-fx-background-color: #4682B4;"+
  192.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  193.                           "-fx-font: bold italic 10pt \"Arial\";");
  194.        
  195.             }
  196.         });
  197.          
  198. //vbcentral
  199.         VBox vbox=new VBox();
  200.          vbox.setStyle("-fx-padding: 2;" +
  201. "-fx-border-style: solid inside;" +
  202. "-fx-border-width: 2;" +
  203. "-fx-border-insets: 5;" +
  204. "-fx-border-radius: 5;" +
  205. "-fx-border-color: blue;"+
  206.                  "-fx-background-color: #B0C4DE;");
  207.          
  208.         HBox hb1=new HBox(5);
  209.         VBox vb2=new VBox(10);
  210.          VBox vb3=new VBox(10);//ajuste
  211.         HBox hb1_1=new HBox(5);
  212.        
  213.         hb1.getChildren().addAll(vb2,hb1_1);
  214.         vb2.getChildren().addAll(lbaction, lbcode);
  215.          
  216.         TextField tfMax, tfMin;
  217.           Text txtemps=new Text("Ajuste de Temperatura:");
  218.          
  219.           tfMax=new TextField("");
  220.           tfMax.setPromptText("MAX");
  221.           tfMax.setPrefSize(40, 5);
  222.          
  223.           tfMin=new TextField();
  224.           tfMin.setPromptText("MIN");
  225.             tfMin.setPrefSize(40, 5);
  226.                   CheckBox  cbxAuto= new CheckBox("Auto");
  227.                  
  228.            cbxAuto.setStyle(
  229.                  
  230.                   "-fx-background-color: #4682B4;"+
  231.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  232.                           "-fx-font: bold italic 10pt \"Arial\";");
  233.            cbxAuto.setOnMouseEntered(new EventHandler<MouseEvent>() {
  234.             @Override
  235.             public void handle(MouseEvent event) {
  236.            cbxAuto.setStyle(
  237.                
  238.                   "-fx-background-color: #7652B4;"+
  239.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  240.                           "-fx-font: bold italic 10pt \"Arial\";");
  241.                  
  242.             }
  243.         });
  244.           cbxAuto.setOnMouseExited(new EventHandler<MouseEvent>() {
  245.             @Override
  246.             public void handle(MouseEvent event) {
  247.            cbxAuto.setStyle(
  248.                    
  249.                   "-fx-background-color: #4682B4;"+
  250.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  251.                           "-fx-font: bold italic 10pt \"Arial\";");
  252.          
  253.             }
  254.         });
  255.        
  256.                  
  257.              HBox hbvb3_1=new HBox(10);
  258.            
  259.        
  260.         VBox vb4=new VBox(cbxAuto,new Separator(Orientation.HORIZONTAL),btest1);
  261.         vb4.setSpacing(3);
  262.         vb4.setAlignment(Pos.CENTER);
  263.        
  264.              hbvb3_1.getChildren().addAll(btsendposi,tfMax,btsendnegativo);
  265.              vb3.getChildren().addAll(txtemps,hbvb3_1);
  266.         hb1_1.getChildren().addAll(vb3,vb4);
  267.        
  268.         TextArea taTerminalAD=new TextArea();
  269.         taTerminalAD.setPrefSize(scene.getWidth()-200, 100);
  270.         TitledPane tl1terminalAD=new TitledPane("Terminal Arduino",taTerminalAD);
  271.          Accordion accTerminalAD=new Accordion();
  272.          accTerminalAD.getPanes().add(tl1terminalAD);
  273.         btest1.setOnMouseClicked(new EventHandler<Event>() {
  274.             @Override
  275.             public void handle(Event event) {
  276.         pbestatistica();
  277.            
  278.            
  279.            
  280.             }
  281.         });
  282.        
  283.        
  284.        
  285.         btest1.setStyle(
  286.                  
  287.                   "-fx-background-color: #4682B4;"+
  288.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  289.                           "-fx-font: bold italic 10pt \"Arial\";");
  290.            btest1.setOnMouseEntered(new EventHandler<MouseEvent>() {
  291.             @Override
  292.             public void handle(MouseEvent event) {
  293.            btest1.setStyle(
  294.                
  295.                   "-fx-background-color: #7652B4;"+
  296.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  297.                           "-fx-font: bold italic 10pt \"Arial\";");
  298.        
  299.             }
  300.         });
  301.           btest1.setOnMouseExited(new EventHandler<MouseEvent>() {
  302.             @Override
  303.             public void handle(MouseEvent event) {
  304.           btest1.setStyle(
  305.                    
  306.                   "-fx-background-color: #4682B4;"+
  307.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  308.                           "-fx-font: bold italic 10pt \"Arial\";");
  309.          
  310.             }
  311.         });
  312.        
  313.         taTerminalJFX.setPrefSize(scene.getWidth()-200, 90);
  314.         TitledPane tl1terminalJFX=new TitledPane("Terminal JAVAFX",taTerminalJFX);
  315.        
  316.         Accordion accTerminalJFX=new Accordion();
  317.         accTerminalJFX.getPanes().add(tl1terminalJFX);
  318.          accTerminalJFX.setStyle(
  319.                  
  320.                   "-fx-background-color: #4682B4;"+
  321.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  322.                           "-fx-font: bold italic 10pt \"Arial\";");
  323.            accTerminalJFX.setOnMouseEntered(new EventHandler<MouseEvent>() {
  324.             @Override
  325.             public void handle(MouseEvent event) {
  326.            accTerminalJFX.setStyle(
  327.                
  328.                   "-fx-background-color: #7652B4;"+
  329.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  330.                           "-fx-font: bold italic 10pt \"Arial\";");
  331.              
  332.             }
  333.         });
  334.           accTerminalJFX.setOnMouseExited(new EventHandler<MouseEvent>() {
  335.             @Override
  336.             public void handle(MouseEvent event) {
  337.           accTerminalJFX.setStyle(
  338.                    
  339.                   "-fx-background-color: #4682B4;"+
  340.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  341.                           "-fx-font: bold italic 10pt \"Arial\";");
  342.      
  343.             }
  344.         });
  345.        
  346.         //binds
  347.         vbox.layoutXProperty().bind(scene.widthProperty().divide(5).subtract(40));
  348.          vbox.layoutYProperty().bind(scene.heightProperty().divide(5).subtract(40));
  349.          hb1.setStyle("-fx-padding: 2;" +
  350. "-fx-border-style: solid inside;" +
  351. "-fx-border-width: 2;" +
  352. "-fx-border-insets: 5;" +
  353. "-fx-border-radius: 5;" +
  354. "-fx-border-color: blue;");
  355.         vb2.setStyle("-fx-padding: 2;" +
  356. "-fx-border-style: solid inside;" +
  357. "-fx-border-width: 2;" +
  358. "-fx-border-insets: 5;" +
  359. "-fx-border-radius: 5;" +
  360. "-fx-border-color: blue;");
  361.        
  362.          
  363.          vbox.getChildren().addAll(hb1,lc, new HBox(cbport,btport , txtimeini,txtimeatu),accTerminalAD, accTerminalJFX);
  364.           cbport.setStyle(
  365.                  
  366.                   "-fx-background-color: #4682B4;"+
  367.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  368.                           "-fx-font: bold italic 10pt \"Arial\";");
  369.            cbport.setOnMouseEntered(new EventHandler<MouseEvent>() {
  370.             @Override
  371.             public void handle(MouseEvent event) {
  372.            cbport.setStyle(
  373.                
  374.                   "-fx-background-color: #7652B4;"+
  375.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  376.                           "-fx-font: bold italic 10pt \"Arial\";");
  377.              
  378.             }
  379.         });
  380.            cbport.setOnMouseExited(new EventHandler<MouseEvent>() {
  381.             @Override
  382.             public void handle(MouseEvent event) {
  383.            cbport.setStyle(
  384.                    
  385.                   "-fx-background-color: #4682B4;"+
  386.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  387.                           "-fx-font: bold italic 10pt \"Arial\";");
  388.            
  389.             }
  390.         });
  391.        
  392.         gp.getChildren().addAll(vbox);
  393.  
  394.          
  395.         lbcode.setFill(Color.RED);
  396.         lbaction.setFill(Color.BLUE);
  397.        
  398.         btsendposi.setOnMouseClicked(new EventHandler<MouseEvent>() {
  399.             @Override
  400.             public void handle(MouseEvent event) {
  401.                  
  402.                  if(cbxAuto.selectedProperty().getValue()==true){
  403.                      System.out.println("modo altomatico ajustado desmarque");
  404.                       taTerminalJFX.appendText("modo altomatico ajustado desmarque" +"\n");
  405.                  }else{
  406.                      try {
  407.                       vlsendPos=1+ vlsendPos;
  408.                  System.out.println("temperatura ajustada para +:"+vlsendPos);
  409.                  taTerminalJFX.appendText("temperatura ajustada para +"+vlsendPos +"\n");
  410.                  tfMax.setText(""+vlsendPos);
  411.                
  412.                        serialport.writeBytes("X".getBytes());  
  413.                      } catch (SerialPortException ex) {
  414.                           taTerminalJFX.appendText("Error+envio de bytes X:");
  415.                        
  416.                      }}
  417.                  
  418.             }
  419.         });
  420.        
  421.           btsendposi.setStyle(
  422.                  
  423.                   "-fx-background-color: #4682B4;"+
  424.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  425.                           "-fx-font: bold italic 10pt \"Arial\";");
  426.            btsendposi.setOnMouseEntered(new EventHandler<MouseEvent>() {
  427.             @Override
  428.             public void handle(MouseEvent event) {
  429.            btsendposi.setStyle(
  430.                
  431.                   "-fx-background-color: #7652B4;"+
  432.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  433.                           "-fx-font: bold italic 10pt \"Arial\";");
  434.                
  435.             }
  436.         });
  437.            btsendposi.setOnMouseExited(new EventHandler<MouseEvent>() {
  438.             @Override
  439.             public void handle(MouseEvent event) {
  440.            btsendposi.setStyle(
  441.                    
  442.                   "-fx-background-color: #4682B4;"+
  443.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  444.                           "-fx-font: bold italic 10pt \"Arial\";");
  445.          
  446.             }
  447.         });
  448.         btsendnegativo.setOnMouseClicked(new EventHandler<MouseEvent>() {
  449.             @Override
  450.             public void handle(MouseEvent event) {
  451.                
  452.              if(cbxAuto.selectedProperty().getValue()==true){
  453.                  System.out.println("modo altomatico ajustado desmarque");
  454.                   taTerminalJFX.appendText("modo altomatico ajustado desmarque"+"\n" );
  455.                   }else{
  456.                  try {
  457.                       vlsendPos= vlsendPos-1;
  458.                        System.out.println("temperatura ajustaada para -:"+vlsendPos);
  459.                         taTerminalJFX.appendText("temperatura ajustaada para -:"+vlsendPos +"\n");
  460.                        tfMax.setText(""+vlsendPos);
  461.                         serialport.writeBytes("Y".getBytes());
  462.                      } catch (SerialPortException ex) {
  463.                         taTerminalJFX.appendText("Error-error ao enviar byte Y:\n" );
  464.                          //Logger.getLogger(TempInoFXb10.class.getName()).log(Level.SEVERE, null, ex);
  465.                      }
  466. }
  467.             }
  468.         });
  469.         btsendnegativo.setStyle(
  470.                  
  471.                   "-fx-background-color: #4682B4;"+
  472.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  473.                           "-fx-font: bold italic 10pt \"Arial\";");
  474.            btsendnegativo.setOnMouseEntered(new EventHandler<MouseEvent>() {
  475.             @Override
  476.             public void handle(MouseEvent event) {
  477.            btsendnegativo.setStyle(
  478.                
  479.                   "-fx-background-color: #7652B4;"+
  480.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  481.                           "-fx-font: bold italic 10pt \"Arial\";");
  482.        
  483.             }
  484.         });
  485.            btsendnegativo.setOnMouseExited(new EventHandler<MouseEvent>() {
  486.             @Override
  487.             public void handle(MouseEvent event) {
  488.            btsendnegativo.setStyle(
  489.                    
  490.                   "-fx-background-color: #4682B4;"+
  491.                           "-fx-effect:dropshadow(one-pass-box,black,8,0.0,2,0);"+
  492.                           "-fx-font: bold italic 10pt \"Arial\";");
  493.            
  494.             }
  495.         });
  496.        
  497.         btport.setOnAction(new EventHandler<ActionEvent>() {
  498.             @Override
  499.             public void handle(ActionEvent event) {
  500.                 Blend blend = new Blend();
  501.                 blend.setMode(BlendMode.COLOR_BURN);
  502.                 btport.setEffect(blend );
  503.                 txtimeini.setText("Horario de Inicio "+""+odatas+":"+dt.getMinutes()+":"+dt.getSeconds());
  504.                 try {
  505.  
  506.                     serialport = new SerialPort(cbport.getValue().toString());
  507.                     try {
  508.                         serialport.openPort();
  509.                         serialport.setParams(9600, 8, 1, 0);
  510.                         serialport.setEventsMask(SerialPort.MASK_RXCHAR);
  511.  
  512.                     } catch (SerialPortException ex) {
  513.                         taTerminalJFX.appendText("Error-error ao conectar ao arduino ER1:"+ex.getMessage()+"\n");
  514.                    
  515.                     }
  516.  
  517.                     if (serialport.isOpened() == true) {
  518.                         stage.setTitle("Conectado");
  519.  
  520.                     } else {
  521.                         stage.setTitle("Desconectando");
  522.  
  523.                     }
  524.                    
  525.                    
  526.                     serialport.addEventListener(new SerialPortEventListener() {
  527.                         @Override
  528.                         public void serialEvent(SerialPortEvent serialPortEvent) {
  529.                             try {
  530.  
  531.                                 input = serialport.readString(serialPortEvent.getEventValue());
  532.                                 if (serialPortEvent.isRXCHAR()) {
  533.                                     if (input.endsWith("\r\n")) {
  534.                                        
  535.                                         taTerminalAD.appendText(input);
  536.                                         taTerminalJFX.appendText("entrada e saida de dados: "+input+"\n");
  537.                                        
  538.                                         System.out.print("dados:");
  539.                                         System.out.println("" + input.substring(0, input.indexOf("\r\n")));
  540.                                         vlCode = input.substring(0, input.indexOf("\r\n"));
  541.                                        
  542.                                          
  543.                                          
  544.                                         if (vlCode.toString().equals("Dallas Temperature library".toString())) {
  545.                                          
  546.                                               lbaction.setText("start");
  547.                                             System.out.println("Action : Iniciando aplicativo" );
  548.                                        taTerminalJFX.appendText("start\n"+"Action : Iniciando aplicativo"+"\n");
  549.                                         }
  550.                                         ///retorno de TEMPERATURA
  551.                                         if (vlCode.toString().equals("-".toString())) {
  552.                                              lbaction.setText("Action: Ventilador OFF");
  553.                                             taTerminalJFX.appendText("Action: Ventilador OFF"+"\n");
  554.                                      
  555.                                             // desligar  o ventilador
  556.                                             serialport.writeBytes("B".getBytes());
  557.                                         }
  558.                                        
  559.                                         if (vlCode.toString().equals("+".toString())) {
  560.                                            lbaction.setText("Action: Ventilador ON");
  561.                                             taTerminalJFX.appendText("Action: Ventilador ON"+"\n");
  562.                                             serialport.writeBytes("A".getBytes());
  563.                                         }
  564.                                        
  565.                                        
  566.                                      if (vlCode.toString().length()==5) {
  567.                                              lbcode.setText("Temperatura: " + vlCode+ " Cº");
  568.                                             taTerminalJFX.appendText("Temperatura: " + vlCode+ " Cº"+"\n");
  569.                                          
  570.                                      };
  571.                                       if (vlCode.toString().equals("DESLIGADO".toString())) {
  572.                                            lbaction.setText("Action: Ventilador OFF");
  573.                                             taTerminalJFX.appendText("Action: Ventilador OFF"+"\n");
  574.                                         }
  575.                                        
  576.                                         if (vlCode.toString().length()==2) {
  577.                                              lbcode.setText("Temperatura: " + vlCode+ " Cº");
  578.                                                taTerminalJFX.appendText("Temperatura: " + vlCode+ " Cº"+"\n");
  579.                                              Date dt=new Date();
  580.                                              int odatas=dt.getHours()-1;
  581.                                             strdatas=""+odatas+":"+dt.getMinutes()+":"+dt.getSeconds();
  582.                                              
  583.                                          double psd=Double.parseDouble(vlCode);
  584.                                           xychtdia.getData().addAll(new XYChart.Data( ""+strdatas, psd));
  585.                                        
  586.                                          
  587.                                           contpieOne= contpieOne+1;
  588.                                           System.out.println("lop de pie e entrada de temperatora"+contpieOne+"tmp"+vlCode);
  589.                                           txtimeatu.setText("Atual "+odatas+":"+dt.getMinutes()+":"+dt.getSeconds());
  590.                                          if(psd>20){
  591.                                          
  592.                                           contfrio=contfrio+1;
  593.                                          System.out.println("entrada maio que 20 contfrio=contfrio+1;"+contfrio);
  594.                                           pieChartDatas1.addAll( new PieChart.Data("Quente",contfrio));
  595.                                          }
  596.                                          if(psd<21){
  597.                                            System.out.println("entrada menor que 21");  
  598.                                        
  599.                                          }
  600.                                          
  601.                                        
  602.                                         };
  603.                                        
  604.                       if(cbxAuto.selectedProperty().getValue()==true){
  605.                      try {
  606.                          serialport.writeBytes("k".getBytes());
  607.                          System.out.println("modo altomatico ajustado");
  608.                           taTerminalJFX.appendText("modo altomatico ajustado"+"\n");
  609.                      } catch (SerialPortException ex) {
  610.                           taTerminalJFX.appendText("error modo automatico"+"\n");
  611.                      }
  612.                      
  613.                  }else  if(cbxAuto.selectedProperty().getValue()==false){
  614.                      System.out.print("AUTOMATICO NAO AJUSTADO");
  615.                         taTerminalJFX.appendText("AUTOMATICO NAO AJUSTADO"+"\n");
  616.                  }                 }
  617.  
  618.                                 }
  619.                             } catch (SerialPortException ex) {
  620.                                  taTerminalJFX.appendText("error : Sem porta de conexao escolhida\n"+ex.getMessage()+"\n");
  621.                                  System.err.println("error : Sem porta de conexao escolhida");
  622.                             }  
  623.                         }
  624.                     });
  625.  
  626.                 } catch (Exception e) {
  627.                     e.getMessage();
  628.                 }
  629.             }
  630.         });
  631.         stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
  632.             @Override
  633.             public void handle(WindowEvent event) {
  634.                   Platform.exit();  
  635.                 try {
  636.                    serialport.closePort();
  637.                    
  638.                      
  639.                 } catch (SerialPortException ex) {
  640.                     System.err.println("a porta ainda estava fechada antes do aplicativo ser finalizado");
  641.                 taTerminalJFX.appendText("error : a porta ainda estava fechada antes do aplicativo ser finalizado"+"\n");
  642.                 }
  643.                      
  644.                  
  645.                
  646.             }
  647.         });
  648.  
  649.         stage.show();
  650.     }
  651.     //
  652. public void pbestatistica(){
  653.  
  654.  
  655.     stageesta.setScene(sceneesta);
  656.    
  657.    
  658.    
  659.    
  660.     VBox vbest1=new VBox(6);
  661.    
  662.     Text txtest=new Text("Estatisticas\n"
  663.             + "Horario de Inicio :");
  664.  
  665.     HBox hbest=new HBox(10);
  666.     vbest1.getChildren().addAll(txtest,hbest);
  667.    
  668.    
  669.    
  670.    
  671.     //base de frio e quente 25 a cim quente a baixo frio
  672.    
  673.      pieChart1.setTitle("Estatisticas do Dia");
  674.      pieChart1.setPrefSize(50, 50);
  675.      pieChart1.setLabelLineLength(10);
  676.        
  677.      pieChart1.setLegendSide(Side.TOP);  
  678.       //
  679.      
  680.     //estatisticas de temparatura que esteve mais tempo ao dia
  681.    
  682.  
  683.      pieChart2.setTitle("Estatisticas de temperaturas ao dia");
  684.      pieChart2.setPrefSize(50, 50);
  685.      pieChart2.setLabelLineLength(10);
  686.        
  687.      pieChart2.setLegendSide(Side.TOP);  
  688.       hbest.getChildren().addAll(pieChart1,pieChart2);
  689.      
  690.     gpesta.getChildren().addAll(vbest1);
  691.     stageesta.show();
  692.    
  693.  
  694.  
  695. }
  696.     /**
  697.      * bem10jfx.blogspot.com
  698.      */
  699.     public static void main(String[] args) {
  700.         launch(args);
  701.     }
  702.  
  703. }
  704.  
  705. ///bem10jfx.blogspot.com
  706. kml
Advertisement
Add Comment
Please, Sign In to add comment