add 标准监测站点action信号 交互逻辑 opc读取线程
This commit is contained in:
@@ -825,13 +825,17 @@ public class AgvServiceImpl implements AgvService {
|
||||
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver();
|
||||
//请求取货
|
||||
if ("Load".equals(action)) {
|
||||
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) {
|
||||
standardInspectSiteDeviceDriver.writing(1);
|
||||
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0
|
||||
&& (standardInspectSiteDeviceDriver.getAction() == 1 || standardInspectSiteDeviceDriver.getAction() == 3)) {
|
||||
inst.setExecute_status("1");
|
||||
is_feedback = true;
|
||||
}
|
||||
//请求放货
|
||||
} else if ("Unload".equals(action)) {
|
||||
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) {
|
||||
standardInspectSiteDeviceDriver.writing(3);
|
||||
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0
|
||||
&& (standardInspectSiteDeviceDriver.getAction() == 2 || standardInspectSiteDeviceDriver.getAction() == 3)) {
|
||||
inst.setExecute_status("3");
|
||||
is_feedback = true;
|
||||
}
|
||||
@@ -973,6 +977,7 @@ public class AgvServiceImpl implements AgvService {
|
||||
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver();
|
||||
//取货完成
|
||||
if ("Load".equals(action)) {
|
||||
standardInspectSiteDeviceDriver.writing(2);
|
||||
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) {
|
||||
inst.setExecute_device_code(processingVehicle);
|
||||
inst.setExecute_status("2");
|
||||
@@ -980,6 +985,7 @@ public class AgvServiceImpl implements AgvService {
|
||||
}
|
||||
//放货完成
|
||||
} else if ("Unload".equals(action)) {
|
||||
standardInspectSiteDeviceDriver.writing(4);
|
||||
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) {
|
||||
inst.setExecute_device_code(address);
|
||||
inst.setExecute_status("4");
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ItemProtocol {
|
||||
public static String item_mode = "mode";
|
||||
public static String item_move = "move";
|
||||
public static String item_ioaction = "ioaction";
|
||||
public static String item_action = "action";
|
||||
public static String item_error = "error";
|
||||
public static String item_task = "task";
|
||||
public static String item_to_command = "to_command";
|
||||
@@ -63,6 +64,9 @@ public class ItemProtocol {
|
||||
public int getToTask() {
|
||||
return this.getOpcIntegerValue(item_to_task);
|
||||
}
|
||||
public int getAction() {
|
||||
return this.getOpcIntegerValue(item_action);
|
||||
}
|
||||
|
||||
//是否有货
|
||||
public int hasGoods(int move) {
|
||||
|
||||
@@ -67,10 +67,12 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
int error = 0;
|
||||
int move = 0;
|
||||
int task = 0;
|
||||
int action = 0;
|
||||
int last_mode = 0;
|
||||
int last_error = 0;
|
||||
int last_move = 0;
|
||||
int last_task = 0;
|
||||
int last_action = 0;
|
||||
Boolean isonline = true;
|
||||
int hasGoods = 0;
|
||||
String message = null;
|
||||
@@ -143,6 +145,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
move = this.itemProtocol.getMove();
|
||||
task = this.itemProtocol.getTask();
|
||||
hasGoods = this.itemProtocol.getMove();
|
||||
action = this.itemProtocol.getAction();
|
||||
|
||||
if (mode != last_mode) {
|
||||
if (mode == 5){
|
||||
@@ -162,6 +165,10 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
this.execute_log.setResource(this.devicecode, this.device.getDevice_name());
|
||||
this.execute_log.log("设备:" + device_code + ",last_error -> error:" + last_error + "->" + error);
|
||||
}
|
||||
if (action != last_action) {
|
||||
this.execute_log.setResource(this.devicecode, this.device.getDevice_name());
|
||||
this.execute_log.log("设备:" + device_code + ",last_action -> action:" + last_action + "->" + action);
|
||||
}
|
||||
|
||||
if (this.getApply_handling()) {
|
||||
String link_device_code = this.getDevice().getExtraValue().get("link_device_code").toString();
|
||||
@@ -331,7 +338,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
last_error = error;
|
||||
last_move = move;
|
||||
last_task = task;
|
||||
|
||||
last_action = action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.nl.modules.udw.UnifiedDataAccessor;
|
||||
import org.nl.modules.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.modules.udw.UnifiedDataAppService;
|
||||
import org.openscada.opc.lib.da.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -26,6 +27,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
private int all_null;
|
||||
private Map<String, OpcItemDto> itemSearchCache;
|
||||
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
this.error_num = 0;
|
||||
this.all_null = 0;
|
||||
@@ -87,13 +89,14 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
if (this.group != null) {
|
||||
group.clear();
|
||||
group.remove();
|
||||
log.trace("{} 清理group{}");
|
||||
log.trace("清理group...");
|
||||
}
|
||||
if (this.server != null) {
|
||||
server.disconnect();
|
||||
log.trace("{} server{}");
|
||||
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();
|
||||
@@ -186,6 +189,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;
|
||||
}
|
||||
|
||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
||||
@@ -193,8 +197,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
if (true) {
|
||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
}
|
||||
|
||||
accessor_value.setValue(itemId, value);
|
||||
if(!ObjectUtil.isEmpty(value)){
|
||||
accessor_value.setValue(itemId, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,18 +219,31 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
int random = (new Random()).nextInt(10) + 1;
|
||||
random *= 1000;
|
||||
if (this.all_null < 3) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random);
|
||||
ThreadUtl.sleep((long) (5000 + random));
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000);
|
||||
break start;
|
||||
} else if (this.all_null < 6) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random);
|
||||
ThreadUtl.sleep((long) (1000 + random));
|
||||
log.warn("重新创建server");
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(tag + "重新创建server");
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random);
|
||||
}
|
||||
// ThreadUtl.sleep((long) (30000 + random));
|
||||
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000);
|
||||
break start;
|
||||
} else if (this.all_null < 12) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random);
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) ('\uea60' + random));
|
||||
} else {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random);
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) (120000 + random));
|
||||
}
|
||||
|
||||
@@ -364,10 +382,19 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
accessor_value.setValue(itemId, value);
|
||||
|
||||
// if (value != null) {
|
||||
// if (log.isTraceEnabled()) {
|
||||
// log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||
// }
|
||||
// } else if (log.isInfoEnabled()) {
|
||||
// log.info("Item {} new value: {}, Timestamp: {}, Quality: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime(), itemState.getQuality()});
|
||||
// }
|
||||
log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||
|
||||
OpcItemDto itemDto = this.getItem(itemId);
|
||||
|
||||
// if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
||||
// this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
// }
|
||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
|
||||
} catch (Exception var7) {
|
||||
@@ -388,14 +415,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
Object obj = accessor_value.getValue(relate);
|
||||
sb.append("key:" + relate + "value:" + obj + ";");
|
||||
}
|
||||
if(!itemId.endsWith("heartbeat") || !itemId.endsWith("time") ) {
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
|
||||
}
|
||||
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
|
||||
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{};信号快照:{}", new Object[]{itemId, his, value, sb});
|
||||
} else {
|
||||
if(!itemId.endsWith("heartbeat") || !itemId.endsWith("time") ) {
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
}
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.concurrent.Executors;
|
||||
public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
public static boolean isRun = false;
|
||||
ExecutorService executorService;
|
||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
@Autowired
|
||||
@@ -39,7 +39,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
public void autoRun() throws Exception {
|
||||
{
|
||||
isRun = true;
|
||||
this.executorService = Executors.newCachedThreadPool();
|
||||
|
||||
Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap();
|
||||
Map<String, List<List<OpcItemDto>>> pros;
|
||||
do{
|
||||
@@ -67,12 +67,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
//Map<String, List<List<OpcItemDto>>> pros1 = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
//List<DeviceDriver> opcDrivers = this.deviceAppService.findDeviceDriver(DeviceDriver.class);
|
||||
|
||||
while(true) {
|
||||
try {
|
||||
Thread.sleep(3600000L);
|
||||
} catch (InterruptedException var11) {
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
Thread.sleep(3000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user