汪菘 1 year ago
parent
commit
a505ab6de5
  1. 68
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java
  2. 64
      acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java
  3. 13
      acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java

68
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java

@ -765,32 +765,52 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic
* @param * @param
*/ */
public synchronized boolean apply_put_empty_vehicle() { public synchronized boolean apply_put_empty_vehicle() {
if(move == 0) { // if(move == 0) {
ApplyTaskRequest request = new ApplyTaskRequest(); // ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code()); // request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(Thread.currentThread().getStackTrace()[1].getMethodName()); // request.setRequest_medthod_code(Thread.currentThread().getStackTrace()[1].getMethodName());
request.setRequest_medthod_name(RequestMethodEnum.getName(Thread.currentThread().getStackTrace()[1].getMethodName())); // request.setRequest_medthod_name(RequestMethodEnum.getName(Thread.currentThread().getStackTrace()[1].getMethodName()));
request.setWeight(String.valueOf(weight)); // request.setWeight(String.valueOf(weight));
ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class); // ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求LMS..."; // message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request))); // lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (resp.getCode() == 200) { // if (resp.getCode() == 200) {
this.writing(200); // this.writing(200);
this.setRequireSucess(true); // this.setRequireSucess(true);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求成功" + resp.getMessage(); // message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求成功" + resp.getMessage();
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp))); // lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp)));
} else { // } else {
this.writing(400); // this.writing(400);
this.setIserror(true); // this.setIserror(true);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求失败" + resp.getMessage(); // message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求失败" + resp.getMessage();
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp))); // lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp)));
} // }
return true; // return true;
// } else {
// message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 设备有货未请求LMS...";
// lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
// return false;
// }
ApplyTaskRequest request = new ApplyTaskRequest();
request.setDevice_code(this.getDevice_code());
request.setRequest_medthod_code(Thread.currentThread().getStackTrace()[1].getMethodName());
request.setRequest_medthod_name(RequestMethodEnum.getName(Thread.currentThread().getStackTrace()[1].getMethodName()));
request.setWeight(String.valueOf(weight));
ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
if (resp.getCode() == 200) {
this.writing(200);
this.setRequireSucess(true);
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求成功" + resp.getMessage();
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp)));
} else { } else {
message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 设备有货未请求LMS..."; this.writing(400);
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message)); this.setIserror(true);
return false; message = RequestMethodEnum.getName("apply_put_empty_vehicle") + "apply_put_empty_vehicle 接口请求失败" + resp.getMessage();
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp)));
} }
return true;
} }
/** /**

64
acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java

@ -54,12 +54,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
this.OpcServer = opcServer; this.OpcServer = opcServer;
} }
private OpcItemDto getItem(String item) { private OpcItemDto getItem(String item) {
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item); OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item);
if (x == null) { if (x == null) {
Iterator var3 = this.protocols.iterator(); Iterator var3 = this.protocols.iterator();
while (var3.hasNext()) { while (var3.hasNext()) {
OpcItemDto dto = (OpcItemDto) var3.next(); OpcItemDto dto = (OpcItemDto) var3.next();
if (StrUtil.equals(item, dto.getItem_code())) { if (StrUtil.equals(item, dto.getItem_code())) {
@ -69,11 +67,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
} }
} }
} }
return x; return x;
} }
@Override @Override
public void run() { public void run() {
if (OpcConfig.opc_item_read_using_callback) { if (OpcConfig.opc_item_read_using_callback) {
@ -83,7 +79,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
} }
} }
private void runOld() { private void runOld() {
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class); OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class);
while (true) { while (true) {
@ -142,6 +137,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
OpcStartTag.is_run = true; OpcStartTag.is_run = true;
} }
//线程名
tag = ""; tag = "";
if (log.isWarnEnabled()) { if (log.isWarnEnabled()) {
tag = Thread.currentThread().getName(); tag = Thread.currentThread().getName();
@ -149,10 +145,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
tag = tag + this.getOpcGroupID(); tag = tag + this.getOpcGroupID();
} }
} }
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
boolean time_out = false; boolean time_out = false;
label97:
while (DeviceOpcSynchronizeAutoRun.isRun) { while (DeviceOpcSynchronizeAutoRun.isRun) {
long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
@ -165,7 +161,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
log.trace("{} 读取耗时:{}", tag, duration); log.trace("{} 读取耗时:{}", tag, duration);
} }
if (duration > 1000L) { if (duration > 1000L) {
if (!time_out) { if (!time_out) {
log.warn("{} 读取超时 : {}", tag, duration); log.warn("{} 读取超时 : {}", tag, duration);
@ -192,10 +187,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
Object his = accessor_value.getValue(itemId); Object his = accessor_value.getValue(itemId);
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
// valueAllNotNull = false;
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000);
break start;
} }
if (!UnifiedDataAppService.isEquals(value, his)) { if (!UnifiedDataAppService.isEquals(value, his)) {
@ -203,9 +194,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
if (true) { if (true) {
this.logItemChanged(itemId, accessor_value, value, itemDto); this.logItemChanged(itemId, accessor_value, value, itemDto);
} }
if(!ObjectUtil.isEmpty(value)){
accessor_value.setValue(itemId, value); accessor_value.setValue(itemId, value);
}
} }
} }
@ -226,17 +216,17 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
random *= 1000; random *= 1000;
if (this.all_null < 3) { if (this.all_null < 3) {
if (log.isWarnEnabled()) { if (log.isWarnEnabled()) {
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random); log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 5000 + random);
} }
ThreadUtl.sleep((long) (5000 + random)); ThreadUtl.sleep((long) (5000 + random));
} else if (this.all_null < 6) { } else if (this.all_null < 6) {
if (log.isWarnEnabled()) { if (log.isWarnEnabled()) {
log.warn(tag + "重新创建server"); log.warn(tag + "重新创建server");
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random); log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 30000 + random);
} }
// ThreadUtl.sleep((long) (30000 + random)); // ThreadUtl.sleep((long) (30000 + random));
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000);
break start; break start;
} else if (this.all_null < 12) { } else if (this.all_null < 12) {
if (log.isWarnEnabled()) { if (log.isWarnEnabled()) {
@ -250,8 +240,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
} }
ThreadUtl.sleep((long) (120000 + random)); ThreadUtl.sleep((long) (120000 + random));
}
}
++this.all_null; ++this.all_null;
} else { } else {
this.all_null = 0; this.all_null = 0;
@ -267,9 +257,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
try { try {
this.server.disconnect(); this.server.disconnect();
} catch (Exception var25) { } catch (Exception var25) {
} }
} }
this.server = null; this.server = null;
if (!DeviceOpcSynchronizeAutoRun.isRun) { if (!DeviceOpcSynchronizeAutoRun.isRun) {
log.warn("opc线程停止2。。。"); log.warn("opc线程停止2。。。");
@ -356,7 +346,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
} }
} }
public void connectionStateChanged(boolean connected) { public void connectionStateChanged(boolean connected) {
if (!connected) { if (!connected) {
this.server = null; this.server = null;
@ -377,8 +366,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
long seconds = mss % 60000L / 1000L; long seconds = mss % 60000L / 1000L;
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds "; return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
} }
public void changed(Item item, ItemState itemState) { public void changed(Item item, ItemState itemState) {
String itemId = item.getId(); String itemId = item.getId();
@ -420,30 +407,23 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
Object obj = accessor_value.getValue(relate); Object obj = accessor_value.getValue(relate);
sb.append("key:" + relate + "value:" + obj + ";"); sb.append("key:" + relate + "value:" + obj + ";");
} }
//log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb}); log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { // 存在上次点位值为null情况 则不记录日志
if(!ObjectUtil.equal(his,"null") || !ObjectUtil.equal(value,"null") || !ObjectUtil.isEmpty(his) || !ObjectUtil.isEmpty(value)){ if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){
// log.warn("{} 信号 {} 发生变更 {} -> {} 信号快照 {}", itemDto.getDevice_code(), itemCode, his, value, sb); //lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
}
}
} else {
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
}
} else { } else {
//log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { // 存在上次点位值为null情况 则不记录日志
// 存在上次点位值为null情况 则不记录日志 if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ //lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
System.out.println("his:"+his + ",value:"+ value);
} else {
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
}
// if(!ObjectUtil.equal(his,"null") || !ObjectUtil.equal(value,"null") || !ObjectUtil.isEmpty(his) || !ObjectUtil.isEmpty(value)){ } else {
// log.warn("{} 信号 {} 发生变更 {} -> {} 信号快照 {}", itemDto.getDevice_code(), itemCode, his, value, sb); lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
// lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
// }
} }
} }
} }

13
acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java

@ -122,12 +122,16 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
if (needcreate) { if (needcreate) {
OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code); OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code);
if (dto == null) { if (dto == null) {
throw new BadRequestException(code + "{} 不存在"); throw new RuntimeException(code+"不存在");
} }
// if (server!=null){
// server.disconnect();
// server=null;
// }
if (server == null) { if (server == null) {
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); }
}
try { try {
group = server.addGroup(groupName); group = server.addGroup(groupName);
@ -136,11 +140,10 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
ThreadUtl.sleep(5000L); ThreadUtl.sleep(5000L);
log.warn("获取opc出错重新获取", code, var12); log.warn("获取opc出错重新获取", code, var12);
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
try { try {
group = server.addGroup(groupName); group = server.addGroup(groupName);
} catch (Exception var11) { } catch (Exception var11) {
var11.printStackTrace(); throw new RuntimeException(var12);
} }
} }

Loading…
Cancel
Save