checkControl仅双工位RGV使用,其余驱动还原control

This commit is contained in:
psh
2023-10-17 13:20:00 +08:00
parent d066787439
commit 96e401b696
8 changed files with 66 additions and 83 deletions

View File

@@ -1,6 +1,7 @@
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;
@@ -64,79 +65,61 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
}
}
public void checkControl(Map<String, Object> itemValues) {
public void checkControl(Map<String, Object> itemValues) {
Group group = opcServerService.getServer(this.getOpcServer());
Map<String, Item> readItems = new LinkedHashMap<>();
List<String> itemsString;
itemsString = new ArrayList<>(itemValues.keySet());
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();
for (String string : itemsString) {
while (is.hasNext()) {
String string = (String) is.next();
try {
readItems.put(string, group.addItem(string));
readitems.put(string, group.addItem(string));
} catch (Exception e) {
log.error("group add item error!", e);
e.printStackTrace();
}
}
int i = 0;
while (true) {
//下发信号
try{
if(i == 0){
control( itemValues);
} else {
controlByNewConn( itemValues);
}
} catch (Exception e){
log.error("check control error!", e);
}
Map<String, Object> read = new HashMap<>();
Map<Item, ItemState> itemStatus;
boolean check = true;
control( itemValues);
Map<String, Object> read = new HashMap();
Map<Item, ItemState> itemStatus = null;
try {
if (i > 0) {
group = opcServerService.getServer(this.getOpcServer());
itemsString = new ArrayList<>(itemValues.keySet());
itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
} catch (JIException e) {
throw new RuntimeException(e);
}
Set<Item> items = itemStatus.keySet();
Iterator var15 = items.iterator();
for (String string : itemsString) {
try {
readItems.put(string, group.addItem(string));
} catch (Exception e) {
log.error("group add item error!", e);
}
}
itemStatus = group.read(true, readItems.values().toArray(new Item[0]));
} else {
itemStatus = group.read(true, readItems.values().toArray(new Item[0]));
}
Set<Item> items = itemStatus.keySet();
for (Item item : items) {
ItemState itemState = itemStatus.get(item);
Object value = OpcUtl.getValue(item, itemState);
read.put(item.getId(), value);
}
for (String itemString : itemsString) {
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
check = false;
}
}
} catch (Exception e) {
log.error("check control error!", e);
check = false;
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);
ThreadUtl.sleep(1000L);
}
if (i > 3) {
log.info("写入次数超过3次而失败");
throw new WDKException("写入次数超过3次而失败");
}
++i;

View File

@@ -340,7 +340,7 @@ public class HfKilnManipulatorDeviceDriver extends AbstractOpcDeviceDriver imple
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_param, value);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
}

View File

@@ -293,7 +293,7 @@ public class HfKilnTrussDeviceDriver extends AbstractOpcDeviceDriver implements
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_command, command);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
}

View File

@@ -405,7 +405,7 @@ public class HfGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver imp
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_param, value);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
}

View File

@@ -580,7 +580,7 @@ public class HfRGVTwoDeviceDriver extends AbstractOpcDeviceDriver implements Dev
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_param, value);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
}

View File

@@ -667,7 +667,7 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_command, command);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
}
@@ -677,7 +677,7 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_param, value);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
}

View File

@@ -519,7 +519,7 @@ public class HfStationTwoDeviceDriver extends AbstractOpcDeviceDriver implements
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_command, command);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
}
@@ -529,7 +529,7 @@ public class HfStationTwoDeviceDriver extends AbstractOpcDeviceDriver implements
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_param, value);
this.checkControl(itemMap);
this.control(itemMap);
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
}

View File

