输送线
This commit is contained in:
@@ -4,9 +4,12 @@ import com.ruoyi.common.domain.CustomThread;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
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.service.IDeviceSsjService;
|
||||
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.scheduleTask.ddj.impl.Ddj1Thread;
|
||||
import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread;
|
||||
@@ -25,12 +28,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class ScheduleThread {
|
||||
|
||||
public CustomThread<PlcSsjRead> plcSsjReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj1ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj2ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj3ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj4ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj5ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj6ReadCustomThread;
|
||||
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread1;
|
||||
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread2;
|
||||
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread3;
|
||||
|
||||
public CustomThread<MonitoringThread> monitoringCustomThread;
|
||||
public CustomThread<SsjThread> ssjThreadCustomThread;
|
||||
@@ -44,6 +44,8 @@ public class ScheduleThread {
|
||||
private IDeviceSsjService deviceSsjService;
|
||||
@Autowired
|
||||
private IMsgDdjService msgDdjService;
|
||||
@Autowired
|
||||
private IDeviceSrgvService deviceSrgvService;
|
||||
|
||||
private boolean isRun = false;
|
||||
private boolean isRun2 = false;
|
||||
@@ -94,56 +96,37 @@ public class ScheduleThread {
|
||||
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
|
||||
}
|
||||
|
||||
|
||||
//plc输送机读取线程
|
||||
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcSsjReadThread = new Thread(plcSsjRead);
|
||||
plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead);
|
||||
|
||||
//plc堆垛机读取现场
|
||||
ConcurrentHashMap<String, MsgDdj> ddjList = new ConcurrentHashMap<>();
|
||||
List<MsgDdj> msgDdjs = msgDdjService.selectMsgDdjList(new MsgDdj());
|
||||
for (MsgDdj msgDdj : msgDdjs) {
|
||||
switch (msgDdj.getId()){
|
||||
ConcurrentHashMap<String, DeviceSrgv> srgvList = new ConcurrentHashMap<>();
|
||||
List<DeviceSrgv> srgvs=deviceSrgvService.selectDeviceSrgvList(new DeviceSrgv());
|
||||
for(DeviceSrgv srgv:srgvs){
|
||||
srgvList.put(srgv.getDeviceId().toString(),srgv);
|
||||
switch (srgv.getDeviceId()){
|
||||
case 1:
|
||||
msgDdj.setPlcDbReadAddress("DB41.0");
|
||||
PlcDdjRead plcDdjRead1 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread1 = new Thread(plcDdjRead1);
|
||||
plcDdj1ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread1, plcDdjRead1);
|
||||
PlcSrgvRead plcSrgvRead1=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
|
||||
Thread plcSrgvReadThread1 = new Thread((plcSrgvRead1));
|
||||
plcSrgvReadCustomThread1=new CustomThread<PlcSrgvRead>(plcSrgvReadThread1,plcSrgvRead1);
|
||||
break;
|
||||
case 2:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead2 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.2", 102));
|
||||
Thread plcDdjReadThread2 = new Thread(plcDdjRead2);
|
||||
plcDdj2ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread2, plcDdjRead2);
|
||||
PlcSrgvRead plcSrgvRead2=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
|
||||
Thread plcSrgvReadThread2 = new Thread((plcSrgvRead2));
|
||||
plcSrgvReadCustomThread2=new CustomThread<PlcSrgvRead>(plcSrgvReadThread2,plcSrgvRead2);
|
||||
break;
|
||||
case 3:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead3 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.3", 102));
|
||||
Thread plcDdjReadThread3 = new Thread(plcDdjRead3);
|
||||
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);
|
||||
PlcSrgvRead plcSrgvRead3=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
|
||||
Thread plcSrgvReadThread3 = new Thread((plcSrgvRead3));
|
||||
plcSrgvReadCustomThread3=new CustomThread<PlcSrgvRead>(plcSrgvReadThread3,plcSrgvRead3);
|
||||
break;
|
||||
}
|
||||
ddjList.put("ddj" + msgDdj.getId(), msgDdj);
|
||||
|
||||
}
|
||||
PlcSrgvRead.deviceSrgvMap=srgvList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,12 +134,10 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void startAllThread() {
|
||||
plcSsjReadCustomThread.getThread().start();
|
||||
plcDdj1ReadCustomThread.getThread().start();
|
||||
plcDdj2ReadCustomThread.getThread().start();
|
||||
plcDdj3ReadCustomThread.getThread().start();
|
||||
plcDdj4ReadCustomThread.getThread().start();
|
||||
plcDdj5ReadCustomThread.getThread().start();
|
||||
plcDdj6ReadCustomThread.getThread().start();
|
||||
plcSrgvReadCustomThread1.getThread().start();
|
||||
plcSrgvReadCustomThread2.getThread().start();
|
||||
plcSrgvReadCustomThread3.getThread().start();
|
||||
|
||||
isRun = true;
|
||||
}
|
||||
|
||||
@@ -180,7 +161,7 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void stopAllThread() {
|
||||
plcSsjReadCustomThread.runnable.isRun = false;
|
||||
plcDdj1ReadCustomThread.runnable.isRun = false;
|
||||
// plcDdj1ReadCustomThread.runnable.isRun = false;
|
||||
/* plcDdj2ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj3ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj4ReadCustomThread.runnable.isRun = false;
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
public class PlcSrgvRead implements Runnable {
|
||||
|
||||
@@ -24,15 +25,17 @@ public class PlcSrgvRead implements Runnable{
|
||||
private final int port;
|
||||
private byte station;
|
||||
private Integer layer;
|
||||
private DeviceSrgv deviceSrgv;
|
||||
private boolean success = false;
|
||||
private IByteTransform byteTransform = null;
|
||||
|
||||
public PlcSrgvRead(ConcurrentHashMap<String, DeviceSrgv> deviceSrgvMap, PlcConnectInfo plcConnectInfo){
|
||||
PlcSrgvRead.deviceSrgvMap = deviceSrgvMap;
|
||||
public PlcSrgvRead(DeviceSrgv deviceSrgv, PlcConnectInfo plcConnectInfo) {
|
||||
this.deviceSrgv = deviceSrgv;
|
||||
this.ip = plcConnectInfo.getIp();
|
||||
this.port = plcConnectInfo.getPort();
|
||||
this.station = (byte) 1;
|
||||
}
|
||||
|
||||
public static int WriteToSSJ(String address, byte[] data) {
|
||||
int a = 0;
|
||||
if (readWriteNet != null) {
|
||||
@@ -42,17 +45,15 @@ public class PlcSrgvRead implements Runnable{
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (isRun) {
|
||||
try {
|
||||
if (IsConnect()) {
|
||||
for(String srgvId:deviceSrgvMap.keySet()){
|
||||
DeviceSrgv deviceSrgv = deviceSrgvMap.get(srgvId);
|
||||
|
||||
if (deviceSrgv != null) {
|
||||
readSrgvPlc(deviceSrgv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
@@ -69,6 +70,7 @@ public class PlcSrgvRead implements Runnable{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void readSrgvPlc(DeviceSrgv deviceSrgv) {
|
||||
OperateResultExOne<byte[]> read1 = modbusTcpNet.Read("2400", (short) 15);//2400-2414
|
||||
if (read1.IsSuccess) {
|
||||
@@ -163,6 +165,7 @@ public class PlcSrgvRead implements Runnable{
|
||||
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsConnect(boolean bflag) {
|
||||
if (!success) {
|
||||
success = bflag;
|
||||
@@ -175,6 +178,7 @@ public class PlcSrgvRead implements Runnable{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void reConnect() {
|
||||
closeServer();
|
||||
ConnectServer();
|
||||
|
||||
Reference in New Issue
Block a user