fix 写入信号问题
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
package org.nl.acs.device_driver.driver;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.nl.acs.ext.wms.data.JsonUtl;
|
||||
import org.nl.acs.opc.OpcConfig;
|
||||
import org.nl.acs.opc.OpcServerService;
|
||||
import org.nl.acs.opc.OpcServerServiceImpl;
|
||||
import org.nl.acs.opc.*;
|
||||
import org.nl.exception.WDKException;
|
||||
import org.nl.modules.udw.UnifiedDataAccessor;
|
||||
import org.nl.modules.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.utils.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.AddFailedException;
|
||||
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.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver {
|
||||
UnifiedDataAccessor opcUdw;
|
||||
|
||||
@Autowired
|
||||
private OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class);
|
||||
|
||||
private Date sendTime;
|
||||
private String last_items;
|
||||
private int noLog_sendTimeOut;
|
||||
@@ -31,6 +36,66 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
return this.opcUdw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void checkcontrol(Map<String, Object> itemValues) throws JIException, AddFailedException {
|
||||
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 = 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);
|
||||
}
|
||||
|
||||
boolean check = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (check) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
ThreadUtl.sleep(300L);
|
||||
}
|
||||
|
||||
if (i > 3) {
|
||||
throw new WDKException("写入次数超过3次而失败");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean control(Map<String, Object> itemValues) {
|
||||
|
||||
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||
|
||||
@@ -598,7 +598,11 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
itemMap.put(to_param, value);
|
||||
|
||||
this.control(itemMap);
|
||||
try{
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", to_param + " 写入 " + value);
|
||||
}
|
||||
|
||||
|
||||
@@ -607,7 +607,11 @@ public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
itemMap.put(to_command, command);
|
||||
this.control(itemMap);
|
||||
try{
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", to_command + " 写入 " + command);
|
||||
}
|
||||
|
||||
|
||||
@@ -650,7 +650,12 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
LnshStationDeviceDriver lnshStationDeviceDriver;
|
||||
if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) {
|
||||
lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver();
|
||||
lnshStationDeviceDriver.writing(3, Integer.parseInt(dto.getInstruction_code()));
|
||||
try {
|
||||
lnshStationDeviceDriver.writing(3, Integer.parseInt(dto.getInstruction_code()));
|
||||
} catch (Exception e){
|
||||
log.info("下发电气信号失败:"+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//变更三色灯状态
|
||||
|
||||
Reference in New Issue
Block a user