From 892b13a55e27a950993f3d0fafb997be5360177d Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 11 八月 2020 14:25:38 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/CrnThread.java | 102 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 72 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/CrnThread.java b/src/main/java/com/zy/core/thread/CrnThread.java
index 9d34452..4839c5b 100644
--- a/src/main/java/com/zy/core/thread/CrnThread.java
+++ b/src/main/java/com/zy/core/thread/CrnThread.java
@@ -1,13 +1,15 @@
package com.zy.core.thread;
import HslCommunication.Core.Types.OperateResult;
+import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
-import com.zy.core.Slave;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.SlaveType;
+import com.zy.core.model.CrnSlave;
import com.zy.core.model.Task;
+import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.protocol.CrnProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -20,12 +22,13 @@
@Slf4j
public class CrnThread implements Runnable, ThreadHandler {
- SiemensS7Net siemensNet;
- private Slave slave;
+ private SiemensS7Net siemensNet;
+ private CrnSlave slave;
private CrnProtocol crnProtocol;
- public CrnThread(Slave slave) {
+ public CrnThread(CrnSlave slave) {
this.slave = slave;
+ this.connect();
}
@Override
@@ -41,12 +44,15 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- readStatus(); // 璇诲彇鐘舵��
+ readStatus();
break;
+ // 鍐欏叆鏁版嵁
case 2:
+ write((CrnCommand) task.getData());
break;
case 3:
break;
+ // 澶嶄綅
case 4:
break;
default:
@@ -63,15 +69,15 @@
@Override
public boolean connect() {
boolean result = false;
- siemensNet = new SiemensS7Net(SiemensPLCS.S1200,slave.getIp());
- siemensNet.setRack((byte) 0);
- siemensNet.setSlot((byte) 1);
+ siemensNet = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp());
+ siemensNet.setRack(slave.getRack().byteValue());
+ siemensNet.setSlot(slave.getSlot().byteValue());
OperateResult connect = siemensNet.ConnectServer();
if(connect.IsSuccess){
result = true;
- log.info("鍫嗗灈鏈簆lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ log.info("鍫嗗灈鏈簆lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
} else {
- log.info("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ log.error("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
siemensNet.ConnectClose();
return result;
@@ -81,36 +87,72 @@
* 璇诲彇鐘舵��
*/
private void readStatus(){
- CrnProtocol protocol = new CrnProtocol();
- protocol.mode = siemensNet.ReadInt16("D2231").Content;
- protocol.eStop = siemensNet.ReadInt16("D2232").Content;
- protocol.taskNo = siemensNet.ReadInt16("D2233").Content;
- protocol.status = siemensNet.ReadInt16("D2234").Content;
- protocol.bay = siemensNet.ReadInt16("D2235").Content;
- protocol.level = siemensNet.ReadInt16("D2236").Content;
- protocol.forkPos = siemensNet.ReadInt16("D2237").Content;
- protocol.liftPos = siemensNet.ReadInt16("D2238").Content;
- protocol.walkPos = siemensNet.ReadInt16("D2239").Content;
- protocol.taskFinish = siemensNet.ReadInt16("D2240").Content;
- protocol.loaded = siemensNet.ReadInt16("D2241").Content;
- protocol.alarm = siemensNet.ReadInt16("D2242").Content;
- protocol.xDistance = siemensNet.ReadInt32("D2251").Content;
- protocol.yDistance = siemensNet.ReadInt32("D2253").Content;
- protocol.duration = siemensNet.ReadInt32("D2255").Content;
- this.crnProtocol = protocol;
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 46);
+ if (result.IsSuccess) {
+ if (null == crnProtocol) {
+ crnProtocol = new CrnProtocol();
+ }
+ crnProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
+ crnProtocol.setTaskNo(siemensNet.getByteTransform().TransInt16(result.Content, 2));
+ crnProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 4));
+ crnProtocol.setBay(siemensNet.getByteTransform().TransInt16(result.Content, 6));
+ crnProtocol.setLevel(siemensNet.getByteTransform().TransInt16(result.Content, 8));
+ crnProtocol.setForkPos(siemensNet.getByteTransform().TransInt16(result.Content, 10));
+ crnProtocol.setLiftPos(siemensNet.getByteTransform().TransInt16(result.Content, 12));
+ crnProtocol.setWalkPos(siemensNet.getByteTransform().TransInt16(result.Content, 14));
+ crnProtocol.setTaskFinish(siemensNet.getByteTransform().TransInt16(result.Content, 16));
+ crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 18));
+ crnProtocol.setAlarm1(siemensNet.getByteTransform().TransInt16(result.Content, 20));
+ crnProtocol.setError1(siemensNet.getByteTransform().TransInt16(result.Content, 22));
+ crnProtocol.setError2(siemensNet.getByteTransform().TransInt16(result.Content, 24));
+ crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 26));
+ crnProtocol.setXSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
+ crnProtocol.setYSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 30));
+ crnProtocol.setZSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
+ crnProtocol.setXDistance(siemensNet.getByteTransform().TransInt32(result.Content, 34));
+ crnProtocol.setYDistance(siemensNet.getByteTransform().TransInt32(result.Content, 38));
+ crnProtocol.setDuration(siemensNet.getByteTransform().TransInt32(result.Content, 42));
+ } else {
+ log.error("璇诲彇鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+ }
}
/**
* 鍐欏叆鏁版嵁
*/
- private void write(){
-
+ private void write(CrnCommand command){
+ if (null == command) {
+ log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+ return;
+ }
+ command.setCrnNo(slave.getId());
+ short[] array = new short[9];
+ array[0] = command.getAckFinish();
+ array[1] = command.getTaskNo();
+ array[2] = command.getTaskMode();
+ array[3] = command.getSourcePosX();
+ array[4] = command.getSourcePosY();
+ array[5] = command.getSourcePosZ();
+ array[6] = command.getDestinationPosX();
+ array[7] = command.getDestinationPosY();
+ array[8] = command.getDestinationPosZ();
+ OperateResult result = siemensNet.Write("DB8.0", array);
+ if (result.IsSuccess) {
+ readStatus();
+ } else {
+ log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+ }
}
@Override
public void close() {
+ }
-
+ public CrnProtocol getCrnProtocol(){
+ if (crnProtocol == null) {
+ readStatus();
+ }
+ return this.crnProtocol;
}
}
--
Gitblit v1.9.1