Compare commits
2 Commits
07e365efb4
...
813c12e130
| Author | SHA1 | Date | |
|---|---|---|---|
| 813c12e130 | |||
| acd00b0678 |
|
|
@ -2,13 +2,11 @@ package org.wcs.business.data.impl;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.wcs.business.data.intf.IDataLoader;
|
import org.wcs.business.data.intf.IDataLoader;
|
||||||
|
import org.wcs.business.redis.DbAddressRedis;
|
||||||
import org.wcs.mapper.intf.*;
|
import org.wcs.mapper.intf.*;
|
||||||
import org.wcs.model.po.app.*;
|
import org.wcs.model.po.app.*;
|
||||||
import org.wcs.plugin.plc.common.PlcCommonData;
|
|
||||||
import org.wcs.plugin.plc.model.SiemensDBAddress;
|
import org.wcs.plugin.plc.model.SiemensDBAddress;
|
||||||
import org.wcs.plugin.webHttpClient.WebHttpClient;
|
import org.wcs.plugin.webHttpClient.WebHttpClient;
|
||||||
import org.wcs.plugin.webHttpClient.model.HttpAddressKeyItem;
|
import org.wcs.plugin.webHttpClient.model.HttpAddressKeyItem;
|
||||||
|
|
@ -24,7 +22,7 @@ import java.util.*;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DataLoader implements IDataLoader {
|
public class DataLoader implements IDataLoader {
|
||||||
|
|
||||||
private final StringRedisTemplate stringRedisTemplate;
|
private final DbAddressRedis dbAddressRedis;
|
||||||
private final AppStackerInfoService stackerInfoService;
|
private final AppStackerInfoService stackerInfoService;
|
||||||
private final AppStackerStandService stackerStandService;
|
private final AppStackerStandService stackerStandService;
|
||||||
private final AppTrayConveyLocationService trayConveyLocationService;
|
private final AppTrayConveyLocationService trayConveyLocationService;
|
||||||
|
|
@ -38,7 +36,7 @@ public class DataLoader implements IDataLoader {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void loadDBAddress() {
|
public void loadDBAddress() {
|
||||||
clearDBAddressRedis(); // 清理DB地址缓存
|
dbAddressRedis.clearDbAddress(); // 清理DB地址缓存
|
||||||
loadStackerDBAddress(); // 加载堆垛机DB地址
|
loadStackerDBAddress(); // 加载堆垛机DB地址
|
||||||
loadStackerStandDBAddress(); // 加载堆垛机站台DB地址
|
loadStackerStandDBAddress(); // 加载堆垛机站台DB地址
|
||||||
loadTrayConveyDBAddress(); // 加载托盘输送DB地址
|
loadTrayConveyDBAddress(); // 加载托盘输送DB地址
|
||||||
|
|
@ -47,15 +45,6 @@ public class DataLoader implements IDataLoader {
|
||||||
loadDbTableAddress(); // 加载数据库表地址
|
loadDbTableAddress(); // 加载数据库表地址
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除DB地址缓存
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void clearDBAddressRedis() {
|
|
||||||
Set<String> keys = stringRedisTemplate.keys(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":*");
|
|
||||||
long delete = stringRedisTemplate.delete(keys);
|
|
||||||
log.info("清除DB地址缓存结果:{}", delete);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载堆垛机数据DB地址
|
* 加载堆垛机数据DB地址
|
||||||
|
|
@ -98,9 +87,7 @@ public class DataLoader implements IDataLoader {
|
||||||
siemensDBAddressMap.put(taskStatusDbAddress.getDbName(), taskStatusDbAddress);
|
siemensDBAddressMap.put(taskStatusDbAddress.getDbName(), taskStatusDbAddress);
|
||||||
}
|
}
|
||||||
log.info("堆垛机DB数据加载完成,数据行数:{}", siemensDBAddressMap.size());
|
log.info("堆垛机DB数据加载完成,数据行数:{}", siemensDBAddressMap.size());
|
||||||
siemensDBAddressMap.forEach((dbName, dbAddress) -> {
|
siemensDBAddressMap.forEach(dbAddressRedis::setDbAddress);
|
||||||
stringRedisTemplate.opsForValue().set(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,9 +121,7 @@ public class DataLoader implements IDataLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("堆垛机站台DB数据加载完成,数据行数:{}", siemensDBAddressMap.size());
|
log.info("堆垛机站台DB数据加载完成,数据行数:{}", siemensDBAddressMap.size());
|
||||||
siemensDBAddressMap.forEach((dbName, dbAddress) -> {
|
siemensDBAddressMap.forEach(dbAddressRedis::setDbAddress);
|
||||||
stringRedisTemplate.opsForValue().set(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -167,9 +152,7 @@ public class DataLoader implements IDataLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("初始化托盘输送DB数据完成,数据行数:{}", siemensDBAddressMap.size());
|
log.info("初始化托盘输送DB数据完成,数据行数:{}", siemensDBAddressMap.size());
|
||||||
siemensDBAddressMap.forEach((dbName, dbAddress) -> {
|
siemensDBAddressMap.forEach(dbAddressRedis::setDbAddress);
|
||||||
stringRedisTemplate.opsForValue().set(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -203,9 +186,7 @@ public class DataLoader implements IDataLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("初始化箱式线输送DB地址完成,数据行数:{}", siemensDBAddressMap.size());
|
log.info("初始化箱式线输送DB地址完成,数据行数:{}", siemensDBAddressMap.size());
|
||||||
siemensDBAddressMap.forEach((dbName, dbAddress) -> {
|
siemensDBAddressMap.forEach(dbAddressRedis::setDbAddress);
|
||||||
stringRedisTemplate.opsForValue().set(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -227,9 +208,7 @@ public class DataLoader implements IDataLoader {
|
||||||
siemensDBAddressMap.put(baseDbAddress.getDbName(), baseDbAddress);
|
siemensDBAddressMap.put(baseDbAddress.getDbName(), baseDbAddress);
|
||||||
}
|
}
|
||||||
log.info("初始化DB地址表完成,数据行数:{}", siemensDBAddressMap.size());
|
log.info("初始化DB地址表完成,数据行数:{}", siemensDBAddressMap.size());
|
||||||
siemensDBAddressMap.forEach((dbName, dbAddress) -> {
|
siemensDBAddressMap.forEach(dbAddressRedis::setDbAddress);
|
||||||
stringRedisTemplate.opsForValue().set(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -262,9 +241,7 @@ public class DataLoader implements IDataLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("初始化扫描器DB地址完成,数据行数:{}", siemensDBAddressMap.size());
|
log.info("初始化扫描器DB地址完成,数据行数:{}", siemensDBAddressMap.size());
|
||||||
siemensDBAddressMap.forEach((dbName, dbAddress) -> {
|
siemensDBAddressMap.forEach(dbAddressRedis::setDbAddress);
|
||||||
stringRedisTemplate.opsForValue().set(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,6 @@ public interface IDataLoader {
|
||||||
*/
|
*/
|
||||||
void loadDBAddress();
|
void loadDBAddress();
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除 DB 地址缓存
|
|
||||||
*/
|
|
||||||
void clearDBAddressRedis();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载堆垛机 DB 地址
|
* 加载堆垛机 DB 地址
|
||||||
|
|
|
||||||
63
wcs/src/main/java/org/wcs/business/redis/DbAddressRedis.java
Normal file
63
wcs/src/main/java/org/wcs/business/redis/DbAddressRedis.java
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.wcs.business.redis;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.wcs.constant.ConstantData;
|
||||||
|
import org.wcs.plugin.plc.common.PlcCommonData;
|
||||||
|
import org.wcs.plugin.plc.model.SiemensDBAddress;
|
||||||
|
import org.wcs.utils.AppStringUtils;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PLC地址缓存
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DbAddressRedis {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis操作类
|
||||||
|
*/
|
||||||
|
private final StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
// 地址缓存key
|
||||||
|
private final String PLC_DB_ADDRESS_REDIS_KEY = ConstantData.SYSTEM_NAME + ":PLC:DBAddress";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除PLC地址缓存
|
||||||
|
*/
|
||||||
|
public void clearDbAddress() {
|
||||||
|
stringRedisTemplate.delete(PLC_DB_ADDRESS_REDIS_KEY);
|
||||||
|
Set<String> keys = stringRedisTemplate.keys(PLC_DB_ADDRESS_REDIS_KEY + ":*");
|
||||||
|
stringRedisTemplate.delete(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存PLC地址信息
|
||||||
|
* @param dbName 地址名称
|
||||||
|
* @param dbAddress 地址信息
|
||||||
|
*/
|
||||||
|
public void setDbAddress(String dbName, SiemensDBAddress dbAddress) {
|
||||||
|
stringRedisTemplate.opsForValue().set(PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName, AppStringUtils.objectToString(dbAddress));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取PLC地址信息
|
||||||
|
* @param dbName 地址名称
|
||||||
|
* @return 地址 信息
|
||||||
|
*/
|
||||||
|
public SiemensDBAddress getDbAddress(String dbName) {
|
||||||
|
String dbJson = stringRedisTemplate.opsForValue().get(PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName);
|
||||||
|
if(AppStringUtils.isEmpty(dbJson)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return AppStringUtils.stringToObject(dbJson, SiemensDBAddress.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,62 +1,28 @@
|
||||||
package org.wcs.plugin.plc;
|
package org.wcs.plugin.plc;
|
||||||
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.wcs.constant.enums.database.PlcTypeEnum;
|
import org.wcs.constant.enums.database.PlcTypeEnum;
|
||||||
import org.wcs.mapper.intf.AppBasePlcService;
|
import org.wcs.mapper.intf.AppBasePlcService;
|
||||||
import org.wcs.model.bo.tuple.Tuple3;
|
|
||||||
import org.wcs.model.po.app.AppBasePlc;
|
import org.wcs.model.po.app.AppBasePlc;
|
||||||
import org.wcs.plugin.plc.common.PlcCommonData;
|
|
||||||
import org.wcs.plugin.plc.communication.IPlcCommunication;
|
import org.wcs.plugin.plc.communication.IPlcCommunication;
|
||||||
import org.wcs.plugin.plc.communication.PlcSiemensCommunication;
|
import org.wcs.plugin.plc.communication.PlcSiemensCommunication;
|
||||||
import org.wcs.plugin.plc.model.SiemensDBAddress;
|
|
||||||
import org.wcs.utils.AppStringUtils;
|
|
||||||
import org.wcs.utils.SpringUtils;
|
import org.wcs.utils.SpringUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class PlcCommunicationFactory {
|
public class PlcCommunicationFactory {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PLC通讯对象 <PLC类型,PLC通讯类>
|
* PLC通讯对象 <PLCID,PLC通讯类>
|
||||||
*/
|
*/
|
||||||
private static Map<Integer, IPlcCommunication> plcCommunicationMap;
|
private static Map<Integer, IPlcCommunication> plcCommunicationMap;
|
||||||
|
|
||||||
/**
|
|
||||||
* PLCID <PLCID,PLC类型>
|
|
||||||
*/
|
|
||||||
private static Map<Integer, Integer> plcIdMap;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册PLC
|
|
||||||
*/
|
|
||||||
public static void registerPlcCommunication() {
|
|
||||||
setPlcCommunicationMap(); // 加载PLC通讯对象
|
|
||||||
setPlcIdMap(); // 加载PLCID和PLC类型的对应关系
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过PLC类型获取PLC通讯对象
|
|
||||||
*
|
|
||||||
* @param plcType PLC类型
|
|
||||||
* @return PLC通讯对象 --- 若不存在则返回西门子方法
|
|
||||||
*/
|
|
||||||
public static IPlcCommunication getPlcCommunicationByPlcType(Integer plcType) {
|
|
||||||
registerPlcCommunication();
|
|
||||||
IPlcCommunication iPlcCommunication;
|
|
||||||
if (plcCommunicationMap.containsKey(plcType)) {
|
|
||||||
iPlcCommunication = plcCommunicationMap.get(plcType);
|
|
||||||
} else {
|
|
||||||
iPlcCommunication = new PlcSiemensCommunication();
|
|
||||||
}
|
|
||||||
iPlcCommunication.initialize(); // 调用初始化方法
|
|
||||||
return iPlcCommunication;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过PLCID获取PLC通讯对象
|
* 通过PLCID获取PLC通讯对象
|
||||||
*
|
*
|
||||||
|
|
@ -64,24 +30,14 @@ public class PlcCommunicationFactory {
|
||||||
* @return PLC通讯对象 --- 若不存在则返回西门子方法
|
* @return PLC通讯对象 --- 若不存在则返回西门子方法
|
||||||
*/
|
*/
|
||||||
public static IPlcCommunication getPlcCommunicationByPlcId(Integer plcId) {
|
public static IPlcCommunication getPlcCommunicationByPlcId(Integer plcId) {
|
||||||
registerPlcCommunication();
|
setPlcCommunicationMap(); // 初始化PLC通讯对象
|
||||||
if(plcId == null) {
|
if(plcId == null) {
|
||||||
return getPlcCommunicationByPlcType(PlcTypeEnum.SIEMENS.getCode());
|
return null;
|
||||||
}
|
}
|
||||||
if(plcIdMap.containsKey(plcId)) {
|
if(plcCommunicationMap.containsKey(plcId)) {
|
||||||
return getPlcCommunicationByPlcType(plcIdMap.get(plcId));
|
return plcCommunicationMap.get(plcId);
|
||||||
}
|
}
|
||||||
return getPlcCommunicationByPlcType(PlcTypeEnum.SIEMENS.getCode());
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取西门子方法
|
|
||||||
*
|
|
||||||
* @return 西门子方法
|
|
||||||
*/
|
|
||||||
public static IPlcCommunication siemens() {
|
|
||||||
return getPlcCommunicationByPlcType(PlcTypeEnum.SIEMENS.getCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -91,38 +47,29 @@ public class PlcCommunicationFactory {
|
||||||
* 加载PLC通讯对象
|
* 加载PLC通讯对象
|
||||||
*/
|
*/
|
||||||
private static void setPlcCommunicationMap() {
|
private static void setPlcCommunicationMap() {
|
||||||
if(plcCommunicationMap == null) {
|
if(plcCommunicationMap == null || plcCommunicationMap.isEmpty()) {
|
||||||
plcCommunicationMap = new HashMap<>();
|
plcCommunicationMap = new HashMap<>();
|
||||||
}
|
} else {
|
||||||
if(!plcCommunicationMap.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 添加西门子方法
|
|
||||||
IPlcCommunication plcCommunication = new PlcSiemensCommunication();
|
|
||||||
plcCommunicationMap.put(PlcTypeEnum.SIEMENS.getCode(), plcCommunication);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载PLCID
|
|
||||||
*/
|
|
||||||
private static void setPlcIdMap() {
|
|
||||||
if(plcIdMap == null) {
|
|
||||||
plcIdMap = new HashMap<>();
|
|
||||||
}
|
|
||||||
if(!plcIdMap.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AppBasePlcService bean = SpringUtils.getBean(AppBasePlcService.class);
|
AppBasePlcService bean = SpringUtils.getBean(AppBasePlcService.class);
|
||||||
List<AppBasePlc> basePlcs = bean.queryAll();
|
List<AppBasePlc> basePlcList = bean.queryAll();
|
||||||
if(basePlcs == null) {
|
if(basePlcList == null) {
|
||||||
|
log.info("初始化PLC连接时查询PLC信息失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(basePlcs.isEmpty()) {
|
for (AppBasePlc plcItem : basePlcList) {
|
||||||
plcIdMap.put(0, 0);
|
// 创建PLC操作对象
|
||||||
return;
|
Integer plcType = plcItem.getPlcType();
|
||||||
|
if(plcType == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(plcType.equals(PlcTypeEnum.SIEMENS.getCode())) {
|
||||||
|
log.info("初始化PLC连接:PLCID:{},PLC名称:{},PLC类型:{}", plcItem.getPlcId(), plcItem.getPlcName(), PlcTypeEnum.SIEMENS.getMessage());
|
||||||
|
IPlcCommunication plcCommunication = new PlcSiemensCommunication();
|
||||||
|
plcCommunication.initialize(plcItem);
|
||||||
|
plcCommunicationMap.put(plcItem.getPlcId(), plcCommunication);
|
||||||
}
|
}
|
||||||
for (AppBasePlc basePlc : basePlcs) {
|
|
||||||
plcIdMap.put(basePlc.getPlcId(), basePlc.getPlcType());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,5 @@ package org.wcs.plugin.plc.common;
|
||||||
|
|
||||||
public class PlcCommonData {
|
public class PlcCommonData {
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储DB信息的 redis key
|
|
||||||
*/
|
|
||||||
public static final String PLC_DB_ADDRESS_REDIS_KEY = "WCS:PLC:DBAddress";
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package org.wcs.plugin.plc.communication;
|
package org.wcs.plugin.plc.communication;
|
||||||
|
|
||||||
import org.wcs.model.bo.tuple.Tuple2;
|
import org.wcs.model.bo.tuple.Tuple2;
|
||||||
|
import org.wcs.model.po.app.AppBasePlc;
|
||||||
import org.wcs.plugin.plc.model.*;
|
import org.wcs.plugin.plc.model.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -13,8 +14,9 @@ public interface IPlcCommunication {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化 --- 当操作被绑定到指定PLC时都会调用一次此方法
|
* 初始化 --- 当操作被绑定到指定PLC时都会调用一次此方法
|
||||||
|
* @param plc PLC信息
|
||||||
*/
|
*/
|
||||||
void initialize();
|
void initialize(AppBasePlc plc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定堆垛机状态
|
* 获取指定堆垛机状态
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,13 @@ import HslCommunication.Core.Types.OperateResultExOne;
|
||||||
import HslCommunication.Profinet.Siemens.SiemensPLCS;
|
import HslCommunication.Profinet.Siemens.SiemensPLCS;
|
||||||
import HslCommunication.Profinet.Siemens.SiemensS7Net;
|
import HslCommunication.Profinet.Siemens.SiemensS7Net;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.wcs.business.redis.DbAddressRedis;
|
||||||
|
import org.wcs.constant.ConstantData;
|
||||||
import org.wcs.constant.enums.plc.StackerTaskTypeEnum;
|
import org.wcs.constant.enums.plc.StackerTaskTypeEnum;
|
||||||
import org.wcs.mapper.intf.AppBasePlcService;
|
|
||||||
import org.wcs.model.bo.tuple.Tuple2;
|
import org.wcs.model.bo.tuple.Tuple2;
|
||||||
import org.wcs.model.bo.tuple.Tuple3;
|
|
||||||
import org.wcs.model.po.app.AppBasePlc;
|
import org.wcs.model.po.app.AppBasePlc;
|
||||||
import org.wcs.plugin.plc.common.PlcCommonData;
|
|
||||||
import org.wcs.plugin.plc.constant.PlcConfig;
|
import org.wcs.plugin.plc.constant.PlcConfig;
|
||||||
import org.wcs.plugin.plc.constant.PlcStackerTaskStatusEnum;
|
import org.wcs.plugin.plc.constant.PlcStackerTaskStatusEnum;
|
||||||
import org.wcs.plugin.plc.constant.PlcTypeEnum;
|
|
||||||
import org.wcs.plugin.plc.model.*;
|
import org.wcs.plugin.plc.model.*;
|
||||||
import org.wcs.utils.AppListUtils;
|
import org.wcs.utils.AppListUtils;
|
||||||
import org.wcs.utils.AppStringUtils;
|
import org.wcs.utils.AppStringUtils;
|
||||||
|
|
@ -25,7 +22,6 @@ import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 西门子PLC通讯类
|
* 西门子PLC通讯类
|
||||||
|
|
@ -34,20 +30,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
public class PlcSiemensCommunication implements IPlcCommunication {
|
public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
|
|
||||||
private boolean isActive = false; // 是否已经初始化
|
private boolean isActive = false; // 是否已经初始化
|
||||||
private Map<Integer, SiemensS7Net> plcS7Net = new ConcurrentHashMap<>(); // PLC 读写操作map
|
private boolean isConnected = false; // 是否已经连接
|
||||||
private Map<Integer, Boolean> plcIsConnect = new ConcurrentHashMap<>();
|
private SiemensS7Net siemensS7Net;// PLC 读写操作S7协议
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储plc基础信息
|
* DB地址的 redis 数据操作类
|
||||||
* <plcId, PlcBaseInfo>
|
|
||||||
*/
|
*/
|
||||||
private Map<Integer, PlcBaseInfo> plcBaseInfoMap = new ConcurrentHashMap<>();
|
private DbAddressRedis dbRedisTemplate;
|
||||||
|
|
||||||
/**
|
|
||||||
* redis 数据操作类
|
|
||||||
*/
|
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -55,7 +44,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize(AppBasePlc plc) {
|
||||||
if(isActive) {
|
if(isActive) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -67,56 +56,17 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
log.info("HslCommunication 组件组册失败,当前应用只能连续使用24小时,请联系本公司");
|
log.info("HslCommunication 组件组册失败,当前应用只能连续使用24小时,请联系本公司");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setPlcInfo(); // 设置PLC信息
|
if(!isConnected || siemensS7Net == null) {
|
||||||
setPlcS7Net(); // 设置PLC连接
|
connectPlc(plc); // 连接PLC
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置PLC信息
|
|
||||||
*/
|
|
||||||
private void setPlcInfo() {
|
|
||||||
if(!plcBaseInfoMap.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plcBaseInfoMap = new HashMap<>();
|
|
||||||
AppBasePlcService bean = SpringUtils.getBean(AppBasePlcService.class);
|
|
||||||
List<AppBasePlc> basePlcs = bean.queryAll();
|
|
||||||
if(basePlcs == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(basePlcs.isEmpty()) {
|
|
||||||
plcBaseInfoMap.put(0, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (AppBasePlc basePlc : basePlcs) {
|
|
||||||
PlcBaseInfo baseInfo = new PlcBaseInfo();
|
|
||||||
baseInfo.setPlcId(basePlc.getPlcId());
|
|
||||||
baseInfo.setPlcName(basePlc.getPlcName());
|
|
||||||
baseInfo.setPlcType(basePlc.getPlcType());
|
|
||||||
baseInfo.setPlcVersion(basePlc.getPlcVersion());
|
|
||||||
baseInfo.setPlcStatus(basePlc.getPlcStatus());
|
|
||||||
baseInfo.setIp(basePlc.getIp());
|
|
||||||
baseInfo.setPort(basePlc.getPort());
|
|
||||||
baseInfo.setSlot(basePlc.getSlot());
|
|
||||||
baseInfo.setRack(basePlc.getRack());
|
|
||||||
plcBaseInfoMap.put(baseInfo.getPlcId(), baseInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
private void connectPlc(AppBasePlc plc) {
|
||||||
* 设置PLC连接
|
if(isConnected) {
|
||||||
*/
|
|
||||||
private void setPlcS7Net() {
|
|
||||||
if(!plcS7Net.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plcS7Net = new HashMap<>(); // 初始化PLC连接
|
SiemensPLCS plcVersion = switch (plc.getPlcVersion()) {
|
||||||
plcBaseInfoMap.forEach((plcId, plcBaseInfo) -> {
|
|
||||||
if(!Objects.equals(plcBaseInfo.getPlcType(), PlcTypeEnum.SIEMENS.getCode())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SiemensPLCS plcVersion = switch (plcBaseInfo.getPlcVersion()) {
|
|
||||||
case "S200" -> SiemensPLCS.S200;
|
case "S200" -> SiemensPLCS.S200;
|
||||||
case "S200Smart" -> SiemensPLCS.S200Smart;
|
case "S200Smart" -> SiemensPLCS.S200Smart;
|
||||||
case "S1500" -> SiemensPLCS.S1500;
|
case "S1500" -> SiemensPLCS.S1500;
|
||||||
|
|
@ -124,15 +74,13 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
case "S400" -> SiemensPLCS.S400;
|
case "S400" -> SiemensPLCS.S400;
|
||||||
default -> SiemensPLCS.S1200;
|
default -> SiemensPLCS.S1200;
|
||||||
};
|
};
|
||||||
SiemensS7Net siemensS7Net = new SiemensS7Net(plcVersion, plcBaseInfo.getIp());
|
siemensS7Net = new SiemensS7Net(plcVersion, plc.getIp());
|
||||||
siemensS7Net.setPort(plcBaseInfo.getPort());
|
siemensS7Net.setPort(plc.getPort());
|
||||||
siemensS7Net.setRack(plcBaseInfo.getRack().byteValue());
|
siemensS7Net.setRack(plc.getRack().byteValue());
|
||||||
siemensS7Net.setSlot(plcBaseInfo.getSlot().byteValue());
|
siemensS7Net.setSlot(plc.getSlot().byteValue());
|
||||||
siemensS7Net.setConnectTimeOut(2000);
|
siemensS7Net.setConnectTimeOut(2000);
|
||||||
OperateResult operateResult = siemensS7Net.ConnectServer();
|
OperateResult operateResult = siemensS7Net.ConnectServer();
|
||||||
plcS7Net.put(plcId, siemensS7Net);
|
isConnected = operateResult.IsSuccess;
|
||||||
plcIsConnect.put(plcId, operateResult.IsSuccess);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -140,28 +88,11 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
* 查找该地址的信息
|
* 查找该地址的信息
|
||||||
* @return < 异常信息,DB地址,plc连接实例>
|
* @return < 异常信息,DB地址,plc连接实例>
|
||||||
*/
|
*/
|
||||||
private Tuple3<String, String, SiemensS7Net> getDbPlcData(String dbName) {
|
private SiemensDBAddress getDbPlcData(String dbName) {
|
||||||
if(stringRedisTemplate == null) {
|
if(dbRedisTemplate == null) {
|
||||||
stringRedisTemplate = SpringUtils.getBean(StringRedisTemplate.class);
|
dbRedisTemplate = SpringUtils.getBean(DbAddressRedis.class);
|
||||||
}
|
}
|
||||||
String dbJson = stringRedisTemplate.opsForValue().get(PlcCommonData.PLC_DB_ADDRESS_REDIS_KEY + ":" + dbName);
|
return dbRedisTemplate.getDbAddress(dbName);
|
||||||
if(AppStringUtils.isEmpty(dbJson)) {
|
|
||||||
return new Tuple3<>("PLC数据库地址不存在,名称:" + dbName, null, null);
|
|
||||||
}
|
|
||||||
SiemensDBAddress siemensDBAddress = AppStringUtils.stringToObject(dbJson, SiemensDBAddress.class);
|
|
||||||
if(siemensDBAddress == null) {
|
|
||||||
return new Tuple3<>("DB名称对应的地址不存在,名称:" + dbName, null, null);
|
|
||||||
}
|
|
||||||
SiemensS7Net siemensS7Net = plcS7Net.get(siemensDBAddress.getPlcId());
|
|
||||||
if(siemensS7Net == null) {
|
|
||||||
return new Tuple3<>("PLC连接不存在,PLC编号:" + siemensDBAddress.getPlcId(), null, null);
|
|
||||||
}
|
|
||||||
Boolean isConnected = plcIsConnect.get(siemensDBAddress.getPlcId());
|
|
||||||
if(isConnected == null || !isConnected) {
|
|
||||||
OperateResult operateResult = siemensS7Net.ConnectServer();
|
|
||||||
plcIsConnect.put(siemensDBAddress.getPlcId(), operateResult.IsSuccess);
|
|
||||||
}
|
|
||||||
return new Tuple3<>(null, siemensDBAddress.getDbAddress(), siemensS7Net);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -172,12 +103,11 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
@Override
|
@Override
|
||||||
public Tuple2<String, StackerStatus> readStackerStatus(Integer stackerId) {
|
public Tuple2<String, StackerStatus> readStackerStatus(Integer stackerId) {
|
||||||
String dbName = "*堆垛机状态" + stackerId;
|
String dbName = "*堆垛机状态" + stackerId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return new Tuple2<>(plcData.item1, null);
|
return new Tuple2<>("地址不存在", null);
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.getDbAddress(), (short)50);
|
||||||
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.item2, (short)50);
|
|
||||||
if(!readResult.IsSuccess) {
|
if(!readResult.IsSuccess) {
|
||||||
return new Tuple2<>(readResult.Message, null);
|
return new Tuple2<>(readResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -209,21 +139,20 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
if(stackerId == null || task == null || task.length < 1) {
|
if(stackerId == null || task == null || task.length < 1) {
|
||||||
return "传入的参数不正确";
|
return "传入的参数不正确";
|
||||||
}
|
}
|
||||||
String dbName = "*堆垛机写任务" + stackerId;
|
String writeTaskDbName = "*堆垛机写任务" + stackerId;
|
||||||
String taskConfirmDbName = "*堆垛机写任务确认" + stackerId;
|
String taskConfirmDbName = "*堆垛机写任务确认" + stackerId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress writeTaskPlcData = getDbPlcData(writeTaskDbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(writeTaskPlcData == null || writeTaskPlcData.getDbAddress() == null) {
|
||||||
return plcData.item1;
|
return "写入任务的地址不存在";
|
||||||
}
|
}
|
||||||
Tuple3<String, String, SiemensS7Net> plcDataTaskConfirm = getDbPlcData(taskConfirmDbName);
|
SiemensDBAddress taskConfirmPlcData = getDbPlcData(taskConfirmDbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcDataTaskConfirm.item1)) {
|
if(taskConfirmPlcData == null) {
|
||||||
return plcDataTaskConfirm.item1;
|
return "写入任务确认的地址不存在";
|
||||||
}
|
}
|
||||||
String[] writeTaskDbs = plcData.item2.split(";");
|
String[] writeTaskDbs = writeTaskPlcData.getDbAddress().split(";");
|
||||||
if(writeTaskDbs.length != task.length) {
|
if(writeTaskDbs.length != task.length) {
|
||||||
return "传入的任务数量与堆垛机接受的任务数量不一致";
|
return "传入的任务数量与堆垛机接受的任务数量不一致";
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
|
||||||
boolean isWrite = false; // 是否写入任务
|
boolean isWrite = false; // 是否写入任务
|
||||||
for (int i = 0; i < task.length; i++) {
|
for (int i = 0; i < task.length; i++) {
|
||||||
StackerTask stackerTask = task[i];
|
StackerTask stackerTask = task[i];
|
||||||
|
|
@ -275,9 +204,9 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
if(!isWrite) {
|
if(!isWrite) {
|
||||||
return "没有写入任务,请检查是否传入的任务都为空";
|
return "没有写入任务,请检查是否传入的任务都为空";
|
||||||
}
|
}
|
||||||
if(AppStringUtils.isNotEmpty(plcDataTaskConfirm.item2)) {
|
if(AppStringUtils.isNotEmpty(taskConfirmPlcData.getDbAddress()) || !taskConfirmPlcData.getDbAddress().equals(ConstantData.OCCUPY_CHAR)) {
|
||||||
// 写入任务确认
|
// 写入任务确认
|
||||||
OperateResult operateResult = plcDataTaskConfirm.item3.Write(plcDataTaskConfirm.item2, (short) 1);
|
OperateResult operateResult = siemensS7Net.Write(taskConfirmPlcData.getDbAddress(), (short) 1);
|
||||||
if (!operateResult.IsSuccess) {
|
if (!operateResult.IsSuccess) {
|
||||||
return operateResult.Message;
|
return operateResult.Message;
|
||||||
}
|
}
|
||||||
|
|
@ -296,12 +225,11 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String dbName = "*堆垛机过账区" + stackerId;
|
String dbName = "*堆垛机过账区" + stackerId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.getDbAddress(), (short)(PlcConfig.PLC_CONFIG_CHECK_ACCOUNT_LENGTH * 6));
|
||||||
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.item2, (short)(PlcConfig.PLC_CONFIG_CHECK_ACCOUNT_LENGTH * 6));
|
|
||||||
if(!readResult.IsSuccess) {
|
if(!readResult.IsSuccess) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -330,12 +258,11 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return "传入的参数存在问题";
|
return "传入的参数存在问题";
|
||||||
}
|
}
|
||||||
String dbName = "*堆垛机过账区" + stackerId;
|
String dbName = "*堆垛机过账区" + stackerId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return plcData.item1;
|
return "地址不存在";
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
String dbAddress = plcData.getDbAddress();
|
||||||
String dbAddress = plcData.item2;
|
|
||||||
if(AppStringUtils.isEmpty(dbAddress)) {
|
if(AppStringUtils.isEmpty(dbAddress)) {
|
||||||
return "过账区地址不正确";
|
return "过账区地址不正确";
|
||||||
}
|
}
|
||||||
|
|
@ -347,7 +274,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
int dbAddressSuffix = Integer.parseInt(addressDetails[1]);
|
int dbAddressSuffix = Integer.parseInt(addressDetails[1]);
|
||||||
int newDbAddressSuffix = dbAddressSuffix + taskIndex * 6;
|
int newDbAddressSuffix = dbAddressSuffix + taskIndex * 6;
|
||||||
String newDbAddress = dbAddressHeader + "." + newDbAddressSuffix;
|
String newDbAddress = dbAddressHeader + "." + newDbAddressSuffix;
|
||||||
OperateResult operateResult = siemensS7Net.Write(newDbAddress, (int)0);
|
OperateResult operateResult = siemensS7Net.Write(newDbAddress, 0);
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return operateResult.Message;
|
return operateResult.Message;
|
||||||
}
|
}
|
||||||
|
|
@ -362,12 +289,11 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
@Override
|
@Override
|
||||||
public Tuple2<String, TaskConveyStatus> readTaskConveyStatus(String conveyId) {
|
public Tuple2<String, TaskConveyStatus> readTaskConveyStatus(String conveyId) {
|
||||||
String dbName = "*输送机状态" + conveyId;
|
String dbName = "*输送机状态" + conveyId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return new Tuple2<>(plcData.item1, null);
|
return new Tuple2<>("地址不存在", null);
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.getDbAddress(), (short)(22 + PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH));
|
||||||
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.item2, (short)(22 + PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH));
|
|
||||||
if(!readResult.IsSuccess) {
|
if(!readResult.IsSuccess) {
|
||||||
return new Tuple2<>(readResult.Message, null);
|
return new Tuple2<>(readResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -394,13 +320,12 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
@Override
|
@Override
|
||||||
public Tuple2<String, List<TaskConveyStatus>> readTaskMultiConveyStatus(String conveyId) {
|
public Tuple2<String, List<TaskConveyStatus>> readTaskMultiConveyStatus(String conveyId) {
|
||||||
String dbName = "*输送机状态" + conveyId;
|
String dbName = "*输送机状态" + conveyId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return new Tuple2<>(plcData.item1, null);
|
return new Tuple2<>("地址不存在", null);
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
|
||||||
List<TaskConveyStatus> taskConveyStatusList = new ArrayList<>();
|
List<TaskConveyStatus> taskConveyStatusList = new ArrayList<>();
|
||||||
String[] dbAddresses = plcData.item2.split(";");
|
String[] dbAddresses = plcData.getDbAddress().split(";");
|
||||||
for (String address : dbAddresses) {
|
for (String address : dbAddresses) {
|
||||||
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(address, (short)(22 + PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH));
|
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(address, (short)(22 + PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH));
|
||||||
if(!readResult.IsSuccess) {
|
if(!readResult.IsSuccess) {
|
||||||
|
|
@ -435,11 +360,10 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return "输送机ID和任务不能为空";
|
return "输送机ID和任务不能为空";
|
||||||
}
|
}
|
||||||
String dbName = "*输送机写任务" + conveyId;
|
String dbName = "*输送机写任务" + conveyId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return plcData.item1;
|
return "地址不存在";
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
|
||||||
List<Byte> bytes = new ArrayList<>();
|
List<Byte> bytes = new ArrayList<>();
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getPlcTaskId()))); // plc任务号
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getPlcTaskId()))); // plc任务号
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getTaskType()))); // 任务类型
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getTaskType()))); // 任务类型
|
||||||
|
|
@ -448,7 +372,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getVehicleSize() == null ? 0 : task.getVehicleSize()))); // 货尺寸
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getVehicleSize() == null ? 0 : task.getVehicleSize()))); // 货尺寸
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getWeight() == null ? 0 : task.getWeight()))); // 货重量
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getWeight() == null ? 0 : task.getWeight()))); // 货重量
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(AppStringUtils.toFixLength(task.getVehicleNo(), PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH, ' '), StandardCharsets.US_ASCII))); // 载具号
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(AppStringUtils.toFixLength(task.getVehicleNo(), PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH, ' '), StandardCharsets.US_ASCII))); // 载具号
|
||||||
OperateResult operateResult = siemensS7Net.Write(plcData.item2, AppListUtils.transfer(bytes));
|
OperateResult operateResult = siemensS7Net.Write(plcData.getDbAddress(), AppListUtils.transfer(bytes));
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return operateResult.Message;
|
return operateResult.Message;
|
||||||
}
|
}
|
||||||
|
|
@ -463,12 +387,11 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
@Override
|
@Override
|
||||||
public Tuple2<String, ScanInfo> readScannerInfo(String scannerId) {
|
public Tuple2<String, ScanInfo> readScannerInfo(String scannerId) {
|
||||||
String dbName = "*扫码器数据" + scannerId;
|
String dbName = "*扫码器数据" + scannerId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return new Tuple2<>(plcData.item1, null);
|
return new Tuple2<>("地址不存在", null);
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.getDbAddress(), (short)(20 + PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH));
|
||||||
OperateResultExOne<byte[]> readResult = siemensS7Net.Read(plcData.item2, (short)(20 + PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH));
|
|
||||||
if(!readResult.IsSuccess) {
|
if(!readResult.IsSuccess) {
|
||||||
return new Tuple2<>(readResult.Message, null);
|
return new Tuple2<>(readResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -496,11 +419,10 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return "传入的扫码器编号或者任务为空";
|
return "传入的扫码器编号或者任务为空";
|
||||||
}
|
}
|
||||||
String dbName = "*扫码器写任务" + scannerId;
|
String dbName = "*扫码器写任务" + scannerId;
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(dbName);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return plcData.item1;
|
return "地址不存在";
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
|
||||||
List<Byte> bytes = new ArrayList<>();
|
List<Byte> bytes = new ArrayList<>();
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getPlcTaskId() == null ? 0 : task.getPlcTaskId())));
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getPlcTaskId() == null ? 0 : task.getPlcTaskId())));
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getTaskType() == null ? 0 : task.getTaskType())));
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getTaskType() == null ? 0 : task.getTaskType())));
|
||||||
|
|
@ -512,7 +434,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getHeight() == null ? 0 : task.getHeight())));
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getHeight() == null ? 0 : task.getHeight())));
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getWeight() == null ? 0 : task.getWeight())));
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(task.getWeight() == null ? 0 : task.getWeight())));
|
||||||
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(AppStringUtils.toFixLength(task.getVehicleNo(), PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH, ' '), StandardCharsets.US_ASCII)));
|
bytes.addAll(AppListUtils.transfer(siemensS7Net.getByteTransform().TransByte(AppStringUtils.toFixLength(task.getVehicleNo(), PlcConfig.PLC_CONFIG_TASK_CONVEY_CODE_LENGTH, ' '), StandardCharsets.US_ASCII)));
|
||||||
OperateResult operateResult = siemensS7Net.Write(plcData.item2, AppListUtils.transfer(bytes));
|
OperateResult operateResult = siemensS7Net.Write(plcData.getDbAddress(), AppListUtils.transfer(bytes));
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return operateResult.Message;
|
return operateResult.Message;
|
||||||
}
|
}
|
||||||
|
|
@ -527,11 +449,10 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String writeWithName(String name, Object value) {
|
public String writeWithName(String name, Object value) {
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(name);
|
SiemensDBAddress plcData = getDbPlcData(name);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return plcData.item1;
|
return "地址不存在";
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
|
||||||
List<Byte> bytes = new ArrayList<>();
|
List<Byte> bytes = new ArrayList<>();
|
||||||
Class<?> valueClass = value.getClass();
|
Class<?> valueClass = value.getClass();
|
||||||
switch (valueClass.getName()) {
|
switch (valueClass.getName()) {
|
||||||
|
|
@ -559,7 +480,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
default:
|
default:
|
||||||
return "不支持的数据类型";
|
return "不支持的数据类型";
|
||||||
}
|
}
|
||||||
OperateResult operateResult = siemensS7Net.Write(plcData.item2, AppListUtils.transfer(bytes));
|
OperateResult operateResult = siemensS7Net.Write(plcData.getDbAddress(), AppListUtils.transfer(bytes));
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return operateResult.Message;
|
return operateResult.Message;
|
||||||
}
|
}
|
||||||
|
|
@ -568,12 +489,12 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取值从指定的DB地址名称
|
* 读取值从指定的DB地址名称
|
||||||
* @param name 数据库名称
|
* @param dbName 地址名称
|
||||||
* @param clazz 数据类型
|
* @param clazz 数据类型
|
||||||
* @return 读取结果
|
* @return 读取结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> Tuple2<String, T> readWithName(String name, Class<T> clazz) {
|
public <T> Tuple2<String, T> readWithName(String dbName, Class<T> clazz) {
|
||||||
// 获取T类型
|
// 获取T类型
|
||||||
Type[] actualTypeArguments = ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments();
|
Type[] actualTypeArguments = ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments();
|
||||||
if(actualTypeArguments.length < 1) {
|
if(actualTypeArguments.length < 1) {
|
||||||
|
|
@ -583,14 +504,13 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
if (!(type instanceof Class)) {
|
if (!(type instanceof Class)) {
|
||||||
return new Tuple2<>("不支持的复杂泛型类型", null);
|
return new Tuple2<>("不支持的复杂泛型类型", null);
|
||||||
}
|
}
|
||||||
Tuple3<String, String, SiemensS7Net> plcData = getDbPlcData(name);
|
SiemensDBAddress plcData = getDbPlcData(dbName);
|
||||||
if(AppStringUtils.isNotEmpty(plcData.item1)) {
|
if(plcData == null) {
|
||||||
return new Tuple2<>(plcData.item1, null);
|
return new Tuple2<>("地址不存在", null);
|
||||||
}
|
}
|
||||||
SiemensS7Net siemensS7Net = plcData.item3;
|
|
||||||
// 直接使用传入的clazz进行类型判断
|
// 直接使用传入的clazz进行类型判断
|
||||||
if(clazz == Integer.class) {
|
if(clazz == Integer.class) {
|
||||||
OperateResultExOne<Integer> operateResult = siemensS7Net.ReadInt32(plcData.item2);
|
OperateResultExOne<Integer> operateResult = siemensS7Net.ReadInt32(plcData.getDbAddress());
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return new Tuple2<>(operateResult.Message, null);
|
return new Tuple2<>(operateResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -599,7 +519,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return new Tuple2<>(null, result);
|
return new Tuple2<>(null, result);
|
||||||
}
|
}
|
||||||
if(clazz == Long.class) {
|
if(clazz == Long.class) {
|
||||||
OperateResultExOne<Long> operateResult = siemensS7Net.ReadInt64(plcData.item2);
|
OperateResultExOne<Long> operateResult = siemensS7Net.ReadInt64(plcData.getDbAddress());
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return new Tuple2<>(operateResult.Message, null);
|
return new Tuple2<>(operateResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -608,7 +528,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return new Tuple2<>(null, result);
|
return new Tuple2<>(null, result);
|
||||||
}
|
}
|
||||||
if(clazz == Short.class) {
|
if(clazz == Short.class) {
|
||||||
OperateResultExOne<Short> operateResult = siemensS7Net.ReadInt16(plcData.item2);
|
OperateResultExOne<Short> operateResult = siemensS7Net.ReadInt16(plcData.getDbAddress());
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return new Tuple2<>(operateResult.Message, null);
|
return new Tuple2<>(operateResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -617,7 +537,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return new Tuple2<>(null, result);
|
return new Tuple2<>(null, result);
|
||||||
}
|
}
|
||||||
if(clazz == Byte.class) {
|
if(clazz == Byte.class) {
|
||||||
OperateResultExOne<Byte> operateResult = siemensS7Net.ReadByte(plcData.item2);
|
OperateResultExOne<Byte> operateResult = siemensS7Net.ReadByte(plcData.getDbAddress());
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return new Tuple2<>(operateResult.Message, null);
|
return new Tuple2<>(operateResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -626,7 +546,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return new Tuple2<>(null, result);
|
return new Tuple2<>(null, result);
|
||||||
}
|
}
|
||||||
if(clazz == Double.class) {
|
if(clazz == Double.class) {
|
||||||
OperateResultExOne<Double> operateResult = siemensS7Net.ReadDouble(plcData.item2);
|
OperateResultExOne<Double> operateResult = siemensS7Net.ReadDouble(plcData.getDbAddress());
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return new Tuple2<>(operateResult.Message, null);
|
return new Tuple2<>(operateResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
@ -635,7 +555,7 @@ public class PlcSiemensCommunication implements IPlcCommunication {
|
||||||
return new Tuple2<>(null, result);
|
return new Tuple2<>(null, result);
|
||||||
}
|
}
|
||||||
if(clazz == Float.class) {
|
if(clazz == Float.class) {
|
||||||
OperateResultExOne<Float> operateResult = siemensS7Net.ReadFloat(plcData.item2);
|
OperateResultExOne<Float> operateResult = siemensS7Net.ReadFloat(plcData.getDbAddress());
|
||||||
if(!operateResult.IsSuccess) {
|
if(!operateResult.IsSuccess) {
|
||||||
return new Tuple2<>(operateResult.Message, null);
|
return new Tuple2<>(operateResult.Message, null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
wcs_web/src/components/manage/AppPermission.vue
Normal file
13
wcs_web/src/components/manage/AppPermission.vue
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
permission: string;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<slot> </slot>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue
Block a user