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