From 4f1089d00806fe23628c6e0ed1482ae616443f93 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期五, 07 六月 2024 08:15:25 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensCrnThread.java | 160 ++++++++++++++++++++++++++++++++++++++++++-----------
src/main/java/com/zy/core/model/protocol/CrnProtocol.java | 2
2 files changed, 129 insertions(+), 33 deletions(-)
diff --git a/src/main/java/com/zy/core/model/protocol/CrnProtocol.java b/src/main/java/com/zy/core/model/protocol/CrnProtocol.java
index 30c7d1e..691649b 100644
--- a/src/main/java/com/zy/core/model/protocol/CrnProtocol.java
+++ b/src/main/java/com/zy/core/model/protocol/CrnProtocol.java
@@ -67,11 +67,13 @@
* 鍫嗗灈鏈哄綋鍓嶅垪鍙�
*/
public Short bay;
+ public Short bayTwo;
/**
* 鍫嗗灈鏈哄綋鍓嶅眰鍙�
*/
public Short level;
+ public Short levelTwo;
/**
* 褰撳墠璐у弶浣嶇疆
diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index 76cb0a0..192e9dc 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -176,7 +176,12 @@
*/
private void readStatus(){
try {
- OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
+ OperateResultExOne<byte[]> result = new OperateResultExOne<byte[]>();
+ if (slave.getId()>2 && slave.getId()<6){
+ result = siemensNet.Read("DB101.0", (short) 62);
+ } else {
+ result = siemensNet.Read("DB101.0", (short) 52);
+ }
if (result.IsSuccess) {
if (null == crnProtocol) {
crnProtocol = new CrnProtocol();
@@ -188,30 +193,46 @@
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().TransInt16(result.Content, 28));
- crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
- crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
- crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
- crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
- crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
- crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
+ if (slave.getId()>2 && slave.getId()<6){
+ 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().TransInt16(result.Content, 28));
+ crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
+ crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
+ crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
+ crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
+ crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
+ crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
+ } else {
+ crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 12));
+ crnProtocol.setTaskNoTwo(siemensNet.getByteTransform().TransInt16(result.Content, 14));
+ crnProtocol.setStatusTwo(siemensNet.getByteTransform().TransInt16(result.Content, 16));
+ crnProtocol.setBayTwo(siemensNet.getByteTransform().TransInt16(result.Content, 18));
+ crnProtocol.setLevelTwo(siemensNet.getByteTransform().TransInt16(result.Content, 20));
+ crnProtocol.setForkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 22));
+ crnProtocol.setLoadedTwo(siemensNet.getByteTransform().TransInt16(result.Content, 24));
+
+ crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 34));
+ crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 38));
+ crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 42));
+// crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 42));
+
+ crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 50));
+ crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 54));
+ crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 58));
+ crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 62));
+ }
//宸ヤ綅2鏁版嵁 鏃犲垯鏃犻渶鐞嗕細
try{
- crnProtocol.setTaskNoTwo(siemensNet.getByteTransform().TransInt16(result.Content, 56));
- crnProtocol.setStatusTwo(siemensNet.getByteTransform().TransInt16(result.Content, 56));
- crnProtocol.setForkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 58));
- crnProtocol.setLiftPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 60));
- crnProtocol.setLoadedTwo(siemensNet.getByteTransform().TransInt16(result.Content, 64));
+
}catch (Exception e){
}
@@ -430,26 +451,99 @@
}
// convertRow(command);
command.setCrnNo(slave.getId());
- short[] array = new short[9];
-// array[0] = command.getAckFinish();
- array[0] = command.getTaskNo();
- array[1] = command.getTaskMode();
- array[2] = command.getSourcePosX();
- array[3] = command.getSourcePosY();
- array[4] = command.getSourcePosZ();
- array[5] = command.getDestinationPosX();
- array[6] = command.getDestinationPosY();
- array[7] = command.getDestinationPosZ();
+ 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();
array[9] = command.getCommand();
- OperateResult result = siemensNet.Write("DB100.0", command.getAckFinish());
- OperateResult result2 = siemensNet.Write("DB100.20", array);
+ OperateResult result18 = siemensNet.Write("DB100.38", (short)0);
+ OperateResult result = siemensNet.Write("DB100.20", array);
+ log.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), array);
+
+ //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
+ Thread.sleep(200);
+ int writeCount = 1;
+ do {
+ try{
+ if(!result.IsSuccess){
+ log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(command),writeCount);
+ result = siemensNet.Write("DB100.20", array);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.20", (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())
+ ){
+ try{
+ log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐�==>涓嶄竴鑷碵id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ }catch (Exception e){
+ try{
+ log.error("鏃ュ織鎵撳嵃澶辫触锛�===>>鍙傛暟one鎶ラ敊 [id:{}],{}", slave.getId(), JSON.toJSON(command),JSON.toJSON(resultRead));
+ }catch (Exception e1){
+ log.error("鏃ュ織鎵撳嵃澶辫触锛�===>> [id:{}],{}", slave.getId(), JSON.toJSON(command));
+ }
+ }
+ try{
+ Thread.sleep(100);
+ }catch (Exception e){
+
+ }
+ log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍥炶涓嶄竴鑷� ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(command),writeCount);
+ result = siemensNet.Write("DB100.20", array);
+ writeCount++;
+ continue;
+ } else {
+ log.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSON(command),JSON.toJSON(one));
+ break;
+ }
+ }
+ }catch (Exception e){
+ log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲嚭閿�,寮傚父锛�"+e);
+ }
+ writeCount++;
+ } while (writeCount<6);
if (command.getAckFinish() == 0) {
short commandFinish = 1;
Thread.sleep(100L);
result = siemensNet.Write("DB100.38", commandFinish);
+ int signFinish = 1;
+ while (signFinish<5){
+ OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.38", (short) 2);
+ short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0);
+ if (transInt16 != commandFinish){
+ log.info("涓嬪彂DB100.38 鍥炶澶辫触" + "commandFinish:"+commandFinish);
+ log.info("涓嬪彂DB100.38 鍥炶澶辫触" + "array:"+ JSON.toJSONString(array));
+ result = siemensNet.Write("DB100.38", commandFinish);
+ signFinish++;
+ }else {
+ log.info("涓嬪彂DB100.38" + "commandFinish:"+commandFinish);
+ log.info("涓嬪彂DB100.38" + "array:"+ JSON.toJSONString(array));
+ break;
+ }
+ }
}
try {
--
Gitblit v1.9.1