From 38adbef1ec9ffdde88026d3ab469d8e907daed6f Mon Sep 17 00:00:00 2001
From: lsh <lsh>
Date: 星期五, 12 七月 2024 22:54:13 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SteThread.java | 141 +++++++++++++++++++----------------------------
1 files changed, 57 insertions(+), 84 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index 536e038..4b538c2 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -123,7 +123,7 @@
*/
private void readStatus(){
try {
- OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) 22);
+ OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) 28);
if (result.IsSuccess) {
if (null == steProtocol) {
steProtocol = new SteProtocol();
@@ -143,57 +143,36 @@
steProtocol.setRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
steProtocol.setBay(siemensS7Net.getByteTransform().TransInt16(result.Content, 16));
steProtocol.setLev(siemensS7Net.getByteTransform().TransInt16(result.Content, 18));
-
-// steProtocol.setReady(siemensS7Net.getByteTransform().TransInt16(result.Content, 20));
- boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, 20, 1);
- steProtocol.setReady(status[0]?(short)1:(short)0);
+ steProtocol.setLoca(siemensS7Net.getByteTransform().TransInt16(result.Content, 20));
+ steProtocol.setLocaStart(siemensS7Net.getByteTransform().TransInt16(result.Content, 22));
+ steProtocol.setLocaEnd(siemensS7Net.getByteTransform().TransInt16(result.Content, 24));
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, 26, 1);
+// steProtocol.setReady(status[0]?(short)1:(short)0);
// steProtocol.setReady(status[1]?(short)1:(short)0);
-// steProtocol.setReady(status[2]?(short)1:(short)0);
-// steProtocol.setLoad(status[3]?(short)1:(short)0);
-// steProtocol.setReady(status[4]?(short)1:(short)0);
- steProtocol.setChargeStatus(status[5]?(short)1:(short)0);
- steProtocol.setTrack(status[6]?(short)1:(short)0);
+ steProtocol.setReady(status[3]?(short)1:(short)0);
+// steProtocol.setReady(status[3]?(short)1:(short)0);
+// steProtocol.setTrack(status[6]?(short)1:(short)0);
- SteLocaType locaType = SteLocaType.NONE;
- boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result.Content, 21, 1);
- if (steProtocol.getRow().intValue() >= 6) {
- if (status[7]){//A鐐�
- locaType = SteLocaType.A;
- }
- if (status2[1]){//A寰呮満鐐�
- if (locaType.equals(SteLocaType.NONE)) {
- locaType = SteLocaType.A_WAITING;
- }
- }
- }else {
- if (status2[0]){//B鐐�
- if (locaType.equals(SteLocaType.NONE)) {
- locaType = SteLocaType.B;
- }
- }
- if (status2[2]){//B寰呮満鐐�
- if (locaType.equals(SteLocaType.NONE)) {
- locaType = SteLocaType.B_WAITING;
- }
- }
- }
+ boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result.Content, 27, 1);
- steProtocol.setLoca(locaType.id.shortValue());
- steProtocol.setReady(status2[3]?(short)1:(short)0);
- steProtocol.setLoad(status2[4]?(short)1:(short)0);
+ steProtocol.setChargeStatus(status[0]?(short)1:(short)0);
+ steProtocol.setTrack(status[1]?(short)1:(short)0);
+
+// steProtocol.setLoad(status2[6]?(short)1:(short)0);
+ steProtocol.setLoad(status2[7]?(short)1:(short)0);
OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
- // 澶嶄綅淇″彿
- if (steProtocol.getWaiting()) {
- if (resetFlag) {
- SteCommand steCommand = new SteCommand();
- steCommand.setComplete(true);
- if (write(steCommand) && confirmPos()) {
- resetFlag = false;
- }
- }
- }
+// // 澶嶄綅淇″彿
+// if (steProtocol.getWaiting()) {
+// if (resetFlag) {
+// SteCommand steCommand = new SteCommand();
+// steCommand.setComplete(true);
+// if (write(steCommand) && confirmPos()) {
+// resetFlag = false;
+// }
+// }
+// }
// 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
BasSteService service = SpringUtils.getBean(BasSteService.class);
@@ -239,13 +218,18 @@
}
command.setSteNo(slave.getId());
OperateResult result = null;
+ News.error("绌挎杞﹀啓鍏ュ懡浠�"+JSON.toJSONString(command));
+
// 寮�濮嬩换鍔�
if (!command.getComplete()) {
//缁勭粐浠诲姟鍓嶏紝鍏堟竻绌哄啓浠诲姟纭浣嶏紝浠ュ強浠诲姟瀹屾垚纭浣�
siemensS7Net.Write("DB100.0", (short) 0);//璁惧鍙�
siemensS7Net.Write("DB100.2", (short) 0);//浠诲姟鍙�
- siemensS7Net.Write("DB100.12.0", false);//浠诲姟寮�濮嬬‘璁や綅
- siemensS7Net.Write("DB100.12.1", false);//浠诲姟瀹屾垚纭
+ siemensS7Net.Write("DB100.12", (short) 0);//璧峰鐐逛綅
+ siemensS7Net.Write("DB100.14", (short) 0);//鐩殑鐐逛綅
+ siemensS7Net.Write("DB100.16.0", false);//浠诲姟寮�濮嬬‘璁や綅
+ siemensS7Net.Write("DB100.16.1", false);//浠诲姟瀹屾垚纭浣�
+// siemensS7Net.Write("DB100.18", (short) 0);//纭寲缃愬彿
// 1.浠诲姟鍙�
OperateResult result0 = siemensS7Net.Write("DB100.2", command.getTaskNo().shortValue());
try {
@@ -257,9 +241,12 @@
if (command.getTaskMode() != 0) {
// 2.浣滀笟
OperateResult result1 = siemensS7Net.Write("DB100.4", command.getTaskMode());
+ OperateResult result2 = siemensS7Net.Write("DB100.12", (short) command.getStartLoad().shortValue());//璧峰鐐逛綅
+ OperateResult result3 = siemensS7Net.Write("DB100.14", (short) command.getEndLoad().shortValue());//鐩殑鐐逛綅
+ OperateResult result4 = siemensS7Net.Write("DB100.18", (short) command.getJarNo());//鐩殑鐐逛綅
// 3.纭寮�濮嬩换鍔�
- if (result0.IsSuccess && result1.IsSuccess) {
- result = siemensS7Net.Write("DB100.12.0", true);
+ if (result0.IsSuccess && result1.IsSuccess && result2.IsSuccess && result3.IsSuccess && result4.IsSuccess) {
+ result = siemensS7Net.Write("DB100.16.0", true);
try {
Thread.sleep(300);
@@ -270,11 +257,11 @@
}
// 浠诲姟瀹屾垚
} else {
- siemensS7Net.Write("DB100.2", (short) 0);//浠诲姟鍙�
- siemensS7Net.Write("DB100.4.0", (short) 0);//浠诲姟绫诲瀷
- siemensS7Net.Write("DB100.12.0", false);//浠诲姟寮�濮嬬‘璁や綅
+// siemensS7Net.Write("DB100.2", (short) 0);//浠诲姟鍙�
+// siemensS7Net.Write("DB100.4.0", (short) 0);//浠诲姟绫诲瀷
+ siemensS7Net.Write("DB100.16.0", false);//浠诲姟寮�濮嬬‘璁や綅
- result = siemensS7Net.Write("DB100.12.1", true);//浠诲姟瀹屾垚纭
+ result = siemensS7Net.Write("DB100.16.1", true);//浠诲姟瀹屾垚纭
}
try {
@@ -307,13 +294,6 @@
} catch (Exception ignore) {}
if (result != null && result.IsSuccess) {
- // 缁存姢鏁版嵁搴撴帓鍒楀眰
- if (!steProtocol.getWaiting()) {
- if (!Cools.isEmpty(command.getRow(), command.getBay(), command.getLev())) {
- this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue());
- }
- }
-
News.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
return true;
@@ -321,13 +301,6 @@
OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戝啓鍏ョ┛姊溅plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
News.error("鍐欏叆绌挎杞lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
return false;
- }
- }
-
- public void modifyPos(Integer row, Integer bay, Integer lev) {
- BasSteService service = SpringUtils.getBean(BasSteService.class);
- if (!service.updatePos(this.slave.getId(), row, bay, lev)) {
- News.error("鏇存柊{}鍙风┛姊溅瀹氫綅澶辫触 ===>> 鎺掞細銆恵}銆�, 鍒楋細銆恵}銆戯紝灞傦細銆恵}銆�", this.slave.getId(), row, bay, lev);
}
}
@@ -388,21 +361,21 @@
/******************************************************************************************/
/**************************************** 娴嬭瘯涓撶敤 *****************************************/
/*****************************************************************************************/
- public static void main(String[] args) throws InterruptedException {
- SteSlave slave = new SteSlave();
- slave.setId(1);
- slave.setIp("192.168.2.1");
- slave.setPort(502);
- SteThread thread = new SteThread(slave);
- thread.connect();
- thread.readStatus();
- System.out.println(JSON.toJSONString(thread.steProtocol));
-
- // 绌挎杞﹁繍琛岀姝�
- SteCommand command = new SteCommand();
- command.setRun((short)0);
- thread.write(command);
-
- }
+// public static void main(String[] args) throws InterruptedException {
+// SteSlave slave = new SteSlave();
+// slave.setId(1);
+// slave.setIp("192.168.2.1");
+// slave.setPort(502);
+// SteThread thread = new SteThread(slave);
+// thread.connect();
+// thread.readStatus();
+// System.out.println(JSON.toJSONString(thread.steProtocol));
+//
+// // 绌挎杞﹁繍琛岀姝�
+// SteCommand command = new SteCommand();
+//// command.setRun((short)0);
+// thread.write(command);
+//
+// }
}
--
Gitblit v1.9.1