fix 读信号 写信号
This commit is contained in:
@@ -157,25 +157,35 @@ public class ReadUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void write(Map<String, Object> strings, Server server) {
|
public static void write(Map<String, Object> strings, Server server) {
|
||||||
|
write(strings, server, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write(Map<String, Object> strings, Server server, int writeCount) {
|
||||||
try {
|
try {
|
||||||
//Group group = this.opcServerService.getServer(opcServiceCode);
|
//Group group = this.opcServerService.getServer(opcServiceCode);
|
||||||
|
if (writeCount == 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
server.connect();
|
||||||
|
} catch (AlreadyConnectedException ignored) {
|
||||||
|
}
|
||||||
Group group = server.addGroup();
|
Group group = server.addGroup();
|
||||||
Iterator it = strings.keySet().iterator();
|
for (String key : strings.keySet()) {
|
||||||
while (it.hasNext()) {
|
|
||||||
String key = (String) it.next();
|
|
||||||
Item byteItem = group.addItem(key);
|
Item byteItem = group.addItem(key);
|
||||||
Object o = strings.get(key);
|
Object o = strings.get(key);
|
||||||
if (o == null || o.equals("")) {
|
if (o == null) {
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
WriteRequest write1 = new WriteRequest(byteItem, new JIVariant(o.toString()));
|
WriteRequest write1 = new WriteRequest(byteItem, new JIVariant(o.toString()));
|
||||||
List<WriteRequest> list = new ArrayList();
|
List<WriteRequest> list = new ArrayList<>();
|
||||||
list.add(write1);
|
list.add(write1);
|
||||||
OpcUtl.writeValue(group, (WriteRequest[]) list.toArray(new WriteRequest[0]));
|
OpcUtl.writeValue(group, list.toArray(new WriteRequest[0]));
|
||||||
}
|
}
|
||||||
server.disconnect();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
write(strings, server, ++writeCount);
|
||||||
|
} finally {
|
||||||
|
server.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
|||||||
private int all_null;
|
private int all_null;
|
||||||
private Map<String, OpcItemDto> itemSearchCache;
|
private Map<String, OpcItemDto> itemSearchCache;
|
||||||
|
|
||||||
|
|
||||||
public DeviceOpcProtocolRunable() {
|
public DeviceOpcProtocolRunable() {
|
||||||
this.error_num = 0;
|
this.error_num = 0;
|
||||||
this.all_null = 0;
|
this.all_null = 0;
|
||||||
@@ -93,7 +94,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
|||||||
server.disconnect();
|
server.disconnect();
|
||||||
log.trace("清理server...");
|
log.trace("清理server...");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
||||||
this.server.addStateListener(this);
|
this.server.addStateListener(this);
|
||||||
group = this.server.addGroup();
|
group = this.server.addGroup();
|
||||||
@@ -186,7 +186,7 @@ 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 = true;
|
valueAllNotNull = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
if (!UnifiedDataAppService.isEquals(value, his)) {
|
||||||
@@ -220,7 +220,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
|||||||
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) ((new Random()).nextInt(3) +1) * 1000);
|
||||||
|
break start;
|
||||||
} 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");
|
||||||
|
|||||||
Reference in New Issue
Block a user