输送线

This commit is contained in:
张怡蓉
2025-11-21 10:47:10 +08:00
parent 9a24fb4be8
commit c3156725d5
2 changed files with 81 additions and 96 deletions

View File

@@ -4,9 +4,12 @@ import com.ruoyi.common.domain.CustomThread;
import com.ruoyi.common.domain.PlcConnectInfo; import com.ruoyi.common.domain.PlcConnectInfo;
import com.ruoyi.device.ddj.domain.MsgDdj; import com.ruoyi.device.ddj.domain.MsgDdj;
import com.ruoyi.device.ddj.service.IMsgDdjService; import com.ruoyi.device.ddj.service.IMsgDdjService;
import com.ruoyi.device.srgv.domain.DeviceSrgv;
import com.ruoyi.device.srgv.service.IDeviceSrgvService;
import com.ruoyi.device.ssj.domain.DeviceSsj; import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.device.ssj.service.IDeviceSsjService; import com.ruoyi.device.ssj.service.IDeviceSsjService;
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead; import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead; import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
import com.ruoyi.schedule.scheduleTask.ddj.impl.Ddj1Thread; import com.ruoyi.schedule.scheduleTask.ddj.impl.Ddj1Thread;
import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread; import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread;
@@ -25,12 +28,9 @@ import java.util.concurrent.ConcurrentHashMap;
public class ScheduleThread { public class ScheduleThread {
public CustomThread<PlcSsjRead> plcSsjReadCustomThread; public CustomThread<PlcSsjRead> plcSsjReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj1ReadCustomThread; public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread1;
public CustomThread<PlcDdjRead> plcDdj2ReadCustomThread; public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread2;
public CustomThread<PlcDdjRead> plcDdj3ReadCustomThread; public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread3;
public CustomThread<PlcDdjRead> plcDdj4ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj5ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj6ReadCustomThread;
public CustomThread<MonitoringThread> monitoringCustomThread; public CustomThread<MonitoringThread> monitoringCustomThread;
public CustomThread<SsjThread> ssjThreadCustomThread; public CustomThread<SsjThread> ssjThreadCustomThread;
@@ -44,6 +44,8 @@ public class ScheduleThread {
private IDeviceSsjService deviceSsjService; private IDeviceSsjService deviceSsjService;
@Autowired @Autowired
private IMsgDdjService msgDdjService; private IMsgDdjService msgDdjService;
@Autowired
private IDeviceSrgvService deviceSrgvService;
private boolean isRun = false; private boolean isRun = false;
private boolean isRun2 = false; private boolean isRun2 = false;
@@ -94,56 +96,37 @@ public class ScheduleThread {
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj); ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
} }
//plc输送机读取线程 //plc输送机读取线程
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 102)); PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 102));
Thread plcSsjReadThread = new Thread(plcSsjRead); Thread plcSsjReadThread = new Thread(plcSsjRead);
plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead); plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead);
//plc堆垛机读取现场 ConcurrentHashMap<String, DeviceSrgv> srgvList = new ConcurrentHashMap<>();
ConcurrentHashMap<String, MsgDdj> ddjList = new ConcurrentHashMap<>(); List<DeviceSrgv> srgvs=deviceSrgvService.selectDeviceSrgvList(new DeviceSrgv());
List<MsgDdj> msgDdjs = msgDdjService.selectMsgDdjList(new MsgDdj()); for(DeviceSrgv srgv:srgvs){
for (MsgDdj msgDdj : msgDdjs) { srgvList.put(srgv.getDeviceId().toString(),srgv);
switch (msgDdj.getId()){ switch (srgv.getDeviceId()){
case 1: case 1:
msgDdj.setPlcDbReadAddress("DB41.0"); PlcSrgvRead plcSrgvRead1=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
PlcDdjRead plcDdjRead1 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102)); Thread plcSrgvReadThread1 = new Thread((plcSrgvRead1));
Thread plcDdjReadThread1 = new Thread(plcDdjRead1); plcSrgvReadCustomThread1=new CustomThread<PlcSrgvRead>(plcSrgvReadThread1,plcSrgvRead1);
plcDdj1ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread1, plcDdjRead1);
break; break;
case 2: case 2:
msgDdj.setPlcDbReadAddress("DB42.0"); PlcSrgvRead plcSrgvRead2=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
PlcDdjRead plcDdjRead2 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.2", 102)); Thread plcSrgvReadThread2 = new Thread((plcSrgvRead2));
Thread plcDdjReadThread2 = new Thread(plcDdjRead2); plcSrgvReadCustomThread2=new CustomThread<PlcSrgvRead>(plcSrgvReadThread2,plcSrgvRead2);
plcDdj2ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread2, plcDdjRead2);
break; break;
case 3: case 3:
msgDdj.setPlcDbReadAddress("DB42.0"); PlcSrgvRead plcSrgvRead3=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
PlcDdjRead plcDdjRead3 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.3", 102)); Thread plcSrgvReadThread3 = new Thread((plcSrgvRead3));
Thread plcDdjReadThread3 = new Thread(plcDdjRead3); plcSrgvReadCustomThread3=new CustomThread<PlcSrgvRead>(plcSrgvReadThread3,plcSrgvRead3);
plcDdj3ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread3, plcDdjRead3);
break;
case 4:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead4 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.4", 102));
Thread plcDdjReadThread4 = new Thread(plcDdjRead4);
plcDdj4ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread4, plcDdjRead4);
break;
case 5:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead5 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.5", 102));
Thread plcDdjReadThread5 = new Thread(plcDdjRead5);
plcDdj5ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread5, plcDdjRead5);
break;
case 6:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead6 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.6", 102));
Thread plcDdjReadThread6 = new Thread(plcDdjRead6);
plcDdj6ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread6, plcDdjRead6);
break; break;
} }
ddjList.put("ddj" + msgDdj.getId(), msgDdj);
} }
PlcSrgvRead.deviceSrgvMap=srgvList;
} }
/** /**
@@ -151,12 +134,10 @@ public class ScheduleThread {
*/ */
public void startAllThread() { public void startAllThread() {
plcSsjReadCustomThread.getThread().start(); plcSsjReadCustomThread.getThread().start();
plcDdj1ReadCustomThread.getThread().start(); plcSrgvReadCustomThread1.getThread().start();
plcDdj2ReadCustomThread.getThread().start(); plcSrgvReadCustomThread2.getThread().start();
plcDdj3ReadCustomThread.getThread().start(); plcSrgvReadCustomThread3.getThread().start();
plcDdj4ReadCustomThread.getThread().start();
plcDdj5ReadCustomThread.getThread().start();
plcDdj6ReadCustomThread.getThread().start();
isRun = true; isRun = true;
} }
@@ -180,7 +161,7 @@ public class ScheduleThread {
*/ */
public void stopAllThread() { public void stopAllThread() {
plcSsjReadCustomThread.runnable.isRun = false; plcSsjReadCustomThread.runnable.isRun = false;
plcDdj1ReadCustomThread.runnable.isRun = false; // plcDdj1ReadCustomThread.runnable.isRun = false;
/* plcDdj2ReadCustomThread.runnable.isRun = false; /* plcDdj2ReadCustomThread.runnable.isRun = false;
plcDdj3ReadCustomThread.runnable.isRun = false; plcDdj3ReadCustomThread.runnable.isRun = false;
plcDdj4ReadCustomThread.runnable.isRun = false; plcDdj4ReadCustomThread.runnable.isRun = false;

View File

@@ -13,6 +13,7 @@ import com.ruoyi.device.srgv.domain.DeviceSrgv;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
public class PlcSrgvRead implements Runnable { public class PlcSrgvRead implements Runnable {
@@ -24,15 +25,17 @@ public class PlcSrgvRead implements Runnable{
private final int port; private final int port;
private byte station; private byte station;
private Integer layer; private Integer layer;
private DeviceSrgv deviceSrgv;
private boolean success = false; private boolean success = false;
private IByteTransform byteTransform = null; private IByteTransform byteTransform = null;
public PlcSrgvRead(ConcurrentHashMap<String, DeviceSrgv> deviceSrgvMap, PlcConnectInfo plcConnectInfo){ public PlcSrgvRead(DeviceSrgv deviceSrgv, PlcConnectInfo plcConnectInfo) {
PlcSrgvRead.deviceSrgvMap = deviceSrgvMap; this.deviceSrgv = deviceSrgv;
this.ip = plcConnectInfo.getIp(); this.ip = plcConnectInfo.getIp();
this.port = plcConnectInfo.getPort(); this.port = plcConnectInfo.getPort();
this.station = (byte) 1; this.station = (byte) 1;
} }
public static int WriteToSSJ(String address, byte[] data) { public static int WriteToSSJ(String address, byte[] data) {
int a = 0; int a = 0;
if (readWriteNet != null) { if (readWriteNet != null) {
@@ -42,17 +45,15 @@ public class PlcSrgvRead implements Runnable{
} }
@Override @Override
public void run() { public void run() {
while (isRun) { while (isRun) {
try { try {
if (IsConnect()) { if (IsConnect()) {
for(String srgvId:deviceSrgvMap.keySet()){
DeviceSrgv deviceSrgv = deviceSrgvMap.get(srgvId);
if (deviceSrgv != null) { if (deviceSrgv != null) {
readSrgvPlc(deviceSrgv); readSrgvPlc(deviceSrgv);
}
} }
Thread.sleep(1000); Thread.sleep(1000);
@@ -69,6 +70,7 @@ public class PlcSrgvRead implements Runnable{
} }
} }
private void readSrgvPlc(DeviceSrgv deviceSrgv) { private void readSrgvPlc(DeviceSrgv deviceSrgv) {
OperateResultExOne<byte[]> read1 = modbusTcpNet.Read("2400", (short) 15);//2400-2414 OperateResultExOne<byte[]> read1 = modbusTcpNet.Read("2400", (short) 15);//2400-2414
if (read1.IsSuccess) { if (read1.IsSuccess) {
@@ -163,6 +165,7 @@ public class PlcSrgvRead implements Runnable{
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage()); log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage());
} }
} }
public void setIsConnect(boolean bflag) { public void setIsConnect(boolean bflag) {
if (!success) { if (!success) {
success = bflag; success = bflag;
@@ -175,6 +178,7 @@ public class PlcSrgvRead implements Runnable{
} }
return false; return false;
} }
void reConnect() { void reConnect() {
closeServer(); closeServer();
ConnectServer(); ConnectServer();