From ba429ae6b8a09bc5667b48df7ebf6b61dd048dd9 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期一, 28 十二月 2020 18:52:45 +0800 Subject: [PATCH] ## --- src/main/java/com/zy/core/thread/MelsecDevpThread.java | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/zy/core/thread/MelsecDevpThread.java b/src/main/java/com/zy/core/thread/MelsecDevpThread.java index 254a8b1..ddf5e9a 100644 --- a/src/main/java/com/zy/core/thread/MelsecDevpThread.java +++ b/src/main/java/com/zy/core/thread/MelsecDevpThread.java @@ -8,6 +8,7 @@ import com.core.common.SpringUtils; import com.zy.asrs.entity.BasDevp; import com.zy.asrs.service.BasDevpService; +import com.zy.asrs.utils.Utils; import com.zy.core.DevpThread; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.OutputQueue; @@ -103,18 +104,20 @@ private void read() throws InterruptedException { OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30); if (result.IsSuccess) { - for (int i = 1; i <= 7; i++) { - StaProtocol staProtocol = station.get(i); + // 绔欑偣鏁版嵁 + for (int i = 1; i <= staNos.size(); i++) { + Integer siteId = staNos.get(i); // 绔欑偣缂栧彿 + StaProtocol staProtocol = station.get(siteId); if (null == staProtocol) { staProtocol = new StaProtocol(); - staProtocol.setSiteId(i); - station.put(i, staProtocol); + staProtocol.setSiteId(siteId); + station.put(siteId, staProtocol); } staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2)); // 宸ヤ綔鍙� staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40)); // 鐩爣绔� } } - Thread.sleep(5000); + Thread.sleep(3000); OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64); if (result1.IsSuccess) { for (int i = 1; i <= 7; i++) { @@ -146,8 +149,8 @@ // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴� try { List<BasDevp> basDevps = new ArrayList<>(); - for (int i = 1; i <= 7; i++) { - StaProtocol staProtocol = station.get(i); + for (Integer siteId : staNos) { + StaProtocol staProtocol = station.get(siteId); basDevps.add(staProtocol.toSqlModel()); } BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); @@ -172,9 +175,9 @@ if (null == staProtocol) { return; } - OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo()); // 宸ヤ綔鍙� + OperateResult write = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+1), 2), staProtocol.getWorkNo()); // 宸ヤ綔鍙� Thread.sleep(400); - OperateResult write1 = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo()); // 鐩爣绔� + OperateResult write1 = melsecMcNet.Write("D1" + Utils.zerofill(String.valueOf(staNos.indexOf(staProtocol.getSiteId())+21), 2), staProtocol.getStaNo()); // 鐩爣绔� if (!write.IsSuccess || !write1.IsSuccess) { staProtocol = station.get(staProtocol.getSiteId()); if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) { -- Gitblit v1.9.1