From cb2e9ba3d787767f4d7593ed53124e1135a391d5 Mon Sep 17 00:00:00 2001
From: pjb <pjb123456>
Date: 星期日, 14 九月 2025 18:24:21 +0800
Subject: [PATCH] 站点转移功能入出罐装线异常修复
---
src/main/java/com/zy/core/thread/SiemensCrnThread.java | 177 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 145 insertions(+), 32 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index 17570b0..e4d6b3a 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -8,11 +8,11 @@
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.common.utils.News;
+import com.zy.entity.BasCrnOpt;
+import com.zy.entity.BasCrnp;
+import com.zy.service.BasCrnOptService;
+import com.zy.service.BasCrnpService;
+import com.zy.utils.News;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
@@ -89,6 +89,7 @@
command.setDestinationPosX((short)0); // 鐩爣搴撲綅鎺�
command.setDestinationPosY((short)0); // 鐩爣搴撲綅鍒�
command.setDestinationPosZ((short)0); // 鐩爣搴撲綅灞�
+ command.setTaskCount((short) 0);
write(command);
break;
default:
@@ -110,6 +111,7 @@
crnProtocol = new CrnProtocol();
}
crnProtocol.setMode((short) -1);
+ crnProtocol.setCrnNo(slave.getId());
// crnProtocol.setTaskNo((short)0);
crnProtocol.setStatus((short)-1);
crnProtocol.setBay((short)0);
@@ -235,30 +237,142 @@
*/
private boolean write(CrnCommand command) throws InterruptedException {
if (null == command) {
- News.error("SiemensCrn"+" - 6"+" - 鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+ News.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
return false;
+ }
+ // 鍚戝爢鍨涙満鍙戜换鍔″墠鐨勫爢鍨涙満鐘舵��
+ try{
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24);
+ if (resultRead.IsSuccess) {
+ CrnCommand one = new CrnCommand();
+ one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2));
+ one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4));
+ one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6));
+ one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8));
+ one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10));
+ one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12));
+ one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14));
+ one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16));
+ if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode())
+ || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY())
+ || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX())
+ || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ())
+ ){
+ News.error("涓嬪彂鍓嶏細[id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ } else {
+ News.info("涓嬪彂鍓嶏細[id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ }
+ }
+ }catch (Exception e){
+ News.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�");
}
// convertRow(command);
command.setCrnNo(slave.getId());
- short[] array = new short[10];
- array[0] = command.getAckFinish();
- array[1] = command.getTaskNo();
- array[2] = command.getTaskMode();
- array[3] = command.getSourcePosX();
- array[4] = command.getSourcePosY();
- array[5] = command.getSourcePosZ();
- array[6] = command.getDestinationPosX();
- array[7] = command.getDestinationPosY();
- array[8] = command.getDestinationPosZ();
-// array[9] = command.getSourceStaNo();
-// array[10] = command.getDestinationStaNo();
+// short[] array = new short[10];
+ short[] array = new short[12];
+ array[0] = command.getAckFinish(); // 浠诲姟瀹屾垚纭浣�
+ array[1] = command.getTaskNo(); // 浠诲姟鍙�
+ array[2] = command.getTaskMode(); // 妯″紡
+ array[3] = command.getSourcePosX(); // 婧愪綅缃帓鍙�
+ array[4] = command.getSourcePosY(); // 婧愪綅缃垪鍙�
+ array[5] = command.getSourcePosZ(); // 婧愪綅缃眰鍙�
+ array[6] = command.getDestinationPosX(); // 鐩爣浣嶇疆鎺掑彿
+ array[7] = command.getDestinationPosY(); // 鐩爣浣嶇疆鍒楀彿
+ array[8] = command.getDestinationPosZ(); // 鐩爣浣嶇疆灞傚彿
array[9] = command.getCommand();
+ array[11] = command.getTaskCount(); // 绌烘《鍑哄簱锛屽憡璇夊爢鍨涙満鍙栦竴涓揣杩樻槸涓や釜璐�
OperateResult result = siemensNet.Write("DB100.0", array);
+ News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), array);
+
+ if(!result.IsSuccess){
+ News.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触锛岄噸鏂版坊鍔犱换鍔″埌闃熷垪 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
+ MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(2, command));
+ Thread.sleep(100);
+ readStatus();
+ return false;
+ }
+
+ //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
+ Thread.sleep(200);
+ try{
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24);
+ if (resultRead.IsSuccess) {
+ CrnCommand one = new CrnCommand();
+ one.setTaskNo(siemensNet.getByteTransform().TransInt16(resultRead.Content, 2));
+ one.setTaskMode(siemensNet.getByteTransform().TransInt16(resultRead.Content, 4));
+ one.setSourcePosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 6));
+ one.setSourcePosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 8));
+ one.setSourcePosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 10));
+ one.setDestinationPosX(siemensNet.getByteTransform().TransInt16(resultRead.Content, 12));
+ one.setDestinationPosY(siemensNet.getByteTransform().TransInt16(resultRead.Content, 14));
+ one.setDestinationPosZ(siemensNet.getByteTransform().TransInt16(resultRead.Content, 16));
+ one.setTraySize(siemensNet.getByteTransform().TransBool(resultRead.Content, 22));
+ if (!command.getTaskNo().equals(one.getTaskNo()) || !command.getTaskMode().equals(one.getTaskMode())
+ || !command.getSourcePosX().equals(one.getSourcePosX()) || !command.getSourcePosY().equals(one.getSourcePosY())
+ || !command.getSourcePosZ().equals(one.getSourcePosZ()) || !command.getDestinationPosX().equals(one.getDestinationPosX())
+ || !command.getDestinationPosY().equals(one.getDestinationPosY()) || !command.getDestinationPosZ().equals(one.getDestinationPosZ())
+
+ ){
+ try{
+ News.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ }catch (Exception e){
+ try{
+ News.error("鏃ュ織鎵撳嵃澶辫触锛�===>>鍙傛暟one鎶ラ敊 [id:{}],{}", slave.getId(), JSON.toJSON(command),JSON.toJSON(resultRead));
+ }catch (Exception e1){
+ News.error("鏃ュ織鎵撳嵃澶辫触锛�===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
+ }
+ }
+ News.error("鍫嗗灈鏈哄懡浠ゅ洖璇诲け璐ュ悗锛岄噸鏂版坊鍔犱换鍔″埌闃熷垪 ===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
+ MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(2, command));
+ Thread.sleep(100);
+ readStatus();
+ return false;
+ } else {
+ News.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ }
+ }
+ }catch (Exception e){
+ News.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�");
+ }
+
if (command.getAckFinish() == 0) {
- short commandFinish = 1;
- Thread.sleep(100L);
- result = siemensNet.Write("DB100.18", commandFinish);
+ if (result.IsSuccess) {
+ Thread.sleep(300);
+ //浠诲姟涓嬪彂娆℃暟
+ int writeCount2 = 0;
+
+ do {
+ writeCount2++;
+ short commandFinish = (short) 1;
+ result = siemensNet.Write("DB100.18", commandFinish);
+ if(result.IsSuccess){
+ //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
+ Thread.sleep(200);
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.18", (short) 2);
+ if (resultRead.IsSuccess) {
+ commandFinish=siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
+ if (commandFinish != 1){
+ News.error("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍐欏叆鏁版嵁涓庡洖璇绘暟鎹笉涓�鑷达紒"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
+ }else{
+ //浠诲姟鍛戒护鍐欏叆鎴愬姛
+ News.info("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍥炶鎴愬姛锛�"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
+ break;
+ }
+ }else {
+ News.error("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍥炶澶辫触锛�"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
+ }
+ } else {
+ News.error("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍐欏叆澶辫触锛�"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
+ }
+ }while (writeCount2<5);
+ }
+ } else {
+ BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
+ BasCrnp basCrnp = basCrnpService.selectById(slave.getId());
+ basCrnp.setModiTime(new Date());
+ basCrnpService.updateById(basCrnp);
+// log.info("鏇存柊{}鍙峰爢鍨涙満鎵ц浠诲姟瀹屾垚澶嶄綅鏃堕棿",slave.getId());
}
try {
@@ -284,15 +398,14 @@
bean.insert(basCrnOpt);
} catch (Exception ignore) {}
- if (result != null && result.IsSuccess) {
- Thread.sleep(200);
+ if (result.IsSuccess) {
this.readStatus();
- News.info("SiemensCrn"+" - 7"+" - 鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
+ News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
return true;
} else {
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- News.error("SiemensCrn"+" - 8"+" - 鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ News.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
return false;
}
}
@@ -313,7 +426,7 @@
public static void main(String[] args) throws InterruptedException {
CrnSlave slave = new CrnSlave();
slave.setId(1);
- slave.setIp("192.168.6.9");
+ slave.setIp("10.10.10.1");
slave.setRack(0);
slave.setSlot(0);
SiemensCrnThread crnThread = new SiemensCrnThread(slave);
@@ -354,15 +467,15 @@
// // 3.搴撲綅绉昏浆 婧愬拰鐩爣閮藉彂 pass
// CrnCommand command = new CrnCommand();
// command.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙�
-// command.setTaskNo((short) 0); // 宸ヤ綔鍙�
+// command.setTaskNo((short) 2); // 宸ヤ綔鍙�
// command.setAckFinish((short) 0); // 浠诲姟瀹屾垚纭浣�
// command.setTaskMode(CrnTaskModeType.LOC_MOVE); // 浠诲姟妯″紡: 搴撲綅绉昏浆
// command.setSourcePosX((short)2); // 婧愬簱浣嶆帓
-// command.setSourcePosY((short)2); // 婧愬簱浣嶅垪
-// command.setSourcePosZ((short)3); // 婧愬簱浣嶅眰
-// command.setDestinationPosX((short)2); // 鐩爣搴撲綅鎺�
-// command.setDestinationPosY((short)4); // 鐩爣搴撲綅鍒�
-// command.setDestinationPosZ((short)4); // 鐩爣搴撲綅灞�
+// command.setSourcePosY((short)1); // 婧愬簱浣嶅垪
+// command.setSourcePosZ((short)1); // 婧愬簱浣嶅眰
+// command.setDestinationPosX((short)3); // 鐩爣搴撲綅鎺�
+// command.setDestinationPosY((short)1); // 鐩爣搴撲綅鍒�
+// command.setDestinationPosZ((short)1); // 鐩爣搴撲綅灞�
// crnThread.write(command);
// 4.绔欎綅绉昏浆 婧愬拰鐩爣閮藉彂
--
Gitblit v1.9.1