rev 更新下发失败逻辑
This commit is contained in:
@@ -62,7 +62,12 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
while(true) {
|
while(true) {
|
||||||
//下发信号
|
//下发信号
|
||||||
try{
|
try{
|
||||||
control( itemValues);
|
if(i == 0){
|
||||||
|
control( itemValues);
|
||||||
|
} else {
|
||||||
|
controlByNewConn( itemValues);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,24 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
Map<Item, ItemState> itemStatus = null;
|
Map<Item, ItemState> itemStatus = null;
|
||||||
boolean check = true;
|
boolean check = true;
|
||||||
try{
|
try{
|
||||||
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
if(i>0){
|
||||||
|
group = opcServerService.getServer(this.getOpcServer());
|
||||||
|
itemsString = new ArrayList<> (itemValues.keySet());
|
||||||
|
Iterator nis = itemsString.iterator();
|
||||||
|
|
||||||
|
while (nis.hasNext()) {
|
||||||
|
String string = (String) nis.next();
|
||||||
|
try {
|
||||||
|
readitems.put(string, group.addItem(string));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||||
|
}
|
||||||
Set<Item> items = itemStatus.keySet();
|
Set<Item> items = itemStatus.keySet();
|
||||||
Iterator var15 = items.iterator();
|
Iterator var15 = items.iterator();
|
||||||
while(var15.hasNext()) {
|
while(var15.hasNext()) {
|
||||||
@@ -130,6 +152,24 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
return this.control(p2);
|
return this.control(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean controlByNewConn(Map<String, Object> itemValues) {
|
||||||
|
|
||||||
|
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||||
|
|
||||||
|
ItemValue p2[];
|
||||||
|
p2 = new ItemValue[itemValues.size()];
|
||||||
|
int i=0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<String, Object> entry = it.next();
|
||||||
|
System.out.println("即将写入值:"+entry.getKey() + ":" + entry.getValue());
|
||||||
|
p2[i] = new ItemValue();
|
||||||
|
p2[i].setItem_code(entry.getKey());
|
||||||
|
p2[i].setItem_value(entry.getValue());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.controlByNewConn(p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean control(ItemValue[] itemValues) {
|
public boolean control(ItemValue[] itemValues) {
|
||||||
@@ -172,6 +212,67 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||||
|
|
||||||
opcServerService.writeInteger(this.getOpcServer(), itemValues);
|
opcServerService.writeInteger(this.getOpcServer(), itemValues);
|
||||||
|
|
||||||
|
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||||
|
ItemValue[] var17 = itemValues;
|
||||||
|
int var18 = itemValues.length;
|
||||||
|
|
||||||
|
for (int var19 = 0; var19 < var18; ++var19) {
|
||||||
|
ItemValue itemValue = var17[var19];
|
||||||
|
String code = itemValue.getItem_code();
|
||||||
|
Object value = itemValue.getItem_value();
|
||||||
|
opcValueAccessor.setValue(code, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new WDKException("下发 无内容");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean controlByNewConn(ItemValue[] itemValues) {
|
||||||
|
if (itemValues != null && itemValues.length != 0) {
|
||||||
|
String this_items = JsonUtl.parseWithoutException(itemValues);
|
||||||
|
boolean need_write = false;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
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;
|
||||||
|
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) {
|
||||||
|
log.trace("发送时间因为小于{}毫秒,而被无视", WcsConfig.opc_write_repeat_check);
|
||||||
|
return false;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
this.last_items = this_items;
|
||||||
|
this.sendTime = date;
|
||||||
|
/* this.execute_log.setResource(this.getDevice().getCode(), this.getDevice().getName());
|
||||||
|
this.execute_log.log("原始记录{}->变更为{}", new Object[]{sb, this_items});
|
||||||
|
OpcServerService opcServerService = OpcServerFactory.getOpcServerService();*/
|
||||||
|
|
||||||
|
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||||
|
|
||||||
|
opcServerService.writeIntegerByNewConn(this.getOpcServer(), itemValues);
|
||||||
|
|
||||||
|
|
||||||
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||||
ItemValue[] var17 = itemValues;
|
ItemValue[] var17 = itemValues;
|
||||||
int var18 = itemValues.length;
|
int var18 = itemValues.length;
|
||||||
|
|||||||
@@ -550,10 +550,10 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
|||||||
String methods_url = addressDto.getMethods_url();
|
String methods_url = addressDto.getMethods_url();
|
||||||
String url = wmsUrl + methods_url;
|
String url = wmsUrl + methods_url;
|
||||||
// log.info("sendDeviceStatus - 请求参数 {}", param);
|
// log.info("sendDeviceStatus - 请求参数 {}", param);
|
||||||
HttpRequest
|
// HttpRequest
|
||||||
.post(url)
|
// .post(url)
|
||||||
.body(param.toString())
|
// .body(param.toString())
|
||||||
.execute();
|
// .execute();
|
||||||
// log.info("sendDeviceStatus - 返回参数 {}", response.body());
|
// log.info("sendDeviceStatus - 返回参数 {}", response.body());
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ public interface OpcServerService {
|
|||||||
|
|
||||||
Group getServer(String var1);
|
Group getServer(String var1);
|
||||||
|
|
||||||
|
Group getServerByNewConn(String var1);
|
||||||
|
|
||||||
void writeInteger(String var1, ItemValue... var2);
|
void writeInteger(String var1, ItemValue... var2);
|
||||||
|
|
||||||
|
void writeIntegerByNewConn(String var1, ItemValue... var2);
|
||||||
|
|
||||||
void clearServer(String var1);
|
void clearServer(String var1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,45 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Group getServerByNewConn(String code) {
|
||||||
|
synchronized(this.buildLock(code)) {
|
||||||
|
|
||||||
|
Server server = (Server)this.servers.get(code);
|
||||||
|
if (server!=null){
|
||||||
|
this.clearServer(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code);
|
||||||
|
if (dto == null) {
|
||||||
|
throw new RuntimeException(code+"不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (server == null) {
|
||||||
|
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||||
|
// }
|
||||||
|
String groupName = code;
|
||||||
|
Group group = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
group = server.addGroup(groupName);
|
||||||
|
} catch (Exception var12) {
|
||||||
|
this.clearServer(code);
|
||||||
|
ThreadUtl.sleep(2000L);
|
||||||
|
log.warn("获取opc出错重新获取", code, var12);
|
||||||
|
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||||
|
try {
|
||||||
|
group = server.addGroup(groupName);
|
||||||
|
} catch (Exception var11) {
|
||||||
|
throw new RuntimeException(var12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.servers.put(code, server);
|
||||||
|
this.groups.put(code, group);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void clearServer(String code) {
|
public void clearServer(String code) {
|
||||||
synchronized(this.buildLock(code)) {
|
synchronized(this.buildLock(code)) {
|
||||||
try {
|
try {
|
||||||
@@ -164,6 +203,18 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeIntegerByNewConn(String code, ItemValue... values) {
|
||||||
|
try {
|
||||||
|
Group group = this.getServerByNewConn(code);
|
||||||
|
OpcUtl.writeValue(group, values);
|
||||||
|
} catch (Exception var4) {
|
||||||
|
this.clearServer(code);
|
||||||
|
log.info("写入出错opc server {} 重新加载", code, var4);
|
||||||
|
ThreadUtl.sleep(1000L);
|
||||||
|
throw var4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String buildLock(String key) {
|
private String buildLock(String key) {
|
||||||
if (StrUtil.isEmpty(key)) {
|
if (StrUtil.isEmpty(key)) {
|
||||||
key = "";
|
key = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user