rev 更新
This commit is contained in:
@@ -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));
|
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"))) {
|
try{
|
||||||
if (ObjectUtil.equal(this.getDevice().getExtraValue().get("noIdleRequest"), "true")) {
|
if ("true".equals(this.device.getExtraValue().get("ship_device_update"))) {
|
||||||
if (!requiresShipDeviceUpdate && move == 0) {
|
if (ObjectUtil.equal(this.getDevice().getExtraValue().get("noIdleRequest"), "true")) {
|
||||||
this.shipDeviceUpdate();
|
if (!requiresShipDeviceUpdate && move == 0) {
|
||||||
}
|
this.shipDeviceUpdate();
|
||||||
} else {
|
}
|
||||||
if (mode == 2 && !requiresShipDeviceUpdate && move == 0) {
|
} else {
|
||||||
this.shipDeviceUpdate();
|
if (mode == 2 && !requiresShipDeviceUpdate && move == 0) {
|
||||||
|
this.shipDeviceUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
logServer.deviceExecuteLog(this.device_code, "", "", "反馈LMS光电信号变化时出现异常:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
this.setIsonline(false);
|
this.setIsonline(false);
|
||||||
message = "未联机";
|
message = "未联机";
|
||||||
@@ -577,6 +583,11 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
|
|||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,28 +61,38 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
//下发信号
|
//下发信号
|
||||||
control( itemValues);
|
try{
|
||||||
|
control( itemValues);
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
Map<String, Object> read = new HashMap();
|
Map<String, Object> read = new HashMap();
|
||||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
Map<Item, ItemState> itemStatus = null;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean check = true;
|
boolean check = true;
|
||||||
Iterator var24 = itemsString.iterator();
|
try{
|
||||||
|
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||||
while(var24.hasNext()) {
|
Set<Item> items = itemStatus.keySet();
|
||||||
String itemString = (String)var24.next();
|
Iterator var15 = items.iterator();
|
||||||
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
|
while(var15.hasNext()) {
|
||||||
check = false;
|
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) {
|
if (check) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -92,6 +102,7 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i > 3) {
|
if (i > 3) {
|
||||||
|
log.info("写入次数超过3次而失败");
|
||||||
throw new WDKException("写入次数超过3次而失败");
|
throw new WDKException("写入次数超过3次而失败");
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
@@ -129,23 +140,22 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
ItemValue[] var5 = itemValues;
|
ItemValue[] var5 = itemValues;
|
||||||
int var6 = itemValues.length;
|
int var6 = itemValues.length;
|
||||||
|
|
||||||
for (int var7 = 0; var7 < var6; ++var7) {
|
// for (int var7 = 0; var7 < var6; ++var7) {
|
||||||
ItemValue itemValue = var5[var7];
|
// ItemValue itemValue = var5[var7];
|
||||||
String code = itemValue.getItem_code();
|
// String code = itemValue.getItem_code();
|
||||||
Object udw_value = this.getUdwValue(code);
|
// Object udw_value = this.getUdwValue(code);
|
||||||
Object write_value = itemValue.getItem_value();
|
// Object write_value = itemValue.getItem_value();
|
||||||
sb.append(code);
|
// sb.append(code);
|
||||||
sb.append(":");
|
// sb.append(":");
|
||||||
sb.append(JsonUtl.parseWithoutException(udw_value));
|
// sb.append(JsonUtl.parseWithoutException(udw_value));
|
||||||
sb.append(";");
|
// sb.append(";");
|
||||||
if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) {
|
// if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) {
|
||||||
need_write = true;
|
// need_write = true;
|
||||||
} else {
|
// } else {
|
||||||
log.warn("下发信号点位{} 当前写入值:{} 与系统内存值:{} 相同,不再写入 ", code, write_value, udw_value );
|
// log.warn("下发信号点位{} 当前写入值:{} 与系统内存值:{} 相同,不再写入 ", code, write_value, udw_value );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//need_write = true;
|
need_write = true;
|
||||||
|
|
||||||
if (need_write) {
|
if (need_write) {
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
/*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) {
|
/*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) {
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
MDC.remove("device_code_log");
|
MDC.remove("device_code_log");
|
||||||
System.out.println("successNum:" + OpcUtl.successNum);
|
|
||||||
System.out.println("errNum:" + OpcUtl.errNum);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
throw new RuntimeException(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())); }
|
||||||
|
|
||||||
@@ -154,7 +159,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
} catch (Exception var4) {
|
} catch (Exception var4) {
|
||||||
this.clearServer(code);
|
this.clearServer(code);
|
||||||
log.info("写入出错opc server {} 重新加载", code, var4);
|
log.info("写入出错opc server {} 重新加载", code, var4);
|
||||||
ThreadUtl.sleep(5000L);
|
ThreadUtl.sleep(1000L);
|
||||||
throw var4;
|
throw var4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import java.util.concurrent.Executors;
|
|||||||
public class OpcUtl {
|
public class OpcUtl {
|
||||||
private static int timeout = 1*60*1000;
|
private static int timeout = 1*60*1000;
|
||||||
private static String key = "rpc.socketTimeout";
|
private static String key = "rpc.socketTimeout";
|
||||||
public static int successNum=0;
|
|
||||||
public static int errNum=0;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
checkTimeout();
|
checkTimeout();
|
||||||
@@ -37,18 +35,7 @@ public class OpcUtl {
|
|||||||
|
|
||||||
public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
|
public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
|
||||||
try {
|
try {
|
||||||
Map<Item, Integer> e=null;
|
Map<Item, Integer> e=group.write(requests);
|
||||||
try{
|
|
||||||
e=group.write(requests);
|
|
||||||
group.write(requests);
|
|
||||||
}catch (Exception e1){
|
|
||||||
try{
|
|
||||||
e= group.write(requests);
|
|
||||||
}catch (Exception e2){
|
|
||||||
e= group.write(requests);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean is_success = true;
|
boolean is_success = true;
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
Iterator arg4 = e.keySet().iterator();
|
Iterator arg4 = e.keySet().iterator();
|
||||||
@@ -69,16 +56,12 @@ public class OpcUtl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_success) {
|
if (!is_success) {
|
||||||
// throw new BusinessException(message.toString());
|
|
||||||
System.out.println("下发信号失败:"+message.toString());
|
|
||||||
System.out.println("下发信号失败原因:"+message.toString());
|
|
||||||
log.info("下发信号失败:"+message.toString());
|
log.info("下发信号失败:"+message.toString());
|
||||||
throw new WDKException(message.toString());
|
throw new WDKException(message.toString());
|
||||||
}
|
}
|
||||||
} catch (JIException arg7) {
|
} catch (JIException arg7) {
|
||||||
log.info("下发信号失败:"+arg7.getMessage());
|
log.info("下发信号失败Exception:"+arg7.getMessage());
|
||||||
System.out.println("下发信号失败原因:"+arg7.getMessage());
|
throw new WDKException("下发信号失败Exception:"+arg7);
|
||||||
throw new WDKException(arg7);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,16 +204,10 @@ public class OpcUtl {
|
|||||||
server = new Server(getConnection(host, clsid, user, password, domain),
|
server = new Server(getConnection(host, clsid, user, password, domain),
|
||||||
Executors.newSingleThreadScheduledExecutor());
|
Executors.newSingleThreadScheduledExecutor());
|
||||||
server.connect();
|
server.connect();
|
||||||
successNum++;
|
|
||||||
return server;
|
return server;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errNum++;
|
|
||||||
// e.printStackTrace();
|
|
||||||
System.out.println("server error:"+e.getMessage());
|
System.out.println("server error:"+e.getMessage());
|
||||||
throw new WDKException(e.getMessage());
|
throw new WDKException(e.getMessage());
|
||||||
}finally{
|
|
||||||
System.out.println("successNum:"+successNum);
|
|
||||||
System.out.println("errNum:"+errNum);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user