指令任务迭代器更新
This commit is contained in:
@@ -21,93 +21,10 @@ import org.openscada.opc.lib.list.ServerList;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ReadUtil {
|
||||
public static void main(String[] args) throws AlreadyConnectedException, JIException, UnknownHostException, NotConnectedException, DuplicateGroupException, AddFailedException, InterruptedException {
|
||||
// 启动服务
|
||||
/* ItemProtocol ipl = new ItemProtocol();
|
||||
List<ItemDto> list = ipl.getReadableItemDtos();
|
||||
List<String> ls = new ArrayList<>();
|
||||
for (ItemDto dto : list) {
|
||||
//ls.add("RD3.RD3.2265."+ dto.getCode());
|
||||
}
|
||||
ls.add("DDJ1.DDJ1.DDJ1.heartbeat");
|
||||
ls.add("DDJ1.DDJ1.DDJ1.action");
|
||||
final Server server = getServer();
|
||||
Map<String, Object> map = read(ls, server);
|
||||
*//*Map<String, Object> params=new HashMap<>();
|
||||
params.put("RD3.RD3.2265."+"mode","0");
|
||||
write(params, server);*//*
|
||||
System.out.println(111);*/
|
||||
|
||||
/* try {
|
||||
test();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
//List<Map<String, String>> maps = showAllOpcServer("192.168.81.207", "administrator", "123", "");
|
||||
|
||||
Server server = getServer();
|
||||
List<String> itemString = new ArrayList<String>();
|
||||
itemString.add("RD1.RD1.1005.test");
|
||||
Map map = read(itemString, server);
|
||||
System.out.println(map.get("RD1.RD1.1005.test"));
|
||||
// int[] a = (int[]) map.get("RD1.RD1.1005.test");
|
||||
// for(int i=0; i<a.length; i++){
|
||||
// System.out.println(a[i]);
|
||||
// }
|
||||
|
||||
|
||||
// Server server = ReadUtil.getServer();
|
||||
// Map<String, Object> itemMap = new HashMap<String, Object>();
|
||||
// itemMap.put("RD1.RD1.1005.test", "1.2");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布订阅测试
|
||||
*/
|
||||
private static final int PERIOD = 100;
|
||||
|
||||
private static final int SLEEP = 2000;
|
||||
|
||||
public static void test() throws AlreadyConnectedException, JIException, UnknownHostException, AddFailedException, NotConnectedException, DuplicateGroupException, InterruptedException {
|
||||
/*ConnectionInformation ci = new ConnectionInformation();
|
||||
ci.setHost("10.1.5.123");
|
||||
ci.setDomain("");
|
||||
ci.setUser("freud");
|
||||
ci.setPassword("password");
|
||||
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
|
||||
|
||||
Server server = new Server(ci,
|
||||
Executors.newSingleThreadScheduledExecutor());*/
|
||||
Server server = getServer();
|
||||
|
||||
// server.connect();
|
||||
|
||||
AccessBase access = new Async20Access(server, PERIOD, false);
|
||||
|
||||
access.addItem("RD1.RD1.B21.mode", new DataCallback() {
|
||||
|
||||
private int count;
|
||||
|
||||
@SneakyThrows
|
||||
public void changed(Item item, ItemState itemstate) {
|
||||
System.out.println("[" + (++count) + "],ItemName:["
|
||||
+ item.getId() + "],value:" + itemstate.getValue());
|
||||
System.out.println(itemstate.getValue().isArray());
|
||||
List<String> listB = Arrays.asList(itemstate.getValue().toString());
|
||||
System.out.println(listB.get(0));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
access.bind();
|
||||
Thread.sleep(SLEEP);
|
||||
access.unbind();
|
||||
server.dispose();
|
||||
}
|
||||
|
||||
public static Server getServer(String opc_id) {
|
||||
//OPC表【acs_opc】
|
||||
@@ -134,28 +51,6 @@ public class ReadUtil {
|
||||
return server;
|
||||
}
|
||||
|
||||
public static Server getServer() {
|
||||
//RD1.RD1.1028
|
||||
// 连接信息
|
||||
ConnectionInformation ci = new ConnectionInformation();
|
||||
ci.setHost("192.168.81.251");
|
||||
ci.setDomain("");
|
||||
ci.setUser("administrator");
|
||||
ci.setPassword("Huawei@123");
|
||||
ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729");
|
||||
final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
|
||||
try {
|
||||
server.connect();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JIException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AlreadyConnectedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void write(Map<String, Object> strings, Server server) {
|
||||
try {
|
||||
//Group group = this.opcServerService.getServer(opcServiceCode);
|
||||
@@ -198,7 +93,6 @@ public class ReadUtil {
|
||||
public static Map<String, Object> read(List<String> itemString, Server server) {
|
||||
HashMap map = new HashMap();
|
||||
try {
|
||||
//Group group = this.opcServerService.getServer(opcServiceCode);
|
||||
Group group = server.addGroup();
|
||||
Map<String, Item> items = new LinkedHashMap();
|
||||
Iterator is = itemString.iterator();
|
||||
@@ -226,6 +120,7 @@ public class ReadUtil {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package org.nl.acs.device.service.impl;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import org.nl.acs.instruction.service.dto.InstructionDto;
|
||||
import org.nl.acs.opc.OpcUtl;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.acs.task.service.dto.TaskDto;
|
||||
import org.nl.acs.task.service.impl.TaskServiceImpl;
|
||||
|
||||
@Data
|
||||
public class ConveyorDevice {
|
||||
|
||||
String id;
|
||||
|
||||
int jobNo = -1;
|
||||
|
||||
int lastjobNo = -1;
|
||||
|
||||
String palletNo;
|
||||
|
||||
InstructionDto inst;
|
||||
|
||||
RecvThread rt;
|
||||
|
||||
public ConveyorDevice(String id) {
|
||||
if (id == null) {
|
||||
throw new NullPointerException("ID is null");
|
||||
} else {
|
||||
this.id = id;
|
||||
}
|
||||
System.out.println("id:" + id);
|
||||
rt = new RecvThread();
|
||||
rt.run();
|
||||
}
|
||||
|
||||
public void adviseData() {
|
||||
System.out.println("test");
|
||||
}
|
||||
|
||||
private class RecvThread implements Runnable {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.nl.acs.device.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1089,12 +1089,14 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
@Override
|
||||
public Instruction findByLinkNumSend(String code) {
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) {
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1102,8 +1104,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public List<Instruction> findByLinkNum(String code) {
|
||||
List<Instruction> list = new ArrayList<>();
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) {
|
||||
list.add(inst);
|
||||
}
|
||||
@@ -1113,19 +1116,22 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
@Override
|
||||
public Instruction findByLinkNumNoSend(String code) {
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) {
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction findByCodeFromCache(String code) {
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(code, inst.getInstruction_code())) {
|
||||
return inst;
|
||||
}
|
||||
@@ -1136,8 +1142,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
@Override
|
||||
public Instruction findByBarcodeFromCache(String barcode) {
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(barcode, inst.getVehicle_code())) {
|
||||
return inst;
|
||||
}
|
||||
@@ -1147,9 +1154,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
@Override
|
||||
public Instruction findByIdFromCache(String id) {
|
||||
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(id, inst.getInstruction_id())) {
|
||||
return inst;
|
||||
}
|
||||
@@ -1244,8 +1251,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Integer querySameDestinationInst(String devicecode) {
|
||||
int num = 0;
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
//处理空盘位站点
|
||||
String next_code = inst.getNext_point_code();
|
||||
if (next_code.indexOf(".") != -1) {
|
||||
@@ -1255,14 +1263,16 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
num = num + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer querySameInstType(String inst_type) {
|
||||
int num = 0;
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
if (StrUtil.equals(inst.getInstruction_type(), inst_type)) {
|
||||
num = num + 1;
|
||||
}
|
||||
@@ -1273,8 +1283,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Integer querySameOriginInst(String devicecode) {
|
||||
int num = 0;
|
||||
for (int i = 0; i < this.instructions.size(); i++) {
|
||||
Instruction inst = instructions.get(i);
|
||||
Iterator<Instruction> it = instructions.iterator();
|
||||
while (it.hasNext()){
|
||||
Instruction inst = it.next();
|
||||
//处理空盘位站点
|
||||
String start_code = inst.getStart_point_code();
|
||||
if (start_code.indexOf(".") != -1) {
|
||||
|
||||
@@ -21,6 +21,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
String message;
|
||||
private Server server;
|
||||
|
||||
Group group;
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
@@ -62,13 +64,15 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
server = OpcServerUtl.getServerWithOutException(
|
||||
server =
|
||||
OpcServerUtl.getServerWithOutException(
|
||||
this.OpcServer.getOpc_host(),
|
||||
this.OpcServer.getCls_id(),
|
||||
this.OpcServer.getUser(),
|
||||
this.OpcServer.getPassword(),
|
||||
this.OpcServer.getDomain());
|
||||
Group group = server.addGroup();
|
||||
group = server.addGroup();
|
||||
|
||||
List<String> itemsString = new ArrayList();
|
||||
Iterator it = this.protocols.iterator();
|
||||
|
||||
@@ -117,10 +121,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
|
||||
label97:
|
||||
while (true) {
|
||||
// System.out.println("label97");
|
||||
// System.out.println("label97");
|
||||
long begin = System.currentTimeMillis();
|
||||
Map<Item, ItemState> itemStatus =
|
||||
group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
//TODO 读完释放server可行否?
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||
long duration = end - begin;
|
||||
@@ -135,12 +141,13 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
time_out = false;
|
||||
}
|
||||
|
||||
// A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var18 = items.iterator();
|
||||
|
||||
while (true) {
|
||||
// System.out.println("label98");
|
||||
Item item;
|
||||
// A1_HK_04.A1_HK_04.A1_HK_04_3.door
|
||||
// 当前值
|
||||
Object value;
|
||||
// 旧的值
|
||||
@@ -155,6 +162,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
}
|
||||
// 所有信号读完并且没有变化的值
|
||||
continue label97;
|
||||
}
|
||||
|
||||
@@ -183,7 +191,6 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
|
||||
log.info("信号{}变更从{}->{};信号快照:{}", new Object[] {item.getId(), his, value, sb});
|
||||
}
|
||||
System.out.println("设置值:【"+item.getId()+"】-->"+value);
|
||||
// 设置值
|
||||
accessor_value.setValue(item.getId(), value);
|
||||
}
|
||||
@@ -197,6 +204,15 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
if (group != null) {
|
||||
try {
|
||||
group.clear();
|
||||
group.remove();
|
||||
} catch (Exception var6) {
|
||||
}
|
||||
this.group = null;
|
||||
}
|
||||
|
||||
String error_message = "设备信息同步异常";
|
||||
if (!StrUtil.equals(this.message, error_message)) {
|
||||
log.warn("", var30);
|
||||
@@ -215,5 +231,4 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -268,31 +268,6 @@ public class OpcUtl {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user