From 97fb61157e1f007c00c10c01a7307b0cc374a745 Mon Sep 17 00:00:00 2001 From: whycq <123456> Date: 星期二, 18 十月 2022 11:53:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/hylywcs' into hylywcs --- src/main/java/com/zy/core/thread/SiemensDevpThread.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java index 85da205..a8bde3c 100644 --- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java +++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java @@ -8,6 +8,7 @@ import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.SpringUtils; +import com.core.exception.CoolException; import com.zy.asrs.entity.BasDevp; import com.zy.asrs.service.BasDevpService; import com.zy.core.DevpThread; @@ -41,10 +42,15 @@ private SiemensS7Net siemensS7Net; private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); private short heartBeatVal = 1; - public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ + + public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{ add(101);add(102);add(103);add(104); add(201);add(202);add(203);add(204); - add(301);add(302);add(303);add(304);add(305);add(306);add(401);add(402); + add(301);add(302);add(303);add(304);add(305);add(306); + }}; + + public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ + add(401);add(402); }}; /** @@ -67,6 +73,17 @@ public SiemensDevpThread(DevpSlave slave) { this.slave = slave; + } + + private ArrayList<Integer> getStaNo() { + switch (slave.getId()) { + case 1: + return staNos1; + case 2: + return staNos2; + default: + throw new CoolException("鏈嶅姟鍣ㄥ紓甯�"); + } } @Override @@ -102,6 +119,33 @@ } } + /** + * 鍒濆鍖栫珯鐐圭姸鎬� + */ + private void initSite() { + ArrayList<Integer> staNos = getStaNo(); + // 绔欑偣缂栧彿 + for (Integer siteId : staNos) { + StaProtocol staProtocol = station.get(siteId); + if (null == staProtocol) { + staProtocol = new StaProtocol(); + staProtocol.setSiteId(siteId); + station.put(siteId, staProtocol); + } + staProtocol.setWorkNo((short) 0); // ID + staProtocol.setAutoing(false); // 鑷姩 + staProtocol.setLoading(false); // 鏈夌墿 + staProtocol.setInEnable(false); // 鍙叆 + staProtocol.setOutEnable(false); // 鍙嚭 + staProtocol.setEmptyMk(false); // 绌烘澘淇″彿 + staProtocol.setStaNo((short) 0); // 鐩爣绔� + + if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { + staProtocol.setPakMk(true); + } + } + } + @Override public boolean connect() { boolean result = false; @@ -116,6 +160,7 @@ } else { OutputQueue.DEVP.offer(MessageFormat.format( "銆恵0}銆戣緭閫佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); log.error("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + initSite(); } siemensS7Net.ConnectClose(); return result; @@ -127,6 +172,7 @@ private void read() throws InterruptedException { // // 鏇存柊鍏ュ嚭搴撴ā寮� updateIoMode(); + ArrayList<Integer> staNos = getStaNo(); int staNoSize = staNos.size(); OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4)); if (result.IsSuccess) { @@ -220,6 +266,7 @@ } } else { + initSite(); OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戣鍙栬緭閫佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); // log.error("璇诲彇杈撻�佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); } @@ -232,6 +279,7 @@ if (null == staProtocol) { return; } + ArrayList<Integer> staNos = getStaNo(); int index = staNos.indexOf(staProtocol.getSiteId()); short[] array = new short[2]; array[0] = staProtocol.getWorkNo(); @@ -297,14 +345,14 @@ } public static void main(String[] args) { - System.out.println(staNos.indexOf(129)); - System.out.println(staNos.size()); - for (int i = 0; i<staNos.size(); i++) { + System.out.println(staNos1.indexOf(129)); + System.out.println(staNos1.size()); + for (int i = 0; i< staNos1.size(); i++) { // System.out.println(i*2); // System.out.println(i*2 + 200); // System.out.println(i); } - int index = staNos.indexOf(128); + int index = staNos1.indexOf(128); System.out.println(index*2); System.out.println(index*2 + 200); } -- Gitblit v1.9.1