diff --git a/user-service/pom.xml b/user-service/pom.xml
index 76b5093..80143bf 100644
--- a/user-service/pom.xml
+++ b/user-service/pom.xml
@@ -148,6 +148,29 @@
4.4
+
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.3.0
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ 2.3.0
+
+
+ com.sun.xml.bind
+ jaxb-core
+ 2.3.0
+
+
+ javax.activation
+ activation
+ 1.1.1
+
+
diff --git a/user-service/src/main/java/com/mh/user/serialport/SendAndReceiveByCom.java b/user-service/src/main/java/com/mh/user/serialport/SendAndReceiveByCom.java
index 5da937b..6d88786 100644
--- a/user-service/src/main/java/com/mh/user/serialport/SendAndReceiveByCom.java
+++ b/user-service/src/main/java/com/mh/user/serialport/SendAndReceiveByCom.java
@@ -37,9 +37,6 @@ public class SendAndReceiveByCom {
DeviceInstallService deviceInstallService = context.getBean(DeviceInstallService.class);
NowDataService nowDataService = context.getBean(NowDataService.class);
BuildingService buildingService = context.getBean(BuildingService.class);
- AnalysisReceiveOrder485 analysisReceiveOrder485 = new AnalysisReceiveOrder485();
-
- SysParamService sysParamService = context.getBean(SysParamService.class);
public void sendAndReceive(String sort, String thread) {
SerialPort serialPort = null;
diff --git a/user-service/src/main/java/com/mh/user/serialport/SerialPortSingle2.java b/user-service/src/main/java/com/mh/user/serialport/SerialPortSingle2.java
index dc20d3a..f851a5f 100644
--- a/user-service/src/main/java/com/mh/user/serialport/SerialPortSingle2.java
+++ b/user-service/src/main/java/com/mh/user/serialport/SerialPortSingle2.java
@@ -18,8 +18,6 @@ import java.io.IOException;
import java.util.Date;
import purejavacomm.SerialPort;
-import purejavacomm.SerialPortEvent;
-import purejavacomm.SerialPortEventListener;
/**
* @author nxr
@@ -33,7 +31,6 @@ public class SerialPortSingle2 {
// 调用service
ApplicationContext context = SpringBeanUtil.getApplicationContext();
- AnalysisReceiveOrder485 analysisReceiveOrder485 = new AnalysisReceiveOrder485();
DeviceInstallService deviceInstallService = context.getBean(DeviceInstallService.class);
NowDataService nowDataService = context.getBean(NowDataService.class);
BuildingService buildingService = context.getBean(BuildingService.class);
@@ -42,6 +39,9 @@ public class SerialPortSingle2 {
SerialPort serialPort = null;
String rtData = "fail";
String comName = deviceCodeParamEntity.getDataCom().toUpperCase();
+ if (StringUtils.isBlank(comName)) {
+ return rtData;
+ }
try {
int baudrate = deviceCodeParamEntity.getBaudrate();
String parity = deviceCodeParamEntity.getParity();
@@ -50,44 +50,42 @@ public class SerialPortSingle2 {
} else {
serialPort = SerialTool.openPort(comName, baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_EVEN);
}
+ if (serialPort == null) {
+ log.info("串口为空,无法进行采集控制");
+ return "fail";
+ }
// 创建设备报文
Device device = DeviceFactory.createDevice(deviceCodeParamEntity.getDeviceType());
- if (serialPort != null) {
- //向串口发送指令
- log.info("-----------------------------单抄向串口" + serialPort.getName() + "发送指令!-----------------------------");
+ //向串口发送指令
+ log.info("-----------------------------单抄向串口" + serialPort.getName() + "发送指令!-----------------------------");
// String sendStr = SendOrderUtils.getSendStr(deviceCodeParamEntity);
- DeviceStrategy strategy = DeviceStrategyFactory.createStrategy(deviceCodeParamEntity.getDeviceType());
- if (null == strategy) {
- return rtData;
- }
- device.setStrategy(strategy);
- String sendStr = device.createOrders(deviceCodeParamEntity);
+ DeviceStrategy strategy = DeviceStrategyFactory.createStrategy(deviceCodeParamEntity.getDeviceType());
+ if (null == strategy) {
+ return rtData;
+ }
+ device.setStrategy(strategy);
+ String sendStr = device.createOrders(deviceCodeParamEntity);
- SerialTool.sendToPort(SerialTool.HexString2Bytes(sendStr), serialPort, sendStr, deviceCodeParamEntity.getDeviceType());
- CacheTools.initReceiveMsg(serialPort.getName());
- SerialPort finalSerialPort = serialPort;
- SerialTool.addListener(serialPortEvent -> {
- try {
- for (int i = 0; i < 5; i++) {
- Thread.sleep(1000);
- byte[] bytes = SerialTool.readFromPort(finalSerialPort);
- if (bytes!= null && bytes.length > 0) {
- if (Constant.WEB_FLAG) {
- CacheTools.setReceiveMsg(finalSerialPort.getName(), ExchangeStringUtil.printHexString(bytes));
- break;
- }
+ SerialTool.sendToPort(SerialTool.HexString2Bytes(sendStr), serialPort, sendStr, deviceCodeParamEntity.getDeviceType());
+ CacheTools.initReceiveMsg(serialPort.getName());
+ SerialPort finalSerialPort = serialPort;
+ SerialTool.addListener(serialPortEvent -> {
+ try {
+ for (int i = 0; i < 5; i++) {
+ Thread.sleep(1000);
+ byte[] bytes = SerialTool.readFromPort(finalSerialPort);
+ if (bytes!= null && bytes.length > 0) {
+ if (Constant.WEB_FLAG) {
+ CacheTools.setReceiveMsg(finalSerialPort.getName(), ExchangeStringUtil.printHexString(bytes));
+ break;
}
}
- } catch (Exception e) {
- log.error("单抄串口" + finalSerialPort + "异常,关闭串口", e);
}
- }, serialPort);
- }
- String receiveStr;
- if (serialPort == null) {
- log.info("串口为空,无法进行采集控制");
- return "fail";
- }
+ } catch (Exception e) {
+ log.error("单抄串口" + finalSerialPort + "异常,关闭串口", e);
+ }
+ }, serialPort);
+ String receiveStr = "";
receiveStr = CacheTools.waitReceiveMsg(serialPort.getName());
//去掉空格和null
if (StringUtils.isBlank(receiveStr)) {
@@ -152,8 +150,6 @@ public class SerialPortSingle2 {
// }
rtData = device.analysisReceiveData(DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss"),
deviceType, registerAddr, brand, buildingId, buildingName, dataStr);
- SerialTool.closePort(serialPort);
- Thread.sleep(200);
log.info("-----------------------------" + serialPort.getName() + "单抄结束!-----------------------------");
return rtData;
} catch (Exception e) {
diff --git a/user-service/src/main/java/com/mh/user/serialport/SerialPortThread.java b/user-service/src/main/java/com/mh/user/serialport/SerialPortThread.java
index 668ce3c..d6ba39f 100644
--- a/user-service/src/main/java/com/mh/user/serialport/SerialPortThread.java
+++ b/user-service/src/main/java/com/mh/user/serialport/SerialPortThread.java
@@ -18,8 +18,6 @@ public class SerialPortThread implements Runnable{
private String thread = "1";
public static SerialPort serialPort = null;
private String name;
- // 调用service
- //ApplicationContext context = SpringBeanUtil.getApplicationContext();
private CountDownLatch countDownLatch;
@@ -36,11 +34,14 @@ public class SerialPortThread implements Runnable{
}
public void run(){
- log.info("创建发送接收数据线程>>>>>>>>>>>>>>"+thread);
-// SerialPortSendReceive2 serial=new SerialPortSendReceive2();
-// serial.serialPortSend(name,thread);
+ log.info("创建发送接收数据线程>>>>>>>>>>>>>>" + thread);
SendAndReceiveByCom sendAndReceiveByCom = new SendAndReceiveByCom();
- sendAndReceiveByCom.sendAndReceive(name,thread);
- this.countDownLatch.countDown();
+ try {
+ sendAndReceiveByCom.sendAndReceive(name, thread);
+ } catch (Exception e) {
+ log.error("串口通信发生异常: ", e);
+ } finally {
+ this.countDownLatch.countDown();
+ }
}
}
diff --git a/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java b/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java
index 3f7431e..696ccce 100644
--- a/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java
+++ b/user-service/src/main/java/com/mh/user/strategy/TempControlStrategy.java
@@ -7,11 +7,13 @@ import com.mh.user.entity.NowPublicDataEntity;
import com.mh.user.service.BuildingService;
import com.mh.user.service.NowDataService;
import com.mh.user.service.NowPublicDataService;
+import com.mh.user.utils.DateUtil;
import com.mh.user.utils.ExchangeStringUtil;
import com.mh.user.utils.SpringBeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -75,54 +77,33 @@ public class TempControlStrategy implements DeviceStrategy {
@Override
public String analysisReceiveData(String dateStr, String deviceType, String registerAddr, String brand, String buildingId, String buildingName, String dataStr) {
String result = Constant.FAIL;
- String checkStr = dataStr.substring(0, dataStr.length() - 4);// 检验报文
+ String checkStr = dataStr.substring(0, dataStr.length() - 4);
String checkWord = ExchangeStringUtil.getStrCRC16(checkStr);//生成校验码
if (!checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) {
- log.info("温度变送器报文检验失败: " + dataStr);
+ log.info("温控报文检验失败: " + dataStr);
return result;
}
- //log.info("温度变送器报文检验成功: " + receiveData);
String addr = ExchangeStringUtil.hexToDec(checkStr.substring(0, 2));//地址
- //log.info("温度变送器:" + addr);
String data = "";
if (checkStr.substring(2, 4).equalsIgnoreCase("03")) {// 读
- Map map = new HashMap<>();
- String L1 = checkStr.substring(6, 10); //1路
- map.put("1", String.valueOf(ExchangeStringUtil.parseHex4(L1) / 10));
- String L2 = checkStr.substring(10, 14); //2路
- map.put("2", String.valueOf(ExchangeStringUtil.parseHex4(L2) / 10));
- String L3 = checkStr.substring(14, 18); //3路
- map.put("3", String.valueOf(ExchangeStringUtil.parseHex4(L3) / 10));
- String L4 = checkStr.substring(18, 22); //4路
- map.put("4", String.valueOf(ExchangeStringUtil.parseHex4(L4) / 10));
- String L5 = checkStr.substring(22, 26); //5路
- map.put("5", String.valueOf(ExchangeStringUtil.parseHex4(L5) / 10));
- String L6 = checkStr.substring(26, 30); //6路
- map.put("6", String.valueOf(ExchangeStringUtil.parseHex4(L6) / 10));
- String L7 = checkStr.substring(30, 34); //7路
- map.put("7", String.valueOf(ExchangeStringUtil.parseHex4(L7) / 10));
- String L8 = checkStr.substring(34, 38); //8路
- map.put("8", String.valueOf(ExchangeStringUtil.parseHex4(L8) / 10));
-
- int count = buildingService.selectPumpCount(buildingId); //楼栋热泵数
- if (count > 0) {
- for (Map.Entry entry : map.entrySet()) {
- addr = entry.getKey();
- data = entry.getValue();
- if (addr != null && Integer.parseInt(addr) <= count) {
- nowDataService.saveNowHistoryData3(addr, "温度变送器", data, "waterTemp", buildingId);
- nowDataService.proWaterTemp(dateStr, buildingId, addr); //保存时间点温度
- }
- }
- log.info("温度变送器:" + addr + ",保存数据库成功!楼栋名称:" + buildingName);
- String avgTemp = nowDataService.selectAve(buildingId);
- NowPublicDataEntity publicData = new NowPublicDataEntity();
- publicData.setBuildingId(buildingId);
- publicData.setUseWaterTemp(avgTemp);
- publicData.setBackWaterTemp(avgTemp);
- nowPublicDataService.saveNowHistoryPublicData(publicData);
- result = JSON.toJSONString(map); //map转json字符串
+ data = ExchangeStringUtil.hexToDec(checkStr.substring(6, 10));
+ Double fdata = Double.parseDouble(data) / 10;
+ if (fdata <= 25) {
+ fdata = 25.0;
+ } else if (fdata >= 65) {
+ fdata = 65.0;
}
+ nowDataService.saveNowHistoryData2(addr, "温控", String.valueOf(fdata), "waterTemp", buildingId);
+ nowDataService.proWaterTemp(dateStr, buildingId, "");//保存时间点温度
+ String avgTemp = nowDataService.selectAve(buildingId);
+ NowPublicDataEntity publicData = new NowPublicDataEntity();
+ publicData.setBuildingId(buildingId);
+ publicData.setUseWaterTemp(avgTemp);
+ publicData.setBackWaterTemp(avgTemp);
+ publicData.setSingleTemp(String.valueOf(fdata));//单箱温度
+ nowPublicDataService.saveNowHistoryPublicData(publicData);
+ log.info("温控号:" + addr + ",温度值:" + fdata + ",保存数据库成功!楼栋名称:" + buildingName);
+ return String.valueOf(fdata);
}
return result;
}
diff --git a/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java b/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java
index afaceac..5d9ccf6 100644
--- a/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java
+++ b/user-service/src/main/java/com/mh/user/strategy/WaterLevelSwitchStrategy.java
@@ -204,8 +204,9 @@ public class WaterLevelSwitchStrategy implements DeviceStrategy {
SysParamEntity sysParamEntity = sysParamService.selectSysParam();
String customName = sysParamEntity.getCustomName();
if (!StringUtils.isBlank(customName)) {
- if (customName.contains(Constant.CUSTOM_NAME_HUAXIA)
- || customName.contains(Constant.CUSTOM_NAME_GUANGSHANG)) {
+ if ((customName.contains(Constant.CUSTOM_NAME_HUAXIA)
+ || customName.contains(Constant.CUSTOM_NAME_GUANGSHANG)) && !Constant.WEB_FLAG ) {
+ analysisPumpStateOrder(dateStr, dataStr, registerAddr, brand, buildingId, buildingName);
return analysisRelayOrder485(dateStr, dataStr,registerAddr,brand,buildingId, buildingName, customName);
} else {
return analysisPumpStateOrder(dateStr, dataStr, registerAddr, brand, buildingId, buildingName);