oyq28 1 year ago
parent
commit
eb3a182b2f

+ 53 - 48
src/main/java/com/htyg/manger/controller/DataController.java

@@ -20,37 +20,42 @@ public class DataController {
         Boolean flag=true;
         Map<String,Integer> map=new HashMap<>();
 
-        //ModbusReader.getData(jsonObject);
+        ModbusReader.getData(jsonObject);
+        ModbusReader1.getData(jsonObject);
 
-        jsonObject.put("1600",0);
-        jsonObject.put("1601",0);
-        jsonObject.put("1602",0);
-        jsonObject.put("1603",0);
-        jsonObject.put("1604",0);
-        jsonObject.put("1605",0);
-        jsonObject.put("1606",0);
-        jsonObject.put("1607",0);
+        /*jsonObject.put("3000",0);
+        jsonObject.put("3001",0);
+        jsonObject.put("3002",0);
+        jsonObject.put("3003",0);
+        jsonObject.put("3004",0);
+        jsonObject.put("3005",0);
+        jsonObject.put("3006",0);
+        jsonObject.put("3007",0);*/
 
 
         //ph值到浊度值
-        jsonObject.put("ph",jsonObject.get("1600"));
-        jsonObject.put("rjy",jsonObject.get("1601"));
-        jsonObject.put("ddl",jsonObject.get("1602"));
-        jsonObject.put("dzl",jsonObject.get("1603"));
-        jsonObject.put("wdz",jsonObject.get("1604"));
-        jsonObject.put("tds",jsonObject.get("1605"));
-        jsonObject.put("ryz",jsonObject.get("1606"));
-        jsonObject.put("zdz",jsonObject.get("1607"));
+        jsonObject.put("ph",jsonObject.get("3000"));
+        jsonObject.put("rjy",jsonObject.get("3001"));
+        jsonObject.put("ddl",jsonObject.get("3002"));
+        jsonObject.put("dzl",jsonObject.get("3003"));
+        jsonObject.put("wdz",jsonObject.get("3004"));
+        jsonObject.put("tds",jsonObject.get("3005"));
+        jsonObject.put("ryz",jsonObject.get("3006"));
+        jsonObject.put("zdz",jsonObject.get("3007"));
 
 
 
-        jsonObject.put("1612",1);
+        /*jsonObject.put("1612",1);
         jsonObject.put("1613",0);
-        jsonObject.put("1614",0);
+        jsonObject.put("1614",0);*/
+        float iff = Float.parseFloat(jsonObject.get("1612").toString());
+        float yff = Float.parseFloat(jsonObject.get("1613").toString());
+        float zff = Float.parseFloat(jsonObject.get("1614").toString());
+
         //设备情况
-        int i = Integer.parseInt(jsonObject.get("1612").toString());
-        int y = Integer.parseInt(jsonObject.get("1613").toString());
-        int z = Integer.parseInt(jsonObject.get("1614").toString());
+        int i = (int)iff;
+        int y = (int)yff;
+        int z = (int)zff;
         jsonObject.put("slqk",jsonObject.get("1612"));
         jsonObject.put("pyqk",jsonObject.get("1613"));
         jsonObject.put("xyqk",jsonObject.get("1614"));
@@ -61,13 +66,13 @@ public class DataController {
 
         //出液温度  排液温度
 
-        jsonObject.put("1600",0);
+        /*jsonObject.put("1600",0);
         jsonObject.put("1601",0);
         jsonObject.put("1602",0);
         jsonObject.put("1603",0);
         jsonObject.put("1604",0);
         jsonObject.put("1605",0);
-
+*/
         jsonObject.put("cywd",jsonObject.get("1600"));
         jsonObject.put("pywd",jsonObject.get("1601"));
         jsonObject.put("pgwd",jsonObject.get("1602"));
@@ -77,20 +82,20 @@ public class DataController {
         jsonObject.put("1000",2);
         jsonObject.put("1001",45);
         jsonObject.put("1002",2);
-        jsonObject.put("1003",45);
-        jsonObject.put("1004",2);
-        jsonObject.put("1005",45);
-        jsonObject.put("1006",2);
-        jsonObject.put("1007",45);
-        jsonObject.put("1008",2);
+        jsonObject.put("1003",55);
+        jsonObject.put("1004",0);
+        jsonObject.put("1005",90);
+        jsonObject.put("1006",0);
+        jsonObject.put("1007",90);
+        jsonObject.put("1008",4);
         jsonObject.put("1009",45);
         jsonObject.put("1010",2);
-        jsonObject.put("1011",45);
+        jsonObject.put("1011",50);
 
 
-       int wd1600 = Integer.parseInt(jsonObject.get("1600").toString());
-       int wd1000 = Integer.parseInt(jsonObject.get("1000").toString());
-       int wd1001 = Integer.parseInt(jsonObject.get("1001").toString());
+       float wd1600 = Float.parseFloat(jsonObject.get("1600").toString());
+       float wd1000 = Float.parseFloat(jsonObject.get("1000").toString());
+       float wd1001 = Float.parseFloat(jsonObject.get("1001").toString());
         if(wd1000 <= wd1600 && wd1600 <= wd1001){
             jsonObject.put("cywdc",0);
         }else{
@@ -98,9 +103,9 @@ public class DataController {
             flag=false;
         }
 
-        int wd1601 = Integer.parseInt(jsonObject.get("1601").toString());
-        int wd1002 = Integer.parseInt(jsonObject.get("1002").toString());
-        int wd1003 = Integer.parseInt(jsonObject.get("1003").toString());
+        float wd1601 = Float.parseFloat(jsonObject.get("1601").toString());
+        float wd1002 = Float.parseFloat(jsonObject.get("1002").toString());
+        float wd1003 = Float.parseFloat(jsonObject.get("1003").toString());
         if(wd1002 <= wd1601 && wd1601 <= wd1003){
             jsonObject.put("pywdc",0);
         }else{
@@ -108,9 +113,9 @@ public class DataController {
             flag=false;
         }
 
-        int wd1602 = Integer.parseInt(jsonObject.get("1602").toString());
-        int wd1004 = Integer.parseInt(jsonObject.get("1004").toString());
-        int wd1005 = Integer.parseInt(jsonObject.get("1005").toString());
+        float wd1602 = Float.parseFloat(jsonObject.get("1602").toString());
+        float wd1004 = Float.parseFloat(jsonObject.get("1004").toString());
+        float wd1005 = Float.parseFloat(jsonObject.get("1005").toString());
         if(wd1004 <= wd1602 && wd1602 <= wd1005){
             jsonObject.put("pgwdc",0);
         }else{
@@ -118,9 +123,9 @@ public class DataController {
             flag=false;
         }
 
-        int wd1603 = Integer.parseInt(jsonObject.get("1603").toString());
-        int wd1006 = Integer.parseInt(jsonObject.get("1006").toString());
-        int wd1007 = Integer.parseInt(jsonObject.get("1007").toString());
+        float wd1603 = Float.parseFloat(jsonObject.get("1603").toString());
+        float wd1006 = Float.parseFloat(jsonObject.get("1006").toString());
+        float wd1007 = Float.parseFloat(jsonObject.get("1007").toString());
         if(wd1006 <= wd1603 && wd1603 <= wd1007){
             jsonObject.put("hjwdc",0);
         }else{
@@ -130,11 +135,11 @@ public class DataController {
         
         
         //制冷模式 水箱温度
-        jsonObject.put("1610",0);
-        jsonObject.put("1605",20);
-        
-        
-        jsonObject.put("zlms",jsonObject.get("1610"));
+        /*jsonObject.put("1610",0);
+        jsonObject.put("1605",20);*/
+
+        float zlmsf = Float.parseFloat(jsonObject.get("1610").toString())*10;
+        jsonObject.put("zlms",(int)zlmsf);
         jsonObject.put("sxwd",jsonObject.get("1605"));
         
         jsonObject.put("status",flag);

+ 9 - 3
src/main/java/com/htyg/manger/controller/ModbusReader.java

@@ -13,7 +13,7 @@ import java.util.Map;
 
 public class ModbusReader {
 
-    private static final String PORT_NAME = "COM6"; // 更改为你的串口名称
+    private static final String PORT_NAME = "COM3"; // 更改为你的串口名称
     private static final int BAUD_RATE = 9600;
     private static final int DATA_BITS = 8;
     private static final int STOP_BITS = 1;
@@ -25,6 +25,10 @@ public class ModbusReader {
         getData(jsonObject);
     }
 
+    private static String formatFloat(float value) {
+        return String.format("%.3f", value);
+    }
+
     public static void getData(JSONObject jsonObject) {
         SerialParameters parameters = new SerialParameters();
         parameters.setPortName(PORT_NAME);
@@ -55,8 +59,10 @@ public class ModbusReader {
                 for (int i = 0; i < response.getWordCount(); i += 2) {
                     int value = response.getRegisterValue(i) << 16 | response.getRegisterValue(i + 1);
                     // 处理读取到的数据
-                    System.out.println("Register " + (i / 2 + 3000) + ": " + value);
-                    jsonObject.put(Integer.valueOf(i / 2 + 3000).toString(),value);
+                    float floatValue = Float.intBitsToFloat(value); // 将整数值转换为浮点数
+                    floatValue = Math.round(floatValue * 1000) / 1000.0f;
+                    System.out.println("Register " + (i / 2 + 3000) + ": " + formatFloat(floatValue));
+                    jsonObject.put(Integer.valueOf(i / 2 + 3000).toString(),formatFloat(floatValue));
                 }
             } else {
                 System.out.println("Response is null.");

+ 9 - 2
src/main/java/com/htyg/manger/controller/ModbusReader1.java

@@ -1,4 +1,5 @@
 package com.htyg.manger.controller;
+import com.alibaba.fastjson.JSONObject;
 import com.ghgande.j2mod.modbus.io.ModbusSerialTransaction;
 import com.ghgande.j2mod.modbus.msg.ReadMultipleRegistersRequest;
 import com.ghgande.j2mod.modbus.msg.ReadMultipleRegistersResponse;
@@ -7,14 +8,19 @@ import com.ghgande.j2mod.modbus.util.SerialParameters;
 
 public class ModbusReader1 {
 
-    private static final String PORT_NAME = "COM6"; // 更改为你的串口名称
+    private static final String PORT_NAME = "COM3"; // 更改为你的串口名称
     private static final int BAUD_RATE = 9600;
     private static final int DATA_BITS = 8;
     private static final int STOP_BITS = 1;
     private static final int PARITY = 0; // 无校验位
 
-    //1605 水箱温度
     public static void main(String[] args) {
+        JSONObject jsonObject=new JSONObject();
+        getData(jsonObject);
+    }
+
+    //1605 水箱温度
+    public static void getData(JSONObject jsonObject) {
         SerialParameters parameters = new SerialParameters();
         parameters.setPortName(PORT_NAME);
         parameters.setBaudRate(BAUD_RATE);
@@ -44,6 +50,7 @@ public class ModbusReader1 {
                     int value = response.getRegisterValue(i);
                     // 处理读取到的数据
                     System.out.println("Register " + (i + 1600) + ": " + value);
+                    jsonObject.put(Integer.valueOf(i + 1600).toString(),value/10.0);
                 }
             } else {
                 System.out.println("Response is null.");

+ 2 - 2
src/main/resources/static/css/style.css

@@ -40,7 +40,7 @@ ul { margin: 0; padding: 0;}
 header{width:100%; height: 90px; background: url(../images/bg_top.png) center no-repeat ; text-align: center; font-size: 36px; color: #00f6ff; line-height: 90px; margin: 0 auto;}
 #content{width: 1860px; height: 100%; margin: 20px auto 0 auto;}
 #content .content_left{width: 20.5%; height: 100%; float: left;}
-.dtuplc{width: 355px; height: 76px; padding: 15px 15px 0 15px; border: 1px solid #2C58A6;
+.dtuplc{width: 355px; height: 90px; padding: 15px 15px 0 15px; border: 1px solid #2C58A6;
 box-shadow: inset 5px 10px 30px 13px #2C58A6;margin-top: 3%}
 .dtu{width: 100%;  float: left;}
 .plc{width: 177px; height: 180px; float: left;}
@@ -177,5 +177,5 @@ tr.aaa:hover{background: #1d3152; cursor: pointer;}
 	width: 12%;
 	margin-left: 2%;
 }
-.dtuplc1{width: 355px; height: 117px; padding: 15px 15px 0 15px; border: 1px solid #2C58A6;
+.dtuplc1{width: 355px; height: 145px; padding: 15px 15px 0 15px; border: 1px solid #2C58A6;
 	box-shadow: inset 5px 10px 30px 13px #2C58A6;margin-top: 3%}

+ 7 - 7
src/main/resources/static/index.html

@@ -8,8 +8,10 @@
 	</head>
 	<body>
 	<div style="position: absolute;">
+<!--
 		<img src="./images/logo2.png" class="logo_ht">
-		<img src="./images/logo1.png" class="logo1">
+-->
+		<!--<img src="./images/logo1.png" class="logo1">-->
 	</div>
 		<header>
 
@@ -359,9 +361,9 @@
 
 			callAPI();
 			// 首次调用函数开始刷新
-			/*setInterval(function() {
+			setInterval(function() {
 				location.reload(true);
-			}, 10000); // 设置10秒钟的定时器*/
+			}, 10000); // 设置10秒钟的定时器
 		}
 
 
@@ -521,9 +523,7 @@
 												<tr>
 												<td class="zhi1">设备正常运行时间:<span class="span">${datas.hours} 小时</span></td>
 												</tr>
-												<tr >
-												<td class="zhi1">设备距离保养时间:<span class="span">1.1 天</span></td>
-												</tr>
+
 												</table>
 												</div>
 
@@ -537,7 +537,7 @@
 												</div>
 
 												<div class="dtuplc" style="position: relative;height: 65px;width: 20%;margin: 0 20% 0% 10%;box-shadow: inset 5px 10px 30px 30px #2C58A6;">
-												<span class="dtuplcSpan" style="font-size: 30px;">制${datas.zlms===0?'冷':'热'}模式</span>
+												<span class="dtuplcSpan" style="font-size: 30px;">制${datas.zlms===1?'冷':'热'}模式</span>
 												</div>`;