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/DevpThread.java | 136 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 135 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java
index 8f99511..03f028f 100644
--- a/src/main/java/com/zy/core/thread/DevpThread.java
+++ b/src/main/java/com/zy/core/thread/DevpThread.java
@@ -1,13 +1,147 @@
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.Task;
+import com.zy.core.model.protocol.StaProtocol;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
+ * 杈撻�佺嚎绾跨▼
* Created by vincent on 2020/8/4
*/
-public class DevpThread implements Runnable {
+@Data
+@Slf4j
+public class DevpThread implements Runnable, ThreadHandler {
+
+ private Slave slave;
+ private SiemensS7Net siemensS7Net;
+ private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
+
+ public DevpThread(Slave slave) {
+ this.slave = slave;
+ connect();
+ }
@Override
+ @SuppressWarnings("InfiniteLoopStatement")
public void run() {
+ while (true) {
+ try {
+ int step = 1;
+ Task task = MessageQueue.poll(SlaveType.Devp, slave.getId());
+ if (task != null) {
+ step = task.getStep();
+ }
+ switch (step) {
+ // 璇绘暟鎹�
+ case 1:
+ readWorkNo(); // 璇诲彇宸ヤ綔鍙�
+ readStaDest(); // 璇诲彇鐩爣绔�
+ readStatus(); // 璇诲彇鐘舵��
+ readError(); // 璇诲彇寮傚父淇℃伅
+ break;
+ case 2:
+ break;
+ case 3:
+ break;
+ case 4:
+ break;
+ default:
+ break;
+ }
+ Thread.sleep(3000);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ @Override
+ public boolean connect() {
+ boolean result = false;
+ siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp());
+ siemensS7Net.setRack((byte) 0);
+ siemensS7Net.setSlot((byte) 1);
+ OperateResult connect = siemensS7Net.ConnectServer();
+ if(connect.IsSuccess){
+ result = true;
+ log.info("杈撻�佺嚎plc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ } else {
+ log.info("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ }
+ siemensS7Net.ConnectClose();
+ return result;
+ }
+
+ /**
+ * 璇诲彇宸ヤ綔鍙�
+ */
+ private void readWorkNo(){
+ OperateResultExOne<int[]> read = siemensS7Net.ReadInt32("DB100", (short) 8);
+ if (read.IsSuccess) {
+ int staNo1 = read.Content[0];
+ int staNo2 = read.Content[1];
+ int staNo3 = read.Content[2];
+ int staNo4 = read.Content[3];
+ int staNo5 = read.Content[4];
+ int staNo6 = read.Content[5];
+ int staNo7 = read.Content[6];
+ int staNo8 = read.Content[7];
+ }
+ }
+
+ /**
+ * 璇诲彇鐩爣绔�
+ */
+ private void readStaDest(){
+ OperateResultExOne<byte[]> read = siemensS7Net.Read("DB101", (short) 8);
+ if (read.IsSuccess) {
+ int staNo1 = siemensS7Net.getByteTransform().TransInt32(read.Content, 0);
+ int staNo2 = siemensS7Net.getByteTransform().TransInt32(read.Content, 4);
+ int staNo3 = siemensS7Net.getByteTransform().TransInt32(read.Content, 8);
+ int staNo4 = siemensS7Net.getByteTransform().TransInt32(read.Content, 12);
+ int staNo5 = siemensS7Net.getByteTransform().TransInt32(read.Content, 16);
+ int staNo6 = siemensS7Net.getByteTransform().TransInt32(read.Content, 20);
+ int staNo7 = siemensS7Net.getByteTransform().TransInt32(read.Content, 24);
+ int staNo8 = siemensS7Net.getByteTransform().TransInt32(read.Content, 28);
+
+ }
+ }
+
+ /**
+ * 璇诲彇鐘舵��
+ */
+ private void readStatus(){
}
+ /**
+ * 璇诲彇寮傚父淇℃伅
+ */
+ private void readError(){
+
+ }
+
+ private void writeWorkNo(){
+
+
+
+ }
+
+ @Override
+ public void close() {
+
+ }
}
--
Gitblit v1.9.1