@@ -139,9 +139,9 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
if (device.getDeviceDriver() instanceof HfStationDeviceDriver) {
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
if (StrUtil.isNotBlank(hfStationDeviceDriver.getOrder())) {
throw new BadRequestException("设备正在生产");
}
// if (StrUtil.isNotBlank(hfStationDeviceDriver.getOrder())) {
// throw new BadRequestException("设备正在生产");
// }
// if (hfStationDeviceDriver.getStatus() != 2) {
// throw new BadRequestException("设备状态不为自动");
// }
@@ -167,7 +167,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
hfStationTwoDeviceDriver.writing("to_b", dto.getB());
hfStationTwoDeviceDriver.writing("to_h", dto.getH());
hfStationTwoDeviceDriver.writing("to_w", dto.getW());
hfStationTwoDeviceDriver.writing("to_number", dto.getNumber());
hfStationTwoDeviceDriver.writing("to_number", ObjectUtil.isNotEmpty(dto.getNumber())?dto.getNumber():"0");
hfStationTwoDeviceDriver.writing("to_product_code", dto.getProduct_code());
hfStationTwoDeviceDriver.writing("to_order", dto.getOrder_code());
hfStationTwoDeviceDriver.writing("to_order_num", String.valueOf(dto.getQty()));
@@ -176,7 +176,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
hfStationTwoDeviceDriver.writing("to_b", dto.getB());
hfStationTwoDeviceDriver.writing("to_h", dto.getH());
hfStationTwoDeviceDriver.writing("to_w", dto.getW());
hfStationTwoDeviceDriver.writing("to_number", dto.getNumber());
hfStationTwoDeviceDriver.writing("to_number", ObjectUtil.isNotEmpty(dto.getNumber())?dto.getNumber():"0");
hfStationTwoDeviceDriver.writing("to_product_code", dto.getProduct_code());
hfStationTwoDeviceDriver.writing("to_material_code", dto.getMaterial_code());
hfStationTwoDeviceDriver.writing("to_command", "1");
@@ -194,7 +194,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
hfStationTwoDeviceDriver.writing("to_b", dto.getB());
hfStationTwoDeviceDriver.writing("to_h", dto.getH());
hfStationTwoDeviceDriver.writing("to_w", dto.getW());
hfStationTwoDeviceDriver.writing("to_number", dto.getNumber());
hfStationTwoDeviceDriver.writing("to_number", ObjectUtil.isNotEmpty(dto.getNumber())?dto.getNumber():"0");
hfStationTwoDeviceDriver.writing("to_product_code", dto.getProduct_code());
hfStationTwoDeviceDriver.writing("to_order", dto.getOrder_code());
hfStationTwoDeviceDriver.writing("to_order_num", String.valueOf(dto.getQty()));
@@ -203,7 +203,7 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
hfStationTwoDeviceDriver.writing("to_b", dto.getB());
hfStationTwoDeviceDriver.writing("to_h", dto.getH());
hfStationTwoDeviceDriver.writing("to_w", dto.getW());
hfStationTwoDeviceDriver.writing("to_number", dto.getNumber());
hfStationTwoDeviceDriver.writing("to_number", ObjectUtil.isNotEmpty(dto.getNumber())?dto.getNumber():"0");
hfStationTwoDeviceDriver.writing("to_product_code", dto.getProduct_code());
hfStationTwoDeviceDriver.writing("to_command", "1");
hfStationTwoDeviceDriver.writing("to_command", "1");
@@ -353,13 +353,13 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
if (device.getDeviceDriver() instanceof HfStationDeviceDriver) {
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
String order = hfStationDeviceDriver.getOrder();
if (StrUtil.isNotBlank(order)){
throw new BadRequestException("设备正在生产");
}
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
if (hfStationDeviceDriver.getStatus() != 2) {
throw new BadRequestException("设备状态不为自动");
}
// if (StrUtil.isNotBlank(order)){
// throw new BadRequestException("设备正在生产");
// }
// hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
// if (hfStationDeviceDriver.getStatus() != 2) {
// throw new BadRequestException("设备状态不为自动");
// }
hfStationDeviceDriver.writing("to_order", produceshiftorderDto.getOrder_code());
hfStationDeviceDriver.writing("to_order_num", String.valueOf(produceshiftorderDto.getQty()));
hfStationDeviceDriver.writing("to_product_number", produceshiftorderDto.getMaterial_code());
@@ -373,9 +373,9 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
Device linkDevice = deviceAppService.findDeviceByCode(link_device_code);
if (linkDevice.getDeviceDriver() instanceof HfStationTwoDeviceDriver) {
HfStationTwoDeviceDriver hfStationTwoDeviceDriver = (HfStationTwoDeviceDriver) linkDevice.getDeviceDriver();
if (StrUtil.isNotBlank(hfStationTwoDeviceDriver.getOrder())) {
throw new BadRequestException("设备正在生产");
}
// if (StrUtil.isNotBlank(hfStationTwoDeviceDriver.getOrder())) {
// throw new BadRequestException("设备正在生产");
// }
hfStationTwoDeviceDriver.writing("to_order", produceshiftorderDto.getOrder_code());
hfStationTwoDeviceDriver.writing("to_order_num", String.valueOf(produceshiftorderDto.getQty()));
hfStationTwoDeviceDriver.writing("to_material_code", produceshiftorderDto.getMaterial_code());
@@ -398,9 +398,9 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
hfStationTwoDeviceDriver.writing("to_command", "3");
}else if (linkDevice.getDeviceDriver() instanceof HfStationTwoDeviceDriver) {
HfStationTwoDeviceDriver hfStationTwoDeviceDriver = (HfStationTwoDeviceDriver) linkDevice.getDeviceDriver();
if (StrUtil.isNotBlank(hfStationTwoDeviceDriver.getOrder())) {
throw new BadRequestException("设备正在生产");
}
// if (StrUtil.isNotBlank(hfStationTwoDeviceDriver.getOrder())) {
// throw new BadRequestException("设备正在生产");
// }
hfStationTwoDeviceDriver.writing("to_order", produceshiftorderDto.getOrder_code());
hfStationTwoDeviceDriver.writing("to_order_num", String.valueOf(produceshiftorderDto.getQty()));
hfStationTwoDeviceDriver.writing("to_material_code", produceshiftorderDto.getMaterial_code());
@@ -424,9 +424,9 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
}
} if (device.getDeviceDriver() instanceof HfStationTwoDeviceDriver) {
HfStationTwoDeviceDriver hfStationTwoDeviceDriver = (HfStationTwoDeviceDriver) device.getDeviceDriver();
if (StrUtil.isNotBlank(hfStationTwoDeviceDriver.getOrder())) {
throw new BadRequestException("设备正在生产");
}
// if (StrUtil.isNotBlank(hfStationTwoDeviceDriver.getOrder())) {
// throw new BadRequestException("设备正在生产");
// }
hfStationTwoDeviceDriver.writing("to_order", produceshiftorderDto.getOrder_code());
hfStationTwoDeviceDriver.writing("to_order_num", String.valueOf(produceshiftorderDto.getQty()));
hfStationTwoDeviceDriver.writing("to_material_code", produceshiftorderDto.getMaterial_code());