From 917a8fae43c303f0efb8e8d7317a7694aaf9bb15 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期二, 30 十二月 2025 19:22:41 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensCrnThread.java | 154 +++++++++++++++++++++++++--------------------------
1 files changed, 76 insertions(+), 78 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index 6986acf..a974565 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -244,35 +244,25 @@
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));
+ int writeAck = 0;
+ do {
+ OperateResult resultAck = siemensNet.Write("DB100.0", (short) 0);
+ if (resultAck.IsSuccess){
+ Thread.sleep(200);
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 2);
+ short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
+ if (ack != 0) {
+ writeAck++;
+ }else {
+ News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), "ack澶嶄綅瀹屾垚");
+ break;
}
}
- }catch (Exception e){
- News.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�");
- }
+ }while (writeAck <5);
+
command.setCrnNo(slave.getId());
-
+// short[] array = new short[10];
short[] array = new short[10];
array[0] = command.getAckFinish(); // 浠诲姟瀹屾垚纭浣�
array[1] = command.getTaskNo(); // 浠诲姟鍙�
@@ -284,61 +274,71 @@
array[7] = command.getDestinationPosY(); // 鐩爣浣嶇疆鍒楀彿
array[8] = command.getDestinationPosZ(); // 鐩爣浣嶇疆灞傚彿
array[9] = command.getCommand();
-// array[10] = 0; //澶囩敤1
+
+
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;
- }
+ News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), array);
//鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
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())
+ int writeCount1 = 1;
- ){
- 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));
+ do {
+ try{
+ if(!result.IsSuccess ){
+ News.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(command),writeCount1);
+// MessageQueue.offer(SlaveType.Crn, slave.getId(), new Task(2, command));
+ result = siemensNet.Write("DB100.0", array);
Thread.sleep(100);
- readStatus();
- return false;
- } else {
- News.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ writeCount1++;
+ continue;
}
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 24);
+ if (resultRead.IsSuccess) {
+ CrnCommand one = new CrnCommand();
+ one.setAckFinish(siemensNet.getByteTransform().TransInt16(resultRead.Content, 0));
+ 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.setCommand(siemensNet.getByteTransform().TransInt16(resultRead.Content, 18));
+ 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())
+ || !command.getCommand().equals(one.getCommand())
+ || !command.getAckFinish().equals(one.getAckFinish())
+ ){
+ 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("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍥炶涓嶄竴鑷� ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(command),writeCount1);
+ result = siemensNet.Write("DB100.0", array);
+ writeCount1++;
+ continue;
+
+ } else {
+ News.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ break;
+ }
+ }
+ }catch (Exception e){
+ News.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�,寮傚父锛�"+e);
}
- }catch (Exception e){
- News.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�");
- }
+ writeCount1++;
+ } while (writeCount1<6);
if (command.getAckFinish() == 0) {
@@ -354,6 +354,7 @@
if(result.IsSuccess){
//鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
Thread.sleep(200);
+ log.info("鍫嗗灈鏈轰换鍔″畬鎴愬浣嶏紝姝ゆ椂鍫嗗灈鏈虹姸鎬�:"+crnProtocol.getStatusType()+",鍫嗗灈鏈篿d:"+crnProtocol.getCrnNo());
OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.18", (short) 2);
if (resultRead.IsSuccess) {
commandFinish=siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
@@ -361,7 +362,7 @@
News.error("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍐欏叆鏁版嵁涓庡洖璇绘暟鎹笉涓�鑷达紒"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
}else{
//浠诲姟鍛戒护鍐欏叆鎴愬姛
- News.info("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍥炶鎴愬姛锛�"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
+// News.info("鍫嗗灈鏈轰换鍔$‘璁や綅"+commandFinish+"鍥炶鎴愬姛锛�"+"寰幆鎵ц娆℃暟:"+writeCount2+"娆�");
break;
}
}else {
@@ -372,12 +373,8 @@
}
}while (writeCount2<5);
}
- } else {
- BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
- BasCrnp basCrnp = basCrnpService.selectById(slave.getId());
- basCrnp.setModiTime(new Date());
- basCrnpService.updateById(basCrnp);
}
+
try {
// 鏃ュ織璁板綍
@@ -402,9 +399,10 @@
bean.insert(basCrnOpt);
} catch (Exception ignore) {}
- if (result.IsSuccess) {
+ if (result != null && result.IsSuccess) {
+ Thread.sleep(200);
this.readStatus();
- News.info("鍫嗗灈鏈哄懡浠や笅鍙慬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 {
--
Gitblit v1.9.1