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 | 69 ++++++++++++++++++++++++----------
1 files changed, 48 insertions(+), 21 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/CrnThread.java b/src/main/java/com/zy/core/thread/CrnThread.java
index 9a2df23..4839c5b 100644
--- a/src/main/java/com/zy/core/thread/CrnThread.java
+++ b/src/main/java/com/zy/core/thread/CrnThread.java
@@ -28,6 +28,7 @@
public CrnThread(CrnSlave slave) {
this.slave = slave;
+ this.connect();
}
@Override
@@ -43,10 +44,11 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- readStatus(); // 璇诲彇鐘舵��
+ readStatus();
break;
+ // 鍐欏叆鏁版嵁
case 2:
- CrnCommand command = (CrnCommand) task.getData();
+ write((CrnCommand) task.getData());
break;
case 3:
break;
@@ -75,7 +77,7 @@
result = true;
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:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+ log.error("鍫嗗灈鏈簆lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
siemensNet.ConnectClose();
return result;
@@ -85,26 +87,31 @@
* 璇诲彇鐘舵��
*/
private void readStatus(){
- OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 10);
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 46);
if (result.IsSuccess) {
if (null == crnProtocol) {
crnProtocol = new CrnProtocol();
}
- crnProtocol.setMode(siemensNet.ReadInt16("D2231").Content);
-// crnProtocol.setEStop(siemensNet.ReadInt16("D2232").Content);
- crnProtocol.setTaskNo(siemensNet.ReadInt16("D2233").Content);
- crnProtocol.setStatus(siemensNet.ReadInt16("D2234").Content);
- crnProtocol.setBay(siemensNet.ReadInt16("D2235").Content);
- crnProtocol.setLevel(siemensNet.ReadInt16("D2236").Content);
- crnProtocol.setForkPos(siemensNet.ReadInt16("D2237").Content);
- crnProtocol.setLiftPos(siemensNet.ReadInt16("D2238").Content);
- crnProtocol.setWalkPos(siemensNet.ReadInt16("D2239").Content);
- crnProtocol.setTaskFinish(siemensNet.ReadInt16("D2240").Content);
- crnProtocol.setLoaded(siemensNet.ReadInt16("D2241").Content);
- crnProtocol.setAlarm(siemensNet.ReadInt16("D2242").Content);
- crnProtocol.setXDistance(siemensNet.ReadInt32("D2251").Content);
- crnProtocol.setYDistance(siemensNet.ReadInt32("D2253").Content);
- crnProtocol.setDuration(siemensNet.ReadInt32("D2255").Content);
+ 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());
}
@@ -113,8 +120,28 @@
/**
* 鍐欏叆鏁版嵁
*/
- 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
--
Gitblit v1.9.1