From 37a50634832b20de8589e4a02d527681d81b53c7 Mon Sep 17 00:00:00 2001
From: whycq <whycq>
Date: 星期二, 15 三月 2022 14:51:07 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SteThread.java | 268 ++++++++++++++++++++++++++++++++---------------------
1 files changed, 161 insertions(+), 107 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index c44d079..2d45b85 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -8,15 +8,12 @@
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.asrs.entity.BasSte;
+import com.zy.asrs.service.BasSteOptService;
+import com.zy.asrs.service.BasSteService;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
-import com.zy.core.enums.CrnStatusType;
-import com.zy.core.enums.CrnTaskModeType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.SteSlave;
import com.zy.core.model.Task;
@@ -31,6 +28,7 @@
/**
* shuttle 绌挎杞︾嚎绋�
* Created by vincent on 2020/8/4
+ * 涓嶈兘鏈� 妲藉彿 鍜� 鏈烘灦鍙�
*/
@Data
@Slf4j
@@ -41,6 +39,10 @@
private SteProtocol steProtocol;
private short heartBeatVal = 1;
private boolean resetFlag = false;
+
+ private Integer lastRow;
+ private Integer lastBay;
+ private Integer lastLev;
public SteThread(SteSlave slave) {
this.slave = slave;
@@ -66,24 +68,6 @@
case 2:
write((SteCommand) task.getData());
break;
- // 澶嶄綅
- case 3:
- SteCommand command = (SteCommand) task.getData();
- if (null == command) {
- command = new SteCommand();
- }
- command.setCrnNo(slave.getId()); // 绌挎杞︾紪鍙�
- command.setTaskNo((short) 0); // 宸ヤ綔鍙�
- command.setAckFinish((short) 1); // 浠诲姟瀹屾垚纭浣�
- command.setTaskMode(CrnTaskModeType.NONE); // 浠诲姟妯″紡
- command.setSourcePosX((short)0); // 婧愬簱浣嶆帓
- command.setSourcePosY((short)0); // 婧愬簱浣嶅垪
- command.setSourcePosZ((short)0); // 婧愬簱浣嶅眰
- command.setDestinationPosX((short)0); // 鐩爣搴撲綅鎺�
- command.setDestinationPosY((short)0); // 鐩爣搴撲綅鍒�
- command.setDestinationPosZ((short)0); // 鐩爣搴撲綅灞�
- write(command);
- break;
default:
break;
}
@@ -104,31 +88,32 @@
if (null == steProtocol) {
steProtocol = new SteProtocol();
}
- steProtocol.setMode((short) -1);
-// crnProtocol.setTaskNo((short)0);
- steProtocol.setStatus((short)-1);
- steProtocol.setBay((short)0);
- steProtocol.setLevel((short)0);
- steProtocol.setForkPos((short) -1);
- steProtocol.setLiftPos((short) -1);
- steProtocol.setWalkPos((short)0);
- steProtocol.setLoaded((short)0);
- steProtocol.setAlarm((short)0);
- steProtocol.setXSpeed(0F);
- steProtocol.setYSpeed(0F);
- steProtocol.setZSpeed(0F);
- steProtocol.setXDistance(0F);
- steProtocol.setYDistance(0F);
- steProtocol.setXDuration(0F);
- steProtocol.setYDuration(0F);
+// steProtocol.setMode((short) -1);
+// steProtocol.setTaskNo((short)0);
+// steProtocol.setStatus((short)-1);
+// steProtocol.setBay((short)0);
+// steProtocol.setLevel((short)0);
+// steProtocol.setForkPos((short) -1);
+// steProtocol.setLiftPos((short) -1);
+// steProtocol.setWalkPos((short)0);
+// steProtocol.setLoaded((short)0);
+// steProtocol.setAlarm((short)0);
+// steProtocol.setXSpeed(0F);
+// steProtocol.setYSpeed(0F);
+// steProtocol.setZSpeed(0F);
+// steProtocol.setXDistance(0F);
+// steProtocol.setYDistance(0F);
+// steProtocol.setXDuration(0F);
+// steProtocol.setYDuration(0F);
}
@Override
public boolean connect() {
boolean result = false;
- siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp());
- siemensS7Net.setRack(slave.getRack().byteValue());
- siemensS7Net.setSlot(slave.getSlot().byteValue());
+ // 涓嶈兘鏈� 妲藉彿 鍜� 鏈烘灦鍙�
+ siemensS7Net = new SiemensS7Net(SiemensPLCS.S200Smart, slave.getIp());
+// siemensS7Net.setRack(slave.getRack().byteValue());
+// siemensS7Net.setSlot(slave.getSlot().byteValue());
OperateResult connect = siemensS7Net.ConnectServer();
if(connect.IsSuccess){
result = true;
@@ -148,35 +133,53 @@
*/
private void readStatus(){
try {
-// if (this.slave.getId() == 1 && flag1.equals(0)) {
-// Thread.sleep(3000);
-// flag1=1;
-// System.out.println("===");
-// }
- OperateResultExOne<byte[]> result = siemensS7Net.Read("D20", (short) 70);
+ OperateResultExOne<byte[]> result = siemensS7Net.Read("V20", (short) 70);
if (result.IsSuccess) {
if (null == steProtocol) {
steProtocol = new SteProtocol();
}
- steProtocol.setMode(siemensS7Net.getByteTransform().TransInt16(result.Content, 0));
- steProtocol.setTaskNo(siemensS7Net.getByteTransform().TransInt16(result.Content, 2));
- steProtocol.setStatus(siemensS7Net.getByteTransform().TransInt16(result.Content, 4));
- steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 6));
- steProtocol.setLevel(siemensS7Net.getByteTransform().TransInt16(result.Content, 8));
- steProtocol.setForkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 10));
- steProtocol.setLiftPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 12));
- steProtocol.setWalkPos(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
- steProtocol.setLoaded(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
- steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
+// steProtocol.setSteNo();
+// steProtocol.setMode();
+// steProtocol.setStatus();
+// steProtocol.setExecute();
+// steProtocol.setWaiting();
+// steProtocol.setAlarm();
+// steProtocol.setAlarm0();
+// steProtocol.setCharge();
+// steProtocol.setFullCharge();
+// steProtocol.setLowCharge();
+// steProtocol.setFeed();
+// steProtocol.setLoca();
+// steProtocol.setCloser();
+// steProtocol.setSpeed();
+// steProtocol.setPos();
+// steProtocol.setLoad();
+// steProtocol.setTrack();
+// steProtocol.setTaskNo();
+// steProtocol.setTaskType();
+// steProtocol.setRow();
+// steProtocol.setBay();
+// steProtocol.setLev();
+//
+// steProtocol.setHisTaskNo();
+// steProtocol.setHisTaskStatus();
+// steProtocol.setCheckQty();
+// steProtocol.setReady();
+// steProtocol.setChargeNo();
+//
+// steProtocol.setHeart();
+// steProtocol.setCrnStopRun();
+// steProtocol.setCrnStopFork();
+// steProtocol.setCrnAllowRun();
OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
// 澶嶄綅淇″彿
- if (steProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+ if (steProtocol.getWaiting()) {
if (resetFlag) {
SteCommand steCommand = new SteCommand();
- steCommand.setAckFinish((short)1);
- if (write(steCommand)) {
+ steCommand.setComplete(true);
+ if (write(steCommand) && confirmPos()) {
resetFlag = false;
}
}
@@ -184,14 +187,15 @@
// 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
- BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
- BasCrnp basCrnp = new BasCrnp();
- basCrnp.setCrnErr(steProtocol.getAlarm()==null?0:steProtocol.getAlarm().longValue());
- basCrnp.setCrnNo(slave.getId());
- if (!basCrnpService.updateById(steProtocol.toSqlModel(basCrnp))){
- log.error("绌挎杞lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
- }
+ BasSteService service = SpringUtils.getBean(BasSteService.class);
+ if (null != service) {
+ BasSte basSte = new BasSte();
+ basSte.setSteNo(slave.getId());
+ if (!service.updateById(steProtocol.toSqlModel(basSte))){
+ log.error("绌挎杞lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ }
+ }
} else {
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()));
@@ -213,49 +217,64 @@
log.error("绌挎杞﹀啓鍏ュ懡浠や负绌�");
return false;
}
- 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 = siemensS7Net.Write("D0", array);
-
- if (command.getAckFinish() == 0) {
- short commandFinish = 1;
- result = siemensS7Net.Write("D9", commandFinish);
+ command.setSteNo(slave.getId());
+ OperateResult result = null;
+ // 寮�濮嬩换鍔�
+ if (!command.getComplete()) {
+ OperateResult result0 = siemensS7Net.Write("D0", command.getTaskNo());
+ short[] array = new short[10];
+ array[0] = command.getTaskMode();
+// 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 result1 = siemensS7Net.Write("D0", array);
+ // 纭寮�濮嬩换鍔�
+ if (result0.IsSuccess) {
+ result = siemensS7Net.Write("D0", true);
+ }
+ // 浠诲姟瀹屾垚
+ } else {
+ result = siemensS7Net.Write("D0", true);
}
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);
+ BasSteOptService bean = SpringUtils.getBean(BasSteOptService.class);
+// BasSteOpt basSteOpt = new BasSteOpt(
+// command.getTaskNo(), // 浠诲姟鍙�
+// command.getSteNo(), // 绌挎杞闈炵┖]
+// new Date(), // 涓嬪彂鏃堕棿
+// command.getTaskModeType().desc, // 妯″紡
+// 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(basSteOpt);
} catch (Exception ignore) {}
- if (result.IsSuccess) {
+ if (result != null && result.IsSuccess) {
+ // 缁存姢鏁版嵁搴撴帓鍒楀眰
+ if (!steProtocol.getWaiting()) {
+ this.lastRow = command.getRow().intValue();
+ this.lastBay = command.getBay().intValue();
+ this.lastLev = command.getLev().intValue();
+ }
+
+
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;
@@ -266,6 +285,41 @@
}
}
+ public void modifyPos(Integer row, Integer bay, Integer lev) {
+ this.lastRow = row;
+ this.lastBay = bay;
+ this.lastLev = lev;
+ }
+
+ public boolean confirmPos() {
+ if (this.lastRow != null && this.lastRow != 0) {
+ if (this.lastBay != null && this.lastBay != 0) {
+ if (this.lastLev != null && this.lastLev != 0) {
+ BasSteService service = SpringUtils.getBean(BasSteService.class);
+ BasSte basSte = service.selectById(slave.getId());
+ if (basSte != null) {
+ // 鏇存柊plc鏁版嵁鍧�
+ short[] arr = new short[] {this.lastRow.shortValue(), this.lastBay.shortValue(), this.lastLev.shortValue()};
+ OperateResult result = siemensS7Net.Write("D0", arr);
+ if (result.IsSuccess) {
+ // 鏇存柊鏁版嵁搴�
+ if (service.updatePos(this.lastRow, this.lastBay, this.lastLev) > 0) {
+ this.lastRow = null;
+ this.lastBay = null;
+ this.lastLev = null;
+ return true;
+ } else {
+ log.error("{}鍙风┛姊溅淇敼鏁版嵁搴撳畾浣嶅け璐ワ紒锛侊紒", slave.getId());
+ }
+ }
+ }
+
+ }
+ }
+ }
+ return false;
+ }
+
@Override
public void close() {
siemensS7Net.ConnectClose();
--
Gitblit v1.9.1