From bc0a69ea4a4fb49dadc02bf548d8f3fd3f60d18a Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 19 八月 2020 09:22:09 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/DevpThread.java | 35 +++++++++++++++++++++++++----------
1 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java
index 6679caf..2c86663 100644
--- a/src/main/java/com/zy/core/thread/DevpThread.java
+++ b/src/main/java/com/zy/core/thread/DevpThread.java
@@ -31,12 +31,12 @@
public DevpThread(Slave slave) {
this.slave = slave;
- connect();
}
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
+ connect();
while (true) {
try {
int step = 1;
@@ -56,7 +56,10 @@
default:
break;
}
- Thread.sleep(500);
+
+ // 蹇冭烦
+ heartbeat();
+ Thread.sleep(400);
} catch (Exception e) {
e.printStackTrace();
}
@@ -75,14 +78,14 @@
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());
+ log.error("杈撻�佺嚎plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
}
siemensS7Net.ConnectClose();
return result;
}
/**
- * 璇诲彇鐘舵��
+ * 璇诲彇鐘舵�� ====> 鏁村潡plc
*/
private void read(){
OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 40);
@@ -111,7 +114,7 @@
}
/**
- * 鍐欏叆
+ * 鍐欏叆 =====> 鍗曠珯鐐瑰啓鍏�
*/
private void write(StaProtocol staProtocol){
if (null == staProtocol) {
@@ -131,22 +134,34 @@
}
}
+ /**
+ * 蹇冭烦
+ */
+ private void heartbeat(){
+ OperateResult write = siemensS7Net.Write("DB100.50", (short) 1);
+ if (!write.IsSuccess) {
+ log.error("杈撻�佺嚎plc缂栧彿={} 蹇冭烦澶辫触", slave.getId());
+ }
+ }
+
@Override
public void close() {
-
+ siemensS7Net.ConnectClose();
}
public static void main(String[] args) {
Slave slave = new Slave();
slave.setIp("192.168.2.125");
DevpThread devpThread = new DevpThread(slave);
+ devpThread.connect();
devpThread.read();
// 鍐�
StaProtocol staProtocol = devpThread.getStation().get(1);
- staProtocol.setWorkNo((short) 9999);
- staProtocol.setStaNo((short) 100);
- staProtocol.setAutoing(false);
- staProtocol.setEmptyMk(false);
+ staProtocol.setWorkNo((short) 232);
+ staProtocol.setStaNo((short) 6);
+ staProtocol.setAutoing(true);
+ staProtocol.setEmptyMk(true);
+ staProtocol.setInEnable(true);
devpThread.write(staProtocol);
System.out.println("----------------------------------------");
// 璇�
--
Gitblit v1.9.1