From 16441fe63adf04e0c434377f7da0fd05ba155eb6 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期二, 21 十一月 2023 17:13:15 +0800
Subject: [PATCH] #联机
---
src/main/java/com/zy/core/thread/SiemensCrnThread.java | 166 +++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 117 insertions(+), 49 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index b2cf911..5d068f5 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -5,25 +5,27 @@
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSON;
+import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
-import com.zy.asrs.entity.BasCrnOpt;
-import com.zy.asrs.entity.BasCrnp;
-import com.zy.asrs.service.BasCrnOptService;
-import com.zy.asrs.service.BasCrnpService;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.*;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.Task;
+import com.zy.core.model.command.CommandPackage;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.protocol.CrnProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
/**
* 鍫嗗灈鏈虹嚎绋�
@@ -37,6 +39,19 @@
private CrnSlave slave;
private CrnProtocol crnProtocol;
private boolean resetFlag = false;
+ public static final List<Short> rowOne = new ArrayList<Short>() {{
+ add((short) 1);add((short) 5);add((short) 7);add((short) 11);add((short) 15);add((short) 19);
+ }};
+ public static final List<Short> rowTwo = new ArrayList<Short>() {{
+ add((short) 2);add((short) 6);add((short) 8);add((short) 12);add((short) 16);add((short) 20);
+ }};
+ public static final List<Short> rowThree = new ArrayList<Short>() {{
+ add((short) 3);add((short) 9);add((short) 13);add((short) 17);add((short) 21);
+ }};
+ public static final List<Short> rowFour = new ArrayList<Short>() {{
+ add((short) 4);add((short) 10);add((short) 14);add((short) 18);
+ }};
+
public SiemensCrnThread(CrnSlave slave) {
this.slave = slave;
@@ -122,6 +137,9 @@
} else {
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝爢鍨涙満plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
log.error("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+// DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+// deviceErrorService.addDeviceError("crn", slave.getId(), "鍫嗗灈鏈簆lc杩炴帴澶辫触");
+ initCrnProtocol();
}
siemensNet.ConnectClose();
return result;
@@ -131,21 +149,33 @@
* 璇诲彇鐘舵��
*/
private void readStatus(){
- OperateResultExOne<byte[]> result = siemensNet.Read("DB11.2", (short) 104);
+
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
if (result.IsSuccess) {
if (null == crnProtocol) {
crnProtocol = new CrnProtocol();
}
- crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0)); // 2
- crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 2)); // 4
- crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 4)); // 6
- crnProtocol.setTaskFinish(siemensNet.getByteTransform().TransInt16(result.Content, 6)); // 8
- crnProtocol.setValid(siemensNet.getByteTransform().TransInt16(result.Content, 8)); // 10
-
- crnProtocol.setLevel(siemensNet.getByteTransform().TransInt16(result.Content, 14)); // 16
- crnProtocol.setBay(siemensNet.getByteTransform().TransInt16(result.Content, 16)); // 18
- crnProtocol.setRow(siemensNet.getByteTransform().TransInt16(result.Content, 18)); // 20
- crnProtocol.setLane(siemensNet.getByteTransform().TransInt16(result.Content, 20)); // 22
+ crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
+ crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2));
+ crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 4));
+ crnProtocol.setBay(siemensNet.getByteTransform().TransInt16(result.Content, 6));
+ crnProtocol.setLevel(siemensNet.getByteTransform().TransInt16(result.Content, 8));
+ crnProtocol.setForkPos(siemensNet.getByteTransform().TransInt16(result.Content, 10));
+ crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
+ crnProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 14));
+ crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 16));
+// crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 18));
+// crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 20));
+// crnProtocol.setTemp2(siemensNet.getByteTransform().TransInt16(result.Content, 22));
+// crnProtocol.setTemp3(siemensNet.getByteTransform().TransInt16(result.Content, 24));
+// crnProtocol.setTemp4(siemensNet.getByteTransform().TransInt16(result.Content, 26));
+ crnProtocol.setXSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 28));
+ crnProtocol.setYSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 32));
+ crnProtocol.setZSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 36));
+ crnProtocol.setXDistance(siemensNet.getByteTransform().TransSingle(result.Content, 40));
+ crnProtocol.setYDistance(siemensNet.getByteTransform().TransSingle(result.Content, 44));
+ crnProtocol.setXDuration(siemensNet.getByteTransform().TransSingle(result.Content, 48));
+ crnProtocol.setYDuration(siemensNet.getByteTransform().TransSingle(result.Content, 52));
// 寮傚父
crnProtocol.setAlarm1(0);
@@ -336,9 +366,13 @@
}
} catch (Exception ignore){}
+ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+ deviceErrorService.deleteDeviceError("crn", slave.getId());
} else {
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栧爢鍨涙満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
log.error("璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+ deviceErrorService.addDeviceError("crn", slave.getId(), "璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐�");
}
}
@@ -353,51 +387,61 @@
if (command.getTaskNo() == 0 && command.getAckFinish() == 0) {
command.setTaskNo((short) 9999);
}
+
command.setCrnNo(slave.getId());
- short[] array = new short[9];
+ short[] array = new short[12];
if (command.getAckFinish() == 0) {
array[0] = 5;
} else {
array[0] = 0;
}
- array[1] = command.getSourcePosZ();
- array[2] = command.getSourcePosY();
- if (command.getSourcePosX()==(short)3){
- array[3] = (short)1;
- }else if (command.getSourcePosX()==(short)4){
- array[3] = (short)2;
+ array[1] = command.getTaskNo();
+ array[2] = command.getTaskMode();
+
+ array[3] = command.getDestinationPosZ();
+ if (rowOne.contains(command.getSourcePosX())){
+ array[4] = (short)1;
+ }else if (rowTwo.contains(command.getSourcePosX())){
+ array[4] = (short)2;
+ }else if (rowThree.contains(command.getSourcePosX())){
+ array[4] = (short)3;
+ }else if (rowFour.contains(command.getSourcePosX())){
+ array[4] = (short)4;
}else {
- array[3] = command.getSourcePosX();
+ array[4] = command.getSourcePosX();
}
- array[4] = command.getDestinationPosZ();
array[5] = command.getDestinationPosY();
- if (command.getDestinationPosX()==(short)3){
- array[6] = (short)1;
- }else if (command.getDestinationPosX()==(short)4){
- array[6] = (short)2;
+
+ array[6] = command.getDestinationPosZ();
+ if (rowOne.contains(command.getDestinationPosX())){
+ array[7] = (short)1;
+ }else if (rowTwo.contains(command.getDestinationPosX())){
+ array[7] = (short)2;
+ }else if (rowThree.contains(command.getDestinationPosX())){
+ array[7] = (short)3;
+ }else if (rowFour.contains(command.getDestinationPosX())){
+ array[7] = (short)4;
}else {
- array[6] = command.getDestinationPosX();
+ array[7] = command.getDestinationPosX();
}
- array[7] = command.getSourceStaNo();
- array[8] = command.getDestinationStaNo();
+ array[8] = command.getDestinationPosY();
+ if (!Cools.isEmpty(command.getAuto())){
+ array[10] = command.getAuto();
+ }
+
+
// 浣滀笟淇℃伅
- OperateResult result = siemensNet.Write("DB10.0", array);
- // 浠诲姟鍙� + 瀹屾垚浣�
- short[] array2 = new short[2];
- array2[0] = command.getTaskNo();
- array2[1] = command.getAckFinish();
- OperateResult result1 = siemensNet.Write("DB10.24", array2);
-
-// //璧峰鎺掋�佺洰鏍囨帓
-// short[] array3 = new short[2];
-// array3[0] = command.getSourcePosX();
-// array3[1] = command.getDestinationPosX();
-// OperateResult result3 = siemensNet.Write("DB10.24", array3);
-
- // 缁撴潫浣�
- if (command.getAckFinish() == 0) {
- OperateResult result2 = siemensNet.Write("DB10.28.1", true);
- }
+ OperateResult result = siemensNet.Write("DB100.0", array);
+// // 浠诲姟鍙� + 瀹屾垚浣�
+// short[] array2 = new short[2];
+// array2[0] = command.getTaskNo();
+// array2[1] = command.getAckFinish();
+// OperateResult result1 = siemensNet.Write("DB10.24", array2);
+//
+// // 缁撴潫浣�
+// if (command.getAckFinish() == 0) {
+// OperateResult result2 = siemensNet.Write("DB10.28.1", true);
+// }
// 鏃ュ織璁板綍
try {
@@ -424,13 +468,37 @@
}
} catch (Exception ignore) {}
- if (result.IsSuccess && result1.IsSuccess) {
+ //鏇存柊鍛戒护鏃ュ織
+ CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
+ CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
+ CommandInfo commandInfo = commandInfoService.selectById(command.getCommandId());
+ CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
+ commandInfoLog.setId(null);
+
+ if (result.IsSuccess) {
log.warn("鍫嗗灈鏈哄懡浠や笅鍙慬id:{},鏃堕棿锛歿}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command));
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
+
+ //鏇存柊鎸囦护鏃ュ織
+ commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛");
+ commandInfoLogService.insert(commandInfoLog);
+
+ //鏇存柊浠诲姟姝ュ簭
+ TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
+ TaskWrk taskWrk = taskWrkService.selectByWrkNo(command.getTaskNo().intValue());
+ if (taskWrk != null) {
+ taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//鏇存柊鎸囦护姝ュ簭
+ taskWrkService.updateById(taskWrk);
+ }
+
return true;
} else {
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+
+ //鏇存柊鎸囦护鏃ュ織
+ commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触");
+ commandInfoLogService.insert(commandInfoLog);
return false;
}
}
--
Gitblit v1.9.1