Commit 804418ce authored by 王晓倩's avatar 王晓倩

采集点位信息,根据主板状态值决定是否写时间

parent 4162d6a0
......@@ -192,48 +192,49 @@ public class EquipmentDataCollection {
/* 4.老化层通讯,72个点位,1-27一个端口号、28-54一个端口号、55-72一个端口号,IP不变 */
// 示例:000100000006 点位地址01 功能码03 起始位置0000 终止位置000A
String sendMsg3 = "00010000000601030000000A";
String receiveMsg3 = storeyCommunication(storeyInfo, sendMsg3);
if (receiveMsg3 == null) {
// 解析服务器返回信息
// 示例:000100000017010314 浓度0000 状态0001 AD值01F7 标定AD值01F7 年07E9 月0005 日0004 时000E 分000F 秒0015
// 获取主板最终状态值
String receiveStatus = pointCommunication(storeyInfo, sendMsg3);
if (receiveStatus == null) {
// 记录异常数据
alarmData.setfAlarmType("03"); //01.老化柜 02.机械臂 03.老化层 04.点位
alarmData.setfEquipmentCode(storeyInfo.getfStoreyCode());
alarmData.setfAlarmData("老化层通讯失败,无响应");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
} else if("0000".equals(receiveStatus) || "0005".equals(receiveStatus)){
continue;
}
// 解析服务器返回信息
// 示例:000100000017010314 浓度0000 状态0001 AD值01F7 标定AD值01F7 年07E9 月0005 日0004 时000E 分000F 秒0015
String value = receiveMsg3.substring(22, 26); //板子状态
if ("0001".equals(value)) {
/* 5.写入时间,年、月、日、时、分 */
// 示例:000100000006 设备地址01写时间06 寄存器地址0004(年04月05日06时07分08) 年/月/日/时/分数值07E9(2025)
Calendar cal = Calendar.getInstance();
// 当前年
int y = cal.get(Calendar.YEAR);
// 当前月
int m = cal.get(Calendar.MONTH) + 1;
// 当前日
int d = cal.get(Calendar.DATE);
// 当前小时
int h = cal.get(Calendar.HOUR_OF_DAY);
// 当前分钟
int mm = cal.get(Calendar.MINUTE);
String minutes = Integer.toHexString(mm).length() < 2 ? "000" + Integer.toHexString(mm) : "00" + Integer.toHexString(mm);
String hours = Integer.toHexString(h).length() < 2 ? "000" + Integer.toHexString(h) : "00" + Integer.toHexString(h);
String date = Integer.toHexString(d).length() < 2 ? "000" + Integer.toHexString(d) : "00" + Integer.toHexString(d);
String month = Integer.toHexString(m).length() < 2 ? "000" + Integer.toHexString(m) : "00" + Integer.toHexString(m);
String year = Integer.toHexString(y).length() < 4 ? "0" + Integer.toHexString(y) : Integer.toHexString(y);
/* 5.写入时间,年、月、日、时、分 */
// 示例:000100000006 设备地址01写时间06 寄存器地址0004(年04月05日06时07分08) 年/月/日/时/分数值07E9(2025)
Calendar cal = Calendar.getInstance();
// 当前年
int y = cal.get(Calendar.YEAR);
// 当前月
int m = cal.get(Calendar.MONTH) + 1;
// 当前日
int d = cal.get(Calendar.DATE);
// 当前小时
int h = cal.get(Calendar.HOUR_OF_DAY);
// 当前分钟
int mm = cal.get(Calendar.MINUTE);
String minutes = Integer.toHexString(mm).length() < 2 ? "000" + Integer.toHexString(mm) : "00" + Integer.toHexString(mm);
String hours = Integer.toHexString(h).length() < 2 ? "000" + Integer.toHexString(h) : "00" + Integer.toHexString(h);
String date = Integer.toHexString(d).length() < 2 ? "000" + Integer.toHexString(d) : "00" + Integer.toHexString(d);
String month = Integer.toHexString(m).length() < 2 ? "000" + Integer.toHexString(m) : "00" + Integer.toHexString(m);
String year = Integer.toHexString(y).length() < 4 ? "0" + Integer.toHexString(y) : Integer.toHexString(y);
String sendMsgYear = "0001000000060" + code + "060004" + year;
String receiveMsgYear = storeyCommunication(storeyInfo, sendMsgYear);
if (!sendMsgYear.equals(receiveMsgYear) || receiveMsgYear == null) {
// 记录异常数据
alarmData.setfAlarmType("04"); //01.老化柜 02.机械臂 03.老化层 04.点位
alarmData.setfEquipmentCode(storeyInfo.getfStoreyCode());
alarmData.setfAlarmData("写入时间失败-年");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
}
String sendMsgYear = "0001000000060" + code + "060004" + year;
String receiveMsgYear = storeyCommunication(storeyInfo, sendMsgYear);
if (!sendMsgYear.equals(receiveMsgYear) || receiveMsgYear == null) {
// 记录异常数据
alarmData.setfAlarmType("04"); //01.老化柜 02.机械臂 03.老化层 04.点位
alarmData.setfEquipmentCode(storeyInfo.getfStoreyCode());
alarmData.setfAlarmData("写入时间失败-年");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
}
}
}
}
......@@ -287,4 +288,33 @@ public class EquipmentDataCollection {
}
return receiveMsg;
}
//点位数据采集
private String pointCommunication(TStoreyInfo storey, String sendMsg) {
String ip = null;
Integer port = null;
String status = null;
int num = 1;
try {
ip = storey.getfIp();
port = Integer.parseInt(storey.getfPort()); // 使用 parseInt 确保字符串到整数的转换
String receiveMsg = null;
if (ip == null || port == null) {
return status;
}
// 若通讯失败将再次通讯,最多通讯3次
while ((!"0001".equals(receiveMsg) || receiveMsg == null) && num <= 3) {
// 发送并接收数据
receiveMsg = TCPClient.PLCConnect(ip, port, sendMsg);
if(receiveMsg != null){
status = receiveMsg.substring(22, 26); //板子状态
}
num++;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return status;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment