From fb9405a0482b22cd9411ab3e24163f4fb17a5260 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期日, 03 一月 2021 13:46:54 +0800 Subject: [PATCH] #1 --- src/main/java/com/zy/core/thread/SiemensCrnThread.java | 65 +++++++++++++++++++++++++------- 1 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java index 3d84147..46b2620 100644 --- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java +++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java @@ -5,9 +5,12 @@ import HslCommunication.Profinet.Siemens.SiemensPLCS; import HslCommunication.Profinet.Siemens.SiemensS7Net; import com.alibaba.fastjson.JSON; +import com.core.common.Arith; import com.core.common.DateUtils; import com.core.common.SpringUtils; +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.core.CrnThread; import com.zy.core.cache.MessageQueue; @@ -70,7 +73,7 @@ } command.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙� command.setTaskNo((short) 0); // 宸ヤ綔鍙� - command.setAckFinish((short) 1); // 浠诲姟瀹屾垚纭浣� +// command.setAckFinish((short) 1); // 浠诲姟瀹屾垚纭浣� command.setTaskMode(CrnTaskModeType.NONE); // 浠诲姟妯″紡 command.setSourcePosX((short)0); // 婧愬簱浣嶆帓 command.setSourcePosY((short)0); // 婧愬簱浣嶅垪 @@ -94,7 +97,7 @@ @Override public boolean connect() { boolean result = false; - siemensNet = new SiemensS7Net(SiemensPLCS.S300, slave.getIp()); + siemensNet = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp()); siemensNet.setRack(slave.getRack().byteValue()); siemensNet.setSlot(slave.getSlot().byteValue()); OperateResult connect = siemensNet.ConnectServer(); @@ -114,7 +117,7 @@ * 璇诲彇鐘舵�� */ private void readStatus(){ - OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 62); + OperateResultExOne<byte[]> result = siemensNet.Read("DB11.2", (short) 90); if (result.IsSuccess) { if (null == crnProtocol) { crnProtocol = new CrnProtocol(); @@ -137,9 +140,11 @@ crnProtocol.setError4(siemensNet.getByteTransform().TransBool(result.Content, 28, 2)); crnProtocol.setError5(siemensNet.getByteTransform().TransBool(result.Content, 30, 2)); crnProtocol.setError6(siemensNet.getByteTransform().TransBool(result.Content, 32, 2)); - crnProtocol.setXSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 34)); + float xSpeed = siemensNet.getByteTransform().TransSingle(result.Content, 34); + crnProtocol.setXSpeed((float) Arith.multiplys(3, xSpeed, 1.15)); crnProtocol.setYSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 38)); - crnProtocol.setZSpeed(siemensNet.getByteTransform().TransSingle(result.Content, 42)); + float zSpeed = siemensNet.getByteTransform().TransSingle(result.Content, 42); + crnProtocol.setZSpeed((float) Arith.multiplys(3, zSpeed, 5)); crnProtocol.setXDistance(siemensNet.getByteTransform().TransSingle(result.Content, 46)); crnProtocol.setYDistance(siemensNet.getByteTransform().TransSingle(result.Content, 50)); crnProtocol.setXDuration(siemensNet.getByteTransform().TransSingle(result.Content, 54)); @@ -182,18 +187,50 @@ return false; } command.setCrnNo(slave.getId()); - short[] array = new short[9]; - array[0] = command.getAckFinish(); - array[1] = command.getTaskNo(); - array[2] = command.getTaskMode(); + short[] array = new short[13]; + if (!command.getTaskModeType().equals(CrnTaskModeType.CLEAR)) { + array[0] = 5; + } else { + array[0] = 7; + } + array[1] = command.getSourcePosZ(); + array[2] = command.getSourcePosY(); array[3] = command.getSourcePosX(); - array[4] = command.getSourcePosY(); - array[5] = command.getSourcePosZ(); + array[4] = command.getDestinationPosZ(); + array[5] = command.getDestinationPosY(); array[6] = command.getDestinationPosX(); - array[7] = command.getDestinationPosY(); - array[8] = command.getDestinationPosZ(); - OperateResult result = siemensNet.Write("DB8.0", array); + array[7] = command.getSourceStaNo(); + array[8] = command.getDestinationStaNo(); + array[9] = command.getSourceLane(); + array[10] = command.getDestinationLane(); + array[11] = + + OperateResult result = siemensNet.Write("DB10.0", array); if (result.IsSuccess) { + + 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); + } catch (Exception ignore) {} + 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; -- Gitblit v1.9.1