From 8b27a98268b1591905cf9054a28789b73285b82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BF=8A=E6=9D=B0?= <9463626+zhou-junjiezjj@user.noreply.gitee.com> Date: Fri, 10 Nov 2023 12:28:00 +0800 Subject: [PATCH] =?UTF-8?q?rev=20=E5=86=99=E5=85=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acs/device_driver/driver/ItemValue.java | 4 + .../ConveyorBarcodeDeviceDriver.java | 9 +- .../ConveyorPressStationDeviceDriver.java | 9 +- .../LnshLaminatingMachineDeviceDriver.java | 9 +- .../LnshFoldDiscSiteDeviceDriver.java | 9 +- .../LnshMixingMillDeviceDriver.java | 9 +- ...hPackagePalletManipulatorDeviceDriver.java | 9 +- .../LnshPackageSiteDeviceDriver.java | 9 +- ...alletizingManipulatorSiteDeviceDriver.java | 11 +- .../lnsh_press/LnshPressDeviceDriver.java | 9 +- .../lnsh/lnsh_rgv/LnshRGVDeviceDriver.java | 9 +- .../LnshSplitManipulatorDeviceDriver.java | 9 +- .../lnsh_station/LnshStationDeviceDriver.java | 9 +- .../java/org/nl/acs/opc/OpcServerService.java | 7 +- .../org/nl/acs/opc/OpcServerServiceImpl.java | 157 ++++----- .../src/main/java/org/nl/acs/opc/OpcUtl.java | 322 ++++++++---------- .../src/views/system/monitor/device/index.vue | 12 +- 17 files changed, 294 insertions(+), 318 deletions(-) create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java new file mode 100644 index 0000000..d6997b8 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java @@ -0,0 +1,4 @@ +package org.nl.acs.device_driver.driver; + +public class ItemValue { +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java index c81fea2..71d4f4f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java @@ -902,10 +902,13 @@ public class ConveyorBarcodeDeviceDriver extends AbstractOpcDeviceDriver impleme if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/conveyor_press_station/ConveyorPressStationDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/conveyor_press_station/ConveyorPressStationDeviceDriver.java index 12259f4..a3b57f9 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/conveyor_press_station/ConveyorPressStationDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/conveyor_press_station/ConveyorPressStationDeviceDriver.java @@ -880,10 +880,13 @@ public class ConveyorPressStationDeviceDriver extends AbstractOpcDeviceDriver im if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_Laminating_machine/LnshLaminatingMachineDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_Laminating_machine/LnshLaminatingMachineDeviceDriver.java index 04010c8..cfb558f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_Laminating_machine/LnshLaminatingMachineDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_Laminating_machine/LnshLaminatingMachineDeviceDriver.java @@ -408,10 +408,13 @@ public class LnshLaminatingMachineDeviceDriver extends AbstractOpcDeviceDriver i if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java index c058117..e440269 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java @@ -298,10 +298,13 @@ public class LnshFoldDiscSiteDeviceDriver extends AbstractOpcDeviceDriver implem if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java index d3e8837..efdc3d3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java @@ -249,10 +249,13 @@ public class LnshMixingMillDeviceDriver extends AbstractOpcDeviceDriver implemen if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java index 4273ee4..034b05e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java @@ -548,10 +548,13 @@ public class LnshPackagePalletManipulatorDeviceDriver extends AbstractOpcDeviceD if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_site/LnshPackageSiteDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_site/LnshPackageSiteDeviceDriver.java index 75db7cc..28e6843 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_site/LnshPackageSiteDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_site/LnshPackageSiteDeviceDriver.java @@ -260,10 +260,13 @@ public class LnshPackageSiteDeviceDriver extends AbstractOpcDeviceDriver impleme if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java index fa29220..f4dced3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java @@ -747,7 +747,7 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class); if (resp.getCode() == 200) { Map map = new LinkedHashMap<>(); - map.put("to_command",102); + map.put("to_command",200); this.writing(map); this.setRequireSucess(true); } else { @@ -1710,10 +1710,13 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java index 6caecbb..c991ba3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java @@ -470,10 +470,13 @@ public class LnshPressDeviceDriver extends AbstractOpcDeviceDriver implements De if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java index 907eb5e..4a11dbf 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java @@ -894,10 +894,13 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java index 0a3a833..d9aa2ce 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java @@ -1441,10 +1441,13 @@ public class LnshSplitManipulatorDeviceDriver extends AbstractOpcDeviceDriver im if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java index 4068ba0..70ddb19 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java @@ -386,10 +386,13 @@ public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements if (ObjectUtil.isNotEmpty(itemMap)) { try { this.checkcontrol(itemMap); - } catch (JIException e) { - e.printStackTrace(); - } catch (AddFailedException e) { + } catch (Exception e) { e.printStackTrace(); + try{ + this.checkcontrol(itemMap); + } catch (Exception e1){ + e1.printStackTrace(); + } } logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java index be38354..6341f02 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java @@ -1,5 +1,6 @@ package org.nl.acs.opc; +import org.nl.acs.device_driver.driver.ItemValue; import org.openscada.opc.lib.da.Group; /** @@ -14,11 +15,11 @@ public interface OpcServerService { Group getServer(String var1); - void writeInteger(String var1, ItemValue... var2); + Group getServerByNewConn(String var1); - void clearServer(String var1); + void writeInteger(String var1, ItemValue... var2); - void cleanGroups(String var1); void writeIntegerByNewConn(String var1, ItemValue... var2); + void clearServer(String var1); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java index 34dd482..ce719ce 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java @@ -3,7 +3,9 @@ package org.nl.acs.opc; import cn.hutool.core.util.StrUtil; import org.jinterop.dcom.common.JIException; import org.nl.acs.auto.initial.ApplicationAutoInitial; +import org.nl.acs.device_driver.driver.ItemValue; import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.wql.exception.WDKException; import org.openscada.opc.lib.common.NotConnectedException; import org.openscada.opc.lib.da.Group; import org.openscada.opc.lib.da.Server; @@ -29,32 +31,33 @@ import java.util.Map; public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial { private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class); - @Autowired - OpcServerManageService opcServerManageService; + @Autowired OpcServerManageService opcServerManageService; Map opcServerManageDtos = new HashMap(); Map servers = Collections.synchronizedMap(new HashMap()); Map groups = Collections.synchronizedMap(new HashMap()); - public OpcServerServiceImpl() { - } + public OpcServerServiceImpl() {} public void autoInitial() throws Exception { this.reload(); if (OpcConfig.auto_start_opc) { - Thread t = new Thread(() -> { - Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator(); - - while (var1.hasNext()) { - OpcServerManageDto dto = (OpcServerManageDto) var1.next(); - - try { - OpcServerServiceImpl.this.getServer(dto.getOpc_code()); - OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code()); - } catch (Exception var4) { - OpcServerServiceImpl.log.warn("启动无法载入servers", var4); - } - } - }); + Thread t = + new Thread() { + public void run() { + Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator(); + + while (var1.hasNext()) { + OpcServerManageDto dto = (OpcServerManageDto) var1.next(); + + try { + OpcServerServiceImpl.this.getServer(dto.getOpc_code()); + OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code()); + } catch (Exception var4) { + OpcServerServiceImpl.log.warn("启动无法载入servers", var4); + } + } + } + }; t.start(); } } @@ -64,31 +67,12 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos); } - public void cleanGroups(String opcCode) { - Group group = (Group) this.groups.get(opcCode); - if (group != null) { - Server server = group.getServer(); - - try { - group.remove(); - } catch (JIException var5) { - var5.printStackTrace(); - } - - this.groups.remove(opcCode); - server.disconnect(); - this.servers.remove(opcCode); - } - - } - - public Group getServer(String code) { - synchronized (this.buildLock(code)) { + public Group getServer(String code) { + synchronized(this.buildLock(code)) { Group group = null; - group = (Group) this.groups.get(code); + group = (Group)this.groups.get(code); if (group != null) { - label68: - { + label68: { Group var10000; try { if (!group.isActive()) { @@ -105,7 +89,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn } } - Server server = (Server) this.servers.get(code); + Server server = (Server)this.servers.get(code); boolean needcreate = false; String groupName = code; if (server == null) { @@ -113,17 +97,16 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn } else { try { group = server.findGroup(groupName); - } catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException | - IllegalArgumentException var13) { + } catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException | IllegalArgumentException var13) { log.error(code, var13); needcreate = true; } } if (needcreate) { - OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code); + OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code); if (dto == null) { - throw new RuntimeException(code + "不存在"); + throw new RuntimeException(code+"不存在"); } // if (server!=null){ @@ -132,8 +115,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn // } if (server == null) { - server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); - } + server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); } try { group = server.addGroup(groupName); @@ -157,42 +139,6 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn } } - public void clearServer(String code) { - synchronized (this.buildLock(code)) { - try { - Server server = (Server) this.servers.get(code); - server.disconnect(); - } catch (Exception var5) { - } - - this.servers.remove(code); - this.groups.remove(code); - } - } - - - public void writeInteger(String code, ItemValue... values) { - try { - Group group = this.getServer(code); - OpcUtl.writeValue(group, values); - } catch (Exception var4) { - this.clearServer(code); - log.warn("写入出错opc server {} 重新加载", code, var4); - ThreadUtl.sleep(5000L); -// throw var4; - } - } - - private String buildLock(String key) { - if (StrUtil.isEmpty(key)) { - key = ""; - } - StringBuilder builder = new StringBuilder(); - builder.append("OpcServerService."); - builder.append(key); - String lock = builder.toString().intern(); - return lock; - } public Group getServerByNewConn(String code) { synchronized(this.buildLock(code)) { @@ -231,6 +177,32 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn return group; } } + + public void clearServer(String code) { + synchronized(this.buildLock(code)) { + try { + Server server = (Server)this.servers.get(code); + server.disconnect(); + } catch (Exception var5) { + } + + this.servers.remove(code); + this.groups.remove(code); + } + } + + public void writeInteger(String code, ItemValue... values) { + try { + Group group = this.getServer(code); + OpcUtl.writeValue(group, values); + } catch (Exception var4) { + this.clearServer(code); + log.info("写入出错opc server {} 重新加载", code, var4); + ThreadUtl.sleep(1000L); + throw var4; + } + } + public void writeIntegerByNewConn(String code, ItemValue... values) { try { Group group = this.getServerByNewConn(code); @@ -239,11 +211,18 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn this.clearServer(code); log.info("写入出错opc server {} 重新加载", code, var4); ThreadUtl.sleep(1000L); - try { - throw var4; - } catch (Exception e) { - e.printStackTrace(); - } + throw var4; } } + + private String buildLock(String key) { + if (StrUtil.isEmpty(key)) { + key = ""; + } + StringBuilder builder = new StringBuilder(); + builder.append("OpcServerService."); + builder.append(key); + String lock = builder.toString().intern(); + return lock; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java index bae6611..26af619 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -1,118 +1,119 @@ package org.nl.acs.opc; -import java.net.UnknownHostException; +import cn.hutool.core.util.NumberUtil; +import lombok.extern.slf4j.Slf4j; +import org.jinterop.dcom.common.JIException; +import org.jinterop.dcom.core.*; +import org.nl.acs.device_driver.driver.ItemValue; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.wql.exception.WDKException; +import org.openscada.opc.lib.common.ConnectionInformation; +import org.openscada.opc.lib.da.*; + import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Executors; -import lombok.extern.slf4j.Slf4j; -import org.jinterop.dcom.common.JIException; -import org.jinterop.dcom.core.IJIUnsigned; -import org.jinterop.dcom.core.JIArray; -import org.jinterop.dcom.core.JIString; -import org.jinterop.dcom.core.JIUnsignedByte; -import org.jinterop.dcom.core.JIUnsignedShort; -import org.jinterop.dcom.core.JIVariant; -import org.nl.modules.wql.exception.WDKException; -import org.openscada.opc.dcom.list.ClassDetails; -import org.openscada.opc.lib.common.AlreadyConnectedException; -import org.openscada.opc.lib.common.ConnectionInformation; -import org.openscada.opc.lib.da.AddFailedException; -import org.openscada.opc.lib.da.AutoReconnectController; -import org.openscada.opc.lib.da.Group; -import org.openscada.opc.lib.da.Item; -import org.openscada.opc.lib.da.ItemState; -import org.openscada.opc.lib.da.Server; -import org.openscada.opc.lib.da.WriteRequest; -import org.openscada.opc.lib.list.Categories; -import org.openscada.opc.lib.list.Category; -import org.openscada.opc.lib.list.ServerList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - @Slf4j public class OpcUtl { - private static int timeout = 180000; + private static int timeout = 1*60*1000; private static String key = "rpc.socketTimeout"; + static { + checkTimeout(); + } + public static void checkTimeout() { - if (Integer.getInteger(key, 0) != timeout) { + if (Integer.getInteger(key, 0).intValue() != timeout) { System.setProperty(key, String.valueOf(timeout)); } } - private OpcUtl() { - } - - public static List> showAllOpcServer(String host, String user, String password, String domain) throws Exception { + public static void writeValue(Group group, WriteRequest... requests) throws WDKException { try { - List> listResult = new ArrayList(); - ServerList serverList = new ServerList(host, user, password, domain); - Collection classDetails = serverList.listServersWithDetails(new Category[]{Categories.OPCDAServer10, Categories.OPCDAServer20, Categories.OPCDAServer30}, new Category[0]); - Iterator var7 = classDetails.iterator(); - - while(var7.hasNext()) { - ClassDetails details = (ClassDetails)var7.next(); - Map result = new LinkedHashMap(); - result.put("classId", details.getClsId()); - result.put("progId", details.getProgId()); - result.put("description", details.getDescription()); - listResult.add(result); + Map e=group.write(requests); + boolean is_success = true; + StringBuilder message = new StringBuilder(); + Iterator arg4 = e.keySet().iterator(); + + while (arg4.hasNext()) { + Item item = (Item) arg4.next(); + Integer integer = (Integer) e.get(item); + if (integer.intValue() != 0) { + if (is_success) { + is_success = false; + } + + message.append(item.getId()); + message.append(":error code:"); + message.append(integer); + message.append("; "); + } } - return listResult; - } catch (UnknownHostException | JIException | IllegalArgumentException var10) { - throw new Exception(var10); + if (!is_success) { + log.info("下发信号失败:"+message.toString()); + throw new WDKException(message.toString()); + } + } catch (JIException arg7) { + log.info("下发信号失败Exception:"+arg7.getMessage()); + throw new WDKException("下发信号失败Exception:"+arg7); } } - - public static Server getServer(String host, String clsid, String user, String password, String domain) - throws WDKException { - checkTimeout(); - Server server = null; - + public static void writeValue(Group group, ItemValue... values) throws WDKException { try { - server = new Server(getConnection(host, clsid, user, password, domain), - Executors.newSingleThreadScheduledExecutor()); - server.connect(); - return server; - } catch (Exception e) { - System.out.println("server error:"+e.getMessage()); - throw new WDKException(e.getMessage()); - } - } + if (values != null && values.length > 0) { + List ws = new ArrayList(); + ItemValue[] var3 = values; + int var4 = values.length; + for(int var5 = 0; var5 < var4; ++var5) { + ItemValue value = var3[var5]; + Item item = group.addItem(value.getItem_code()); + ws.add(new WriteRequest(item, getVariant(value.getItem_value()))); + } + writeValue(group, (WriteRequest[])ws.toArray(new WriteRequest[0])); + } - public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws Exception { - checkTimeout(); - Server server = null; - server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor()); - AutoReconnectController autoReconnectController = new AutoReconnectController(server); - autoReconnectController.connect(); - return server; + } catch (AddFailedException | JIException var8) { + throw new WDKException(var8); + } } - public static ConnectionInformation getConnection(String host, String clsid, String user, String password, String domain) { - ConnectionInformation connection = new ConnectionInformation(); - connection.setHost(host); - connection.setClsid(clsid); - connection.setUser(user); - connection.setPassword(password); - connection.setDomain(domain); - return connection; + public static JIVariant getVariant(Object object) { + if (object instanceof Integer) { + return getIntegerVariant((Integer)object); + } else if (object instanceof String) { + return getStringVariant((String)object); + } else if (object instanceof byte[]) { + return getByteArrayVariant((byte[])((byte[])object)); + } else if (object instanceof Byte[]) { + return getByteArrayVariant((Byte[])((Byte[])object)); + } else if (object instanceof Boolean) { + return new JIVariant((Boolean)object); + } else if (object instanceof int[]) { + return getByteArrayVariantxx((int[])((int[])object)); + } else if (object instanceof Integer[]) { + JIArray array = new JIArray((Integer)object, false); + JIVariant value = new JIVariant(array); + return value; + } else if (object instanceof JIVariant) { + return (JIVariant)object; + } else { + throw new WDKException("未实现目前支持是int,string,byte[]"); + } } - public static Object getValue(Item item, ItemState itemState) throws Exception { - if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD)) { + public static Object getValue(Item item, ItemState itemState) throws BadRequestException { + if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) { if (item != null) { log.debug("value is not good {} : {}", item.getId(), itemState.getQuality()); +// throw new WDKException("值不健康进行重连!"); } else { log.debug("value is not good {}", itemState.getQuality()); } @@ -124,36 +125,24 @@ public class OpcUtl { } } - public static int getIntegerValue(Item item, ItemState itemState) throws Exception { - return (Integer)getValue(item, itemState); - } - - public static String getStringValue(Item item, ItemState itemState) throws Exception { - return (String)getValue(item, itemState); - } - - public static byte[] getByteArrayValue(Item item, ItemState itemState) throws Exception { - return (byte[])((byte[])getValue(item, itemState)); - } - - public static Object getValue(JIVariant jiVariant, String id) { + public static Object getValue(JIVariant jiVariant, String id) throws BadRequestException { try { - Object object = jiVariant.getObject(); - if (object instanceof IJIUnsigned) { - return ((IJIUnsigned)object).getValue().intValue(); - } else if (object instanceof Boolean) { - return jiVariant.getObjectAsBoolean() ? 1 : 0; - } else if (object instanceof JIString) { - return ((JIString)object).getString(); - } else if (!(object instanceof JIArray)) { - if (object instanceof Integer) { + Object e = jiVariant.getObject(); + if (e instanceof IJIUnsigned) { + return Integer.valueOf(((IJIUnsigned) e).getValue().intValue()); + } else if (e instanceof Boolean) { + return jiVariant.getObjectAsBoolean() ? Integer.valueOf(1) : Integer.valueOf(0); + } else if (e instanceof JIString) { + return ((JIString) e).getString(); + } else if (!(e instanceof JIArray)) { + if (e instanceof Integer) { return jiVariant.getObject(); - } else if (object instanceof Short) { + } else if (e instanceof Short) { return jiVariant.getObject(); - } else if (object instanceof Float) { + } else if (e instanceof Float) { return jiVariant.getObject(); } else { - System.err.println(id + "不明类型" + object.getClass()); + System.err.println(id + "不明类型" + e.getClass()); if (jiVariant.getType() == 0) { System.err.println("因类型为emtpy 返回 null"); return null; @@ -165,15 +154,15 @@ public class OpcUtl { } } } else { - Class clazz = ((JIArray)object).getArrayClass(); + Class clazz = ((JIArray) e).getArrayClass(); int[] r; int i; if (JIUnsignedByte.class.isAssignableFrom(clazz)) { - JIUnsignedByte[] array = (JIUnsignedByte[])((JIUnsignedByte[])((JIArray)object).getArrayInstance()); - r = new int[array.length]; + JIUnsignedByte[] arg7 = (JIUnsignedByte[]) ((JIUnsignedByte[]) ((JIArray) e).getArrayInstance()); + r = new int[arg7.length]; - for(i = 0; i < array.length; ++i) { - r[i] = array[i].getValue().byteValue(); + for (i = 0; i < arg7.length; ++i) { + r[i] = arg7[i].getValue().byteValue(); } return r; @@ -186,99 +175,60 @@ public class OpcUtl { System.err.println("因类型为null 返回 null"); return null; } else { - return ((JIArray)object).getArrayInstance(); + return ((JIArray) e).getArrayInstance(); } } else { - JIUnsignedShort[] array = (JIUnsignedShort[])((JIUnsignedShort[])((JIArray)object).getArrayInstance()); + JIUnsignedShort[] array = (JIUnsignedShort[]) ((JIUnsignedShort[]) ((JIArray) e) + .getArrayInstance()); r = new int[array.length]; - for(i = 0; i < array.length; ++i) { + for (i = 0; i < array.length; ++i) { r[i] = array[i].getValue().intValue(); } return r; } } - } catch (JIException var7) { -// throw new Exception(var7); - var7.printStackTrace(); + } catch (JIException e) { + throw new BadRequestException(e.getMessage()); } - return null; } - public static void writeValue(Group group, WriteRequest... requests) throws Exception { - try { - Map write = group.write(requests); - boolean is_success = true; - StringBuilder message = new StringBuilder(); - Iterator var5 = write.keySet().iterator(); - while(var5.hasNext()) { - Item item = (Item)var5.next(); - Integer integer = (Integer)write.get(item); - if (integer != 0) { - if (is_success) { - is_success = false; - } - - message.append(item.getId()); - message.append(":error code:"); - message.append(integer); - message.append("; "); - } - } + public static Server getServer(String host, String clsid, String user, String password, String domain) + throws WDKException { + checkTimeout(); + Server server = null; - if (!is_success) { - throw new Exception(message.toString()); - } - } catch (JIException var8) { - throw new Exception(var8); + try { + server = new Server(getConnection(host, clsid, user, password, domain), + Executors.newSingleThreadScheduledExecutor()); + server.connect(); + return server; + } catch (Exception e) { + System.out.println("server error:"+e.getMessage()); + throw new WDKException(e.getMessage()); } } - public static void writeValue(Group group, ItemValue... values) throws Exception { - try { - if (values != null && values.length > 0) { - List ws = new ArrayList(); - ItemValue[] var3 = values; - int var4 = values.length; - - for(int var5 = 0; var5 < var4; ++var5) { - ItemValue value = var3[var5]; - Item item = group.addItem(value.getItem_code()); - ws.add(new WriteRequest(item, getVariant(value.getItem_value()))); - } - - writeValue(group, (WriteRequest[])ws.toArray(new WriteRequest[0])); - } - - } catch (AddFailedException | JIException var8) { - throw new Exception(var8); - } + public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws WDKException { + checkTimeout(); + Server server = null; + server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor()); + AutoReconnectController autoReconnectController = new AutoReconnectController(server); + autoReconnectController.connect(); + return server; } - public static JIVariant getVariant(Object object) throws Exception { - if (object instanceof Integer) { - return getIntegerVariant((Integer)object); - } else if (object instanceof String) { - return getStringVariant((String)object); - } else if (object instanceof byte[]) { - return getByteArrayVariant((byte[])((byte[])object)); - } else if (object instanceof Byte[]) { - return getByteArrayVariant((Byte[])((Byte[])object)); - } else if (object instanceof Boolean) { - return new JIVariant((Boolean)object); - } else if (object instanceof int[]) { - return getByteArrayVariantxx((int[])((int[])object)); - } else if (object instanceof Integer[]) { - JIArray array = new JIArray((Integer)object, false); - JIVariant value = new JIVariant(array); - return value; - } else if (object instanceof JIVariant) { - return (JIVariant)object; - } else { - throw new Exception("未实现目前支持是int,string,byte[]"); - } + public static ConnectionInformation getConnection(String host, String clsid, String user, String password, + String domain) { + ConnectionInformation connection = new ConnectionInformation(); + connection.setHost(host); + connection.setClsid(clsid); + connection.setUser(user); + connection.setPassword(password); + connection.setDomain(domain); + return connection; } public static JIVariant getByteArrayVariantxx(int[] bytes) { @@ -319,8 +269,6 @@ public class OpcUtl { return value; } - static { - checkTimeout(); - } + } diff --git a/acs/nladmin-ui/src/views/system/monitor/device/index.vue b/acs/nladmin-ui/src/views/system/monitor/device/index.vue index 18a5a80..07c84ee 100644 --- a/acs/nladmin-ui/src/views/system/monitor/device/index.vue +++ b/acs/nladmin-ui/src/views/system/monitor/device/index.vue @@ -470,9 +470,10 @@ export default { const obj = { name: '行走列', value: data[val] } this.arr.push(obj) } else if (val === 'task1') { - const obj = { name: '前工位任务号', value: data[val] } + const obj = { name: '前工位任务', value: data[val] } this.arr.push(obj) - } else if (val === 'task2') { + } + else if (val === 'task2') { const obj = { name: '后工位任务号', value: data[val] } this.arr.push(obj) } else if (val === 'labeling_qty') { @@ -539,6 +540,13 @@ export default { const obj = { name: '模式名称', value: data[val] } this.arr.push(obj) } + else if (val==='requireSucess1'){ + const obj = { name: '请求成功标记', value: data[val] } + this.arr.push(obj) + } + + // const obj = { name: '请求成功标记', value: data[requireSucess1] } + // this.arr.push(obj) } } // console.log('arr:', this.arr)