驱动读不到fix
This commit is contained in:
@@ -1,70 +1,40 @@
|
||||
package org.nl.acs.device_driver.driver;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.nl.acs.ext.wms.data.JsonUtl;
|
||||
import org.nl.acs.opc.*;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver {
|
||||
UnifiedDataAccessor opcUdw;
|
||||
|
||||
private final OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
private OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
|
||||
public AbstractOpcDeviceDriver() {
|
||||
this.opcUdw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
}
|
||||
|
||||
|
||||
private Date sendTime;
|
||||
private String last_items;
|
||||
private int noLog_sendTimeOut;
|
||||
private Date noLog_sendTime;
|
||||
private String noLog_last_items;
|
||||
|
||||
@Override
|
||||
public UnifiedDataAccessor getOpcValueAccessor() {
|
||||
return this.opcUdw;
|
||||
}
|
||||
|
||||
public void control(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();
|
||||
log.info(entry.getKey() + " 即将写入 " + entry.getValue());
|
||||
p2[i] = new ItemValue();
|
||||
p2[i].setItem_code(entry.getKey());
|
||||
p2[i].setItem_value(entry.getValue());
|
||||
i++;
|
||||
}
|
||||
|
||||
this.control(p2);
|
||||
}
|
||||
|
||||
public void control(ItemValue[] itemValues) {
|
||||
if (itemValues != null && itemValues.length != 0) {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
|
||||
opcServerService.writeInteger(this.getOpcServer(), itemValues);
|
||||
|
||||
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||
for (ItemValue itemValue : itemValues) {
|
||||
String code = itemValue.getItem_code();
|
||||
Object value = itemValue.getItem_value();
|
||||
opcValueAccessor.setValue(code, value);
|
||||
}
|
||||
} else {
|
||||
log.warn("写入信号无内容!");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkcontrol(Map<String, Object> itemValues){
|
||||
public void checkcontrol(Map<String, Object> itemValues) throws Exception {
|
||||
Group group = opcServerService.getServer(this.getOpcServer());
|
||||
Map<String, Object> write = new HashMap();
|
||||
Map<String, Item> readitems = new LinkedHashMap();
|
||||
@@ -82,104 +52,10 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
}
|
||||
int i = 0;
|
||||
while(true) {
|
||||
//下发信号
|
||||
try{
|
||||
if(i == 0){
|
||||
control( itemValues);
|
||||
} else {
|
||||
controlByNewConn( itemValues);
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String, Object> read = new HashMap();
|
||||
Map<Item, ItemState> itemStatus = null;
|
||||
boolean check = true;
|
||||
try{
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
ThreadUtl.sleep(300L);
|
||||
}
|
||||
|
||||
if (i > 3) {
|
||||
log.info("写入次数超过3次而失败");
|
||||
throw new RuntimeException("写入次数超过3次而失败");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
public void checkControl(Map<String, Object> itemValues) {
|
||||
Group group = opcServerService.getServer(this.getOpcServer());
|
||||
Map<String, Object> write = new HashMap();
|
||||
Map<String, Item> readitems = new LinkedHashMap();
|
||||
List<String> itemsString = new ArrayList();
|
||||
itemsString = new ArrayList<> (itemValues.keySet());
|
||||
Iterator is = itemsString.iterator();
|
||||
|
||||
while (is.hasNext()) {
|
||||
String string = (String) is.next();
|
||||
try {
|
||||
readitems.put(string, group.addItem(string));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
while (true) {
|
||||
//下发信号
|
||||
control( itemValues);
|
||||
Map<String, Object> read = new HashMap();
|
||||
Map<Item, ItemState> itemStatus = null;
|
||||
try {
|
||||
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||
} catch (JIException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var15 = items.iterator();
|
||||
|
||||
@@ -204,7 +80,7 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
ThreadUtl.sleep(1000L);
|
||||
ThreadUtl.sleep(300L);
|
||||
}
|
||||
|
||||
if (i > 3) {
|
||||
@@ -214,42 +90,84 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
}
|
||||
}
|
||||
|
||||
public void controlByNewConn(Map<String, Object> itemValues) {
|
||||
|
||||
public boolean control(Map<String, Object> itemValues) {
|
||||
|
||||
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||
|
||||
ItemValue[] p2;
|
||||
ItemValue p2[];
|
||||
p2 = new ItemValue[itemValues.size()];
|
||||
int i = 0;
|
||||
int i=0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, Object> entry = it.next();
|
||||
log.info(entry.getKey() + " 即将写入 " + entry.getValue());
|
||||
System.out.println("即将写入值:"+entry.getKey() + ":" + entry.getValue());
|
||||
p2[i] = new ItemValue();
|
||||
p2[i].setItem_code(entry.getKey());
|
||||
p2[i].setItem_value(entry.getValue());
|
||||
i++;
|
||||
}
|
||||
|
||||
this.controlByNewConn(p2);
|
||||
return this.control(p2);
|
||||
}
|
||||
|
||||
public void controlByNewConn(ItemValue[] itemValues) {
|
||||
|
||||
|
||||
public boolean control(ItemValue[] itemValues) {
|
||||
if (itemValues != null && itemValues.length != 0) {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
String this_items = JsonUtl.parseWithoutException(itemValues);
|
||||
boolean need_write = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ItemValue[] var5 = itemValues;
|
||||
int var6 = itemValues.length;
|
||||
|
||||
opcServerService.writeIntegerByNewConn(this.getOpcServer(), itemValues);
|
||||
|
||||
|
||||
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||
|
||||
for (ItemValue itemValue : itemValues) {
|
||||
for (int var7 = 0; var7 < var6; ++var7) {
|
||||
ItemValue itemValue = var5[var7];
|
||||
String code = itemValue.getItem_code();
|
||||
Object value = itemValue.getItem_value();
|
||||
opcValueAccessor.setValue(code, value);
|
||||
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.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 {
|
||||
log.warn("写入信号无内容!");
|
||||
throw new RuntimeException("下发 无内容");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ItemProtocol {
|
||||
public int getOpcIntegerValue(String protocol) {
|
||||
Integer value = this.driver.getIntegeregerValue(protocol);
|
||||
if (value == null) {
|
||||
// log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
|
||||
// log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
|
||||
setIsonline(false);
|
||||
} else {
|
||||
setIsonline(true);
|
||||
|
||||
@@ -151,13 +151,12 @@ public class SiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceD
|
||||
hasGoods = this.itemProtocol.getMove();
|
||||
action = this.itemProtocol.getAction();
|
||||
pallet_type = this.itemProtocol.getPalletType();
|
||||
if (mode != last_mode) {
|
||||
this.setRequireSucess(false);
|
||||
if (mode == 2) {
|
||||
this.writing(0);
|
||||
}
|
||||
if("ZCSSX0101".equals(devicecode)){
|
||||
log.info("123");
|
||||
}
|
||||
|
||||
if (move != last_move) {
|
||||
this.setRequireSucess(false);
|
||||
//反馈输送线点位状态
|
||||
if (devicecode.startsWith("ZCSSX")) {
|
||||
BaseRequest request = new BaseRequest();
|
||||
|
||||
@@ -15,7 +15,13 @@ import org.nl.acs.device_driver.driver.OpcDeviceDriver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
|
||||
@@ -13,7 +13,13 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
|
||||
@@ -7,8 +7,16 @@ import org.nl.config.thread.TheadFactoryName;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -75,10 +83,10 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
||||
@Override
|
||||
public void autoRun() throws Exception {
|
||||
for (int i = 0; !OpcStartTag.is_run; ++i) {
|
||||
//log.info("设备执行线程等待opc同步线程...");
|
||||
log.info("设备执行线程等待opc同步线程...");
|
||||
Thread.sleep(1000L);
|
||||
if (i > 60) {
|
||||
//log.info("设备执行线程放弃等待opc同步线程...");
|
||||
log.info("设备执行线程放弃等待opc同步线程...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -109,6 +117,7 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
||||
if (!this.runs.keySet().contains(deviceDriver.getDeviceCode())) {
|
||||
this.runs.put(deviceDriver.getDeviceCode(), runnable);
|
||||
}
|
||||
|
||||
runnable.setIndex(this.runs);
|
||||
this.executorService.submit(runnable);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,12 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import eu.bitwalker.useragentutils.DeviceType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
public class DeviceManageDto {
|
||||
|
||||
@@ -8,12 +8,28 @@ import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.openscada.opc.lib.da.*;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Async20Access;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.ServerConnectionStateListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener {
|
||||
List<OpcItemDto> protocols;
|
||||
OpcServerManageDto OpcServer;
|
||||
@@ -26,6 +42,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
private int all_null;
|
||||
private Map<String, OpcItemDto> itemSearchCache;
|
||||
|
||||
// @Autowired
|
||||
// OpcServerService opcServerService;
|
||||
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
this.error_num = 0;
|
||||
@@ -94,11 +113,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
server.disconnect();
|
||||
log.trace("清理server...");
|
||||
}
|
||||
|
||||
// group =opcServerService.getServer(this.getOpcServer().getOpc_code());
|
||||
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);
|
||||
group = this.server.addGroup();
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
group =opcServerService.getServer(this.getOpcServer().getOpc_code());
|
||||
// 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);
|
||||
// group = this.server.addGroup();
|
||||
List<String> itemsString = new ArrayList();
|
||||
Iterator var3 = this.protocols.iterator();
|
||||
|
||||
@@ -188,7 +207,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
Object his = accessor_value.getValue(itemId);
|
||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
valueAllNotNull = false;
|
||||
valueAllNotNull = true;
|
||||
}
|
||||
|
||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
||||
@@ -222,8 +241,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000);
|
||||
break start;
|
||||
ThreadUtl.sleep((long) (5000 + random));
|
||||
} else if (this.all_null < 6) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(tag + "重新创建server");
|
||||
|
||||
@@ -43,10 +43,10 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap();
|
||||
Map<String, List<List<OpcItemDto>>> pros;
|
||||
do{
|
||||
Thread.sleep(1000L);
|
||||
pros = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
}while (ObjectUtil.isEmpty(pros));
|
||||
do{
|
||||
Thread.sleep(1000L);
|
||||
pros = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
}while (ObjectUtil.isEmpty(pros));
|
||||
Set<String> keys = pros.keySet();
|
||||
Iterator var4 = keys.iterator();
|
||||
//代码执行一次
|
||||
|
||||
@@ -17,7 +17,5 @@ public interface OpcServerService {
|
||||
|
||||
void writeInteger(String var1, ItemValue... var2);
|
||||
|
||||
void writeIntegerByNewConn(String var1, ItemValue... var2);
|
||||
|
||||
void clearServer(String var1);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.nl.acs.auto.initial.ApplicationAutoInitial;
|
||||
import org.nl.acs.device_driver.driver.ItemValue;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.openscada.opc.lib.common.NotConnectedException;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
@@ -147,68 +145,6 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
this.groups.remove(code);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private String buildLock(String key) {
|
||||
if (StrUtil.isEmpty(key)) {
|
||||
key = "";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("OpcServerService.");
|
||||
builder.append(key);
|
||||
String lock = builder.toString().intern();
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void writeInteger(String code, ItemValue... values) {
|
||||
try {
|
||||
Group group = this.getServer(code);
|
||||
|
||||
@@ -3,12 +3,22 @@ package org.nl.acs.opc;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.*;
|
||||
import org.jinterop.dcom.core.IJIUnsigned;
|
||||
import org.jinterop.dcom.core.JIArray;
|
||||
import org.jinterop.dcom.core.JIString;
|
||||
import org.jinterop.dcom.core.JIUnsignedByte;
|
||||
import org.jinterop.dcom.core.JIUnsignedShort;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.nl.acs.device_driver.driver.ItemValue;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.*;
|
||||
import org.openscada.opc.lib.da.AddFailedException;
|
||||
import org.openscada.opc.lib.da.AutoReconnectController;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.WriteRequest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -17,7 +27,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Slf4j
|
||||
public class OpcUtl {
|
||||
public class OpcUtl {
|
||||
private static int timeout = 1*60*1000;
|
||||
private static String key = "rpc.socketTimeout";
|
||||
public static int successNum=0;
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package org.nl.acs.opc.domain;
|
||||
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.validation.constraints.*;
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package org.nl.acs.opc.domain;
|
||||
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.validation.constraints.*;
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.acs.opc.service.mapper.OpcMapper;
|
||||
import org.nl.acs.utils.ConvertUtil;
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
package org.nl.acs.opc.rest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.acs.opc.service.OpcService;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcQueryParam;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
|
||||
@@ -2,9 +2,9 @@ package org.nl.acs.opc.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.common.base.PageInfo;
|
||||
import org.nl.acs.common.base.CommonService;
|
||||
import org.nl.acs.common.base.PageInfo;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcQueryParam;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package org.nl.acs.opc.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.sql.Timestamp;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package org.nl.acs.opc.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.sql.Timestamp;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
|
||||
@@ -2,10 +2,6 @@ package org.nl.acs.opc.service.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import org.nl.common.annotation.Query;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
|
||||
@@ -2,10 +2,6 @@ package org.nl.acs.opc.service.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
import org.nl.common.annotation.Query;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
|
||||
@@ -10,34 +10,36 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.opc.domain.OpcPlc;
|
||||
import org.nl.acs.opc.service.mapper.OpcPlcMapper;
|
||||
import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.acs.common.base.PageInfo;
|
||||
import org.nl.acs.common.base.QueryHelpMybatisPlus;
|
||||
import org.nl.acs.common.base.impl.CommonServiceImpl;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.acs.utils.ConvertUtil;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.acs.utils.PageUtil;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.domain.OpcPlc;
|
||||
import org.nl.acs.opc.service.OpcService;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcQueryParam;
|
||||
import org.nl.acs.opc.service.mapper.OpcMapper;
|
||||
import org.nl.acs.opc.service.mapper.OpcPlcMapper;
|
||||
import org.nl.acs.utils.ConvertUtil;
|
||||
import org.nl.acs.utils.PageUtil;
|
||||
import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
// 默认不使用缓存
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.nl.acs.opc.service.mapper;
|
||||
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.common.base.CommonMapper;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user