From 448e5b139e803002547552b989e32c0392d59e4b Mon Sep 17 00:00:00 2001
From: 18516761980 <56479841@qq.com>
Date: 星期二, 12 七月 2022 16:05:42 +0800
Subject: [PATCH] Merge branch 'hylywcs' of http://47.97.1.152:5880/r/zy-wcs into hylywcs
---
src/main/java/com/zy/core/thread/MelsecCrnThread.java | 76 ++++++++++++++++++++++++++++++++++++-
1 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/MelsecCrnThread.java b/src/main/java/com/zy/core/thread/MelsecCrnThread.java
index 16028aa..4999239 100644
--- a/src/main/java/com/zy/core/thread/MelsecCrnThread.java
+++ b/src/main/java/com/zy/core/thread/MelsecCrnThread.java
@@ -24,6 +24,7 @@
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 +43,11 @@
private short heartBeatVal = 1;
private boolean resetFlag = false;
+ /**
+ * 鍫嗗灈鏈烘槸鍚﹀湪鍥炲師鐐硅繍鍔ㄤ腑鏍囪
+ */
+ private boolean backHpFlag = false;
+
public MelsecCrnThread(CrnSlave slave) {
this.slave = slave;
}
@@ -50,6 +56,11 @@
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
this.connect();
+// try {
+// Thread.sleep(2000);
+// } catch (InterruptedException e) {
+// e.printStackTrace();
+// }
while (true) {
try {
int step = 1;
@@ -137,7 +148,7 @@
log.error("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
initCrn();
}
- melsecMcNet.ConnectClose();
+// melsecMcNet.ConnectClose();
return result;
}
@@ -146,10 +157,16 @@
*/
private void readStatus(){
try {
+// if (this.slave.getId() == 1 && flag1.equals(0)) {
+// Thread.sleep(3000);
+// flag1=1;
+// System.out.println("===");
+// }
OperateResultExOne<byte[]> result = melsecMcNet.Read("D20", (short) 70);
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));
@@ -179,6 +196,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)) {
@@ -192,6 +212,7 @@
BasCrnp basCrnp = new BasCrnp();
basCrnp.setCrnErr(crnProtocol.getAlarm()==null?0:crnProtocol.getAlarm().longValue());
basCrnp.setCrnNo(slave.getId());
+ basCrnp.setCrnSts((int)crnProtocol.getMode());
if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
}
@@ -217,6 +238,55 @@
log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
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();
@@ -259,7 +329,7 @@
bean.insert(basCrnOpt);
} catch (Exception ignore) {}
- if (result.IsSuccess) {
+ if (result != null && result.IsSuccess) {
log.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;
@@ -286,7 +356,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());
}
}
--
Gitblit v1.9.1