From 658b3d9b66b11001935317c04521c7a37ce97db1 Mon Sep 17 00:00:00 2001
From: lsh <lsh123456>
Date: 星期一, 15 七月 2024 10:11:34 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/MelsecCrnThread.java | 172 ++++++++++++++++++++++++++++++--------------------------
1 files changed, 92 insertions(+), 80 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/MelsecCrnThread.java b/src/main/java/com/zy/core/thread/MelsecCrnThread.java
index 73e1d1b..59c5e82 100644
--- a/src/main/java/com/zy/core/thread/MelsecCrnThread.java
+++ b/src/main/java/com/zy/core/thread/MelsecCrnThread.java
@@ -24,7 +24,6 @@
import com.zy.core.model.protocol.CrnProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import java.text.MessageFormat;
import java.util.Date;
@@ -42,6 +41,11 @@
private CrnProtocol crnProtocol;
private short heartBeatVal = 1;
private boolean resetFlag = false;
+
+ /**
+ * 鍫嗗灈鏈烘槸鍚﹀湪鍥炲師鐐硅繍鍔ㄤ腑鏍囪
+ */
+ private boolean backHpFlag = false;
public MelsecCrnThread(CrnSlave slave) {
this.slave = slave;
@@ -120,13 +124,13 @@
crnProtocol.setWalkPos((short)0);
crnProtocol.setLoaded((short)0);
crnProtocol.setAlarm((short)0);
- crnProtocol.setXSpeed(0F);
- crnProtocol.setYSpeed(0F);
- crnProtocol.setZSpeed(0F);
- crnProtocol.setXDistance(0F);
- crnProtocol.setYDistance(0F);
- crnProtocol.setXDuration(0F);
- crnProtocol.setYDuration(0F);
+ crnProtocol.setxSpeed((short)0);
+ crnProtocol.setySpeed((short)0);
+ crnProtocol.setzSpeed((short)0);
+ crnProtocol.setxDistance((short)0);
+ crnProtocol.setyDistance((short)0);
+ crnProtocol.setxDuration((short)0);
+ crnProtocol.setyDuration((short)0);
}
@Override
@@ -161,6 +165,7 @@
if (result.IsSuccess) {
if (null == crnProtocol) {
crnProtocol = new CrnProtocol();
+ crnProtocol.setCrnNo(slave.getId());
}
crnProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0));
crnProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 2));
@@ -176,13 +181,13 @@
crnProtocol.setTemp2(melsecMcNet.getByteTransform().TransInt16(result.Content, 22));
crnProtocol.setTemp3(melsecMcNet.getByteTransform().TransInt16(result.Content, 24));
crnProtocol.setTemp4(melsecMcNet.getByteTransform().TransInt16(result.Content, 26));
- crnProtocol.setXSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 28));
- crnProtocol.setYSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 32));
- crnProtocol.setZSpeed(melsecMcNet.getByteTransform().TransSingle(result.Content, 36));
- crnProtocol.setXDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 40));
- crnProtocol.setYDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 44));
- crnProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 48));
- crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 52));
+ crnProtocol.setxSpeed(melsecMcNet.getByteTransform().TransInt16(result.Content, 28));
+ crnProtocol.setySpeed(melsecMcNet.getByteTransform().TransInt16(result.Content, 32));
+ crnProtocol.setzSpeed(melsecMcNet.getByteTransform().TransInt16(result.Content, 36));
+ crnProtocol.setxDistance(melsecMcNet.getByteTransform().TransInt16(result.Content, 40));
+ crnProtocol.setyDistance(melsecMcNet.getByteTransform().TransInt16(result.Content, 44));
+ crnProtocol.setxDuration(melsecMcNet.getByteTransform().TransInt16(result.Content, 48));
+ crnProtocol.setyDuration(melsecMcNet.getByteTransform().TransInt16(result.Content, 52));
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
@@ -190,6 +195,9 @@
if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
log.error("-------------------------------------------绗竴姝ャ�乕鍫嗗灈鏈哄彿锛歿}][宸ヤ綔鍙凤細{}]==>> 鐘舵�佷负90锛岀瓑寰呯‘璁わ紒锛�",slave.getId(),crnProtocol.getTaskNo());
if (resetFlag) {
+ if(crnProtocol.getTaskNo()==9999){
+ backHpFlag = false;
+ }
CrnCommand crnCommand = new CrnCommand();
crnCommand.setAckFinish((short)1);
if (write(crnCommand)) {
@@ -230,72 +238,72 @@
return false;
}
- OperateResult result = null;
- try{
- Integer exeCount=0;
- do{
- 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.getCommand();
- result = melsecMcNet.Write("D0", array);
- if(result.IsSuccess) {
- if (command.getAckFinish() == 0) {
- short commandFinish = 1;
- result = melsecMcNet.Write("D9", commandFinish);
- if(result.IsSuccess){
- //鍐欎换鍔$‘璁よ繑鍥炴垚鍔熷悗锛屾煡璇㈢‘璁や竴娆�
- Thread.sleep(200);
- OperateResultExOne<byte[]> result1 = melsecMcNet.Read("D9", (short)2);
- if(result1.IsSuccess){
- short commandVal = melsecMcNet.getByteTransform().TransInt16(result1.Content,2);
- if(commandVal==1){
- break;
- } else {
- exeCount++;
- }
- } else{
- exeCount++;
- }
- }else{
- exeCount++;
- }
- }
- }else{
- exeCount++;
- }
- Thread.sleep(200);
- }while(exeCount>3);
- }catch (Exception e){
-
- }
-
-// 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.getCommand();
-// OperateResult result = melsecMcNet.Write("D0", array);
+// OperateResult result = null;
+// try{
+// Integer exeCount=0;
+// do{
+// 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.getCommand();
+// result = melsecMcNet.Write("D0", array);
+// if(result.IsSuccess) {
+// if (command.getAckFinish() == 0) {
+// short commandFinish = 1;
+// result = melsecMcNet.Write("D9", commandFinish);
+// if(result.IsSuccess){
+// //鍐欎换鍔$‘璁よ繑鍥炴垚鍔熷悗锛屾煡璇㈢‘璁や竴娆�
+// Thread.sleep(200);
+// OperateResultExOne<byte[]> result1 = melsecMcNet.Read("D9", (short)2);
+// if(result1.IsSuccess){
+// short commandVal = melsecMcNet.getByteTransform().TransInt16(result1.Content,2);
+// if(commandVal==1){
+// break;
+// } else {
+// exeCount++;
+// }
+// } else{
+// exeCount++;
+// }
+// }else{
+// exeCount++;
+// }
+// }
+// }else{
+// exeCount++;
+// }
+// Thread.sleep(200);
+// }while(exeCount>3);
+// }catch (Exception e){
//
-// if (command.getAckFinish() == 0) {
-// short commandFinish = 1;
-// result = melsecMcNet.Write("D9", commandFinish);
// }
+
+ 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.getCommand();
+ OperateResult result = melsecMcNet.Write("D0", array);
+
+ if (command.getAckFinish() == 0) {
+ short commandFinish = 1;
+ result = melsecMcNet.Write("D9", commandFinish);
+ }
try {
// 鏃ュ織璁板綍
@@ -347,7 +355,7 @@
}
OperateResult write = melsecMcNet.Write("D10", heartBeatVal);
if (!write.IsSuccess) {
- log.error("杈撻�佺嚎plc缂栧彿={} 蹇冭烦澶辫触", slave.getId());
+ log.error("鍫嗗灈鏈簆lc蹇冭烦閫氳澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
}
}
@@ -454,4 +462,8 @@
}
+ @Override
+ public void setResetFlagTwo(boolean flag) {
+
+ }
}
--
Gitblit v1.9.1