ts
This commit is contained in:
@@ -10,14 +10,13 @@ import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.domain.HslRead;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.schedule.plcRead.util.ParseUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class PlcDdjRead extends Thread {
|
||||
public class PlcDdj1Read extends Thread {
|
||||
public static ConcurrentHashMap<String, MsgDdj> deviceDdjMap;
|
||||
public volatile boolean isRun = true;
|
||||
|
||||
@@ -28,20 +27,12 @@ public class PlcDdjRead extends Thread {
|
||||
private boolean success = false;
|
||||
private MsgDdj msgDdj;
|
||||
|
||||
public PlcDdjRead(MsgDdj msgDdj, PlcConnectInfo plcConnectInfo) {
|
||||
public PlcDdj1Read(MsgDdj msgDdj, PlcConnectInfo plcConnectInfo) {
|
||||
this.msgDdj = msgDdj;
|
||||
this.ip = plcConnectInfo.getIp();
|
||||
this.port = plcConnectInfo.getPort();
|
||||
}
|
||||
|
||||
public static int WriteToSSJ(String address, byte[] data) {
|
||||
int a = 0;
|
||||
if (readWriteNet != null) {
|
||||
a = HslRead.WriteResultRender(readWriteNet.Write(address, data), address);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (isRun) {
|
||||
@@ -56,7 +47,7 @@ public class PlcDdjRead extends Thread {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣 " + e.getMessage());
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -119,7 +110,7 @@ public class PlcDdjRead extends Thread {
|
||||
void reConnect() {
|
||||
closeServer();
|
||||
ConnectServer();
|
||||
log.info("重新连接 SSJ-PLC");
|
||||
log.info("重新连接 DDJ1-PLC");
|
||||
}
|
||||
|
||||
void closeServer() {
|
||||
@@ -129,6 +120,8 @@ public class PlcDdjRead extends Thread {
|
||||
setIsConnect(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int WriteToDDJ(String address, byte[] data) {
|
||||
int a = 0;
|
||||
if (readWriteNet != null) {
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.ruoyi.schedule.plcRead.ddj;
|
||||
|
||||
import HslCommunication.BasicFramework.SoftBasic;
|
||||
import HslCommunication.Core.Net.IReadWriteNet;
|
||||
import HslCommunication.Core.Types.OperateResult;
|
||||
import HslCommunication.Core.Types.OperateResultExOne;
|
||||
import HslCommunication.Profinet.Siemens.SiemensPLCS;
|
||||
import HslCommunication.Profinet.Siemens.SiemensS7Net;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.domain.HslRead;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.schedule.plcRead.util.ParseUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class PlcDdj2Read extends Thread {
|
||||
public static ConcurrentHashMap<String, MsgDdj> deviceDdjMap;
|
||||
public volatile boolean isRun = true;
|
||||
|
||||
public SiemensS7Net siemensS7Net = null;
|
||||
public static IReadWriteNet readWriteNet = null;
|
||||
private final String ip;
|
||||
private final int port;
|
||||
private boolean success = false;
|
||||
private MsgDdj msgDdj;
|
||||
|
||||
public PlcDdj2Read(MsgDdj msgDdj, PlcConnectInfo plcConnectInfo) {
|
||||
this.msgDdj = msgDdj;
|
||||
this.ip = plcConnectInfo.getIp();
|
||||
this.port = plcConnectInfo.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (isRun) {
|
||||
try {
|
||||
if (IsConnect()) {
|
||||
readPlcDdj(msgDdj);
|
||||
Thread.sleep(1000);
|
||||
} else {
|
||||
reConnect();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void readPlcDdj(MsgDdj msgDdj) {
|
||||
OperateResultExOne<byte[]> read2 = readWriteNet.Read(msgDdj.getPlcDbReadAddress(), Convert.toShort("38"));
|
||||
String ddsx = "0";
|
||||
if (read2.IsSuccess) {
|
||||
ddsx = SoftBasic.ByteToHexString(read2.Content);
|
||||
msgDdj.setCzfs(ParseUtil.optInt(0, ddsx));
|
||||
msgDdj.setSbzt(ParseUtil.optInt(2, ddsx));
|
||||
msgDdj.setRwh(Convert.toLong(ParseUtil.optDInt(4, ddsx)));
|
||||
msgDdj.setHczt(ParseUtil.optInt(8, ddsx));
|
||||
msgDdj.setJdbz(ParseUtil.optInt(10, ddsx));
|
||||
msgDdj.setYph(ParseUtil.optInt(12, ddsx));
|
||||
msgDdj.setYlh(ParseUtil.optInt(14, ddsx));
|
||||
msgDdj.setYch(ParseUtil.optInt(16, ddsx));
|
||||
msgDdj.setMbph(ParseUtil.optInt(18, ddsx));
|
||||
msgDdj.setMblh(ParseUtil.optInt(20, ddsx));
|
||||
msgDdj.setMbch(ParseUtil.optInt(22, ddsx));
|
||||
msgDdj.setYxxf(ParseUtil.optInt(24, ddsx));
|
||||
msgDdj.setXtxh(ParseUtil.optInt(26, ddsx));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConnectServer() {
|
||||
siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500);
|
||||
try {
|
||||
siemensS7Net.setIpAddress(this.ip);
|
||||
siemensS7Net.setPort(this.port);
|
||||
siemensS7Net.setRack((byte) 0);
|
||||
siemensS7Net.setSlot((byte) 1);
|
||||
|
||||
OperateResult connect = siemensS7Net.ConnectServer();
|
||||
if (connect.IsSuccess) {
|
||||
setIsConnect(true);
|
||||
readWriteNet = siemensS7Net;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setIsConnect(boolean bflag) {
|
||||
if (!success) {
|
||||
success = bflag;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean IsConnect() {
|
||||
if (success) {
|
||||
return success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void reConnect() {
|
||||
closeServer();
|
||||
ConnectServer();
|
||||
log.info("重新连接 DDJ2-PLC");
|
||||
}
|
||||
|
||||
void closeServer() {
|
||||
if (readWriteNet != null) {
|
||||
readWriteNet.ConnectClose();
|
||||
}
|
||||
setIsConnect(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int WriteToDDJ(String address, byte[] data) {
|
||||
int a = 0;
|
||||
if (readWriteNet != null) {
|
||||
a = HslRead.WriteResultRender(readWriteNet.Write(address, data), address);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user