rev 更新写入信号方法
This commit is contained in:
@@ -8,6 +8,7 @@ import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.modules.wql.exception.WDKException;
|
||||
import org.nl.modules.wql.util.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;
|
||||
@@ -65,6 +66,95 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
//下发信号
|
||||
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 WDKException("写入次数超过3次而失败");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
public void checkControl(Map<String, Object> itemValues) {
|
||||
Group group = opcServerService.getServer(this.getOpcServer());
|
||||
Map<String, Object> write = new HashMap();
|
||||
|
||||
@@ -405,7 +405,17 @@ public class HfGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
Map<String, Object> itemMap = new HashMap<>();
|
||||
|
||||
itemMap.put(to_param, value);
|
||||
this.control(itemMap);
|
||||
// this.control(itemMap);
|
||||
try {
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try{
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e1){
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||
}
|
||||
|
||||
@@ -413,13 +423,44 @@ public class HfGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
ReadUtil.write(itemMap, server);
|
||||
}
|
||||
|
||||
public void writing(int command) {
|
||||
// public void writing(int command) {
|
||||
//
|
||||
// String opcservcerid = this.getDevice().getOpc_server_id();
|
||||
// Server server = ReadUtil.getServer(opcservcerid);
|
||||
// Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
// ReadUtil.write(itemMap, server);
|
||||
//
|
||||
// }
|
||||
|
||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
||||
Server server = ReadUtil.getServer(opcservcerid);
|
||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
ReadUtil.write(itemMap, server);
|
||||
/**
|
||||
* 抽取统一下发电气信号前缀
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getToParam() {
|
||||
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
|
||||
}
|
||||
|
||||
public void writing(Map<String, Object> map) {
|
||||
Map<String, Object> itemMap = new LinkedHashMap<>();
|
||||
map.forEach((key, value) -> {
|
||||
if (ObjectUtil.isNotEmpty(value)) {
|
||||
itemMap.put(getToParam() + key, value);
|
||||
}
|
||||
});
|
||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||
try {
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try{
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e1){
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void sendSignalType(Instruction dto) {
|
||||
@@ -432,11 +473,13 @@ public class HfGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver imp
|
||||
this.isSetAddress(nextDevice);
|
||||
String start_addr = startDevice.getExtraValue().get("address").toString();
|
||||
String next_addr = nextDevice.getExtraValue().get("address").toString();
|
||||
this.writing("to_onset", start_addr);
|
||||
this.writing("to_target", next_addr);
|
||||
this.writing("to_task", dto.getInstruction_code());
|
||||
this.writing("to_barcode", dto.getVehicle_code());
|
||||
this.writing("to_command", "1");
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("to_onset",start_addr);
|
||||
map.put("to_target",next_addr);
|
||||
map.put("to_task", dto.getInstruction_code());
|
||||
map.put("to_barcode", dto.getVehicle_code());
|
||||
map.put("to_command", "1");
|
||||
this.writing(map);
|
||||
logServer.deviceInfo("机械手申请任务", this.getDevice_code(), "机械手申请任务指令创建成功,信号写入成功");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user