rev 更新

This commit is contained in:
USER-20220102CG\noblelift
2023-08-09 17:17:19 +08:00
parent 44dc4aab81
commit 7a826801af
5 changed files with 73 additions and 72 deletions

View File

@@ -280,19 +280,25 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol));
}
if ("true".equals(this.device.getExtraValue().get("ship_device_update"))) {
if (ObjectUtil.equal(this.getDevice().getExtraValue().get("noIdleRequest"), "true")) {
if (!requiresShipDeviceUpdate && move == 0) {
this.shipDeviceUpdate();
}
} else {
if (mode == 2 && !requiresShipDeviceUpdate && move == 0) {
this.shipDeviceUpdate();
try{
if ("true".equals(this.device.getExtraValue().get("ship_device_update"))) {
if (ObjectUtil.equal(this.getDevice().getExtraValue().get("noIdleRequest"), "true")) {
if (!requiresShipDeviceUpdate && move == 0) {
this.shipDeviceUpdate();
}
} else {
if (mode == 2 && !requiresShipDeviceUpdate && move == 0) {
this.shipDeviceUpdate();
}
}
}
} catch (Exception e){
e.printStackTrace();
logServer.deviceExecuteLog(this.device_code, "", "", "反馈LMS光电信号变化时出现异常:" + e.getMessage());
}
if (mode == 0) {
this.setIsonline(false);
message = "未联机";
@@ -577,6 +583,11 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
this.checkcontrol(itemMap);
} catch (Exception e) {
e.printStackTrace();
try{
this.checkcontrol(itemMap);
} catch (Exception e1){
e1.printStackTrace();
}
}
}

View File

@@ -61,28 +61,38 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
int i = 0;
while(true) {
//下发信号
control( itemValues);
try{
control( itemValues);
} catch (Exception e){
e.printStackTrace();
}
Map<String, Object> read = new HashMap();
Map<Item, ItemState> itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
Set<Item> items = itemStatus.keySet();
Iterator var15 = items.iterator();
while(var15.hasNext()) {
Item item = (Item)var15.next();
ItemState itemState = (ItemState)itemStatus.get(item);
Object value = OpcUtl.getValue(item, itemState);
read.put(item.getId(), value);
}
Map<Item, ItemState> itemStatus = null;
boolean check = true;
Iterator var24 = itemsString.iterator();
while(var24.hasNext()) {
String itemString = (String)var24.next();
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
check = false;
try{
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
Set<Item> items = itemStatus.keySet();
Iterator var15 = items.iterator();
while(var15.hasNext()) {
Item item = (Item)var15.next();
ItemState itemState = (ItemState)itemStatus.get(item);
Object value = OpcUtl.getValue(item, itemState);
read.put(item.getId(), value);
}
Iterator var24 = itemsString.iterator();
while(var24.hasNext()) {
String itemString = (String)var24.next();
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
check = false;
}
}
} catch (Exception e){
e.printStackTrace();
check = false;
}
if (check) {
return;
}
@@ -92,6 +102,7 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
}
if (i > 3) {
log.info("写入次数超过3次而失败");
throw new WDKException("写入次数超过3次而失败");
}
++i;
@@ -129,23 +140,22 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
ItemValue[] var5 = itemValues;
int var6 = itemValues.length;
for (int var7 = 0; var7 < var6; ++var7) {
ItemValue itemValue = var5[var7];
String code = itemValue.getItem_code();
Object udw_value = this.getUdwValue(code);
Object write_value = itemValue.getItem_value();
sb.append(code);
sb.append(":");
sb.append(JsonUtl.parseWithoutException(udw_value));
sb.append(";");
if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) {
need_write = true;
} else {
log.warn("下发信号点位{} 当前写入值:{} 与系统内存值:{} 相同,不再写入 ", code, write_value, udw_value );
}
}
//need_write = true;
// for (int var7 = 0; var7 < var6; ++var7) {
// ItemValue itemValue = var5[var7];
// String code = itemValue.getItem_code();
// Object udw_value = this.getUdwValue(code);
// Object write_value = itemValue.getItem_value();
// sb.append(code);
// sb.append(":");
// sb.append(JsonUtl.parseWithoutException(udw_value));
// sb.append(";");
// if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) {
// need_write = true;
// } else {
// log.warn("下发信号点位{} 当前写入值:{} 与系统内存值:{} 相同,不再写入 ", code, write_value, udw_value );
// }
// }
need_write = true;
if (need_write) {
Date date = new Date();
/*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) {

View File

@@ -33,8 +33,6 @@ public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService {
e.printStackTrace();
} finally {
MDC.remove("device_code_log");
System.out.println("successNum:" + OpcUtl.successNum);
System.out.println("errNum:" + OpcUtl.errNum);
}
}

View File

@@ -109,6 +109,11 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
throw new RuntimeException(code+"不存在");
}
// if (server!=null){
// server.disconnect();
// server=null;
// }
if (server == null) {
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); }
@@ -154,7 +159,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
} catch (Exception var4) {
this.clearServer(code);
log.info("写入出错opc server {} 重新加载", code, var4);
ThreadUtl.sleep(5000L);
ThreadUtl.sleep(1000L);
throw var4;
}
}

View File

@@ -20,8 +20,6 @@ import java.util.concurrent.Executors;
public class OpcUtl {
private static int timeout = 1*60*1000;
private static String key = "rpc.socketTimeout";
public static int successNum=0;
public static int errNum=0;
static {
checkTimeout();
@@ -37,18 +35,7 @@ public class OpcUtl {
public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
try {
Map<Item, Integer> e=null;
try{
e=group.write(requests);
group.write(requests);
}catch (Exception e1){
try{
e= group.write(requests);
}catch (Exception e2){
e= group.write(requests);
}
}
Map<Item, Integer> e=group.write(requests);
boolean is_success = true;
StringBuilder message = new StringBuilder();
Iterator arg4 = e.keySet().iterator();
@@ -69,16 +56,12 @@ public class OpcUtl {
}
if (!is_success) {
// throw new BusinessException(message.toString());
System.out.println("下发信号失败:"+message.toString());
System.out.println("下发信号失败原因:"+message.toString());
log.info("下发信号失败:"+message.toString());
throw new WDKException(message.toString());
}
} catch (JIException arg7) {
log.info("下发信号失败:"+arg7.getMessage());
System.out.println("下发信号失败原因:"+arg7.getMessage());
throw new WDKException(arg7);
log.info("下发信号失败Exception"+arg7.getMessage());
throw new WDKException("下发信号失败Exception:"+arg7);
}
}
@@ -221,16 +204,10 @@ public class OpcUtl {
server = new Server(getConnection(host, clsid, user, password, domain),
Executors.newSingleThreadScheduledExecutor());
server.connect();
successNum++;
return server;
} catch (Exception e) {
errNum++;
// e.printStackTrace();
System.out.println("server error:"+e.getMessage());
throw new WDKException(e.getMessage());
}finally{
System.out.println("successNum:"+successNum);
System.out.println("errNum:"+errNum);
}
}