From 1d802b852c023933b5ea3ed5b24810583e02b27f Mon Sep 17 00:00:00 2001
From: zhangchao <zc857179121@qq.com>
Date: 星期五, 30 八月 2024 09:42:12 +0800
Subject: [PATCH] 对照协议调整
---
src/main/java/com/zy/core/thread/SiemensCrnThread.java | 154 ++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 127 insertions(+), 27 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index 2c9e8f3..2a19974 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -149,33 +149,41 @@
*/
private void readStatus(){
try {
- OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 66);
if (result.IsSuccess) {
if (null == crnProtocol) {
crnProtocol = new CrnProtocol();
crnProtocol.setCrnNo(slave.getId());
}
crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
+ //宸ヤ綅1
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().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));
+ crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 12));
+ //宸ヤ綅2
+ 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.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 26));
+ crnProtocol.setWalkPosTwo(siemensNet.getByteTransform().TransInt16(result.Content, 28));
+ crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 30));
+ crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 32));
+ 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.setzSpeedTwo(siemensNet.getByteTransform().TransInt16(result.Content, 46));
+ 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));
+
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
@@ -236,27 +244,119 @@
}
// 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();
+ short[] array = new short[17];
+ 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();
+ array[8] = command.getSourcePosXTwo();
+ array[9] = command.getSourcePosYTwo();
+ array[10] = command.getSourcePosZTwo();
+ array[11] = command.getDestinationPosXTwo();
+ array[12] = command.getDestinationPosYTwo();
+ array[13] = command.getDestinationPosZTwo();
+ array[14] = command.getCommand();
+ array[15] = command.getAckFinish();
+
// array[9] = command.getSourceStaNo();
// array[10] = command.getDestinationStaNo();
- array[9] = command.getCommand();
+ //array[9] = command.getCommand();
OperateResult result = siemensNet.Write("DB100.0", 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.toJSONString(command),writeCount);
+ result = siemensNet.Write("DB100.0", array);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ 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())
+ ){
+ try{
+ log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐�==>涓嶄竴鑷碵id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSONString(command),JSON.toJSONString(one));
+ }catch (Exception e){
+ try{
+ log.error("鏃ュ織鎵撳嵃澶辫触锛�===>>鍙傛暟one鎶ラ敊 [id:{}],{}", slave.getId(), JSON.toJSONString(command),JSON.toJSONString(resultRead));
+ }catch (Exception e1){
+ log.error("鏃ュ織鎵撳嵃澶辫触锛�===>> [id:{}],{}", slave.getId(), JSON.toJSONString(command));
+ }
+ }
+ try{
+ Thread.sleep(100);
+ }catch (Exception e){
+
+ }
+ log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍥炶涓嶄竴鑷� ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSONString(command),writeCount);
+ result = siemensNet.Write("DB100.0", array);
+ writeCount++;
+ continue;
+ } else {
+ log.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇绘垚鍔焄id:{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), JSON.toJSONString(command),JSON.toJSONString(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.18", commandFinish);
+ int signFinish = 1;
+ while (signFinish<5){
+ OperateResultExOne<byte[]> result10018 = siemensNet.Read("DB100.18", (short) 2);
+ short transInt16 = siemensNet.getByteTransform().TransInt16(result10018.Content, 0);
+ if (transInt16 != commandFinish){
+ log.info("涓嬪彂DB100.18 鍥炶澶辫触" + "commandFinish:"+commandFinish);
+ log.info("涓嬪彂DB100.18 鍥炶澶辫触" + "array:"+ JSON.toJSONString(array));
+ result = siemensNet.Write("DB100.18", commandFinish);
+ signFinish++;
+ }else {
+ log.info("涓嬪彂DB100.18" + "commandFinish:"+commandFinish);
+ log.info("涓嬪彂DB100.18" + "array:"+ JSON.toJSONString(array));
+ break;
+ }
+ }
}
+
+// if (command.getAckFinish() == 0) {
+// short commandFinish = 1;
+// Thread.sleep(100L);
+// result = siemensNet.Write("DB100.18", commandFinish);
+// }
+
try {
// 鏃ュ織璁板綍
BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
--
Gitblit v1.9.1