From bf2652a293a744a365c3c966cd1e1c621254f08e Mon Sep 17 00:00:00 2001
From: whycq <whycq>
Date: 星期四, 30 十二月 2021 15:17:06 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/xgmwcs' into xgmwcs
---
src/main/java/com/zy/core/thread/CrnThread.java | 86 ++++++++++++++++++++++++++----------------
1 files changed, 53 insertions(+), 33 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/CrnThread.java b/src/main/java/com/zy/core/thread/CrnThread.java
index f560126..868a52f 100644
--- a/src/main/java/com/zy/core/thread/CrnThread.java
+++ b/src/main/java/com/zy/core/thread/CrnThread.java
@@ -7,7 +7,9 @@
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
+import com.zy.asrs.entity.BasCrnOpt;
import com.zy.asrs.entity.BasCrnp;
+import com.zy.asrs.service.BasCrnOptService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
@@ -113,13 +115,13 @@
*/
private void readStatus(){
try {
- if (null == crnProtocol) {
- crnProtocol = new CrnProtocol();
- }
/* 鏂规硶1 */
- OperateResultExOne<byte[]> result = melsecMcNet.Read("D2231", (short) 62);
+ OperateResultExOne<byte[]> result = melsecMcNet.Read("D2231", (short) 70);
if (result.IsSuccess) {
+ if (null == crnProtocol) {
+ crnProtocol = new CrnProtocol();
+ }
crnProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0));
crnProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 4));
crnProtocol.setStatus(melsecMcNet.getByteTransform().TransInt16(result.Content, 6));
@@ -142,10 +144,32 @@
crnProtocol.setXDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 46));
crnProtocol.setYDistance(melsecMcNet.getByteTransform().TransSingle(result.Content, 50));
crnProtocol.setXDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 54));
- crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 58));
+ crnProtocol.setYDuration(melsecMcNet.getByteTransform().TransSingle(result.Content, 62));
+
+ OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+
+ // 澶嶄綅淇″彿
+ if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+ log.error("-------------------------------------------绗竴姝ャ�乕鍫嗗灈鏈哄彿锛歿}][宸ヤ綔鍙凤細{}]==>> 鐘舵�佷负90锛岀瓑寰呯‘璁わ紒锛�",slave.getId(),crnProtocol.getTaskNo());
+ if (resetFlag) {
+ if (melsecMcNet.Write("D2218", (short) 1).IsSuccess) {
+ resetFlag = false;
+ }
+ }
+ }
+
+ // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
+ BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
+ BasCrnp basCrnp = new BasCrnp();
+ basCrnp.setCrnErr(crnProtocol.getAlarm()==null?0:crnProtocol.getAlarm().longValue());
+ basCrnp.setCrnNo(slave.getId());
+ if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
+ log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ }
} else {
- throw new CoolException("鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐�");
+ OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆憑1}鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐�",DateUtils.convert(new Date()), slave.getId()));
+ throw new CoolException(MessageFormat.format( "鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
}
/* 鏂规硶2 */
// crnProtocol.setMode(melsecMcNet.ReadInt16("D2231").Content);
@@ -175,27 +199,7 @@
e.printStackTrace();
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栧爢鍨涙満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
log.error("璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
- return;
}
-
- OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
-
- // 澶嶄綅淇″彿
- if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
- if (resetFlag) {
- if (melsecMcNet.Write("D2218", (short) 1).IsSuccess) {
- resetFlag = false;
- }
- }
- }
-
- // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
-// BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
-// BasCrnp basCrnp = new BasCrnp();
-// basCrnp.setCrnNo(slave.getId());
-// if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
-// log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
-// }
}
@@ -238,6 +242,29 @@
if (!melsecMcNet.Write("D2218", command.getAckFinish()).IsSuccess) { break; }
}
+ try {
+ // 鏃ュ織璁板綍
+ BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);
+ BasCrnOpt basCrnOpt = new BasCrnOpt(
+ command.getTaskNo().intValue(), // 浠诲姟鍙�
+ command.getCrnNo(), // 鍫嗗灈鏈篬闈炵┖]
+ new Date(), // 涓嬪彂鏃堕棿
+ command.getTaskModeType().toString(), // 妯″紡
+ command.getSourcePosX().intValue(), // 婧愭帓
+ command.getSourcePosY().intValue(), // 婧愬垪
+ command.getSourcePosZ().intValue(), // 婧愬眰
+ null, // 婧愮珯
+ command.getDestinationPosX().intValue(), // 鐩爣鎺�
+ command.getDestinationPosY().intValue(), // 鐩爣鍒�
+ command.getDestinationPosZ().intValue(), // 鐩爣灞�
+ null, // 鐩爣绔�
+ null, // 鍝嶅簲缁撴灉
+ null, // 淇敼鏃堕棿
+ null // 淇敼浜哄憳
+ );
+ bean.insert(basCrnOpt);
+ } catch (Exception ignore) {}
+
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)));
@@ -267,13 +294,6 @@
@Override
public void close() {
melsecMcNet.ConnectClose();
- }
-
- public CrnProtocol getCrnProtocol(){
- if (crnProtocol == null) {
- readStatus();
- }
- return this.crnProtocol;
}
--
Gitblit v1.9.1