From faef35dc856e18c84706f1cd020a0e2f1413b504 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Fri, 16 Dec 2022 19:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acs/device_driver/agv/ItemProtocol.java | 28 +++++--- .../agv/MaGangAgvDeviceDriver.java | 19 ++++-- .../device_driver/driver/OpcDeviceDriver.java | 4 ++ .../quartz/task/QueryXZAgvDeviceStatus.java | 64 +++++++++++-------- 4 files changed, 76 insertions(+), 39 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/ItemProtocol.java index bb4989c..66d7c5c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/ItemProtocol.java @@ -32,12 +32,12 @@ public class ItemProtocol { return this.getOpcIntegerValue(item_type); } - public int getX_coordinate() { - return this.getOpcIntegerValue(item_x_coordinate); + public float getX_coordinate() { + return this.getOpcFloatValue(item_x_coordinate); } - public int getY_coordinate() { - return this.getOpcIntegerValue(item_y_coordinate); + public float getY_coordinate() { + return this.getOpcFloatValue(item_y_coordinate); } Boolean isonline; @@ -54,12 +54,24 @@ public class ItemProtocol { } + public Float getOpcFloatValue(String protocol) { + Float value = this.driver.getFloatValue(protocol); + if (value == null) { + log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0.00f; + } + public static List getReadableItemDtos() { ArrayList list = new ArrayList(); list.add(new ItemDto(item_status, "AGV状态", "DB602.W0")); list.add(new ItemDto(item_type, "AGV任务类型", "DB602.W2")); - list.add(new ItemDto(item_x_coordinate, "AGVx坐标", "DB602.W4")); - list.add(new ItemDto(item_y_coordinate, "AGVy坐标", "DB602.W6")); + list.add(new ItemDto(item_x_coordinate, "AGVx坐标", "DB602.D4")); + list.add(new ItemDto(item_y_coordinate, "AGVy坐标", "DB602.D6")); return list; } @@ -67,8 +79,8 @@ public class ItemProtocol { ArrayList list = new ArrayList(); list.add(new ItemDto(item_status, "AGV状态", "DB602.W0")); list.add(new ItemDto(item_type, "AGV任务类型", "DB602.W2")); - list.add(new ItemDto(item_x_coordinate, "AGVx坐标", "DB602.W4")); - list.add(new ItemDto(item_y_coordinate, "AGVy坐标", "DB602.W6")); + list.add(new ItemDto(item_x_coordinate, "AGVx坐标", "DB602.D4")); + list.add(new ItemDto(item_y_coordinate, "AGVy坐标", "DB602.D6")); return list; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/MaGangAgvDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/MaGangAgvDeviceDriver.java index 64f501a..ed27869 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/MaGangAgvDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/agv/MaGangAgvDeviceDriver.java @@ -69,12 +69,12 @@ public class MaGangAgvDeviceDriver extends AbstractOpcDeviceDriver implements De int last_type = 0; //x坐标 - int x_coordinate = 0; - int last_x_coordinate = 0; + float x_coordinate = 0; + float last_x_coordinate = 0; //y坐标 - int y_coordinate = 0; - int last_y_coordinate = 0; + float y_coordinate = 0; + float last_y_coordinate = 0; Boolean isonline = true; Boolean iserror = false; @@ -120,6 +120,17 @@ public class MaGangAgvDeviceDriver extends AbstractOpcDeviceDriver implements De log.info("设备号{},kep点位名称{},下发信号{}", this.getDevice().getDevice_code(), to_command, value); } + public void writing(String param, float value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + param; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, value); + ReadUtil.write(itemMap, server); + log.info("设备号{},kep点位名称{},下发信号{}", this.getDevice().getDevice_code(), to_command, value); + } + @Override public JSONObject getDeviceStatusName() { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java index 8b3cf17..570df1e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java @@ -65,6 +65,10 @@ public interface OpcDeviceDriver extends DeviceDriver { return (int[]) this.getOpcValueAccessor().getValue(this.getItem(protocol)); } + default Float getFloatValue(String protocol) { + return (Float) this.getOpcValueAccessor().getValue(this.getItem(protocol)); + } + default String getStringValue(String protocol) { return (String) this.getOpcValueAccessor().getValue(this.getItem(protocol)); } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java index b1a6cea..63629b9 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java @@ -16,6 +16,9 @@ import org.nl.acs.opc.DeviceAppService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.math.RoundingMode; +import java.text.DecimalFormat; + /** * 查询先工AGV设备状态 */ @@ -54,34 +57,41 @@ public class QueryXZAgvDeviceStatus { Boolean is_error = jo.getBoolean("is_error"); //执行运单信息 JSONObject current_order = jo.getJSONObject("current_order"); + Integer connectionStatus = jo.getInteger("connection_status"); String inst_code = current_order.getString("id"); String task_type = "0"; if (StrUtil.isNotEmpty(inst_code)) { Instruction inst = instructionService.findByCodeFromCache(inst_code); - if (ObjectUtil.isNotEmpty(inst)){ + if (ObjectUtil.isNotEmpty(inst)) { //任务类型 task_type = inst.getInstruction_type(); } } + DecimalFormat hisFormat = new DecimalFormat("########.###"); + hisFormat.setRoundingMode(RoundingMode.DOWN); //x坐标 - int x = Double.valueOf(rbk_report.getString("x")).intValue(); + float x = rbk_report.getFloatValue("x"); //y坐标 - int y = Double.valueOf(rbk_report.getString("y")).intValue(); + float y = rbk_report.getFloatValue("y"); String status = "0"; - if (procBusiness) { - //工作中 - status = "1"; + if (connectionStatus == 0) { + status = "5"; } else { - if (charging) { - //充电中 - status = "2"; + if (procBusiness) { + //工作中 + status = "1"; } else { - if (is_error) { - //故障 - status = "3"; + if (charging) { + //充电中 + status = "2"; } else { - //休息中 - status = "4"; + if (is_error) { + //故障 + status = "3"; + } else { + //休息中 + status = "4"; + } } } } @@ -91,14 +101,14 @@ public class QueryXZAgvDeviceStatus { maGangAgvDeviceDriver = (MaGangAgvDeviceDriver) device.getDeviceDriver(); String kepStatus = String.valueOf(maGangAgvDeviceDriver.getStatus()); String kepType = String.valueOf(maGangAgvDeviceDriver.getType()); - if (!StrUtil.equals(kepStatus,status)){ + if (!StrUtil.equals(kepStatus, status)) { maGangAgvDeviceDriver.writing("status", status); } - if (!StrUtil.equals(kepType,task_type)){ + if (!StrUtil.equals(kepType, task_type)) { maGangAgvDeviceDriver.writing("type", task_type); } - maGangAgvDeviceDriver.writing("x_coordinate", String.valueOf(x)); - maGangAgvDeviceDriver.writing("y_coordinate", String.valueOf(y)); + maGangAgvDeviceDriver.writing("x_coordinate", hisFormat.format(x) + ""); + maGangAgvDeviceDriver.writing("y_coordinate", hisFormat.format(y) + ""); } } } @@ -110,32 +120,32 @@ public class QueryXZAgvDeviceStatus { try { JSONObject map = new JSONObject(); JSONArray blocks = new JSONArray(); - map.put("blockGroup",blocks); + map.put("blockGroup", blocks); JSONArray jsonArray = agvService.blockGroupStatus(map); - if (ObjectUtil.isNotEmpty(jsonArray)){ + if (ObjectUtil.isNotEmpty(jsonArray)) { for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Boolean status = jsonObject.getBoolean("status"); - if (status){ + if (status) { String name = jsonObject.getString("name"); Device device = deviceAppService.findDeviceByCode(name); MaGangLedDeviceDriver maGangLedDeviceDriver; - if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver){ + if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) { maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver(); - maGangLedDeviceDriver.writing("D01","1"); + maGangLedDeviceDriver.writing("D01", "1"); } - }else { + } else { String name = jsonObject.getString("name"); Device device = deviceAppService.findDeviceByCode(name); MaGangLedDeviceDriver maGangLedDeviceDriver; - if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver){ + if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) { maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver(); - maGangLedDeviceDriver.writing("D01","0"); + maGangLedDeviceDriver.writing("D01", "0"); } } } } - }catch (Exception e){ + } catch (Exception e) { } }