From 911460b3d9c47ed0443e6b1e635ab5a91817701e Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <xltys1995> Date: 星期四, 27 八月 2020 14:50:18 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/DevpThread.java | 57 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java index cc8c752..6fcc130 100644 --- a/src/main/java/com/zy/core/thread/DevpThread.java +++ b/src/main/java/com/zy/core/thread/DevpThread.java @@ -75,7 +75,7 @@ } // 蹇冭烦 - heartbeat(); +// heartbeat(); Thread.sleep(400); } catch (Exception e) { e.printStackTrace(); @@ -104,8 +104,8 @@ /** * 璇诲彇鐘舵�� ====> 鏁村潡plc */ - private void read(){ - OperateResultExOne<byte[]> result = melsecMcNet.Read("DB100.0", (short) 40); + private void read() throws InterruptedException { + OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30); if (result.IsSuccess) { for (int i = 1; i <= 8; i++) { StaProtocol staProtocol = station.get(i); @@ -115,19 +115,19 @@ station.put(i, staProtocol); } staProtocol.setWorkNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2)); // 宸ヤ綔鍙� - staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+20)); // 鐩爣绔� + staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40)); // 鐩爣绔� } } - OperateResultExOne<byte[]> result1 = melsecMcNet.Read("DB100.40", (short) 8); + Thread.sleep(100); + OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64); if (result1.IsSuccess) { for (int i = 1; i <= 8; i++) { - boolean[] status = melsecMcNet.getByteTransform().TransBool(result1.Content, i-1, 1); StaProtocol staProtocol = station.get(i); - staProtocol.setAutoing(status[0]); // 鑷姩 - staProtocol.setLoading(status[1]); // 鏈夌墿 - staProtocol.setInEnable(status[2]); // 鍙叆 - staProtocol.setOutEnable(status[3]);// 鍙嚭 - staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿 + staProtocol.setAutoing(result1.Content[(i-1)*8]); // 鑷姩 + staProtocol.setLoading(result1.Content[(i-1)*8+1]); // 鏈夌墿 + staProtocol.setInEnable(result1.Content[(i-1)*8+2]); // 鍙叆 + staProtocol.setOutEnable(result1.Content[(i-1)*8+3]);// 鍙嚭 + staProtocol.setEmptyMk(result1.Content[(i-1)*8+4]); // 绌烘澘淇″彿 } } if (result.IsSuccess && result1.IsSuccess) { @@ -158,12 +158,13 @@ /** * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏� */ - private void write(StaProtocol staProtocol){ + private void write(StaProtocol staProtocol) throws InterruptedException { if (null == staProtocol) { return; } - OperateResult write = melsecMcNet.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 宸ヤ綔鍙� - OperateResult write1 = melsecMcNet.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 鐩爣绔� + OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo()); // 宸ヤ綔鍙� + Thread.sleep(100); + OperateResult write1 = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo()); // 鐩爣绔� // boolean[] status = new boolean[8]; // status[0] = staProtocol.isAutoing(); // status[1] = staProtocol.isLoading(); @@ -186,7 +187,7 @@ if (null == staProtocol) { return; } - OperateResult write = melsecMcNet.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 宸ヤ綔鍙� + OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo()); // 宸ヤ綔鍙� if (!write.IsSuccess ) { OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol))); log.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol)); @@ -202,7 +203,7 @@ if (null == staProtocol) { return; } - OperateResult write = melsecMcNet.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 鐩爣绔� + OperateResult write = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo()); // 鐩爣绔� if (!write.IsSuccess ) { OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol))); log.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol)); @@ -231,23 +232,27 @@ melsecMcNet.ConnectClose(); } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { DevpSlave slave = new DevpSlave(); - slave.setIp("192.168.2.125"); + slave.setIp("192.168.3.65"); + slave.setPort(6000); DevpThread devpThread = new DevpThread(slave); devpThread.connect(); devpThread.read(); + System.out.println("绗竴娆¤"); // 鍐� - StaProtocol staProtocol = devpThread.getStation().get(1); - staProtocol.setWorkNo((short) 232); - staProtocol.setStaNo((short) 6); - staProtocol.setAutoing(true); - staProtocol.setEmptyMk(true); - staProtocol.setInEnable(true); - devpThread.write(staProtocol); - System.out.println("----------------------------------------"); +// StaProtocol staProtocol = devpThread.getStation().get(1); +// staProtocol.setWorkNo((short) 232); +// staProtocol.setStaNo((short) 6); +// staProtocol.setAutoing(true); +// staProtocol.setEmptyMk(true); +// staProtocol.setInEnable(true); +// devpThread.write(staProtocol); +// System.out.println("----------------------------------------"); + Thread.sleep(400); // 璇� devpThread.read(); + System.out.println("绗簩娆¤"); System.out.println(JSON.toJSONString(devpThread.station)); } -- Gitblit v1.9.1