rev 写入方法
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
package org.nl.acs.device_driver.driver;
|
||||||
|
|
||||||
|
public class ItemValue {
|
||||||
|
}
|
||||||
@@ -902,10 +902,13 @@ public class ConveyorBarcodeDeviceDriver extends AbstractOpcDeviceDriver impleme
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -880,10 +880,13 @@ public class ConveyorPressStationDeviceDriver extends AbstractOpcDeviceDriver im
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -408,10 +408,13 @@ public class LnshLaminatingMachineDeviceDriver extends AbstractOpcDeviceDriver i
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -298,10 +298,13 @@ public class LnshFoldDiscSiteDeviceDriver extends AbstractOpcDeviceDriver implem
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -249,10 +249,13 @@ public class LnshMixingMillDeviceDriver extends AbstractOpcDeviceDriver implemen
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -548,10 +548,13 @@ public class LnshPackagePalletManipulatorDeviceDriver extends AbstractOpcDeviceD
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -260,10 +260,13 @@ public class LnshPackageSiteDeviceDriver extends AbstractOpcDeviceDriver impleme
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -747,7 +747,7 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic
|
|||||||
ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class);
|
ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class);
|
||||||
if (resp.getCode() == 200) {
|
if (resp.getCode() == 200) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("to_command",102);
|
map.put("to_command",200);
|
||||||
this.writing(map);
|
this.writing(map);
|
||||||
this.setRequireSucess(true);
|
this.setRequireSucess(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1710,10 +1710,13 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -470,10 +470,13 @@ public class LnshPressDeviceDriver extends AbstractOpcDeviceDriver implements De
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -894,10 +894,13 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -1441,10 +1441,13 @@ public class LnshSplitManipulatorDeviceDriver extends AbstractOpcDeviceDriver im
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -386,10 +386,13 @@ public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements
|
|||||||
if (ObjectUtil.isNotEmpty(itemMap)) {
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
||||||
try {
|
try {
|
||||||
this.checkcontrol(itemMap);
|
this.checkcontrol(itemMap);
|
||||||
} catch (JIException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (AddFailedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
this.checkcontrol(itemMap);
|
||||||
|
} catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
||||||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap));
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.nl.acs.opc;
|
package org.nl.acs.opc;
|
||||||
|
|
||||||
|
import org.nl.acs.device_driver.driver.ItemValue;
|
||||||
import org.openscada.opc.lib.da.Group;
|
import org.openscada.opc.lib.da.Group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,11 +15,11 @@ public interface OpcServerService {
|
|||||||
|
|
||||||
Group getServer(String var1);
|
Group getServer(String var1);
|
||||||
|
|
||||||
|
Group getServerByNewConn(String var1);
|
||||||
|
|
||||||
void writeInteger(String var1, ItemValue... var2);
|
void writeInteger(String var1, ItemValue... var2);
|
||||||
|
|
||||||
void clearServer(String var1);
|
|
||||||
|
|
||||||
void cleanGroups(String var1);
|
|
||||||
void writeIntegerByNewConn(String var1, ItemValue... var2);
|
void writeIntegerByNewConn(String var1, ItemValue... var2);
|
||||||
|
|
||||||
|
void clearServer(String var1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package org.nl.acs.opc;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.jinterop.dcom.common.JIException;
|
import org.jinterop.dcom.common.JIException;
|
||||||
import org.nl.acs.auto.initial.ApplicationAutoInitial;
|
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.common.exception.BadRequestException;
|
||||||
|
import org.nl.modules.wql.exception.WDKException;
|
||||||
import org.openscada.opc.lib.common.NotConnectedException;
|
import org.openscada.opc.lib.common.NotConnectedException;
|
||||||
import org.openscada.opc.lib.da.Group;
|
import org.openscada.opc.lib.da.Group;
|
||||||
import org.openscada.opc.lib.da.Server;
|
import org.openscada.opc.lib.da.Server;
|
||||||
@@ -29,32 +31,33 @@ import java.util.Map;
|
|||||||
public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial {
|
public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
|
||||||
@Autowired
|
@Autowired OpcServerManageService opcServerManageService;
|
||||||
OpcServerManageService opcServerManageService;
|
|
||||||
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
|
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
|
||||||
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
|
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
|
||||||
Map<String, Group> groups = Collections.synchronizedMap(new HashMap());
|
Map<String, Group> groups = Collections.synchronizedMap(new HashMap());
|
||||||
|
|
||||||
public OpcServerServiceImpl() {
|
public OpcServerServiceImpl() {}
|
||||||
}
|
|
||||||
|
|
||||||
public void autoInitial() throws Exception {
|
public void autoInitial() throws Exception {
|
||||||
this.reload();
|
this.reload();
|
||||||
if (OpcConfig.auto_start_opc) {
|
if (OpcConfig.auto_start_opc) {
|
||||||
Thread t = new Thread(() -> {
|
Thread t =
|
||||||
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
|
new Thread() {
|
||||||
|
public void run() {
|
||||||
|
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
|
||||||
|
|
||||||
while (var1.hasNext()) {
|
while (var1.hasNext()) {
|
||||||
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
|
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
||||||
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
||||||
} catch (Exception var4) {
|
} catch (Exception var4) {
|
||||||
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
};
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,31 +67,12 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanGroups(String opcCode) {
|
public Group getServer(String code) {
|
||||||
Group group = (Group) this.groups.get(opcCode);
|
synchronized(this.buildLock(code)) {
|
||||||
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)) {
|
|
||||||
Group group = null;
|
Group group = null;
|
||||||
group = (Group) this.groups.get(code);
|
group = (Group)this.groups.get(code);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
label68:
|
label68: {
|
||||||
{
|
|
||||||
Group var10000;
|
Group var10000;
|
||||||
try {
|
try {
|
||||||
if (!group.isActive()) {
|
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;
|
boolean needcreate = false;
|
||||||
String groupName = code;
|
String groupName = code;
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
@@ -113,17 +97,16 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
group = server.findGroup(groupName);
|
group = server.findGroup(groupName);
|
||||||
} catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException |
|
} catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException | IllegalArgumentException var13) {
|
||||||
IllegalArgumentException var13) {
|
|
||||||
log.error(code, var13);
|
log.error(code, var13);
|
||||||
needcreate = true;
|
needcreate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needcreate) {
|
if (needcreate) {
|
||||||
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
|
OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code);
|
||||||
if (dto == null) {
|
if (dto == null) {
|
||||||
throw new RuntimeException(code + "不存在");
|
throw new RuntimeException(code+"不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (server!=null){
|
// if (server!=null){
|
||||||
@@ -132,8 +115,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (server == null) {
|
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 {
|
try {
|
||||||
group = server.addGroup(groupName);
|
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) {
|
public Group getServerByNewConn(String code) {
|
||||||
synchronized(this.buildLock(code)) {
|
synchronized(this.buildLock(code)) {
|
||||||
|
|
||||||
@@ -231,6 +177,32 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
return group;
|
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) {
|
public void writeIntegerByNewConn(String code, ItemValue... values) {
|
||||||
try {
|
try {
|
||||||
Group group = this.getServerByNewConn(code);
|
Group group = this.getServerByNewConn(code);
|
||||||
@@ -239,11 +211,18 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
|||||||
this.clearServer(code);
|
this.clearServer(code);
|
||||||
log.info("写入出错opc server {} 重新加载", code, var4);
|
log.info("写入出错opc server {} 重新加载", code, var4);
|
||||||
ThreadUtl.sleep(1000L);
|
ThreadUtl.sleep(1000L);
|
||||||
try {
|
throw var4;
|
||||||
throw var4;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,196 @@
|
|||||||
package org.nl.acs.opc;
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
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
|
@Slf4j
|
||||||
public class OpcUtl {
|
public class OpcUtl {
|
||||||
private static int timeout = 180000;
|
private static int timeout = 1*60*1000;
|
||||||
private static String key = "rpc.socketTimeout";
|
private static String key = "rpc.socketTimeout";
|
||||||
|
|
||||||
|
static {
|
||||||
|
checkTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
public static void checkTimeout() {
|
public static void checkTimeout() {
|
||||||
if (Integer.getInteger(key, 0) != timeout) {
|
if (Integer.getInteger(key, 0).intValue() != timeout) {
|
||||||
System.setProperty(key, String.valueOf(timeout));
|
System.setProperty(key, String.valueOf(timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OpcUtl() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
|
||||||
public static List<Map<String, String>> showAllOpcServer(String host, String user, String password, String domain) throws Exception {
|
|
||||||
try {
|
try {
|
||||||
List<Map<String, String>> listResult = new ArrayList();
|
Map<Item, Integer> e=group.write(requests);
|
||||||
ServerList serverList = new ServerList(host, user, password, domain);
|
boolean is_success = true;
|
||||||
Collection<ClassDetails> classDetails = serverList.listServersWithDetails(new Category[]{Categories.OPCDAServer10, Categories.OPCDAServer20, Categories.OPCDAServer30}, new Category[0]);
|
StringBuilder message = new StringBuilder();
|
||||||
Iterator var7 = classDetails.iterator();
|
Iterator arg4 = e.keySet().iterator();
|
||||||
|
|
||||||
while(var7.hasNext()) {
|
while (arg4.hasNext()) {
|
||||||
ClassDetails details = (ClassDetails)var7.next();
|
Item item = (Item) arg4.next();
|
||||||
Map<String, String> result = new LinkedHashMap();
|
Integer integer = (Integer) e.get(item);
|
||||||
result.put("classId", details.getClsId());
|
if (integer.intValue() != 0) {
|
||||||
result.put("progId", details.getProgId());
|
if (is_success) {
|
||||||
result.put("description", details.getDescription());
|
is_success = false;
|
||||||
listResult.add(result);
|
}
|
||||||
|
|
||||||
|
message.append(item.getId());
|
||||||
|
message.append(":error code:");
|
||||||
|
message.append(integer);
|
||||||
|
message.append("; ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return listResult;
|
if (!is_success) {
|
||||||
} catch (UnknownHostException | JIException | IllegalArgumentException var10) {
|
log.info("下发信号失败:"+message.toString());
|
||||||
throw new Exception(var10);
|
throw new WDKException(message.toString());
|
||||||
|
}
|
||||||
|
} catch (JIException arg7) {
|
||||||
|
log.info("下发信号失败Exception:"+arg7.getMessage());
|
||||||
|
throw new WDKException("下发信号失败Exception:"+arg7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeValue(Group group, ItemValue... values) throws WDKException {
|
||||||
|
try {
|
||||||
|
if (values != null && values.length > 0) {
|
||||||
|
List<WriteRequest> 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 WDKException(var8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
JIVariant value = itemState.getValue();
|
||||||
|
return getValue(value, item.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getValue(JIVariant jiVariant, String id) throws BadRequestException {
|
||||||
|
try {
|
||||||
|
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 (e instanceof Short) {
|
||||||
|
return jiVariant.getObject();
|
||||||
|
} else if (e instanceof Float) {
|
||||||
|
return jiVariant.getObject();
|
||||||
|
} else {
|
||||||
|
System.err.println(id + "不明类型" + e.getClass());
|
||||||
|
if (jiVariant.getType() == 0) {
|
||||||
|
System.err.println("因类型为emtpy 返回 null");
|
||||||
|
return null;
|
||||||
|
} else if (jiVariant.getType() == 1) {
|
||||||
|
System.err.println("因类型为null 返回 null");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return jiVariant.getObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Class clazz = ((JIArray) e).getArrayClass();
|
||||||
|
int[] r;
|
||||||
|
int i;
|
||||||
|
if (JIUnsignedByte.class.isAssignableFrom(clazz)) {
|
||||||
|
JIUnsignedByte[] arg7 = (JIUnsignedByte[]) ((JIUnsignedByte[]) ((JIArray) e).getArrayInstance());
|
||||||
|
r = new int[arg7.length];
|
||||||
|
|
||||||
|
for (i = 0; i < arg7.length; ++i) {
|
||||||
|
r[i] = arg7[i].getValue().byteValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
} else if (!JIUnsignedShort.class.isAssignableFrom(clazz)) {
|
||||||
|
System.err.println(id + "不明类型");
|
||||||
|
if (jiVariant.getType() == 0) {
|
||||||
|
System.err.println("因类型为emtpy 返回 null");
|
||||||
|
return null;
|
||||||
|
} else if (jiVariant.getType() == 1) {
|
||||||
|
System.err.println("因类型为null 返回 null");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return ((JIArray) e).getArrayInstance();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
JIUnsignedShort[] array = (JIUnsignedShort[]) ((JIUnsignedShort[]) ((JIArray) e)
|
||||||
|
.getArrayInstance());
|
||||||
|
r = new int[array.length];
|
||||||
|
|
||||||
|
for (i = 0; i < array.length; ++i) {
|
||||||
|
r[i] = array[i].getValue().intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JIException e) {
|
||||||
|
throw new BadRequestException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +211,7 @@ public class OpcUtl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws WDKException {
|
||||||
public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws Exception {
|
|
||||||
checkTimeout();
|
checkTimeout();
|
||||||
Server server = null;
|
Server server = null;
|
||||||
server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor());
|
server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor());
|
||||||
@@ -99,7 +220,8 @@ public class OpcUtl {
|
|||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionInformation getConnection(String host, String clsid, String user, String password, String domain) {
|
public static ConnectionInformation getConnection(String host, String clsid, String user, String password,
|
||||||
|
String domain) {
|
||||||
ConnectionInformation connection = new ConnectionInformation();
|
ConnectionInformation connection = new ConnectionInformation();
|
||||||
connection.setHost(host);
|
connection.setHost(host);
|
||||||
connection.setClsid(clsid);
|
connection.setClsid(clsid);
|
||||||
@@ -109,178 +231,6 @@ public class OpcUtl {
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getValue(Item item, ItemState itemState) throws Exception {
|
|
||||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD)) {
|
|
||||||
if (item != null) {
|
|
||||||
log.debug("value is not good {} : {}", item.getId(), itemState.getQuality());
|
|
||||||
} else {
|
|
||||||
log.debug("value is not good {}", itemState.getQuality());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
JIVariant value = itemState.getValue();
|
|
||||||
return getValue(value, item.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
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) {
|
|
||||||
return jiVariant.getObject();
|
|
||||||
} else if (object instanceof Short) {
|
|
||||||
return jiVariant.getObject();
|
|
||||||
} else if (object instanceof Float) {
|
|
||||||
return jiVariant.getObject();
|
|
||||||
} else {
|
|
||||||
System.err.println(id + "不明类型" + object.getClass());
|
|
||||||
if (jiVariant.getType() == 0) {
|
|
||||||
System.err.println("因类型为emtpy 返回 null");
|
|
||||||
return null;
|
|
||||||
} else if (jiVariant.getType() == 1) {
|
|
||||||
System.err.println("因类型为null 返回 null");
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return jiVariant.getObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Class<?> clazz = ((JIArray)object).getArrayClass();
|
|
||||||
int[] r;
|
|
||||||
int i;
|
|
||||||
if (JIUnsignedByte.class.isAssignableFrom(clazz)) {
|
|
||||||
JIUnsignedByte[] array = (JIUnsignedByte[])((JIUnsignedByte[])((JIArray)object).getArrayInstance());
|
|
||||||
r = new int[array.length];
|
|
||||||
|
|
||||||
for(i = 0; i < array.length; ++i) {
|
|
||||||
r[i] = array[i].getValue().byteValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
} else if (!JIUnsignedShort.class.isAssignableFrom(clazz)) {
|
|
||||||
System.err.println(id + "不明类型");
|
|
||||||
if (jiVariant.getType() == 0) {
|
|
||||||
System.err.println("因类型为emtpy 返回 null");
|
|
||||||
return null;
|
|
||||||
} else if (jiVariant.getType() == 1) {
|
|
||||||
System.err.println("因类型为null 返回 null");
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return ((JIArray)object).getArrayInstance();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
JIUnsignedShort[] array = (JIUnsignedShort[])((JIUnsignedShort[])((JIArray)object).getArrayInstance());
|
|
||||||
r = new int[array.length];
|
|
||||||
|
|
||||||
for(i = 0; i < array.length; ++i) {
|
|
||||||
r[i] = array[i].getValue().intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JIException var7) {
|
|
||||||
// throw new Exception(var7);
|
|
||||||
var7.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeValue(Group group, WriteRequest... requests) throws Exception {
|
|
||||||
try {
|
|
||||||
Map<Item, Integer> 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("; ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_success) {
|
|
||||||
throw new Exception(message.toString());
|
|
||||||
}
|
|
||||||
} catch (JIException var8) {
|
|
||||||
throw new Exception(var8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeValue(Group group, ItemValue... values) throws Exception {
|
|
||||||
try {
|
|
||||||
if (values != null && values.length > 0) {
|
|
||||||
List<WriteRequest> 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 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 JIVariant getByteArrayVariantxx(int[] bytes) {
|
public static JIVariant getByteArrayVariantxx(int[] bytes) {
|
||||||
Integer[] byte_Data = new Integer[bytes.length];
|
Integer[] byte_Data = new Integer[bytes.length];
|
||||||
|
|
||||||
@@ -319,8 +269,6 @@ public class OpcUtl {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
checkTimeout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -470,9 +470,10 @@ export default {
|
|||||||
const obj = { name: '行走列', value: data[val] }
|
const obj = { name: '行走列', value: data[val] }
|
||||||
this.arr.push(obj)
|
this.arr.push(obj)
|
||||||
} else if (val === 'task1') {
|
} else if (val === 'task1') {
|
||||||
const obj = { name: '前工位任务号', value: data[val] }
|
const obj = { name: '前工位任务', value: data[val] }
|
||||||
this.arr.push(obj)
|
this.arr.push(obj)
|
||||||
} else if (val === 'task2') {
|
}
|
||||||
|
else if (val === 'task2') {
|
||||||
const obj = { name: '后工位任务号', value: data[val] }
|
const obj = { name: '后工位任务号', value: data[val] }
|
||||||
this.arr.push(obj)
|
this.arr.push(obj)
|
||||||
} else if (val === 'labeling_qty') {
|
} else if (val === 'labeling_qty') {
|
||||||
@@ -539,6 +540,13 @@ export default {
|
|||||||
const obj = { name: '模式名称', value: data[val] }
|
const obj = { name: '模式名称', value: data[val] }
|
||||||
this.arr.push(obj)
|
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)
|
// console.log('arr:', this.arr)
|
||||||
|
|||||||
Reference in New Issue
Block a user