@@ -43,16 +43,16 @@ public class ConveyorDevice {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// System.out.println("test");
|
System.out.println("test");
|
||||||
// String MODE = "RD1.RD1." + id + ".mode";
|
String MODE = "RD1.RD1." + id + ".mode";
|
||||||
// String code = OpcUtl.read(MODE);
|
String code = OpcUtl.read(MODE);
|
||||||
// if ("2".equals(code)) {
|
if ("2".equals(code)) {
|
||||||
// TaskService taskserver = new TaskServiceImpl();
|
TaskService taskserver = new TaskServiceImpl();
|
||||||
// TaskDto dto = new TaskDto();
|
TaskDto dto = new TaskDto();
|
||||||
// dto.setStart_point_code(id);
|
dto.setStart_point_code(id);
|
||||||
// dto.setNext_point_code("1002");
|
dto.setNext_point_code("1002");
|
||||||
// taskserver.create(dto);
|
taskserver.create(dto);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// String device = "1001,1002";
|
String device = "1001,1002";
|
||||||
// List list = new ArrayList<>();
|
List list = new ArrayList<>();
|
||||||
// list.add("1001");
|
list.add("1001");
|
||||||
// list.add("1002");
|
list.add("1002");
|
||||||
// for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
// ConveyorDevice condev = new ConveyorDevice(list.get(i).toString());
|
ConveyorDevice condev = new ConveyorDevice(list.get(i).toString());
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package org.nl.acs.device_driver.driver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ldjun
|
|
||||||
* @version 1.0
|
|
||||||
* @date 2023年02月01日 11:21
|
|
||||||
* @desc desc
|
|
||||||
*/
|
|
||||||
public class ItemValue {
|
|
||||||
private String item_code;
|
|
||||||
private Object item_value;
|
|
||||||
|
|
||||||
public ItemValue() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemValue(String item_code, Object item_value) {
|
|
||||||
this.item_code = item_code;
|
|
||||||
this.item_value = item_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getItem_code() {
|
|
||||||
return this.item_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItem_code(String item_code) {
|
|
||||||
this.item_code = item_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getItem_value() {
|
|
||||||
return this.item_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItem_value(Object item_value) {
|
|
||||||
this.item_value = item_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -380,10 +380,6 @@ public class StandardInspectSiteSmartDeviceDriver extends AbstractOpcDeviceDrive
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == 0 && ("1005".equals(devicecode) || "1006".equals(devicecode))) {
|
|
||||||
writing(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
last_mode = mode;
|
last_mode = mode;
|
||||||
last_error = error;
|
last_error = error;
|
||||||
|
|||||||
@@ -4,27 +4,19 @@ import cn.hutool.core.util.NumberUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jinterop.dcom.common.JIException;
|
import org.jinterop.dcom.common.JIException;
|
||||||
import org.jinterop.dcom.core.*;
|
import org.jinterop.dcom.core.*;
|
||||||
import org.nl.acs.device_driver.driver.ItemValue;
|
import org.nl.exception.BadRequestException;
|
||||||
import org.nl.exception.WDKException;
|
import org.nl.exception.WDKException;
|
||||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||||
import org.openscada.opc.lib.da.*;
|
import org.openscada.opc.lib.da.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OpcUtl {
|
public class OpcUtl {
|
||||||
private static int timeout = 1*60*1000;
|
private static int timeout = 180000;
|
||||||
private static String key = "rpc.socketTimeout";
|
private static String key = "rpc.socketTimeout";
|
||||||
public static int successNum=0;
|
|
||||||
public static int errNum=0;
|
|
||||||
|
|
||||||
static {
|
|
||||||
checkTimeout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void checkTimeout() {
|
public static void checkTimeout() {
|
||||||
if (Integer.getInteger(key, 0).intValue() != timeout) {
|
if (Integer.getInteger(key, 0).intValue() != timeout) {
|
||||||
@@ -36,18 +28,7 @@ public class OpcUtl {
|
|||||||
|
|
||||||
public static void writeValue(Group group, WriteRequest... requests) {
|
public static void writeValue(Group group, WriteRequest... requests) {
|
||||||
try {
|
try {
|
||||||
Map<Item, Integer> e=null;
|
Map e = group.write(requests);
|
||||||
try{
|
|
||||||
e=group.write(requests);
|
|
||||||
group.write(requests);
|
|
||||||
}catch (Exception e1){
|
|
||||||
try{
|
|
||||||
e= group.write(requests);
|
|
||||||
}catch (Exception e2){
|
|
||||||
e= group.write(requests);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean is_success = true;
|
boolean is_success = true;
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
Iterator arg4 = e.keySet().iterator();
|
Iterator arg4 = e.keySet().iterator();
|
||||||
@@ -69,68 +50,16 @@ public class OpcUtl {
|
|||||||
|
|
||||||
if (!is_success) {
|
if (!is_success) {
|
||||||
// throw new BusinessException(message.toString());
|
// throw new BusinessException(message.toString());
|
||||||
System.out.println("下发信号失败:"+message.toString());
|
|
||||||
System.out.println("下发信号失败原因:"+message.toString());
|
|
||||||
log.info("下发信号失败:"+message.toString());
|
|
||||||
throw new RuntimeException(message.toString());
|
|
||||||
}
|
}
|
||||||
} catch (JIException arg7) {
|
} catch (JIException arg7) {
|
||||||
log.info("下发信号失败:"+arg7.getMessage());
|
// throw new BusinessException(arg7);
|
||||||
System.out.println("下发信号失败原因:"+arg7.getMessage());
|
|
||||||
throw new RuntimeException(arg7);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeValue(Group group, ItemValue... values) throws WDKException {
|
public static Object getValue(Item item, ItemState itemState) throws BadRequestException {
|
||||||
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) {
|
|
||||||
if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) {
|
if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
log.debug("value is not good {} : {}", item.getId(), itemState.getQuality());
|
log.debug("value is not good {} : {}", item.getId(), itemState.getQuality());
|
||||||
// throw new WDKException("值不健康进行重连!");
|
|
||||||
} else {
|
} else {
|
||||||
log.debug("value is not good {}", itemState.getQuality());
|
log.debug("value is not good {}", itemState.getQuality());
|
||||||
}
|
}
|
||||||
@@ -142,7 +71,7 @@ public class OpcUtl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getValue(JIVariant jiVariant, String id) {
|
public static Object getValue(JIVariant jiVariant, String id) throws BadRequestException {
|
||||||
try {
|
try {
|
||||||
Object e = jiVariant.getObject();
|
Object e = jiVariant.getObject();
|
||||||
if (e instanceof IJIUnsigned) {
|
if (e instanceof IJIUnsigned) {
|
||||||
@@ -207,7 +136,7 @@ public class OpcUtl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JIException e) {
|
} catch (JIException e) {
|
||||||
throw new RuntimeException(e.getMessage());
|
throw new BadRequestException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,28 +150,12 @@ public class OpcUtl {
|
|||||||
server = new Server(getConnection(host, clsid, user, password, domain),
|
server = new Server(getConnection(host, clsid, user, password, domain),
|
||||||
Executors.newSingleThreadScheduledExecutor());
|
Executors.newSingleThreadScheduledExecutor());
|
||||||
server.connect();
|
server.connect();
|
||||||
successNum++;
|
|
||||||
return server;
|
return server;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errNum++;
|
throw new WDKException(e);
|
||||||
// e.printStackTrace();
|
|
||||||
System.out.println("server error:"+e.getMessage());
|
|
||||||
throw new WDKException(e.getMessage());
|
|
||||||
}finally{
|
|
||||||
System.out.println("successNum:"+successNum);
|
|
||||||
System.out.println("errNum:"+errNum);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ConnectionInformation getConnection(String host, String clsid, String user, String password,
|
public static ConnectionInformation getConnection(String host, String clsid, String user, String password,
|
||||||
String domain) {
|
String domain) {
|
||||||
ConnectionInformation connection = new ConnectionInformation();
|
ConnectionInformation connection = new ConnectionInformation();
|
||||||
@@ -254,44 +167,31 @@ public class OpcUtl {
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JIVariant getByteArrayVariantxx(int[] bytes) {
|
public static String read(String item) throws Exception {
|
||||||
Integer[] byte_Data = new Integer[bytes.length];
|
System.out.println(item);
|
||||||
|
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", "");
|
||||||
for(int i = 0; i < bytes.length; ++i) {
|
// String byteItemString = "RD1.RD1.1001.mode";
|
||||||
byte_Data[i] = bytes[i];
|
Group group = server.addGroup();
|
||||||
}
|
Item byteItem = group.addItem(item);
|
||||||
|
ItemState itemState = null;
|
||||||
JIArray array = new JIArray(byte_Data, false);
|
JIVariant value = null;
|
||||||
JIVariant value = new JIVariant(array);
|
itemState = byteItem.read(true);
|
||||||
return value;
|
value = itemState.getValue();
|
||||||
|
String data = OpcUtl.getValue(byteItem, itemState) + "";
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JIVariant getIntegerVariant(Integer integer) {
|
public static void main(String[] args) throws Exception {
|
||||||
return new JIVariant(integer);
|
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", "");
|
||||||
|
String byteItemString = "RD1.RD1.1001.mode";
|
||||||
|
Group group = server.addGroup();
|
||||||
|
Item byteItem = group.addItem(byteItemString);
|
||||||
|
ItemState itemState = null;
|
||||||
|
JIVariant value = null;
|
||||||
|
System.out.println(byteItem.getId());
|
||||||
|
itemState = byteItem.read(true);
|
||||||
|
System.out.println(itemState.getQuality());
|
||||||
|
System.out.println(getValue(byteItem, itemState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JIVariant getStringVariant(String string) {
|
|
||||||
return new JIVariant(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JIVariant getByteArrayVariant(byte[] bytes) {
|
|
||||||
Byte[] byte_Data = new Byte[bytes.length];
|
|
||||||
|
|
||||||
for(int i = 0; i < bytes.length; ++i) {
|
|
||||||
byte_Data[i] = bytes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
JIArray array = new JIArray(byte_Data, false);
|
|
||||||
JIVariant value = new JIVariant(array);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JIVariant getByteArrayVariant(Byte[] bytes) {
|
|
||||||
JIArray array = new JIArray(bytes, false);
|
|
||||||
JIVariant value = new JIVariant(array);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user