Browse Source

Revert "更新"

This reverts commit 19a4a2a8ee.
master
张江玮 2 years ago
parent
commit
1cd22fe0f0
  1. 20
      hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java
  2. 20
      hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/Test.java
  3. 36
      hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java
  4. 4
      hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_inspect_site_smart200/StandardInspectSiteSmartDeviceDriver.java
  5. 166
      hd/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java

20
hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java

@ -43,16 +43,16 @@ public class ConveyorDevice {
@SneakyThrows
@Override
public void run() {
// System.out.println("test");
// String MODE = "RD1.RD1." + id + ".mode";
// String code = OpcUtl.read(MODE);
// if ("2".equals(code)) {
// TaskService taskserver = new TaskServiceImpl();
// TaskDto dto = new TaskDto();
// dto.setStart_point_code(id);
// dto.setNext_point_code("1002");
// taskserver.create(dto);
// }
System.out.println("test");
String MODE = "RD1.RD1." + id + ".mode";
String code = OpcUtl.read(MODE);
if ("2".equals(code)) {
TaskService taskserver = new TaskServiceImpl();
TaskDto dto = new TaskDto();
dto.setStart_point_code(id);
dto.setNext_point_code("1002");
taskserver.create(dto);
}
}
}
}

20
hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/Test.java

@ -5,14 +5,14 @@ import java.util.List;
public class Test {
// public static void main(String[] args) {
// String device = "1001,1002";
// List list = new ArrayList<>();
// list.add("1001");
// list.add("1002");
// for (int i = 0; i < list.size(); i++) {
// ConveyorDevice condev = new ConveyorDevice(list.get(i).toString());
// }
//
// }
public static void main(String[] args) {
String device = "1001,1002";
List list = new ArrayList<>();
list.add("1001");
list.add("1002");
for (int i = 0; i < list.size(); i++) {
ConveyorDevice condev = new ConveyorDevice(list.get(i).toString());
}
}
}

36
hd/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ItemValue.java

@ -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;
}
}

4
hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_inspect_site_smart200/StandardInspectSiteSmartDeviceDriver.java

@ -380,10 +380,6 @@ public class StandardInspectSiteSmartDeviceDriver extends AbstractOpcDeviceDrive
}
if (action == 0 && ("1005".equals(devicecode) || "1006".equals(devicecode))) {
writing(0);
}
}
last_mode = mode;
last_error = error;

166
hd/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java

@ -4,27 +4,19 @@ 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.exception.BadRequestException;
import org.nl.exception.WDKException;
import org.openscada.opc.lib.common.ConnectionInformation;
import org.openscada.opc.lib.da.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
@Slf4j
public class OpcUtl {
private static int timeout = 1*60*1000;
private static int timeout = 180000;
private static String key = "rpc.socketTimeout";
public static int successNum=0;
public static int errNum=0;
static {
checkTimeout();
}
public static void checkTimeout() {
if (Integer.getInteger(key, 0).intValue() != timeout) {
@ -36,18 +28,7 @@ public class OpcUtl {
public static void writeValue(Group group, WriteRequest... requests) {
try {
Map<Item, Integer> e=null;
try{
e=group.write(requests);
group.write(requests);
}catch (Exception e1){
try{
e= group.write(requests);
}catch (Exception e2){
e= group.write(requests);
}
}
Map e = group.write(requests);
boolean is_success = true;
StringBuilder message = new StringBuilder();
Iterator arg4 = e.keySet().iterator();
@ -69,68 +50,16 @@ public class OpcUtl {
if (!is_success) {
// 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) {
log.info("下发信号失败:"+arg7.getMessage());
System.out.println("下发信号失败原因:"+arg7.getMessage());
throw new RuntimeException(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);
// throw new BusinessException(arg7);
}
}
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) {
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());
}
@ -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 {
Object e = jiVariant.getObject();
if (e instanceof IJIUnsigned) {
@ -207,7 +136,7 @@ public class OpcUtl {
}
}
} catch (JIException e) {
throw new RuntimeException(e.getMessage());
throw new BadRequestException(e.getMessage());
}
}
@ -221,26 +150,10 @@ public class OpcUtl {
server = new Server(getConnection(host, clsid, user, password, domain),
Executors.newSingleThreadScheduledExecutor());
server.connect();
successNum++;
return server;
} catch (Exception e) {
errNum++;
// 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);
}
throw new WDKException(e);
}
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,
@ -254,44 +167,31 @@ public class OpcUtl {
return connection;
}
public static JIVariant getByteArrayVariantxx(int[] bytes) {
Integer[] byte_Data = new Integer[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 getIntegerVariant(Integer integer) {
return new JIVariant(integer);
}
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;
public static String read(String item) throws Exception {
System.out.println(item);
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(item);
ItemState itemState = null;
JIVariant value = null;
itemState = byteItem.read(true);
value = itemState.getValue();
String data = OpcUtl.getValue(byteItem, itemState) + "";
return data;
}
public static void main(String[] args) throws Exception {
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));
}
}

Loading…
Cancel
Save