diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java b/wcs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java index c86cdd28..2606f028 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/AcsConfig.java @@ -18,6 +18,10 @@ public interface AcsConfig { String AGVURL = "agvurl"; //AGV系统端口 String AGVPORT = "agvport"; + //单工agv系统接口地址 + String ONEAGVURL = "oneagvurl"; + //单工AGV系统端口 + String ONEAGVPORT = "oneagvport"; //二楼1区agv系统接口地址 String AGVURL2 = "agvurl2"; //二楼1区AGV系统端口 diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java index 42960b7f..ae7869d8 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java @@ -32,4 +32,8 @@ public interface NDCAgvService { public byte[] sendAgvOneModeInst(int phase, int index,int result); public byte[] sendAgvTwoModeInst(int phase, int index,int result); + + public void sendAgvOneInstToNDC(Instruction inst) throws Exception; + + public void sendAgvTwoInstToNDC(Instruction inst,Instruction inst2) throws Exception; } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java index 61db0ffa..652a45a9 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.auto.run.NDCSocketConnectionAutoRun; import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.auto.run.TwoNDC2SocketConnectionAutoRun; import org.nl.acs.auto.run.TwoNDCSocketConnectionAutoRun; @@ -351,4 +352,157 @@ public class NDCAgvServiceImpl implements NDCAgvService { return AGVDeviceStatus; } + @Override + public void sendAgvOneInstToNDC(Instruction inst) { + if (StrUtil.equals(paramService.findByCode(AcsConfig.ONEFORKAGV).getValue(), "1")) { + String instcode = inst.getLink_num(); + int type = Integer.parseInt(inst.getAgv_inst_type()); + int priority = Integer.parseInt(inst.getPriority()) + 128; + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); + int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); + + byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); + byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); + byte typehigh = (byte) IntToHexHigh(type); + byte typelow = (byte) IntToHexLow(type); + byte qhdhigh = (byte) IntToHexHigh(startAddress); + byte qhdlow = (byte) IntToHexLow(startAddress); + byte fhdhigh = (byte) IntToHexHigh(nextAddress); + byte fhdlow = (byte) IntToHexLow(nextAddress); + byte prioritylow = (byte) IntToHexLow(priority); + + String str = "十进制下发:"; + String str1 = "十六进制下发:"; + str += "ikey:" + (Integer.parseInt(instcode)); + str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); + + str += "/type:" + (type); + str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); + + str += "/qhd:" + (startAddress); + str1 += "/qhd:" + hexToString(qhdhigh & 0xFF) + hexToString(qhdlow & 0xFF); + str += "/fhd:" + (nextAddress); + str1 += "/fhd:" + hexToString(fhdhigh & 0xFF) + hexToString(fhdlow & 0xFF); + + str += "/priority:" + (priority); + str1 += "/priority:" + hexToString(prioritylow & 0xFF); + + System.out.println(str); + System.out.println(str1); + + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X12, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X71, + (byte) 0X00, (byte) 0X0E, + (byte) 0X01, prioritylow, + (byte) 0X00, (byte) 0X01, + (byte) ikeyhigh, (byte) ikeylow, + (byte) ikeyhigh, (byte) ikeylow, + (byte) typehigh, (byte) typelow, + (byte) qhdhigh, (byte) qhdlow, + (byte) fhdhigh, (byte) fhdlow + }; + log.info("下发AGV作业指令--{}", str1); + + OneNDCSocketConnectionAutoRun.write(b); + System.out.println("下发agv指令数据:" + Bytes2HexString(b)); + } + } + + /** + * 双工位诺宝车任务 + * @param inst + */ + @Override + public void sendAgvTwoInstToNDC(Instruction inst,Instruction inst2) { + String instcode = inst.getLink_num(); + int type = Integer.parseInt(inst.getAgv_inst_type()); + int priority = Integer.parseInt(inst.getPriority()) + 128; + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int startAddress1 = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); + int putAddress1 = deviceService.queryAddressBydeviceCode(inst.getPut_point_code()); + int nextAddress1 = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); + int startAddress2 = 0; + int putAddress2 = 0; + int nextAddress2 = 0; + if(ObjectUtil.isNotEmpty(inst2)){ + startAddress2 = deviceService.queryAddressBydeviceCode(inst2.getStart_point_code()); + putAddress2 = deviceService.queryAddressBydeviceCode(inst2.getPut_point_code()); + nextAddress2 = deviceService.queryAddressBydeviceCode(inst2.getNext_point_code()); + } + + + + byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); + byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); + byte typehigh = (byte) IntToHexHigh(type); + byte typelow = (byte) IntToHexLow(type); + + byte qhd1high = (byte) IntToHexHigh(startAddress1); + byte qhd1low = (byte) IntToHexLow(startAddress1); + + byte qhd2high = (byte) IntToHexHigh(startAddress2); + byte qhd2low = (byte) IntToHexLow(startAddress2); + + byte dld1high = (byte) IntToHexHigh(putAddress1); + byte dld1low = (byte) IntToHexLow(putAddress1); + + byte dld2high = (byte) IntToHexHigh(putAddress2); + byte dld2low = (byte) IntToHexLow(putAddress2); + + byte fhd1high = (byte) IntToHexHigh(nextAddress1); + byte fhd1low = (byte) IntToHexLow(nextAddress1); + + byte fhd2high = (byte) IntToHexHigh(nextAddress2); + byte fhd2low = (byte) IntToHexLow(nextAddress2); + + byte prioritylow = (byte) IntToHexLow(priority); + + String str = "十进制下发:"; + String str1 = "十六进制下发:"; + str1+="ikey:"+hexToString(ikeyhigh & 0xFF)+hexToString(ikeylow & 0xFF); + + str+="/type:"+(type); + str1+="/type:"+hexToString(typehigh & 0xFF)+hexToString(typelow & 0xFF); + + str1+="/qhd1:"+hexToString(qhd1high & 0xFF)+hexToString(qhd1low & 0xFF); + str1+="/qhd2:"+hexToString(qhd2high & 0xFF)+hexToString(qhd2low & 0xFF); + str1+="/dld1:"+hexToString(dld1high & 0xFF)+hexToString(dld1low & 0xFF); + + str1+="/dld2:"+hexToString(dld2high & 0xFF)+hexToString(dld2low & 0xFF); + str1+="/fhd1:"+hexToString(fhd1high & 0xFF)+hexToString(fhd1low & 0xFF); + str1+="/fhd2:"+hexToString(fhd2high & 0xFF)+hexToString(fhd2low & 0xFF); + + System.out.println(str); + System.out.println(str1); + + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X1A, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X71, + (byte) 0X00, (byte) 0X16, + (byte) 0X01, (byte) 0X80, + (byte) 0X00, (byte) 0X01, + (byte) ikeyhigh, (byte) ikeylow, + (byte) ikeyhigh, (byte) ikeylow, + (byte) typehigh, (byte) typelow, + + (byte) qhd1high, (byte) qhd1low, + (byte) qhd2high, (byte) qhd2low, + (byte) dld1high, (byte) dld1low, + (byte) dld2high, (byte) dld2low, + (byte) fhd1high, (byte) fhd1low, + (byte) fhd2high, (byte) fhd2low + }; + log.info("下发AGV作业指令--{}", str1); + + NDCSocketConnectionAutoRun.write(b); + System.out.println("下发agv指令数据:" + Bytes2HexString(b)); + } + } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/ZheDaAgvServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/ZheDaAgvServiceImpl.java index a144cbfc..d42db572 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/ZheDaAgvServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/ZheDaAgvServiceImpl.java @@ -13,8 +13,6 @@ import org.nl.acs.agv.server.ZheDaAgvService; import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position.EmptyVehicleStackingPositionDeviceDriver; import org.nl.acs.device_driver.basedriver.hailiang_smart_plc_test.HailiangSmartplcTestDeviceDriver; -import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.paint_conveyor.PaintConveyorDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; @@ -148,8 +146,6 @@ public class ZheDaAgvServiceImpl implements ZheDaAgvService { CargoLiftConveyorDeviceDriver cargoLiftConveyorDeviceDriver; EmptyVehicleStackingPositionDeviceDriver emptyVehicleStackingPositionDeviceDriver; HailiangSmartplcTestDeviceDriver hailiangSmartplcTestDeviceDriver; - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - PaintConveyorDeviceDriver paintConveyorDeviceDriver; //取货的进入前等待和离开等待 if (action.equals("Load")) { @@ -181,22 +177,22 @@ public class ZheDaAgvServiceImpl implements ZheDaAgvService { is_feedback = true; } } - //豪凯自动线对接位 - if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); - if ((hongXiangConveyorDeviceDriver.getAction() == 1 || hongXiangConveyorDeviceDriver.getAction() == 3) && hongXiangConveyorDeviceDriver.getMove() == 1) { - inst.setExecute_status("1"); - is_feedback = true; - } - } - //油漆线 - if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { - paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); - if ((paintConveyorDeviceDriver.getAction() == 1 || paintConveyorDeviceDriver.getAction() == 3) && paintConveyorDeviceDriver.getMove() == 1) { - inst.setExecute_status("1"); - is_feedback = true; - } - } +// //豪凯自动线对接位 +// if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { +// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// if ((hongXiangConveyorDeviceDriver.getAction() == 1 || hongXiangConveyorDeviceDriver.getAction() == 3) && hongXiangConveyorDeviceDriver.getMove() == 1) { +// inst.setExecute_status("1"); +// is_feedback = true; +// } +// } +// //油漆线 +// if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { +// paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// if ((paintConveyorDeviceDriver.getAction() == 1 || paintConveyorDeviceDriver.getAction() == 3) && paintConveyorDeviceDriver.getMove() == 1) { +// inst.setExecute_status("1"); +// is_feedback = true; +// } +// } } if ("PauseOnStation".equals(type)) { if (addressdevice.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { @@ -220,19 +216,19 @@ public class ZheDaAgvServiceImpl implements ZheDaAgvService { is_feedback = true; } - if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); - inst.setExecute_status("2"); - hongXiangConveyorDeviceDriver.writing(2); - is_feedback = true; - } - - if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { - paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); - inst.setExecute_status("2"); - paintConveyorDeviceDriver.writing(2); - is_feedback = true; - } +// if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { +// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// inst.setExecute_status("2"); +// hongXiangConveyorDeviceDriver.writing(2); +// is_feedback = true; +// } +// +// if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { +// paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// inst.setExecute_status("2"); +// paintConveyorDeviceDriver.writing(2); +// is_feedback = true; +// } } } @@ -333,21 +329,21 @@ public class ZheDaAgvServiceImpl implements ZheDaAgvService { } } - if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); - if ((hongXiangConveyorDeviceDriver.getAction() == 2 || hongXiangConveyorDeviceDriver.getAction() == 3) && hongXiangConveyorDeviceDriver.getMove() == 0) { - inst.setExecute_status("3"); - is_feedback = true; - } - } - - if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { - paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); - if ((paintConveyorDeviceDriver.getAction() == 2 || paintConveyorDeviceDriver.getAction() == 3) && paintConveyorDeviceDriver.getMove() == 0) { - inst.setExecute_status("3"); - is_feedback = true; - } - } +// if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { +// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// if ((hongXiangConveyorDeviceDriver.getAction() == 2 || hongXiangConveyorDeviceDriver.getAction() == 3) && hongXiangConveyorDeviceDriver.getMove() == 0) { +// inst.setExecute_status("3"); +// is_feedback = true; +// } +// } +// +// if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { +// paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// if ((paintConveyorDeviceDriver.getAction() == 2 || paintConveyorDeviceDriver.getAction() == 3) && paintConveyorDeviceDriver.getMove() == 0) { +// inst.setExecute_status("3"); +// is_feedback = true; +// } +// } } if ("PauseOnStation".equals(type)) { if (addressdevice.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { @@ -371,19 +367,19 @@ public class ZheDaAgvServiceImpl implements ZheDaAgvService { is_feedback = true; } - if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); - inst.setExecute_status("4"); - hongXiangConveyorDeviceDriver.writing(3); - is_feedback = true; - } +// if (addressdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { +// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// inst.setExecute_status("4"); +// hongXiangConveyorDeviceDriver.writing(3); +// is_feedback = true; +// } - if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { - paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); - inst.setExecute_status("4"); - paintConveyorDeviceDriver.writing(3); - is_feedback = true; - } +// if (addressdevice.getDeviceDriver() instanceof PaintConveyorDeviceDriver) { +// paintConveyorDeviceDriver = (PaintConveyorDeviceDriver) addressdevice.getDeviceDriver(); +// inst.setExecute_status("4"); +// paintConveyorDeviceDriver.writing(3); +// is_feedback = true; +// } } } JSONObject requestjo = new JSONObject(); diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/NDCSocketConnectionAutoRun.java b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/NDCSocketConnectionAutoRun.java new file mode 100644 index 00000000..24dd7d85 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/NDCSocketConnectionAutoRun.java @@ -0,0 +1,228 @@ +package org.nl.acs.auto.run; + +import cn.hutool.core.util.ObjectUtil; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.AcsConfig; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.device_driver.basedriver.agv.ndctwo.AgvNdcTwoDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.instruction.service.impl.InstructionServiceImpl; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; +import java.util.Date; +import java.util.List; + +import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString; + + +@Slf4j +@Component +public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { + + Socket s; + String ip = "192.168.46.225"; + int port = 1234; + static DataOutputStream dos; + static DataInputStream dis; + private int recordTimeOut = 10000; + private Date recordTime; + String[] ERROR = new String[]{ + "货叉尖部传感器触发", "S300传感器触发", "载货状态改变", "急停按钮触发", "触边开关出发", "需要复位", + "停在充电位", "取货失败", "放货失败", "轮子打滑", "没有动作码不能进入站点", "取货时有货", "丢失定位", + "抬叉停止"}; + boolean bConnected = true; + + boolean isReConnect = false; + + @Autowired + ParamService paramService; + @Autowired + AutoRunService autoRunService; + + + public NDCSocketConnectionAutoRun() { + this.recordTime = new Date((new Date()).getTime() - (long) this.recordTimeOut); + } + + public String getCode() { + return NDCSocketConnectionAutoRun.class.getSimpleName(); + } + + public String getName() { + return "双工NDC在线连接"; + } + + public void autoRun() { + try { + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); + ip = paramService.findByCode(AcsConfig.AGVURL).getValue(); + port = Integer.parseInt(paramService.findByCode(AcsConfig.AGVPORT).getValue()); + byte[] b = new byte[1028]; + s = new Socket(ip, port); + dos = new DataOutputStream(s.getOutputStream()); + dis = new DataInputStream(s.getInputStream()); + + while (bConnected) { + int count = dis.read(b); + + if (count == -1) { + break; + } + + int[] arr = new int[count]; + StringBuffer bs = new StringBuffer(); + + for (int i = 0; i < count; i++) { + int temp = b[i]; + if (temp < 0) + temp += 256; + arr[i] = temp; + StringBuffer bs1 = new StringBuffer("0"); + bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp)); + } + + //System.out.println("收到请求参数:" + bs); + boolean flag = false; + if (arr[8] * 256 + arr[9] == 0x73) { + byte[] data = null; + System.out.println("接收agv上报信息:" + bs); + //执行阶段 + int phase = arr[16] * 256 + arr[17]; + // agv任务号 + int index = arr[12] * 256 + arr[13]; + //任务号 + int ikey = arr[26] * 256 + arr[27]; + //站点号 + int agvaddr = arr[18] * 256 + arr[19]; + //车号 + int carno = arr[20]; + Instruction link_inst = null; + List insts = null; + boolean link_flag = false; + Device agv_device = null; + if (carno != 0) { + agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); + } + if (ikey != 0) { + insts = instructionService.findByLinkNum(String.valueOf(ikey)); + } + if (!ObjectUtil.isEmpty(link_inst)) { + link_flag = true; + } + log.info("接收agv上报信息:" + bs); + log.info("接收agv上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); + Device device = null; + String device_code = null; + + + // + AgvNdcTwoDeviceDriver agvNdcTwoDeviceDriver; + + //开始任务/上报订单号 + if (phase == 0x01) { + for (Instruction inst : insts) { + inst.setInstruction_status("1"); + inst.setAgv_jobno(String.valueOf(index)); + inst.setSend_status("1"); + instructionService.update(inst); + } + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + + + } else if (phase == 0x1A) { + + for (Instruction inst : insts) { + if (!ObjectUtil.isEmpty(inst)) { + instructionService.finish(inst.getInstruction_id()); + } + } + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + + } else if (phase == 0x30) { + data = ndcAgvService.sendAgvTwoModeInst(143, index, 0); + + } else if (phase == 0xFF) { + + for (Instruction inst : insts) { + if (!ObjectUtil.isEmpty(inst)) { + instructionService.cancelNOSendAgv(inst.getInstruction_id()); + } + } + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + + } else { + + if (phase == 0x67) { + device = deviceAppService.findDeviceByCode(Integer.toString(arr[27])); + } else { + device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); + } + + if (ObjectUtil.isEmpty(device)) { + return; + } + if (device.getDeviceDriver() instanceof AgvNdcTwoDeviceDriver) { + agvNdcTwoDeviceDriver = (AgvNdcTwoDeviceDriver) device.getDeviceDriver(); + + agvNdcTwoDeviceDriver.processSocket(arr); + } + } + if (!ObjectUtil.isEmpty(data)) { + write(data); + } + + } else { +// System.out.println("agv上报不是0073类型动作,不处理"); + } + } + + } catch (Exception e) { + + + } finally { + + + } + + } + + + @Override + public void stop() { + super.after(); + try { + s.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static void write(byte[] b) { + try { + log.info("下发agv数据:" + Bytes2HexString(b)); + System.out.println("下发agv数据:" + Bytes2HexString(b)); + dos.write(b); + dos.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java index 6eb984a8..aece1afa 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java @@ -4,14 +4,11 @@ import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.NDCAgvService; -import org.nl.acs.device.service.DeviceService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; import org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.instruction.service.impl.InstructionServiceImpl; -import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; import org.nl.modules.system.service.ParamService; @@ -64,29 +61,26 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { } public String getName() { - return "1楼NDC在线连接"; + return "单工NDC在线连接"; } public void autoRun() throws IOException { - System.out.println("1楼NDCAgv链接开始"); - ParamService ParamService = SpringContextHolder.getBean(ParamServiceImpl.class); + System.out.println("OneAgv链接开始"); + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - NDCAgvService NDCAgvService = SpringContextHolder.getBean(NDCAgvService.class); + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); - ip = paramService.findByCode(AcsConfig.AGVURL).getValue(); - port = Integer.parseInt(paramService.findByCode(AcsConfig.AGVPORT).getValue()); + ip = paramService.findByCode(AcsConfig.ONEAGVURL).getValue(); + port = Integer.parseInt(paramService.findByCode(AcsConfig.ONEAGVPORT).getValue()); try { - byte[] b = new byte[1024]; + + byte[] b = new byte[1028]; s = new Socket(ip, port); dos = new DataOutputStream(s.getOutputStream()); dis = new DataInputStream(s.getInputStream()); - System.out.println("1楼NDCAgv链接成功"); - log.info("1楼NDCAgv链接成功"); + System.out.println("OneAgv链接成功"); while (bConnected) { int count = dis.read(b); @@ -122,18 +116,14 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //车号 int carno = arr[20]; Instruction link_inst = null; - Instruction inst = null; List insts = null; boolean link_flag = false; Device agv_device = null; - if(carno != 0){ + if (carno != 0) { agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); } if (ikey != 0) { - inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); - if (ObjectUtil.isEmpty(inst)){ - inst = instructionService.findByCode(String.valueOf(ikey)); - } + insts = instructionService.findByLinkNum(String.valueOf(ikey)); } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; @@ -149,75 +139,68 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //开始任务/上报订单号 if (phase == 0x01) { - if (!ObjectUtil.isEmpty(inst)) { + for (Instruction inst : insts) { inst.setInstruction_status("1"); inst.setAgv_jobno(String.valueOf(index)); inst.setSend_status("1"); instructionService.update(inst); } - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - //任务完毕 - //(无车id及状态) - else if (phase == 0x0A) { + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); - if (!ObjectUtil.isEmpty(inst)) { + + } else if (phase == 0x0A) { + + for (Instruction inst : insts) { if (!ObjectUtil.isEmpty(inst)) { instructionService.finish(inst.getInstruction_id()); } } - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); - } - //请求删除任务 - //(需要WCS反馈) - else if(phase == 0x30){ - data = NDCAgvService.sendAgvOneModeInst(0x8F, index, 0); + } else if (phase == 0x30) { + data = ndcAgvService.sendAgvOneModeInst(143, index, 0); - } - //任务删除确认 - //(需要WCS反馈) - else if(phase == 0xFF) { + } else if (phase == 0xFF) { - if (!ObjectUtil.isEmpty(inst)) { + for (Instruction inst : insts) { if (!ObjectUtil.isEmpty(inst)) { instructionService.cancelNOSendAgv(inst.getInstruction_id()); } } - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + + } else if (phase == 0x50) {//离开区域 + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + + } else if (phase == 0x51) {//离开区域 + + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); } else { - //上报异常信息 - //(不需要WCS反馈) - if(phase == 0x67){ + + if (phase == 0x67) { device = deviceAppService.findDeviceByCode(Integer.toString(arr[27])); } else { device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); } - if(ObjectUtil.isNotEmpty(device)){ - if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { - agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); - agvNdcOneDeviceDriver.processSocket(arr); - } - } + if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { + agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); + agvNdcOneDeviceDriver.processSocket(arr); + } } if (!ObjectUtil.isEmpty(data)) { write(data); } } else { - System.out.println("agv上报不是0073类型动作,不处理"); +// System.out.println("agv上报不是0073类型动作,不处理"); } } } catch (Exception e) { System.out.println("OneAgv链接异常"); - log.info("OneAgv链接异常"); - log.error("agv连接出现异常:{}", e); - logServer.deviceExecuteLog("1","","","agv异常"+e.getMessage()); - logServer.deviceExecuteLog("1","","","agv异常" + e); - if(ObjectUtil.isNotEmpty(s)){ + if (ObjectUtil.isNotEmpty(s)) { s.close(); } System.out.println(e.getMessage()); @@ -252,5 +235,6 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { // TODO Auto-generated catch block e.printStackTrace(); } + } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 4c9deab0..fe5fad77 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -13,45 +13,68 @@ public enum DriverTypeEnum { INSPECT_SITE(2, "standard_inspect_site", "检测站点", "conveyor"), - STORAGE(3, "standard_storage", "标准版-货架", "storage"), + AUTODOOR(3, "standard_autodoor", "标准版-自动门", "autodoor"), - SCANNER(4, "standard_scanner", "标准版-扫码器", "scanner"), + LAMP_THREE_COLOR(4, "lamp_three_color", "标准版-三色灯", "三色灯"), - INSPECT_CONVEYOR_CONTROL(5, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"), + STORAGE(5, "standard_storage", "标准版-货架", "storage"), - INSPECT_CONVEYOR_MONITOR(6, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"), + SCANNER(6, "standard_scanner", "标准版-扫码器", "scanner"), - AGV_NDC_ONE(7, "agv_ndc_one", "NDC1楼AGV", "agv"), + INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(7, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "conveyor"), - AGV_NDC_TWO(8, "agv_ndc_two", "NDC2楼AGV", "agv"), + INSPECT_CONVEYOR_CONTROL(8, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"), - HONGXIANG_DEVICE(9, "hongxiang_device", "烘箱设备点位", "conveyor"), + INSPECT_CONVEYOR_MONITOR(9, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"), - OVEN_MANIPULATOR(10, "oven_manipulator", "烘箱-行架机械手", "station"), + HAILIANG_PACKING(10, "hailiang_packing", "海亮包装项目-包装机", "conveyor"), - SLIT_TWO_MANIPULATOR(11, "slit_two_manipulator", "分切双工位-行架机械手", "station"), + HAILIANG_LABELING(11, "hailiang_labeling", "海亮包装项目-贴标机", "conveyor"), - BOX_PALLETIZING_MANIPULATOR(12, "box_palletizing_manipulator", "木箱码垛-行架机械手", "station"), + HAILIANG_COATING(12, "hailiang_coating", "海亮包装项目-裹膜机", "conveyor"), - SIEMENS_CONVEYOR(13, "siemens_conveyor", "西门子-输送机驱动", "conveyor"), + HAILIANG_SPECIAL_EMPTY_STATION(13, "hailiang_special_empty_station", "海亮专机空料点", "conveyor"), - HONGXIANG_CONVEYOR(13, "hongxiang_conveyor", "烘箱对接位", "conveyor"), + HAILIANG_SPECIAL_PICK_STATION(14, "hailiang_special_pick_station", "海亮专机接料点", "conveyor"), - INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(14, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "conveyor"), + HAILIANG_SPECIAL_FULL_STATION(15, "hailiang_special_full_station", "海亮专机满料点", "conveyor"), - PLUG_PULL_DEVICE_SITE(15, "plug_pull_device_site", "插拔轴站点", "conveyor"), + HAILIANG_SPECIAL_POUR_STATION(16, "hailiang_special_pour_station", "海亮专机倒料点", "conveyor"), - SIEMENS_CONVEYOR_LABELING(16, "siemens_conveyor_labeling", "西门子-输送机驱动-贴标", "conveyor"), + HAILIANG_SPECIAL_DEVICE(17, "hailiang_special_device", "海亮专机设备", "conveyor"), - SIEMENS_CONVEYOR_CKK(17, "siemens_conveyor_ckk", "西门子-输送机驱动-出库口", "conveyor"), + HAILIANG_AUTO_CACHE_LINE(18, "hailiang_auto_cache_line", "海亮自动缓存线", "conveyor"), - SIEMENS_ONEFLOOR_AGV_CONVEYOR(17, "siemens_onefloor_agv_conveyor", "西门子-1LAGV-输送机驱动", "conveyor"), + HAILIANG_ENGRAVING_MACHINE(19, "hailiang_engraving_machine", "海亮-激光刻字工位", "conveyor"), - PHOTOELECTRIC_INSPECTION_SITE(19, "photoelectric_inspection_site", "光电-检测站点", "conveyor"), + HAILIANG_CLEANING_MACHINE_STORAGE_STATION(20, "hailiang_cleaning_machine_storage_station", "海亮-清洗机储料仓", "conveyor"), - STANDARD_AUTODOOR(20, "standard_autodoor", "标准版-自动门", "autodoor"), + HAILIANG_CLEANING_MACHINE(21, "hailiang_cleaning_machine", "海亮-清洗机", "conveyor"), + + HAILIANG_CLEANING_FEEDING_LINE(22, "hailiang_cleaning_feeding_line", "海亮-清洗上料线体", "conveyor"), + + AGV_NDC_ONE(23, "agv_ndc_one", "NDC单工位AGV", "agv"), + + AGV_NDC_TWO(24, "agv_ndc_two", "NDC双工位AGV", "agv"), + + HAILIANG_ENGRAVING_CACHE(25, "hailiang_engraving_cache", "海亮-刻字缓存位", "conveyor"), + + HAILIANG_PACKER_STATION(26, "hailiang_packer_station", "海亮-包装机工位", "conveyor"), + + HAILIANG_XJ_PLC_TEST(27, "hailiang_xj_plc_test", "海亮-信捷PLC", "conveyor"), + + HAILIANG_SMART_PLC_TEST(28, "hailiang_smart_plc_test", "海亮-西门子SMART200PLC", "conveyor"), + + HAILIANG_THREESTATION_SMART(29, "hailiang_threestation_smart", "海亮-三工位Smart200", "conveyor"), + + HAILIANG_FOLDINGDISC_SMART(30, "hailiang_foldingDisc_smart", "海亮-叠盘位Smart200", "conveyor"), + + HAILIANG_ELEVATOR_WIRING(31, "hailiang_elevator_wiring", "海亮-货梯对接线", "conveyor"), + + HAILIANG_PAINT_LINE(32, "hailiang_paint_line", "海亮-油漆线", "conveyor"), + + HAILIANG_STACKING_STATION(33, "hailiang_stacking_station", "海亮-包装线体", "conveyor"); - LAMP_THREE_COLOR(21, "lamp_three_color", "标准版-三色灯", "三色灯"); //驱动索引 diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 9b12517b..5e0dbc17 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -23,11 +23,8 @@ import org.nl.acs.device.service.dto.*; import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.DeviceDriverDefination; import org.nl.acs.device_driver.ScannerDeviceDriver; -import org.nl.acs.device_driver.basedriver.oven_manipulator.OvenGantryManipulatorDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk.SiemensConveyorCkkDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling.SiemensConveyorLabelingDeviceDriver; -import org.nl.acs.device_driver.basedriver.slit_two_manipulator.SlitTwoManipulatorDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache.HailiangEngravingCacheDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station.HailiangPackerStationDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; @@ -729,35 +726,108 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial throw new BadRequestException("未找到对应设备:" + device_code); } StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - SlitTwoManipulatorDeviceDriver slitTwoManipulatorDeviceDriver; //检测站点 StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + //刻字缓存位 + HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver; + HailiangPackerStationDeviceDriver hailiangPackerStationDeviceDriver; if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setDeviceStatus(form); - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + if (!StrUtil.isEmpty(hasGoodStatus)) { + standardOrdinarySiteDeviceDriver.setHasGoods(Integer.parseInt(hasGoodStatus)); + device.setHas_goods(Integer.parseInt(hasGoodStatus)); + } + if (StrUtil.isNotEmpty(material_type)) { + standardOrdinarySiteDeviceDriver.setMaterial(material_type); + device.setMaterial_type(material_type); + } else { + standardOrdinarySiteDeviceDriver.setMaterial(""); + device.setMaterial_type(""); + } + if (StrUtil.isNotEmpty(quantity)) { + standardOrdinarySiteDeviceDriver.setQty(quantity); + device.setQuantity(quantity); + } else { + standardOrdinarySiteDeviceDriver.setQty(""); + device.setQuantity(""); + } + if (StrUtil.isNotEmpty(remark)) { + standardOrdinarySiteDeviceDriver.setRemark(remark); + device.setRemark(remark); + } else { + standardOrdinarySiteDeviceDriver.setRemark(""); + device.setRemark(""); + } + if (StrUtil.isNotEmpty(batch)) { + standardOrdinarySiteDeviceDriver.setBatch(batch); + device.setBatch(batch); + } else { + standardOrdinarySiteDeviceDriver.setBatch(""); + device.setBatch(""); + } + WQLObject runpointwo = WQLObject.getWQLObject("acs_device_runpoint"); + JSONObject json = runpointwo.query("device_code ='" + device_code + "'").uniqueResult(0); + if (!ObjectUtil.isEmpty(json)) { + DeviceRunpointDto obj = json.toJavaObject(DeviceRunpointDto.class); + obj.setHasgoods(hasGoodStatus); + obj.setMaterial_type(material_type); + obj.setBatch(batch); + device.setHas_goods(Integer.parseInt(hasGoodStatus)); + device.setMaterial_type(material_type); + device.setRemark(remark); + device.setQuantity(quantity); + device.setBatch(batch); + device.setIslock(islock); + JSONObject updatejson = (JSONObject) JSONObject.toJSON(obj); + runpointwo.update(updatejson, "device_code = '" + device_code + "'"); + } + } + else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.setDeviceStatus(form); + standardInspectSiteDeviceDriver.setMaterial(material_type); + standardInspectSiteDeviceDriver.setBatch(batch); + device.setMaterial_type(material_type); + device.setBatch(batch); + } - } else if (device.getDeviceDriver() instanceof SlitTwoManipulatorDeviceDriver) { - slitTwoManipulatorDeviceDriver = (SlitTwoManipulatorDeviceDriver) device.getDeviceDriver(); - slitTwoManipulatorDeviceDriver.setDeviceStatus(form); - } else if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - siemensConveyorDeviceDriver.setDeviceStatus(form); - } else if (device.getDeviceDriver() instanceof SiemensConveyorLabelingDeviceDriver) { - SiemensConveyorLabelingDeviceDriver siemensConveyorLabelingDeviceDriver = (SiemensConveyorLabelingDeviceDriver) device.getDeviceDriver(); - siemensConveyorLabelingDeviceDriver.setDeviceStatus(form); - } else if (device.getDeviceDriver() instanceof OvenGantryManipulatorDeviceDriver) { - OvenGantryManipulatorDeviceDriver ovenGantryManipulatorDeviceDriver = (OvenGantryManipulatorDeviceDriver) device.getDeviceDriver(); - ovenGantryManipulatorDeviceDriver.setDeviceStatus(form); - } else if (device.getDeviceDriver() instanceof SiemensConveyorCkkDeviceDriver) { - SiemensConveyorCkkDeviceDriver siemensConveyorCkkDeviceDriver = (SiemensConveyorCkkDeviceDriver) device.getDeviceDriver(); - siemensConveyorCkkDeviceDriver.setDeviceStatus(form); - } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver){ - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver - = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); - standardCoveyorControlWithScannerDeviceDriver.setDeviceStatus(form); + else if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver(); + WQLObject runpointwo = WQLObject.getWQLObject("acs_device_runpoint"); + JSONObject json = runpointwo.query("device_code ='" + device_code + "'").uniqueResult(0); + if (!ObjectUtil.isEmpty(json)) { + DeviceRunpointDto obj = json.toJavaObject(DeviceRunpointDto.class); + obj.setHasgoods(hasGoodStatus); + obj.setMaterial_type(material_type); + obj.setBatch(batch); + obj.setIslock(islock); + hailiangEngravingCacheDeviceDriver.setMaterial(material_type); + if (hailiangEngravingCacheDeviceDriver.getMove() != Integer.parseInt(hasGoodStatus)){ + hailiangEngravingCacheDeviceDriver.writing("to_cache_write",hasGoodStatus); + } + hailiangEngravingCacheDeviceDriver.setHasGoods(Integer.parseInt(hasGoodStatus)); + device.setHas_goods(Integer.parseInt(hasGoodStatus)); + device.setMaterial_type(material_type); + hailiangEngravingCacheDeviceDriver.setMaterial(material_type); + JSONObject updatejson = (JSONObject) JSONObject.toJSON(obj); + runpointwo.update(updatejson, "device_code = '" + device_code + "'"); + } + } + else if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + if(StrUtil.isNotEmpty(requireSucess)) { + if (requireSucess.equals("0")){ + hailiangPackerStationDeviceDriver.setRequireSucess(false); + } else { + hailiangPackerStationDeviceDriver.setRequireSucess(true); + } + } + if(StrUtil.isNotEmpty(fullrequireSucess)) { + if (fullrequireSucess.equals("0")){ + hailiangPackerStationDeviceDriver.setFullrequireSucess(false); + } else { + hailiangPackerStationDeviceDriver.setFullrequireSucess(true); + } + } } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDefination.java index 7a7ec932..ccb93c9e 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDefination.java @@ -21,12 +21,12 @@ public class AgvNdcOneDefination implements DeviceDriverDefination { @Override public String getDriverName() { - return "NDC1楼AGV"; + return "NDC单工位AGV"; } @Override public String getDriverDescription() { - return "NDC1楼AGV"; + return "NDC单工位AGV"; } @Override diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index 8596c85a..fe4e35f5 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -2,16 +2,17 @@ package org.nl.acs.device_driver.basedriver.agv.ndcone; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_onefloor_agv_conveyor.SiemensOneFloorAGVConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache.HailiangEngravingCacheDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_machine.HailiangEngravingMachineDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station.HailiangPackerStationDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.device_driver.driver.AbstractDeviceDriver; @@ -20,20 +21,15 @@ import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.instruction.service.impl.InstructionServiceImpl; -import org.nl.acs.log.LokiLog; -import org.nl.acs.log.LokiLogType; import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; import org.nl.modules.system.service.ParamService; import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * NDC单工位AGV @@ -41,19 +37,20 @@ import java.util.Map; @Slf4j @Data @RequiredArgsConstructor -public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, DeviceStageMonitor { +public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements DeviceDriver { - ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - NDCAgvService NDCAgvService = SpringContextHolder.getBean(NDCAgvService.class); - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); int agvaddr = 0; int agvaddr_copy = 0; int weight = 0; - String device_code = ""; + String device_code = ""; int phase = 0; int x = 0; //x坐标 @@ -69,10 +66,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic int last_electric_qty = 0; int last_status = 0; int last_error = 0; - - int mode = 2; - -// @LokiLog(type = LokiLogType.AGV) public synchronized void processSocket(int[] arr) throws Exception { device_code = this.getDeviceCode(); byte[] data = null; @@ -85,62 +78,59 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic agvaddr = arr[18] * 256 + arr[19]; //车号 int carno = arr[20]; - logServer.deviceExecuteLog(this.device_code, "", "", "接收agv上报信息:" + "phase--" + phase + " index--" + index + " 指令号--" + ikey + " 站点号--" + agvaddr + " 车号--" + carno); Instruction link_inst = null; List insts = null; - Instruction inst = null; boolean link_flag = false; Device agv_device = null; if (carno != 0) { agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); } if (ikey != 0) { - inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); - if (ObjectUtil.isEmpty(inst)){ - inst = instructionService.findByCode(String.valueOf(ikey)); - } + insts = instructionService.findByLinkNum(String.valueOf(ikey)); } if (!ObjectUtil.isEmpty(link_inst)) { link_flag = true; } + logServer.deviceExecuteLog(this.device_code,"","","接收AGV上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); Device device = null; String old_device_code = null; String emptyNum = null; String device_code = null; - if (phase == 0x67) { + if(phase==0x67) { //故障信息 - if (arr[18] * 256 + arr[19] == 0) { + if(arr[18]*256+arr[19]==0){ } - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); } - + //刻字缓存位 + HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver; + //刻字机工位 + HailiangEngravingMachineDeviceDriver hailiangEngravingMachineDeviceDriver; + //包装机工位 + HailiangPackerStationDeviceDriver hailiangPackerStationDeviceDriver; //普通站点 StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; //货架 StandardStorageDeviceDriver standardStorageDeviceDriver; - // - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; - //1LAGV取货 - SiemensOneFloorAGVConveyorDeviceDriver siemensOneFloorAGVConveyorDeviceDriver; - //分配 车id - //(不需要WCS反馈) + //开始任务/上报订单号 if (phase == 0x02) { - inst.setCarno(String.valueOf(carno)); - instructionService.update(inst); - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈车号:" +carno+",指令号:" + ikey); + for (Instruction inst : insts) { + inst.setCarno(String.valueOf(carno)); + instructionService.update(inst); + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); - //到达取货点 - //(需要WCS反馈) + //请求取货 } else if (phase == 0x03) { if (agvaddr == 0) { agvaddr = agvaddr_copy; } if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + logServer.deviceExecuteLog(this.device_code,"","","agv地址参数有误,phase:" + phase ); return; } device_code = deviceService.queryDeviceCodeByAddress(agvaddr); @@ -161,60 +151,87 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic device = deviceAppService.findDeviceByCode(device_code); if (ObjectUtil.isEmpty(device_code)) { log.info(agvaddr + "对应设备号为空!"); - logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空"); - return; - } - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到编号{}对应的指令", ikey); - logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); + logServer.deviceExecuteLog(this.device_code,"","",agvaddr+"对应设备号为空"); return; } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + logServer.deviceExecuteLog(this.device_code,"","","未找到关联编号对应的指令"+ikey); + break; + } - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + hailiangEngravingMachineDeviceDriver.setAgvphase(phase); + hailiangEngravingMachineDeviceDriver.setIndex(index); + hailiangEngravingMachineDeviceDriver.setInst(inst); + } - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if (siemensConveyorDeviceDriver.getMove() == 1) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else { - log.info("请求取货条件不满足待机有货"); + if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver(); + hailiangEngravingCacheDeviceDriver.setAgvphase(phase); + hailiangEngravingCacheDeviceDriver.setIndex(index); + hailiangEngravingCacheDeviceDriver.setInst(inst); + } + + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setAgvphase(phase); + standardOrdinarySiteDeviceDriver.setIndex(index); + standardOrdinarySiteDeviceDriver.setInst(inst); + } + + if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + hailiangPackerStationDeviceDriver.setAgvphase(phase); + hailiangPackerStationDeviceDriver.setIndex(index); + hailiangPackerStationDeviceDriver.setInst(inst); + } + + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + } } } - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if (siemensConveyorDeviceDriver.getMove() == 1) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else { - log.info("请求取货条件不满足待机有货"); - } - } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); - if (device.getDeviceDriver() instanceof SiemensOneFloorAGVConveyorDeviceDriver) { - siemensOneFloorAGVConveyorDeviceDriver = (SiemensOneFloorAGVConveyorDeviceDriver) device.getDeviceDriver(); - if (siemensOneFloorAGVConveyorDeviceDriver.getMove() == 1) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else { - log.info("请求取货条件不满足待机有货"); + } else if (phase == 0x65) {//param,重量待定 + //1、得到重量信息 + int weight = (arr[18] * 256 + arr[19]) * 10; + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + // 4010 待处理 + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + inst.setWeight(String.valueOf(weight)); } } - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //取货完毕/取满框完毕1/点对点取货完毕 + } else if (phase == 0x64) {//param,agv货位id待定 + //1、根据货位id找到对应三工位设备,赋给agv属性地址对应的满料位设备 + agvaddr = arr[18] * 256 + arr[19]; + agvaddr_copy = agvaddr; + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + //取货完毕 - //(需要WCS反馈) } else if (phase == 0x05) { if (agvaddr == 0) { agvaddr = agvaddr_copy; } if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + logServer.deviceExecuteLog(this.device_code,"","","agv地址参数有误,phase:" + phase ); return; } if (agvaddr != 0) { @@ -234,77 +251,57 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic if (ObjectUtil.isEmpty(device_code)) { log.info(agvaddr + "对应设备号为空!"); - logServer.deviceExecuteLog(this.device_code, "", "", "对应设备号为空" + device_code); + logServer.deviceExecuteLog(this.device_code,"","","对应设备号为空"+device_code); return; } - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到关联编号{}对应的指令", ikey); - logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey); - return; - } - - if (StrUtil.equals(inst.getStart_device_code(), device_code)) { - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + logServer.deviceExecuteLog(this.device_code,"","","未找到关联编号对应的指令"+ikey); + break; } - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if(siemensConveyorDeviceDriver.getTo_command() == 2){ - log.info("取货完成请求离开,当前输送to_command:"+siemensConveyorDeviceDriver.getTo_command()); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else { - log.info("取货完成请求离开下发输送信号,当前输送to_command:"+siemensConveyorDeviceDriver.getTo_command()); - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "2"); - list.add(map); - siemensConveyorDeviceDriver.writing(list); - siemensConveyorDeviceDriver.writing(list); + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + hailiangEngravingMachineDeviceDriver.setAgvphase(phase); + hailiangEngravingMachineDeviceDriver.setIndex(index); + hailiangEngravingMachineDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver(); + hailiangEngravingCacheDeviceDriver.setAgvphase(phase); + hailiangEngravingCacheDeviceDriver.setIndex(index); + hailiangEngravingCacheDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setAgvphase(phase); + standardOrdinarySiteDeviceDriver.setIndex(index); + standardOrdinarySiteDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + hailiangPackerStationDeviceDriver.setAgvphase(phase); + hailiangPackerStationDeviceDriver.setIndex(index); + hailiangPackerStationDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); } } - - if (device.getDeviceDriver() instanceof SiemensOneFloorAGVConveyorDeviceDriver) { - siemensOneFloorAGVConveyorDeviceDriver = (SiemensOneFloorAGVConveyorDeviceDriver) device.getDeviceDriver(); - if(siemensOneFloorAGVConveyorDeviceDriver.getTo_command() == 2){ - log.info("取货完成请求离开,当前输送to_command:"+siemensOneFloorAGVConveyorDeviceDriver.getTo_command()); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else { - log.info("取货完成请求离开下发输送信号,当前输送to_command:"+siemensOneFloorAGVConveyorDeviceDriver.getTo_command()); - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "2"); - list.add(map); - siemensOneFloorAGVConveyorDeviceDriver.writing(list); - siemensOneFloorAGVConveyorDeviceDriver.writing(list); - } - } - - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - } - if(ObjectUtil.isNotEmpty(data)){ - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + Bytes2HexString(data)); - } - //到达放货点 - //(需要WCS反馈) + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //请求放货 } else if (phase == 0x07) { if (agvaddr == 0) { agvaddr = agvaddr_copy; } if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + logServer.deviceExecuteLog(this.device_code,"","","agv地址参数有误,phase:" + phase ); return; } if (agvaddr != 0) { @@ -325,32 +322,53 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic log.info(agvaddr + "对应设备号为空!"); return; } - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到关联编号{}对应的指令", ikey); - return; - } - if (StrUtil.equals(inst.getNext_device_code(), device_code)) { - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + hailiangEngravingMachineDeviceDriver.setAgvphase(phase); + hailiangEngravingMachineDeviceDriver.setIndex(index); + hailiangEngravingMachineDeviceDriver.setInst(inst); + } - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver(); + hailiangEngravingCacheDeviceDriver.setAgvphase(phase); + hailiangEngravingCacheDeviceDriver.setIndex(index); + hailiangEngravingCacheDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setAgvphase(phase); + standardOrdinarySiteDeviceDriver.setIndex(index); + standardOrdinarySiteDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + hailiangPackerStationDeviceDriver.setAgvphase(phase); + hailiangPackerStationDeviceDriver.setIndex(index); + hailiangPackerStationDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + } } - } - //放货完毕 - //(需要WCS反馈) + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //放货完成 } else if (phase == 0x09) { if (agvaddr == 0) { agvaddr = agvaddr_copy; } if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + logServer.deviceExecuteLog(this.device_code,"","","agv地址参数有误,phase:" + phase ); return; } if (agvaddr != 0) { @@ -372,79 +390,82 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic log.info(agvaddr + "对应设备号为空!"); return; } - //校验agv上报站点编号与指令起始点相同 - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到编号{}对应的指令", ikey); - return; - } - if (StrUtil.equals(inst.getNext_device_code(), device_code)) { - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + hailiangEngravingMachineDeviceDriver.setAgvphase(phase); + hailiangEngravingMachineDeviceDriver.setIndex(index); + hailiangEngravingMachineDeviceDriver.setInst(inst); + } - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + if (device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) device.getDeviceDriver(); + hailiangEngravingCacheDeviceDriver.setAgvphase(phase); + hailiangEngravingCacheDeviceDriver.setIndex(index); + hailiangEngravingCacheDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + hailiangPackerStationDeviceDriver.setAgvphase(phase); + hailiangPackerStationDeviceDriver.setIndex(index); + hailiangPackerStationDeviceDriver.setInst(inst); + } + + if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); + standardOrdinarySiteDeviceDriver.setAgvphase(phase); + standardOrdinarySiteDeviceDriver.setIndex(index); + standardOrdinarySiteDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + } } - } - } - //到达位置点 - //(需要WCS反馈) - else if (phase == 0x64) {//param,agv货位id待定 - //1、根据货位id找到对应三工位设备,赋给agv属性地址对应的满料位设备 - agvaddr = arr[18] * 256 + arr[19]; - agvaddr_copy = agvaddr; - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else if (phase == 0x50) {//进入交通灯区域 - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } else if (phase == 0x51) {//离开交通灯区域 - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + } else if (phase == 0x71){ + x = ikey; + if (x != last_x){ + logServer.deviceItemValue(this.device_code, "x", String.valueOf(x)); + } + } else if (phase == 0x72){ + y = ikey; + if (y != last_y){ + logServer.deviceItemValue(this.device_code, "y", String.valueOf(y)); + } + } else if (phase == 0x73){ + angle = last_angle; + if (angle != last_angle){ + logServer.deviceItemValue(this.device_code, "angle", String.valueOf(angle)); + } + } else if (phase == 0x74){ + electric_qty = ikey; + if (electric_qty != last_electric_qty){ + logServer.deviceItemValue(this.device_code, "electric_qty", String.valueOf(electric_qty)); + } + } else if (phase == 0x75){ + status = ikey; + if (status != last_status){ + logServer.deviceItemValue(this.device_code, "status", String.valueOf(status)); + } + } else if (phase == 0x76){ + error = ikey; + if (error != last_error){ + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + } } if (!ObjectUtil.isEmpty(data)) { - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" +Bytes2HexString(data)); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); OneNDCSocketConnectionAutoRun.write(data); } - } - public static String Bytes2HexString(byte[] b) { - String ret = ""; - for (int i = 0; i < b.length; i++) { - String hex = Integer.toHexString(b[i] & 0xFF); - if (hex.length() == 1) { - hex = '0' + hex; - } - ret += hex.toUpperCase(); - } - return ret; - } - - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String move = ""; - if (this.getMode() == 0) { - mode = "未联机"; - } else if (this.getMode() == 1) { - mode = "联机"; - } else if (this.getMode() == 2) { - mode = "联机"; - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("error", this.getError()); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndctwo/AgvNdcTwoDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndctwo/AgvNdcTwoDeviceDriver.java index 83dcb5a3..69bc4332 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndctwo/AgvNdcTwoDeviceDriver.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndctwo/AgvNdcTwoDeviceDriver.java @@ -2,71 +2,76 @@ package org.nl.acs.device_driver.basedriver.agv.ndctwo; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; import org.nl.acs.agv.server.NDCAgvService; -import org.nl.acs.auto.run.TwoNDC2SocketConnectionAutoRun; -import org.nl.acs.auto.run.TwoNDCSocketConnectionAutoRun; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.NDCSocketConnectionAutoRun; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.basedriver.photoelectric_inspection_site.PhotoelectricInspectionSiteDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_autodoor.StandardAutodoorDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_auto_cache_line.HailiangAutoCacheLineDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine_storage_station.HailiangCleaningMachineStorageStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_empty_station.HailiangSpecialEmptyStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_full_station.HailiangSpecialFullStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pick_station.HailiangSpecialPickStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pour_station.HailiangSpecialPourStationDeviceDriver; import org.nl.acs.device_driver.driver.AbstractDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.instruction.service.impl.InstructionServiceImpl; -import org.nl.acs.log.LokiLog; -import org.nl.acs.log.LokiLogType; import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.acs.task.service.impl.TaskServiceImpl; import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; /** - * NDC双工位AGV + * 双工位诺宝AGV */ @Slf4j @Data @RequiredArgsConstructor -public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, DeviceStageMonitor { +public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements DeviceDriver { - ParamService ParamService = SpringContextHolder.getBean(ParamService.class); + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); - TaskService taskService = SpringContextHolder.getBean(TaskServiceImpl.class); AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); int agvaddr = 0; int agvaddr_copy = 0; int weight = 0; - int agv_power = 0; - String device_code = ""; + String device_code = ""; int phase = 0; - int region = 0; - int error = 0; - String message = null; - Boolean isonline = true; - Boolean iserror = false; - int mode = 2; - @LokiLog(type = LokiLogType.AGV) + int x = 0; //x坐标 + int y = 0; //y坐标 + int angle = 0; //角度 + int electric_qty = 0; //电量 + int status = 0; //三色灯状态 + int error = 0; //车辆故障 + + int last_x = 0; + int last_y = 0; + int last_angle = 0; + int last_electric_qty = 0; + int last_status = 0; + int last_error = 0; public synchronized void processSocket(int[] arr) throws Exception { device_code = this.getDeviceCode(); + logServer.deviceExecuteLog(this.device_code,"","","接收AGV上报信息:" + arr); + byte[] data = null; phase = arr[16] * 256 + arr[17]; // agv任务号 @@ -77,679 +82,657 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic agvaddr = arr[18] * 256 + arr[19]; //车号 int carno = arr[20]; - logServer.deviceExecuteLog(this.device_code, "", "", "接收agv上报信息:" + "phase--" + phase + " index--" + index + " 指令号--" + ikey + " 站点号--" + agvaddr + " 车号--" + carno); - Instruction inst = null; + Instruction link_inst = null; + List insts = null; + boolean link_flag = false; Device agv_device = null; if (carno != 0) { agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); } - TaskDto task = null; if (ikey != 0) { - inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); - if(ObjectUtil.isEmpty(inst)){ - log.info("该指令号未找到对应指令:"+ikey); - message = "该指令号未找到对应指令:"+ikey; - logServer.deviceExecuteLog(this.device_code, "", "", "该指令号未找到对应指令:"+ikey); - return; - } - task = taskService.findByTaskCode(inst.getTask_code()); - if(ObjectUtil.isEmpty(task)){ - log.info("该指令号未找到对应任务:"+ikey); - message = "该指令号未找到对应任务:"+ikey; - logServer.deviceExecuteLog(this.device_code, "", "", "该指令号未找到对应任务:"+ikey); - return; - } + insts = instructionService.findByLinkNum(String.valueOf(ikey)); } - + if (!ObjectUtil.isEmpty(link_inst)) { + link_flag = true; + } + log.info("接收agv上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); + logServer.deviceExecuteLog(this.device_code,"","","接收AGV上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno); Device device = null; String old_device_code = null; String emptyNum = null; String device_code = null; - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; + if(phase==0x67) { + //故障信息 + if(arr[18]*256+arr[19]==0){ + } + return; } - device = deviceAppService.findDeviceByCode(device_code); - //普通站点 - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - //货架 - StandardStorageDeviceDriver standardStorageDeviceDriver; - //普通-光电检测 - PhotoelectricInspectionSiteDeviceDriver photoelectricInspectionSiteDeviceDriver; - //标准-光电检测 - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - //自动门 - StandardAutodoorDeviceDriver standardAutodoorDeviceDriver; + //海亮专机设备空框位 + HailiangSpecialEmptyStationDeviceDriver hailiangSpecialEmptyStationDeviceDriver; + //海亮专机设备满框位 + HailiangSpecialFullStationDeviceDriver hailiangSpecialFullStationDeviceDriver; + //海亮专机设备接框位 + HailiangSpecialPickStationDeviceDriver hailiangSpecialPickStationDeviceDriver; + //海亮专机设备倒料位 + HailiangSpecialPourStationDeviceDriver hailiangSpecialPourStationDeviceDriver; + //自动缓存线 + HailiangAutoCacheLineDeviceDriver hailiangAutoCacheLineDeviceDriver; + //清洗倒料 + HailiangCleaningMachineStorageStationDeviceDriver hailiangCleaningMachineStorageStationDeviceDriver; + //开始任务/上报订单号 if (phase == 0x02) { - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; + for (Instruction inst : insts) { + inst.setCarno(String.valueOf(carno)); + instructionService.update(inst); } - inst.setCarno(String.valueOf(carno)); - instructionService.update(inst); - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈车号:" +carno+",指令号:" + ikey); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); - } - //到达取货点 - //(Itype=1/2/3,需要WCS反馈Phase) - else if (phase == 0x03) { + //到达取货点1 + } else if (phase == 0x03) { if (agvaddr == 0) { agvaddr = agvaddr_copy; } if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); return; } device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - } - device = deviceAppService.findDeviceByCode(device_code); if (ObjectUtil.isEmpty(device_code)) { log.info(agvaddr + "对应设备号为空!"); - logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空"); return; } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(this.device.getExtraValue().get("wait")) - && StrUtil.equals("true",this.device.getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - // - if(standardOrdinarySiteDeviceDriver.getOption() == 1){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } else { - log.info("等待LMS系统进行确认允许取货,设备号{},指令号{}", device_code,ikey); - message = "等待LMS系统进行确认允许取货,设备号:"+device_code +",指令号:"+ikey; - logServer.deviceExecuteLog(this.device_code, "", "", "等待LMS系统进行确认允许取货,设备号"+device.getDevice_code()+",指令号"+ikey); + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialFullStationDeviceDriver) { + hailiangSpecialFullStationDeviceDriver = (HailiangSpecialFullStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialFullStationDeviceDriver.setAgvphase(phase); + hailiangSpecialFullStationDeviceDriver.setIndex(index); + hailiangSpecialFullStationDeviceDriver.setInst(inst); } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - this.setPhase(phase); - - } else if (device.getDeviceDriver() instanceof PhotoelectricInspectionSiteDeviceDriver){ - photoelectricInspectionSiteDeviceDriver = (PhotoelectricInspectionSiteDeviceDriver) device.getDeviceDriver(); - if(photoelectricInspectionSiteDeviceDriver.getMove() == 1) - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){ - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.writing("to_command","1"); - if(standardInspectSiteDeviceDriver.getMove() == 1 && standardInspectSiteDeviceDriver.getAction() == 1){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } else { - message = "设备号:"+device_code + "光电信号:" + standardInspectSiteDeviceDriver.getMove() + ",动作信号:"+ standardInspectSiteDeviceDriver.getAction() + ",指令号:"+ikey; - log.info("设备{}当前光电信号{},动作信号{},不满足取货条件,指令号{}", device_code,standardInspectSiteDeviceDriver.getMove(),standardInspectSiteDeviceDriver.getAction(),ikey); - } - } - else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - } - // 取货完毕 - //(Itype=1/2/3,需要WCS反馈Phase) - else if (phase == 0x05) { - if (agvaddr == 0) { - agvaddr = agvaddr_copy; - } - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - } - device = deviceAppService.findDeviceByCode(device_code); - - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - logServer.deviceExecuteLog(this.device_code, "", "", "对应设备号为空" + device_code); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(this.device.getExtraValue().get("wait")) - && StrUtil.equals("true",this.device.getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - // - standardOrdinarySiteDeviceDriver.setOption(0); - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - this.setPhase(phase); - - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){ - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.writing("to_command","0"); - if(standardInspectSiteDeviceDriver.getMove() == 0 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } else { - message = "设备号:"+device_code + "光电信号:" + standardInspectSiteDeviceDriver.getMove() + ",动作信号:"+ standardInspectSiteDeviceDriver.getAction() + ",指令号:"+ikey; - log.info("设备{}当前光电信号{},动作信号{},不满足取货条件", device_code,standardInspectSiteDeviceDriver.getMove()); - } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } - //到达取货点(Itype=1、3,需要WCS反馈) - else if (phase == 0x08) { - if (agvaddr == 0) { - agvaddr = agvaddr_copy; - } - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - } - device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) - && StrUtil.equals("true",standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - // - if(standardOrdinarySiteDeviceDriver.getOption() == 1 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } else { - log.info("等待LMS系统进行确认允许取货,设备号{},指令号{}", device_code,ikey); - message = "等待LMS系统进行确认允许取货,设备号:"+device_code +",指令号:"+ikey; - logServer.deviceExecuteLog(this.device_code, "", "", "等待LMS系统进行确认允许取货,设备号"+device.getDevice_code()); - - } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - this.setPhase(phase); - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - } - // 取货完毕 - //(Itype=1、3,需要WCS反馈) - else if (phase == 0x0A) { - if (agvaddr == 0) { - agvaddr = agvaddr_copy; - } - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; } } - device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - //生箔取满完成请求离开 不需要判断 - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) - && StrUtil.equals("true",standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - standardOrdinarySiteDeviceDriver.setOption(0); - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); - } - //(Itype=1,上传称重数据) - else if (phase == 0x64) { - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - String instruction_type = inst.getInstruction_type(); - //上传称重数据 - if (StrUtil.equals(instruction_type, "1")) { - weight = agvaddr; - inst.setWeight(String.valueOf(weight)); - instructionService.update(inst); - - if(ObjectUtil.isNotEmpty(task)){ - logServer.deviceExecuteLog(this.device_code, "", "", "上报满卷重量,weight:" + weight); - message = "上报满卷重量,weight:"+weight +",指令号:"+ikey; - task.setWeight(String.valueOf(weight)); - task.setCarno(this.device_code); - taskService.update(task); + } else if (phase == 0x65) {//param,重量待定 + //1、得到重量信息 + int weight = (arr[18] * 256 + arr[19]) * 10; + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; } - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } - // 到达放货点 - //(Itype=1/2/3,需要WCS反馈) - else if (phase == 0x0C) { - if (agvaddr == 0) { - agvaddr = agvaddr_copy; - } - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; + // 4010 待处理 + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + inst.setWeight(String.valueOf(weight)); } } - - device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - //请求放空 可以直接走 - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - - } else if (device.getDeviceDriver() instanceof PhotoelectricInspectionSiteDeviceDriver){ - photoelectricInspectionSiteDeviceDriver = (PhotoelectricInspectionSiteDeviceDriver) device.getDeviceDriver(); - if(photoelectricInspectionSiteDeviceDriver.getMove() == 0) - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){ - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.writing("to_command","1"); - if(standardInspectSiteDeviceDriver.getMove() == 0 && standardInspectSiteDeviceDriver.getAction() ==1 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } - else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } - //放货完成 - //(Itype=1/2/3,需要WCS反馈) - else if (phase == 0x0E) { - if (agvaddr == 0) { - agvaddr = agvaddr_copy; - } - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - } - - device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) - && StrUtil.equals("true",standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - // - if(standardOrdinarySiteDeviceDriver.getOption() == 2 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setOption(0); - } else { - log.info("等待LMS系统进行确认离开,设备号{},指令号:{}", device_code,ikey); - message = "等待LMS系统进行确认离开,设备号:"+device_code +",指令号:"+ikey; - } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - this.setPhase(phase); - } else if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){ - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - standardInspectSiteDeviceDriver.writing("to_command","0"); - if(standardInspectSiteDeviceDriver.getMove() == 1 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } - //到达放货点 - //(Itype=1、3,需要WCS反馈) - else if (phase == 0x10) { - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - } - - device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) - && StrUtil.equals("true",standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - // - if(standardOrdinarySiteDeviceDriver.getOption() == 2 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setOption(0); - } else { - log.info("等待LMS系统进行确认离开,设备号{},指令号:{}", device_code,ikey); - message = "等待LMS系统进行确认离开,设备号:"+device_code +",指令号:"+ikey; - } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - this.setPhase(phase); - - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - } - //放货完成 - //(Itype=1、3,需要WCS反馈) - else if (phase == 0x12) { - if (agvaddr == 0) { - agvaddr = agvaddr_copy; - } - if (agvaddr < 1) { - logServer.deviceExecuteLog(this.device_code, "", "", "agv地址参数有误,phase:" + phase); - return; - } - if (agvaddr != 0) { - old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr); - if (StrUtil.contains(old_device_code, "-")) { - String[] point = old_device_code.split("-"); - device_code = point[0]; - } else if (StrUtil.contains(old_device_code, ".")) { - String[] point = old_device_code.split("\\."); - device_code = point[0]; - emptyNum = point[1]; - } else { - device_code = old_device_code; - } - } - - device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device_code)) { - log.info(agvaddr + "对应设备号为空!"); - return; - } - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - if(ObjectUtil.isNotEmpty(standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait")) - && StrUtil.equals("true",standardOrdinarySiteDeviceDriver.getDevice().getExtraValue().get("wait").toString()) - && StrUtil.equals(task.getTask_type(),"1")){ - // - if(standardOrdinarySiteDeviceDriver.getOption() == 2 ){ - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - standardOrdinarySiteDeviceDriver.setOption(0); - } else { - log.info("等待LMS系统进行确认离开,设备号{},指令号:{}", device_code,ikey); - message = "等待LMS系统进行确认离开,设备号:"+device_code +",指令号:"+ikey; - } - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - - this.setPhase(phase); - - } else { - data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } - } - //上传AGV电量 - else if (phase == 0x73) { - if (ObjectUtil.isEmpty(inst)) { - log.info("未找到指令号{}对应的指令", ikey); - return; - } - agv_power = ikey; data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); - } //进入区域(phase值) - else if (phase == 0x50) { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + //取货完毕/取满框完毕1/点对点取货完毕 + } else if (phase == 0x64) {//param,agv货位id待定 + //1、根据货位id找到对应三工位设备,赋给agv属性地址对应的满料位设备 + agvaddr = arr[18] * 256 + arr[19]; + agvaddr_copy = agvaddr; + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); - - - } - //离开区域(phase值) - else if (phase == 0x51) { - - - } - //上报异常信息 - //(不需要WCS反馈) - else if (phase == 0x67) { - //故障信息 + //取货点1取货完毕 + } else if (phase == 0x05) { if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialFullStationDeviceDriver) { + hailiangSpecialFullStationDeviceDriver = (HailiangSpecialFullStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialFullStationDeviceDriver.setAgvphase(phase); + hailiangSpecialFullStationDeviceDriver.setIndex(index); + hailiangSpecialFullStationDeviceDriver.setInst(inst); + } + } } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //到达取货点2 + } else if (phase == 0x07) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialFullStationDeviceDriver) { + hailiangSpecialFullStationDeviceDriver = (HailiangSpecialFullStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialFullStationDeviceDriver.setAgvphase(phase); + hailiangSpecialFullStationDeviceDriver.setIndex(index); + hailiangSpecialFullStationDeviceDriver.setInst(inst); + } + } + + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //取货点2取货完毕 + } else if (phase == 0x09) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialFullStationDeviceDriver) { + hailiangSpecialFullStationDeviceDriver = (HailiangSpecialFullStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialFullStationDeviceDriver.setAgvphase(phase); + hailiangSpecialFullStationDeviceDriver.setIndex(index); + hailiangSpecialFullStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //自动缓存线--到达送满框1 + } else if (phase == 0x0A) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + + + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + + //到达倒料点1 + } else if (phase == 0x0B) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + + if (StrUtil.equals(inst.getPut_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialPourStationDeviceDriver) { + hailiangSpecialPourStationDeviceDriver = (HailiangSpecialPourStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialPourStationDeviceDriver.setAgvphase(phase); + hailiangSpecialPourStationDeviceDriver.setIndex(index); + hailiangSpecialPourStationDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangCleaningMachineStorageStationDeviceDriver) { + hailiangCleaningMachineStorageStationDeviceDriver = (HailiangCleaningMachineStorageStationDeviceDriver) device.getDeviceDriver(); + hailiangCleaningMachineStorageStationDeviceDriver.setAgvphase(phase); + hailiangCleaningMachineStorageStationDeviceDriver.setIndex(index); + hailiangCleaningMachineStorageStationDeviceDriver.setInst(inst); + } + } + + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //自动缓存线--送满框完毕1 + } else if (phase == 0x0C) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getPut_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialEmptyStationDeviceDriver) { + hailiangSpecialEmptyStationDeviceDriver = (HailiangSpecialEmptyStationDeviceDriver) device.getDeviceDriver(); + if (hailiangSpecialEmptyStationDeviceDriver.getMove() == 0 + && hailiangSpecialEmptyStationDeviceDriver.getError() == 0 && + hailiangSpecialEmptyStationDeviceDriver.getAllready() == 1) { + inst.setExecute_status("4"); + instructionService.update(inst); + data = ndcAgvService.sendAgvTwoModeInst(phase, index, 0); + } else { + log.info("AGV请求放货设备{}条件不满足,无法反馈", device_code); + } + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //倒料点1倒料完毕 + } else if (phase == 0x0D) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + + if (StrUtil.equals(inst.getPut_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialPourStationDeviceDriver) { + hailiangSpecialPourStationDeviceDriver = (HailiangSpecialPourStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialPourStationDeviceDriver.setAgvphase(phase); + hailiangSpecialPourStationDeviceDriver.setIndex(index); + hailiangSpecialPourStationDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangCleaningMachineStorageStationDeviceDriver) { + hailiangCleaningMachineStorageStationDeviceDriver = (HailiangCleaningMachineStorageStationDeviceDriver) device.getDeviceDriver(); + hailiangCleaningMachineStorageStationDeviceDriver.setAgvphase(phase); + hailiangCleaningMachineStorageStationDeviceDriver.setIndex(index); + hailiangCleaningMachineStorageStationDeviceDriver.setInst(inst); + } + + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //自动缓存线--到达取空框1 + } else if (phase == 0x0E) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //到达倒料点2 + } else if (phase == 0x0F) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + + if (StrUtil.equals(inst.getPut_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialPourStationDeviceDriver) { + hailiangSpecialPourStationDeviceDriver = (HailiangSpecialPourStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialPourStationDeviceDriver.setAgvphase(phase); + hailiangSpecialPourStationDeviceDriver.setIndex(index); + hailiangSpecialPourStationDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangCleaningMachineStorageStationDeviceDriver) { + hailiangCleaningMachineStorageStationDeviceDriver = (HailiangCleaningMachineStorageStationDeviceDriver) device.getDeviceDriver(); + hailiangCleaningMachineStorageStationDeviceDriver.setAgvphase(phase); + hailiangCleaningMachineStorageStationDeviceDriver.setIndex(index); + hailiangCleaningMachineStorageStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //倒料点2倒料完毕 + } else if (phase == 0x11) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getPut_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialPourStationDeviceDriver) { + hailiangSpecialPourStationDeviceDriver = (HailiangSpecialPourStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialPourStationDeviceDriver.setAgvphase(phase); + hailiangSpecialPourStationDeviceDriver.setIndex(index); + hailiangSpecialPourStationDeviceDriver.setInst(inst); + } + if (device.getDeviceDriver() instanceof HailiangCleaningMachineStorageStationDeviceDriver) { + hailiangCleaningMachineStorageStationDeviceDriver = (HailiangCleaningMachineStorageStationDeviceDriver) device.getDeviceDriver(); + hailiangCleaningMachineStorageStationDeviceDriver.setAgvphase(phase); + hailiangCleaningMachineStorageStationDeviceDriver.setIndex(index); + hailiangCleaningMachineStorageStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //到达送箱点1 + } else if (phase == 0x13) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialEmptyStationDeviceDriver) { + hailiangSpecialEmptyStationDeviceDriver = (HailiangSpecialEmptyStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialEmptyStationDeviceDriver.setAgvphase(phase); + hailiangSpecialEmptyStationDeviceDriver.setIndex(index); + hailiangSpecialEmptyStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //送箱点1送箱完毕 + } else if (phase == 0x15) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialEmptyStationDeviceDriver) { + hailiangSpecialEmptyStationDeviceDriver = (HailiangSpecialEmptyStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialEmptyStationDeviceDriver.setAgvphase(phase); + hailiangSpecialEmptyStationDeviceDriver.setIndex(index); + hailiangSpecialEmptyStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //到达送箱点2 + } else if (phase == 0x17) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialEmptyStationDeviceDriver) { + hailiangSpecialEmptyStationDeviceDriver = (HailiangSpecialEmptyStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialEmptyStationDeviceDriver.setAgvphase(phase); + hailiangSpecialEmptyStationDeviceDriver.setIndex(index); + hailiangSpecialEmptyStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //送箱完毕/送空框完毕2 + } else if (phase == 0x19) { + if (agvaddr == 0) { + agvaddr = agvaddr_copy; + } + if (agvaddr < 1) { + log.info("phase:" + phase + "--agv地址参数有误agvaddr=" + agvaddr); + return; + } + device_code = deviceService.queryDeviceCodeByAddress(agvaddr); + device = deviceAppService.findDeviceByCode(device_code); + + if (ObjectUtil.isEmpty(device_code)) { + log.info(agvaddr + "对应设备号为空!"); + return; + } + for (Instruction inst : insts) { + //校验agv上报站点编号与指令起始点相同 + if (ObjectUtil.isEmpty(inst)) { + log.info("未找到关联编号{}对应的指令", ikey); + break; + } + + if (StrUtil.equals(inst.getNext_device_code(), device_code)) { + if (device.getDeviceDriver() instanceof HailiangSpecialEmptyStationDeviceDriver) { + hailiangSpecialEmptyStationDeviceDriver = (HailiangSpecialEmptyStationDeviceDriver) device.getDeviceDriver(); + hailiangSpecialEmptyStationDeviceDriver.setAgvphase(phase); + hailiangSpecialEmptyStationDeviceDriver.setIndex(index); + hailiangSpecialEmptyStationDeviceDriver.setInst(inst); + } + } + } + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + //自动缓存线--到达送满框1 + } else if (phase == 0x0A) { + + //到达倒料点1 + } else if (phase == 0x0B) { + + ///自动缓存线--送满框完毕1 + } else if (phase == 0x0C) { + + //倒料完毕 + } else if (phase == 0x0D) { + + //自动缓存线--到达取空框1 + } else if (phase == 0x0E) { + + //到达倒料点2 + } else if (phase == 0x0F) { + + //自动缓存线--取空框完毕1 + } else if (phase == 0x10) { + + //自动缓存线--到达送满框2 + } else if (phase == 0x21) { + + //自动缓存线--送满框完毕2 + } else if (phase == 0x23) { + + //自动缓存线--到达取空框2 + } else if (phase == 0x25) { + + //自动缓存线--取空框完毕2 + } else if (phase == 0x27) { + + //请求删除任务 + } else if (phase == 0x30) { + + data = ndcAgvService.sendAgvTwoModeInst(143, index, 0); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + phase + "反馈:"+data); + + } else if (phase == 0x71){ + x = ikey; + if (x != last_x){ + logServer.deviceItemValue(this.device_code, "x", String.valueOf(x)); + } + } else if (phase == 0x72){ + y = ikey; + if (y != last_y){ + logServer.deviceItemValue(this.device_code, "y", String.valueOf(y)); + } + } else if (phase == 0x73){ + angle = last_angle; + if (angle != last_angle){ + logServer.deviceItemValue(this.device_code, "angle", String.valueOf(angle)); + } + } else if (phase == 0x74){ + electric_qty = ikey; + if (electric_qty != last_electric_qty){ + logServer.deviceItemValue(this.device_code, "electric_qty", String.valueOf(electric_qty)); + } + } else if (phase == 0x75){ + status = ikey; + if (status != last_status){ + logServer.deviceItemValue(this.device_code, "status", String.valueOf(status)); + } + } else if (phase == 0x76){ + error = ikey; + if (error != last_error){ + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + } } + if (!ObjectUtil.isEmpty(data)) { - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" +Bytes2HexString(data)); - if (StrUtil.equals(inst.getAgv_system_type(), "2")) { - TwoNDCSocketConnectionAutoRun.write(data); - } else if (StrUtil.equals(inst.getAgv_system_type(), "3")) { - TwoNDC2SocketConnectionAutoRun.write(data); - } + NDCSocketConnectionAutoRun.write(data); } } - - public static String Bytes2HexString(byte[] b) { - String ret = ""; - for (int i = 0; i < b.length; i++) { - String hex = Integer.toHexString(b[i] & 0xFF); - if (hex.length() == 1) { - hex = '0' + hex; - } - ret += hex.toUpperCase(); - } - return ret; - } - - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String phase = ""; - if (this.getMode() == 0) { - mode = "未联机"; - } else if (this.getMode() == 1) { - mode = "联机"; - } else if (this.getMode() == 2) { - mode = "联机"; - } - - if(this.getPhase() ==0 ){ - phase = "无任务"; - } else if (this.getPhase() == 1) { - phase = "1 0X01 开始任务"; - } else if (this.getPhase() == 2) { - phase = "2 0X02 分配车号"; - } else if (this.getPhase() == 3) { - phase = "3 0X03 到达取货点1"; - } else if (this.getPhase() == 5) { - phase = "5 0X05 取货点1请求离开"; - } else if (this.getPhase() == 8) { - phase = "8 0X08 到达取货点2"; - } else if (this.getPhase() == 10) { - phase = "10 0X0A 取货点2请求离开"; - } else if (this.getPhase() == 12) { - phase = "12 0X0C 到达放货点"; - } else if (this.getPhase() == 14) { - phase = "14 0X0E 放货完成"; - } else if (this.getPhase() == 16) { - phase = "16 0X10 到达放货点"; - } else if (this.getPhase() == 18) { - phase = "18 0X12 放货完成"; - } else if (this.getPhase() == 20) { - phase = "20 0X14 任务完毕"; - } else if (this.getPhase() == 100) { - phase = "100 0X64 上报称重"; - } - jo.put("phase", phase); - jo.put("isOnline", true); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("agv_power", this.getAgv_power()); - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("action", action); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/HailiangAutoCacheLineDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/HailiangAutoCacheLineDefination.java new file mode 100644 index 00000000..8b586fb6 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/HailiangAutoCacheLineDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_auto_cache_line; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮专自动缓存线 + */ +@Service +public class HailiangAutoCacheLineDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_auto_cache_line"; + } + + @Override + public String getDriverName() { + return "海亮-自动缓存线"; + } + + @Override + public String getDriverDescription() { + return "海亮-自动缓存线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangAutoCacheLineDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangAutoCacheLineDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/HailiangAutoCacheLineDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/HailiangAutoCacheLineDeviceDriver.java new file mode 100644 index 00000000..42bb224f --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/HailiangAutoCacheLineDeviceDriver.java @@ -0,0 +1,505 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_auto_cache_line; + +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮自动缓存线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangAutoCacheLineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + int mode = 0; + int error = 0; + int move = 0; + int task = 0; + + //开始条码匹配 + int matching_barcode = 0; + //准备位就绪 + int prepare_ready = 0; + //对接位入箱就绪 + int in_ready = 0; + //对接位入箱完成 + int in_finish = 0; + //对接位出箱就绪 + int out_ready = 0; + //任务完成 + int task_finish = 0; + //盘点中 + int checking = 0; + //盘点完成 + int check_finish =0; + //盘点强制完成 + int check_compel_finish =0; + //匹配条码失败 + int matching_barcode_fail =0; + //专机暂停 + int pause = 0; + //提升机条码目的层 + int hoist_target_layer =0; + //任务类型 + int task_type =0; + + int material_spec1,material_spec2,material_spec3,material_spec4,material_spec5,material_spec6,material_spec7, + material_spec8,material_spec9,material_spec10; + + //准备位条码 + int prepare_barcode =0; + //对接位条码 + int docking_barcode =0; + //提升机条码 + int hoist_barcode =0; + + int one_floor_barcode1,one_floor_barcode2,one_floor_barcode3,one_floor_barcode4,one_floor_barcode5,one_floor_barcode6, + one_floor_barcode7,one_floor_barcode8,one_floor_barcode9,one_floor_barcode10; + + int two_floor_barcode1,two_floor_barcode2,two_floor_barcode3,two_floor_barcode4,two_floor_barcode5,two_floor_barcode6, + two_floor_barcode7,two_floor_barcode8,two_floor_barcode9,two_floor_barcode10; + + int three_floor_barcode1,three_floor_barcode2,three_floor_barcode3,three_floor_barcode4,three_floor_barcode5, + three_floor_barcode6,three_floor_barcode7,three_floor_barcode8,three_floor_barcode9,three_floor_barcode10; + + + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task_finish = 0; + int last_task = 0; + //开始条码匹配 + int last_matching_barcode = 0; + //准备位就绪 + int last_prepare_ready = 0; + //对接位入箱就绪 + int last_in_ready = 0; + //对接位入箱完成 + int last_in_finish = 0; + //对接位出箱就绪 + int last_out_ready = 0; + //盘点中 + int last_checking = 0; + //盘点完成 + int last_check_finish =0; + //盘点强制完成 + int last_check_compel_finish =0; + //匹配条码失败 + int last_matching_barcode_fail =0; + //专机暂停 + int last_pause = 0; + //提升机条码目的层 + int last_hoist_target_layer =0; + //任务类型 + int last_task_type =0; + + + int hasGoods = 0; + Boolean isonline = false; + Boolean iserror = false; + Boolean task_finish_flag = false; + String material_spec = null; + String last_material_spec = null; + + boolean requireSucess = false; + + int one_barcode1,one_barcode2,one_barcode3,one_barcode4,one_barcode5,one_barcode6,one_barcode7,one_barcode8, + one_barcode9,one_barcode10; + int two_barcode1,two_barcode2,two_barcode3,two_barcode4,two_barcode5,two_barcode6,two_barcode7,two_barcode8, + two_barcode9,two_barcode10; + int three_barcode1,three_barcode2,three_barcode3,three_barcode4,three_barcode5,three_barcode6,three_barcode7, + three_barcode8,three_barcode9,three_barcode10; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + //agv 执行动作 + int agv_phase =0 ; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute(){ + String message = null; + try { + device_code = this.getDeviceCode(); + error = this.itemProtocol.getError(); + mode = this.itemProtocol.getMode(); + hasGoods = this.itemProtocol.getItem_move(); + task = this.itemProtocol.getTask(); + matching_barcode = this.itemProtocol.getItem_matching_barcode(); + prepare_ready = this.itemProtocol.getItem_prepare_ready(); + in_ready = this.itemProtocol.getItem_in_ready(); + in_finish = this.itemProtocol.getItem_in_finish(); + out_ready = this.itemProtocol.getItem_out_ready(); + task_finish = this.itemProtocol.getItem_task_finish(); + checking = this.itemProtocol.getItem_checking(); + check_finish = this.itemProtocol.getItem_check_finish(); + check_compel_finish = this.itemProtocol.getItem_check_compel_finish(); + matching_barcode_fail = this.itemProtocol.getItem_matching_barcode_fail(); + pause = this.itemProtocol.getItem_pause(); + hoist_target_layer = this.itemProtocol.getItem_hoist_target_layer(); + task_type = this.itemProtocol.getItem_task_type(); + material_spec1 = this.itemProtocol.getItem_material_spec1(); + material_spec2 = this.itemProtocol.getItem_material_spec2(); + material_spec3 = this.itemProtocol.getItem_material_spec3(); + material_spec4 = this.itemProtocol.getItem_material_spec4(); + material_spec5 = this.itemProtocol.getItem_material_spec5(); + material_spec6 = this.itemProtocol.getItem_material_spec6(); + material_spec7 = this.itemProtocol.getItem_material_spec7(); + material_spec8 = this.itemProtocol.getItem_material_spec8(); + material_spec9 = this.itemProtocol.getItem_material_spec9(); + material_spec10 = this.itemProtocol.getItem_material_spec10(); + prepare_barcode = this.itemProtocol.getItem_prepare_barcode(); + docking_barcode = this.itemProtocol.getItem_docking_barcode(); + hoist_barcode = this.itemProtocol.getItem_hoist_barcode(); + one_floor_barcode1 = this.itemProtocol.getItem_one_floor_barcode1(); + one_floor_barcode2 = this.itemProtocol.getItem_one_floor_barcode2(); + one_floor_barcode3 = this.itemProtocol.getItem_one_floor_barcode3(); + one_floor_barcode4 = this.itemProtocol.getItem_one_floor_barcode4(); + one_floor_barcode5 = this.itemProtocol.getItem_one_floor_barcode5(); + one_floor_barcode6 = this.itemProtocol.getItem_one_floor_barcode6(); + one_floor_barcode7 = this.itemProtocol.getItem_one_floor_barcode7(); + one_floor_barcode8 = this.itemProtocol.getItem_one_floor_barcode8(); + one_floor_barcode9 = this.itemProtocol.getItem_one_floor_barcode9(); + one_floor_barcode10 = this.itemProtocol.getItem_one_floor_barcode10(); + two_floor_barcode1 = this.itemProtocol.getItem_two_floor_barcode1(); + two_floor_barcode2 = this.itemProtocol.getItem_two_floor_barcode2(); + two_floor_barcode3 = this.itemProtocol.getItem_two_floor_barcode3(); + two_floor_barcode4 = this.itemProtocol.getItem_two_floor_barcode4(); + two_floor_barcode5 = this.itemProtocol.getItem_two_floor_barcode5(); + two_floor_barcode6 = this.itemProtocol.getItem_two_floor_barcode6(); + two_floor_barcode7 = this.itemProtocol.getItem_two_floor_barcode7(); + two_floor_barcode8 = this.itemProtocol.getItem_two_floor_barcode8(); + two_floor_barcode9 = this.itemProtocol.getItem_two_floor_barcode9(); + two_floor_barcode10 = this.itemProtocol.getItem_two_floor_barcode10(); + three_floor_barcode1 = this.itemProtocol.getItem_three_floor_barcode1(); + three_floor_barcode2 = this.itemProtocol.getItem_three_floor_barcode2(); + three_floor_barcode3 = this.itemProtocol.getItem_three_floor_barcode3(); + three_floor_barcode4 = this.itemProtocol.getItem_three_floor_barcode4(); + three_floor_barcode5 = this.itemProtocol.getItem_three_floor_barcode5(); + three_floor_barcode6 = this.itemProtocol.getItem_three_floor_barcode6(); + three_floor_barcode7 = this.itemProtocol.getItem_three_floor_barcode7(); + three_floor_barcode8 = this.itemProtocol.getItem_three_floor_barcode8(); + three_floor_barcode9 = this.itemProtocol.getItem_three_floor_barcode9(); + three_floor_barcode10 = this.itemProtocol.getItem_three_floor_barcode10(); + + material_spec = stringToascii(material_spec1)+stringToascii(material_spec2)+stringToascii(material_spec3) + +stringToascii(material_spec4)+stringToascii(material_spec5)+stringToascii(material_spec6)+ + stringToascii(material_spec7)+stringToascii(material_spec8)+stringToascii(material_spec9)+ + stringToascii(material_spec10); + + if(StrUtil.equals(material_spec,last_material_spec)){ + logServer.deviceItemValue(this.device_code,"material_spec" ,String.valueOf(material_spec)); + logServer.deviceExecuteLog(this.device_code,"","","信号material_spec:" + last_material_spec + "->" + material_spec); + } + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if(task_finish != last_task_finish){ + if(task_finish == 1){ + writing("item_to_task_finish","1"); + } + logServer.deviceItemValue(this.device_code,"task_finish" ,String.valueOf(task_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号task_finish:" + last_task_finish + "->" + task_finish); + } + + + if (task != last_task) { + logServer.deviceItemValue(this.device_code,"task" ,String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code,"","","信号task:" + last_task + "->" + task); + } + if (matching_barcode != last_matching_barcode) { + logServer.deviceItemValue(this.device_code,"matching_barcode" ,String.valueOf(matching_barcode)); + logServer.deviceExecuteLog(this.device_code,"","","信号matching_barcode:" + last_matching_barcode + "->" + matching_barcode); + } + if (prepare_ready != last_prepare_ready) { + logServer.deviceItemValue(this.device_code,"prepare_ready" ,String.valueOf(prepare_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号prepare_ready:" + last_prepare_ready + "->" + prepare_ready); + } + if (in_ready != last_in_ready) { + logServer.deviceItemValue(this.device_code,"in_ready" ,String.valueOf(in_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号in_ready:" + last_in_ready + "->" + in_ready); + } + if (in_finish != last_in_finish) { + logServer.deviceItemValue(this.device_code,"in_finish" ,String.valueOf(in_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号in_finish:" + last_in_finish + "->" + in_finish); + } + if (out_ready != last_out_ready) { + logServer.deviceItemValue(this.device_code,"out_ready" ,String.valueOf(out_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号out_ready:" + last_out_ready + "->" + out_ready); + } + if (checking != last_checking) { + logServer.deviceItemValue(this.device_code,"checking" ,String.valueOf(checking)); + logServer.deviceExecuteLog(this.device_code,"","","信号checking:" + last_checking + "->" + checking); + } + if (check_finish != last_check_finish) { + logServer.deviceItemValue(this.device_code,"check_finish" ,String.valueOf(check_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号check_finish:" + last_check_finish + "->" + check_finish); + } + if (check_compel_finish != last_check_compel_finish) { + logServer.deviceItemValue(this.device_code,"check_compel_finish" ,String.valueOf(check_compel_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号check_compel_finish:" + last_check_compel_finish + "->" + check_compel_finish); + } + if (matching_barcode_fail != last_matching_barcode_fail) { + logServer.deviceItemValue(this.device_code,"matching_barcode_fail" ,String.valueOf(matching_barcode_fail)); + logServer.deviceExecuteLog(this.device_code,"","","信号matching_barcode_fail:" + last_matching_barcode_fail + "->" + matching_barcode_fail); + } + if (pause != last_pause) { + logServer.deviceItemValue(this.device_code,"pause" ,String.valueOf(pause)); + logServer.deviceExecuteLog(this.device_code,"","","信号pause:" + last_pause + "->" + pause); + } + if (hoist_target_layer != last_hoist_target_layer) { + logServer.deviceItemValue(this.device_code,"hoist_target_layer" ,String.valueOf(hoist_target_layer)); + logServer.deviceExecuteLog(this.device_code,"","","信号hoist_target_layer:" + last_hoist_target_layer + "->" + hoist_target_layer); + } + if (task_type != last_task_type) { + logServer.deviceItemValue(this.device_code,"task_type" ,String.valueOf(task_type)); + logServer.deviceExecuteLog(this.device_code,"","","信号task_type:" + last_task_type + "->" + task_type); + } + + + + if( prepare_ready == 1 && move ==0 && in_ready ==0 && in_finish ==0 && ( agv_phase==0x0A || agv_phase==0x21) ){ + +// if(this.准备位条码==this.条码异常值) +// { +// debug(d.getID()+" 准备位条码异常"); +// return; +// } + writing("item_to_agv_put_ready","1"); + + } + + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + } + + + + + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_task_finish = task_finish; + last_material_spec = material_spec; + last_matching_barcode = matching_barcode; + last_prepare_ready = prepare_ready; + last_in_ready = in_ready; + last_in_finish = in_finish; + last_out_ready = out_ready; + last_checking = checking; + last_check_finish =check_finish; + last_check_compel_finish =check_compel_finish; + last_matching_barcode_fail =matching_barcode_fail; + last_pause = pause; + last_hoist_target_layer =hoist_target_layer; + last_task_type =task_type; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + } + + public void writing(int command) {} + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + + } + + + public String stringToascii(int num) + { + String str=""; + switch (num) + { + case 48: str="0";break; + case 49: str="1";break; + case 50: str="2";break; + case 51: str="3";break; + case 52: str="4";break; + case 53: str="5";break; + case 54: str="6";break; + case 55: str="7";break; + case 56: str="8";break; + case 57: str="9";break; + case 65: str="A";break; + case 66: str="B";break; + case 67: str="C";break; + case 68: str="D";break; + case 69: str="E";break; + case 70: str="F";break; + case 71: str="G";break; + case 72: str="H";break; + case 73: str="I";break; + case 74: str="J";break; + case 75: str="K";break; + case 76: str="L";break; + case 77: str="M";break; + case 78: str="N";break; + case 79: str="O";break; + case 80: str="P";break; + case 81: str="Q";break; + case 82: str="R";break; + case 83: str="S";break; + case 84: str="T";break; + case 85: str="U";break; + case 86: str="V";break; + case 87: str="W";break; + case 88: str="X";break; + case 89: str="Y";break; + case 90: str="Z";break; + case 97: str="a";break; + case 98: str="b";break; + case 99: str="c";break; + case 100: str="d";break; + case 101: str="e";break; + case 102: str="f";break; + case 103: str="g";break; + case 104: str="h";break; + case 105: str="i";break; + case 106: str="j";break; + case 107: str="k";break; + case 108: str="l";break; + case 109: str="m";break; + case 110: str="n";break; + case 111: str="o";break; + case 112: str="p";break; + case 113: str="q";break; + case 114: str="r";break; + case 115: str="s";break; + case 116: str="t";break; + case 117: str="u";break; + case 118: str="v";break; + case 119: str="w";break; + case 120: str="x";break; + case 121: str="y";break; + case 122: str="z";break; + + case 40: str="(";break; + case 41: str=")";break; + case 43: str="+";break; + case 45: str="-";break; + case 47: str="/";break; + case 91: str="[";break; + case 93: str="]";break; + case 95: str="_";break; + default: str="*"; + } + return str; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/ItemProtocol.java new file mode 100644 index 00000000..054fd5cb --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_auto_cache_line/ItemProtocol.java @@ -0,0 +1,682 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_auto_cache_line; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_error = "error"; + //开始条码匹配 + public static String item_matching_barcode = "matching_barcode"; + //对接位有货 + public static String item_move = "move"; + //准备位就绪 + public static String item_prepare_ready = "prepare_ready"; + //对接位入箱就绪 + public static String item_in_ready = "in_ready"; + //对接位入箱完成 + public static String item_in_finish = "in_finish"; + //对接位出箱就绪 + public static String item_out_ready = "out_ready"; + //任务完成 + public static String item_task_finish = "task_finish"; + //盘点中 + public static String item_checking = "checking"; + //盘点完成 + public static String item_check_finish = "check_finish"; + //盘点强制完成 + public static String item_check_compel_finish = "check_compel_finish"; + //匹配条码失败 + public static String item_matching_barcode_fail = "matching_barcode_fail"; + //专机暂停 + public static String item_pause = "pause"; + //提升机条码目的层 + public static String item_hoist_target_layer = "hoist_target_layer"; + //任务类型 + public static String item_task_type = "task_type"; + //物料规格 + public static String item_material_spec1= "material_spec1"; + + public static String item_material_spec2= "material_spec2"; + + public static String item_material_spec3= "material_spec3"; + + public static String item_material_spec4= "material_spec4"; + + public static String item_material_spec5= "material_spec5"; + + public static String item_material_spec6= "material_spec6"; + + public static String item_material_spec7= "material_spec7"; + + public static String item_material_spec8= "material_spec8"; + + public static String item_material_spec9= "material_spec9"; + + public static String item_material_spec10= "material_spec10"; + //准备位条码 + public static String item_prepare_barcode = "prepare_barcode"; + //对接位条码 + public static String item_docking_barcode = "docking_barcode"; + //任务号 + public static String item_task = "task"; + //提升机条码 + public static String item_hoist_barcode = "hoist_barcode"; + + + //一层条码 + public static String item_one_floor_barcode1 = "one_floor_barcode1"; + + public static String item_one_floor_barcode2 = "one_floor_barcode2"; + + public static String item_one_floor_barcode3 = "one_floor_barcode3"; + + public static String item_one_floor_barcode4 = "one_floor_barcode4"; + + public static String item_one_floor_barcode5 = "one_floor_barcode5"; + + public static String item_one_floor_barcode6 = "one_floor_barcode6"; + + public static String item_one_floor_barcode7 = "one_floor_barcode7"; + + public static String item_one_floor_barcode8 = "one_floor_barcode8"; + + public static String item_one_floor_barcode9 = "one_floor_barcode9"; + + public static String item_one_floor_barcode10 = "one_floor_barcode10"; + //二层条码 + public static String item_two_floor_barcode1 = "two_floor_barcode1"; + + public static String item_two_floor_barcode2 = "two_floor_barcode2"; + + public static String item_two_floor_barcode3 = "two_floor_barcode3"; + + public static String item_two_floor_barcode4 = "two_floor_barcode4"; + + public static String item_two_floor_barcode5 = "two_floor_barcode5"; + + public static String item_two_floor_barcode6 = "two_floor_barcode6"; + + public static String item_two_floor_barcode7 = "two_floor_barcode7"; + + public static String item_two_floor_barcode8 = "two_floor_barcode8"; + + public static String item_two_floor_barcode9 = "two_floor_barcode9"; + + public static String item_two_floor_barcode10 = "two_floor_barcode10"; + //三层条码 + public static String item_three_floor_barcode1 = "three_floor_barcode1"; + + public static String item_three_floor_barcode2 = "three_floor_barcode2"; + + public static String item_three_floor_barcode3 = "three_floor_barcode3"; + + public static String item_three_floor_barcode4 = "three_floor_barcode4"; + + public static String item_three_floor_barcode5 = "three_floor_barcode5"; + + public static String item_three_floor_barcode6 = "three_floor_barcode6"; + + public static String item_three_floor_barcode7 = "three_floor_barcode7"; + + public static String item_three_floor_barcode8 = "three_floor_barcode8"; + + public static String item_three_floor_barcode9 = "three_floor_barcode9"; + + public static String item_three_floor_barcode10 = "three_floor_barcode10"; + + //设备开关 + public static String item_to_open = "to_open"; + //开始匹配条码 + public static String item_to_open_check_barcode = "to_open_check_barcode"; + //任务类型 + public static String item_to_task_type = "to_task_type"; + //放货就绪 + public static String item_to_agv_put_ready = "to_agv_put_ready"; + //放货完成 + public static String item_to_agv_put_finish = "to_agv_put_finish"; + //准备位到对接位 + public static String item_to_prepare_docking = "to_prepare_docking"; + //取货就绪 + public static String item_to_agv_get_ready = "to_agv_get_ready"; + //放货完成 + public static String item_to_agv_get_finish = "to_agv_get_finish"; + //任务完成 + public static String item_to_task_finish = "to_task_finish"; + //专机暂停 + public static String item_to_pause = "to_pause"; + //优先层 + public static String item_to_priority_layer = "to_priority_layer"; + //开始盘点 + public static String item_to_start_checking = "to_start_checking"; + //盘点完成清零 + public static String item_to_check_finish = "to_check_finish"; + //暂停出箱匹配 + public static String item_to_pause_out_check = "to_pause_out_check"; + + //物料规格 + public static String item_to_material_spec1= "to_material_spec1"; + + public static String item_to_material_spec2= "to_material_spec2"; + + public static String item_to_material_spec3= "to_material_spec3"; + + public static String item_to_material_spec4= "to_material_spec4"; + + public static String item_to_material_spec5= "to_material_spec5"; + + public static String item_to_material_spec6= "to_material_spec6"; + + public static String item_to_material_spec7= "to_material_spec7"; + + public static String item_to_material_spec8= "to_material_spec8"; + + public static String item_to_material_spec9= "to_material_spec9"; + + public static String item_to_material_spec10= "to_material_spec10"; + + public static String item_to_material_spec11= "to_material_spec11"; + + public static String item_to_material_spec12= "to_material_spec12"; + + public static String item_to_material_spec13= "to_material_spec13"; + + public static String item_to_material_spec14= "to_material_spec14"; + + public static String item_to_material_spec15= "to_material_spec15"; + + public static String item_to_material_spec16= "to_material_spec16"; + + public static String item_to_material_spec17= "to_material_spec17"; + + public static String item_to_material_spec18= "to_material_spec18"; + + public static String item_to_material_spec19= "to_material_spec19"; + + public static String item_to_material_spec20= "to_material_spec20"; + + //准备位条码准备 + public static String item_to_prepare_barcode_write = "to_prepare_barcode_write"; + //对接位条码准备 + public static String item_to_docking_barcode_write = "to_docking_barcode_write"; + //任务号 + public static String item_to_task = "to_task"; + //条码 + public static String item_to_barcode1 = "to_barcode1"; + + public static String item_to_barcode2 = "to_barcode2"; + + public static String item_to_barcode3 = "to_barcode3"; + + public static String item_to_barcode4 = "to_barcode4"; + + public static String item_to_barcode5 = "to_barcode5"; + + public static String item_to_barcode6 = "to_barcode6"; + + public static String item_to_barcode7 = "to_barcode7"; + + public static String item_to_barcode8 = "to_barcode8"; + + public static String item_to_barcode9 = "to_barcode9"; + + public static String item_to_barcode10 = "to_barcode10"; + + public static String item_to_barcode11 = "to_barcode11"; + + public static String item_to_barcode12 = "to_barcode12"; + + public static String item_to_barcode13 = "to_barcode13"; + + public static String item_to_barcode14 = "to_barcode14"; + + public static String item_to_barcode15 = "to_barcode15"; + + public static String item_to_barcode16 = "to_barcode16"; + + public static String item_to_barcode17 = "to_barcode17"; + + public static String item_to_barcode18 = "to_barcode18"; + + public static String item_to_barcode19 = "to_barcode19"; + + public static String item_to_barcode20 = "to_barcode20"; + + public static String item_to_barcode21 = "to_barcode21"; + + public static String item_to_barcode22 = "to_barcode22"; + + public static String item_to_barcode23 = "to_barcode23"; + + public static String item_to_barcode24 = "to_barcode24"; + + public static String item_to_barcode25 = "to_barcode25"; + + public static String item_to_barcode26 = "to_barcode26"; + + public static String item_to_barcode27 = "to_barcode27"; + + public static String item_to_barcode28 = "to_barcode28"; + + public static String item_to_barcode29 = "to_barcode29"; + + public static String item_to_barcode30 = "to_barcode30"; + + + + private HailiangAutoCacheLineDeviceDriver driver; + + public ItemProtocol(HailiangAutoCacheLineDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getItem_matching_barcode() { + return this.getOpcIntegerValue(item_matching_barcode); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_prepare_ready() { + return this.getOpcIntegerValue(item_prepare_ready); + } + + public int getItem_in_ready() { + return this.getOpcIntegerValue(item_in_ready); + } + + public int getItem_in_finish() { + return this.getOpcIntegerValue(item_in_finish); + } + + public int getItem_out_ready() { + return this.getOpcIntegerValue(item_out_ready); + } + + public int getItem_task_finish() { + return this.getOpcIntegerValue(item_task_finish); + } + + public int getItem_checking() { + return this.getOpcIntegerValue(item_checking); + } + + public int getItem_check_finish() { + return this.getOpcIntegerValue(item_check_finish); + } + + public int getItem_check_compel_finish() { + return this.getOpcIntegerValue(item_check_compel_finish); + } + + public int getItem_matching_barcode_fail() { + return this.getOpcIntegerValue(item_matching_barcode_fail); + } + + public int getItem_pause() { + return this.getOpcIntegerValue(item_pause); + } + + public int getItem_hoist_target_layer() { + return this.getOpcIntegerValue(item_hoist_target_layer); + } + + public int getItem_task_type() { + return this.getOpcIntegerValue(item_task_type); + } + + public int getItem_material_spec1() { + return this.getOpcIntegerValue(item_material_spec1); + } + + public int getItem_material_spec2() { + return this.getOpcIntegerValue(item_material_spec2); + } + + public int getItem_material_spec3() { + return this.getOpcIntegerValue(item_material_spec3); + } + + public int getItem_material_spec4() { + return this.getOpcIntegerValue(item_material_spec4); + } + + public int getItem_material_spec5() { + return this.getOpcIntegerValue(item_material_spec5); + } + + public int getItem_material_spec6() { + return this.getOpcIntegerValue(item_material_spec6); + } + + public int getItem_material_spec7() { + return this.getOpcIntegerValue(item_material_spec7); + } + + public int getItem_material_spec8() { + return this.getOpcIntegerValue(item_material_spec8); + } + + public int getItem_material_spec9() { + return this.getOpcIntegerValue(item_material_spec9); + } + + public int getItem_material_spec10() { + return this.getOpcIntegerValue(item_material_spec10); + } + + public int getItem_prepare_barcode() { + return this.getOpcIntegerValue(item_prepare_barcode); + } + + public int getItem_docking_barcode() { + return this.getOpcIntegerValue(item_docking_barcode); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + public int getItem_hoist_barcode() { + return this.getOpcIntegerValue(item_hoist_barcode); + } + + public int getItem_one_floor_barcode1() { + return this.getOpcIntegerValue(item_one_floor_barcode1); + } + + public int getItem_one_floor_barcode2() { + return this.getOpcIntegerValue(item_one_floor_barcode2); + } + + public int getItem_one_floor_barcode3() { + return this.getOpcIntegerValue(item_one_floor_barcode3); + } + + public int getItem_one_floor_barcode4() { + return this.getOpcIntegerValue(item_one_floor_barcode4); + } + + public int getItem_one_floor_barcode5() { + return this.getOpcIntegerValue(item_one_floor_barcode5); + } + + public int getItem_one_floor_barcode6() { + return this.getOpcIntegerValue(item_one_floor_barcode6); + } + + public int getItem_one_floor_barcode7() { + return this.getOpcIntegerValue(item_one_floor_barcode7); + } + + public int getItem_one_floor_barcode8() { + return this.getOpcIntegerValue(item_one_floor_barcode8); + } + + public int getItem_one_floor_barcode9() { + return this.getOpcIntegerValue(item_one_floor_barcode9); + } + + public int getItem_one_floor_barcode10() { + return this.getOpcIntegerValue(item_one_floor_barcode10); + } + + public int getItem_two_floor_barcode1() { + return this.getOpcIntegerValue(item_two_floor_barcode1); + } + + public int getItem_two_floor_barcode2() { + return this.getOpcIntegerValue(item_two_floor_barcode2); + } + + public int getItem_two_floor_barcode3() { + return this.getOpcIntegerValue(item_two_floor_barcode3); + } + + public int getItem_two_floor_barcode4() { + return this.getOpcIntegerValue(item_two_floor_barcode4); + } + + public int getItem_two_floor_barcode5() { + return this.getOpcIntegerValue(item_two_floor_barcode5); + } + + public int getItem_two_floor_barcode6() { + return this.getOpcIntegerValue(item_two_floor_barcode6); + } + + public int getItem_two_floor_barcode7() { + return this.getOpcIntegerValue(item_two_floor_barcode7); + } + + public int getItem_two_floor_barcode8() { + return this.getOpcIntegerValue(item_two_floor_barcode8); + } + + public int getItem_two_floor_barcode9() { + return this.getOpcIntegerValue(item_two_floor_barcode9); + } + + public int getItem_two_floor_barcode10() { + return this.getOpcIntegerValue(item_two_floor_barcode10); + } + + public int getItem_three_floor_barcode1() { + return this.getOpcIntegerValue(item_three_floor_barcode1); + } + + public int getItem_three_floor_barcode2() { + return this.getOpcIntegerValue(item_three_floor_barcode2); + } + + public int getItem_three_floor_barcode3() { + return this.getOpcIntegerValue(item_three_floor_barcode3); + } + + public int getItem_three_floor_barcode4() { + return this.getOpcIntegerValue(item_three_floor_barcode4); + } + + public int getItem_three_floor_barcode5() { + return this.getOpcIntegerValue(item_three_floor_barcode5); + } + + public int getItem_three_floor_barcode6() { + return this.getOpcIntegerValue(item_three_floor_barcode6); + } + + public int getItem_three_floor_barcode7() { + return this.getOpcIntegerValue(item_three_floor_barcode7); + } + + public int getItem_three_floor_barcode8() { + return this.getOpcIntegerValue(item_three_floor_barcode8); + } + + public int getItem_three_floor_barcode9() { + return this.getOpcIntegerValue(item_three_floor_barcode9); + } + + public int getItem_three_floor_barcode10() { + return this.getOpcIntegerValue(item_three_floor_barcode10); + } + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_mode, "手自动状态", "DB1.B0.0", Boolean.valueOf(true))); + list.add(new ItemDto(item_matching_barcode, "开始条码匹配", "DB1.B1.0")); + list.add(new ItemDto(item_move, "对接位有货", "DB1.B1.2")); + list.add(new ItemDto(item_prepare_ready, "准备位就绪", "DB1.B1.3")); + list.add(new ItemDto(item_in_ready, "对接位入箱就绪", "DB1.B1.4")); + list.add(new ItemDto(item_in_finish, "对接位入箱完成", "DB1.B1.5")); + list.add(new ItemDto(item_out_ready, "对接位出箱就绪", "DB1.B1.6")); + list.add(new ItemDto(item_task_finish, "任务完成", "DB1.B2.0")); + list.add(new ItemDto(item_checking, "盘点中", "DB1.B2.1")); + list.add(new ItemDto(item_check_finish, "盘点完成", "DB1.B2.2")); + list.add(new ItemDto(item_check_compel_finish, "盘点强制完成", "DB1.B2.3")); + list.add(new ItemDto(item_matching_barcode_fail, "匹配条码失败", "DB1.B2.4")); + list.add(new ItemDto(item_pause, "暂停", "DB1.B2.5")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_hoist_target_layer, "提升机条码目的层", "DB1.W6")); + list.add(new ItemDto(item_task_type, "任务类型", "DB1.W8")); + list.add(new ItemDto(item_material_spec1, "物料规格1", "DB1.W10")); + list.add(new ItemDto(item_material_spec2, "物料规格2", "DB1.W12")); + list.add(new ItemDto(item_material_spec3, "物料规格3", "DB1.W14")); + list.add(new ItemDto(item_material_spec4, "物料规格4", "DB1.W16")); + list.add(new ItemDto(item_material_spec5, "物料规格5", "DB1.W18")); + list.add(new ItemDto(item_material_spec6, "物料规格6", "DB1.W20")); + list.add(new ItemDto(item_material_spec7, "物料规格7", "DB1.W22")); + list.add(new ItemDto(item_material_spec8, "物料规格8", "DB1.W24")); + list.add(new ItemDto(item_material_spec9, "物料规格9", "DB1.W26")); + list.add(new ItemDto(item_material_spec10, "物料规格10", "DB1.W28")); + list.add(new ItemDto(item_prepare_barcode, "准备位条码", "DB1.D84")); + list.add(new ItemDto(item_docking_barcode, "对接位条码", "DB1.D88")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_hoist_barcode, "提升机条码", "DB1.D96")); + list.add(new ItemDto(item_one_floor_barcode1, "一层条码1", "DB1.D124")); + list.add(new ItemDto(item_one_floor_barcode2, "一层条码2", "DB1.D128")); + list.add(new ItemDto(item_one_floor_barcode3, "一层条码3", "DB1.D132")); + list.add(new ItemDto(item_one_floor_barcode4, "一层条码4", "DB1.D136")); + list.add(new ItemDto(item_one_floor_barcode5, "一层条码5", "DB1.D140")); + list.add(new ItemDto(item_one_floor_barcode6, "一层条码6", "DB1.D144")); + list.add(new ItemDto(item_one_floor_barcode7, "一层条码7", "DB1.D148")); + list.add(new ItemDto(item_one_floor_barcode8, "一层条码8", "DB1.D152")); + list.add(new ItemDto(item_one_floor_barcode9, "一层条码9", "DB1.D156")); + list.add(new ItemDto(item_one_floor_barcode10, "一层条码10", "DB1.D160")); + list.add(new ItemDto(item_two_floor_barcode1, "二层条码1", "DB1.D164")); + list.add(new ItemDto(item_two_floor_barcode2, "二层条码2", "DB1.D168")); + list.add(new ItemDto(item_two_floor_barcode3, "二层条码3", "DB1.D172")); + list.add(new ItemDto(item_two_floor_barcode4, "二层条码4", "DB1.D176")); + list.add(new ItemDto(item_two_floor_barcode5, "二层条码5", "DB1.D180")); + list.add(new ItemDto(item_two_floor_barcode6, "二层条码6", "DB1.D184")); + list.add(new ItemDto(item_two_floor_barcode7, "二层条码7", "DB1.D188")); + list.add(new ItemDto(item_two_floor_barcode8, "二层条码8", "DB1.D192")); + list.add(new ItemDto(item_two_floor_barcode9, "二层条码9", "DB1.D196")); + list.add(new ItemDto(item_two_floor_barcode10, "二层条码10", "DB1.D200")); + list.add(new ItemDto(item_three_floor_barcode1, "三层条码1", "DB1.D204")); + list.add(new ItemDto(item_three_floor_barcode2, "三层条码2", "DB1.D208")); + list.add(new ItemDto(item_three_floor_barcode3, "三层条码3", "DB1.D212")); + list.add(new ItemDto(item_three_floor_barcode4, "三层条码4", "DB1.D216")); + list.add(new ItemDto(item_three_floor_barcode5, "三层条码5", "DB1.D220")); + list.add(new ItemDto(item_three_floor_barcode6, "三层条码6", "DB1.D224")); + list.add(new ItemDto(item_three_floor_barcode7, "三层条码7", "DB1.D228")); + list.add(new ItemDto(item_three_floor_barcode8, "三层条码8", "DB1.D232")); + list.add(new ItemDto(item_three_floor_barcode9, "三层条码9", "DB1.D236")); + list.add(new ItemDto(item_three_floor_barcode10, "三层条码10", "DB1.D240")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB1.W4")); + list.add(new ItemDto(item_to_open_check_barcode, "开始匹配条码", "DB1.W6")); + list.add(new ItemDto(item_to_task_type, "任务类型", "DB1.W8")); + list.add(new ItemDto(item_to_agv_put_ready, "放货就绪", "DB1.W10")); + list.add(new ItemDto(item_to_agv_put_finish, "放货完成", "DB1.W12")); + list.add(new ItemDto(item_to_prepare_docking, "准备位到对接位", "DB1.W14")); + list.add(new ItemDto(item_to_agv_get_ready, "取货就绪", "DB1.W16")); + list.add(new ItemDto(item_to_agv_get_finish, "取货完成", "DB1.W18")); + list.add(new ItemDto(item_to_task_finish, "任务完成", "DB1.W20")); + list.add(new ItemDto(item_to_pause, "专机暂停", "DB1.W22")); + list.add(new ItemDto(item_to_priority_layer, "优先层", "DB1.W24")); + list.add(new ItemDto(item_to_start_checking, "开始盘点", "DB1.W28")); + list.add(new ItemDto(item_to_check_finish, "盘点完成清零", "DB1.W30")); + list.add(new ItemDto(item_to_pause_out_check, "暂停出箱匹配", "DB1.W34")); + list.add(new ItemDto(item_to_material_spec1, "物料规格1", "DB1.W40")); + list.add(new ItemDto(item_to_material_spec2, "物料规格2", "DB1.W42")); + list.add(new ItemDto(item_to_material_spec3, "物料规格3", "DB1.W44")); + list.add(new ItemDto(item_to_material_spec4, "物料规格4", "DB1.W46")); + list.add(new ItemDto(item_to_material_spec5, "物料规格5", "DB1.W48")); + list.add(new ItemDto(item_to_material_spec6, "物料规格6", "DB1.W50")); + list.add(new ItemDto(item_to_material_spec7, "物料规格7", "DB1.W52")); + list.add(new ItemDto(item_to_material_spec8, "物料规格8", "DB1.W54")); + list.add(new ItemDto(item_to_material_spec9, "物料规格9", "DB1.W56")); + list.add(new ItemDto(item_to_material_spec10, "物料规格10", "DB1.W58")); + list.add(new ItemDto(item_to_material_spec11, "物料规格11", "DB1.W60")); + list.add(new ItemDto(item_to_material_spec12, "物料规格12", "DB1.W62")); + list.add(new ItemDto(item_to_material_spec13, "物料规格13", "DB1.W64")); + list.add(new ItemDto(item_to_material_spec14, "物料规格14", "DB1.W66")); + list.add(new ItemDto(item_to_material_spec15, "物料规格15", "DB1.W68")); + list.add(new ItemDto(item_to_material_spec16, "物料规格16", "DB1.W70")); + list.add(new ItemDto(item_to_material_spec17, "物料规格17", "DB1.W72")); + list.add(new ItemDto(item_to_material_spec18, "物料规格18", "DB1.W74")); + list.add(new ItemDto(item_to_material_spec19, "物料规格19", "DB1.W76")); + list.add(new ItemDto(item_to_material_spec20, "物料规格20", "DB1.W78")); + list.add(new ItemDto(item_to_prepare_barcode_write, "准备位条码准备", "DB1.D84")); + list.add(new ItemDto(item_to_docking_barcode_write, "对接位条码准备", "DB1.D88")); + list.add(new ItemDto(item_to_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_to_barcode1, "条码1", "DB1.D96")); + list.add(new ItemDto(item_to_barcode2, "条码2", "DB1.D100")); + list.add(new ItemDto(item_to_barcode3, "条码3", "DB1.D104")); + list.add(new ItemDto(item_to_barcode4, "条码4", "DB1.D108")); + list.add(new ItemDto(item_to_barcode5, "条码5", "DB1.D112")); + list.add(new ItemDto(item_to_barcode6, "条码6", "DB1.D116")); + list.add(new ItemDto(item_to_barcode7, "条码7", "DB1.D120")); + list.add(new ItemDto(item_to_barcode8, "条码8", "DB1.D124")); + list.add(new ItemDto(item_to_barcode9, "条码9", "DB1.D128")); + list.add(new ItemDto(item_to_barcode10, "条码10", "DB1.D132")); + list.add(new ItemDto(item_to_barcode11, "条码11", "DB1.D136")); + list.add(new ItemDto(item_to_barcode12, "条码12", "DB1.D140")); + list.add(new ItemDto(item_to_barcode13, "条码13", "DB1.D144")); + list.add(new ItemDto(item_to_barcode14, "条码14", "DB1.D148")); + list.add(new ItemDto(item_to_barcode15, "条码15", "DB1.D152")); + list.add(new ItemDto(item_to_barcode16, "条码16", "DB1.D156")); + list.add(new ItemDto(item_to_barcode17, "条码17", "DB1.D160")); + list.add(new ItemDto(item_to_barcode18, "条码18", "DB1.D164")); + list.add(new ItemDto(item_to_barcode19, "条码19", "DB1.D168")); + list.add(new ItemDto(item_to_barcode20, "条码20", "DB1.D172")); + list.add(new ItemDto(item_to_barcode21, "条码21", "DB1.D176")); + list.add(new ItemDto(item_to_barcode22, "条码22", "DB1.D180")); + list.add(new ItemDto(item_to_barcode23, "条码23", "DB1.D184")); + list.add(new ItemDto(item_to_barcode24, "条码24", "DB1.D188")); + list.add(new ItemDto(item_to_barcode25, "条码25", "DB1.D192")); + list.add(new ItemDto(item_to_barcode26, "条码26", "DB1.D196")); + list.add(new ItemDto(item_to_barcode27, "条码27", "DB1.D200")); + list.add(new ItemDto(item_to_barcode28, "条码28", "DB1.D204")); + list.add(new ItemDto(item_to_barcode29, "条码29", "DB1.D208")); + list.add(new ItemDto(item_to_barcode30, "条码30", "DB1.D212")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_feeding_line/HailiangCleaningFeedingLineDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_feeding_line/HailiangCleaningFeedingLineDefination.java new file mode 100644 index 00000000..5595a799 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_feeding_line/HailiangCleaningFeedingLineDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_feeding_line; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮-清洗上料线体 + */ +@Service +public class HailiangCleaningFeedingLineDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_cleaning_feeding_line"; + } + + @Override + public String getDriverName() { + return "海亮-清洗上料线体"; + } + + @Override + public String getDriverDescription() { + return "海亮-清洗上料线体"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangCleaningFeedingLineDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangCleaningFeedingLineDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_feeding_line/HailiangCleaningFeedingLineDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_feeding_line/HailiangCleaningFeedingLineDriver.java new file mode 100644 index 00000000..0cc162d6 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_feeding_line/HailiangCleaningFeedingLineDriver.java @@ -0,0 +1,385 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_feeding_line; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮-清洗上料线体 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangCleaningFeedingLineDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); +// @Autowired +// ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; //线体状态 + int is_open = 0; //是否启动 开机状态 + int in_ready = 0; //入料就绪 + int all_ready = 0; //所有设备就绪 + int task_finish = 0; //任务完成 + int allowed_in = 0; //清洗机允许上料 + int error = 0; //报警信号 + int in_pcsn = 0; //上料批次号 + //出入库模式 + int operation_type = 0; + int last_mode = 0; //线体状态 + int last_is_open = 0; //是否启动 开机状态 + int last_in_ready = 0; //入料就绪 + int last_all_ready = 0; //所有设备就绪 + int last_task_finish = 0; //任务完成 + int last_allowed_in = 0; //清洗机允许上料 + int last_error = 0; //报警信号 + int last_in_pcsn = 0; //上料批次号 + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute(){ + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getItem_mode(); + is_open = this.itemProtocol.getItem_is_open(); + in_ready = this.itemProtocol.getItem_in_ready(); + all_ready = this.itemProtocol.getItem_all_ready(); + task_finish = this.itemProtocol.getItem_task_finish(); + allowed_in = this.itemProtocol.getItem_allowed_in(); + error = this.itemProtocol.getItem_error(); + in_pcsn = this.itemProtocol.getItem_in_pcsn(); + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (is_open != last_is_open) { + logServer.deviceItemValue(this.device_code,"is_open" ,String.valueOf(is_open)); + logServer.deviceExecuteLog(this.device_code,"","","信号is_open:" + last_is_open + "->" + is_open); + } + if (in_ready != last_in_ready) { + logServer.deviceItemValue(this.device_code,"in_ready" ,String.valueOf(in_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号in_ready:" + last_in_ready + "->" + in_ready); + } + if (all_ready != last_all_ready) { + logServer.deviceItemValue(this.device_code,"all_ready" ,String.valueOf(all_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号all_ready:" + last_all_ready + "->" + all_ready); + } + if (task_finish != last_task_finish) { + logServer.deviceItemValue(this.device_code,"task_finish" ,String.valueOf(task_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号task_finish:" + last_task_finish + "->" + task_finish); + } + if (allowed_in != last_allowed_in) { + logServer.deviceItemValue(this.device_code,"allowed_in" ,String.valueOf(allowed_in)); + logServer.deviceExecuteLog(this.device_code,"","","信号allowed_in:" + last_allowed_in + "->" + allowed_in); + } + if (in_pcsn != last_in_pcsn) { + logServer.deviceItemValue(this.device_code,"in_pcsn" ,String.valueOf(in_pcsn)); + logServer.deviceExecuteLog(this.device_code,"","","信号in_pcsn:" + last_in_pcsn + "->" + in_pcsn); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + + if(!requireSucess){ + /* if ( mode == 1 && move != 0 && task > 0) { + logServer.deviceLogToacs(this.device_code,"","",device_code+":,move:"+move+",requireSucess:" + requireSucess + "开始申请任务"); + apply_task(); + }*/ + } + + + + } + last_mode = mode; //线体状态 + last_is_open = is_open; //是否启动 开机状态 + last_in_ready = in_ready; //入料就绪 + last_all_ready = all_ready; //所有设备就绪 + last_task_finish = task_finish; //任务完成 + last_allowed_in = allowed_in; //清洗机允许上料 + last_error = error; //报警信号 + last_in_pcsn = in_pcsn; //上料批次号 + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + +/* public synchronized boolean apply_task() throws Exception { + Boolean flag = false; + //通过路由找到所有的目标设备 + //找到当前设备生产的物料,并且判断下个工序生产的物料相同 + //判断是否已经有前往这个工位的任务 + List list = routeLineService.getShortPathLinesByCode(this.device_code,"normal"); + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(this.device_code); + //查找当前工单对应的物料编号 + String cpbh = order.getMaterial_code(); + HailiangSpecialPourStationDeviceDriver hailiangSpecialPourStationDeviceDriver; + //遍历路由,找到对应所有的物料进行匹配 + for(int i=0;i getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_mode, "线体状态", "DB1.X0.0")); + list.add(new ItemDto(item_is_open, "开机状态", "DB1.X0.1")); + list.add(new ItemDto(item_in_ready, "入料就绪", "DB1.X0.7")); + list.add(new ItemDto(item_all_ready, "所有设备就绪", "DB1.X1.0")); + list.add(new ItemDto(item_task_finish, "任务完成", "DB1.X1.1")); + list.add(new ItemDto(item_allowed_in, "清洗机允许上料", "DB1.X1.2")); + list.add(new ItemDto(item_error, "报警信号", "DB1.w4")); + list.add(new ItemDto(item_in_pcsn, "上料批次号", "DB1.D156")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB2.W4")); + list.add(new ItemDto(item_to_compel_finished, "强制完成", "DB2.W6")); + list.add(new ItemDto(item_to_dis_weight, "称重禁用", "DB2.W8")); + list.add(new ItemDto(item_to_in_confirm_req, "上料请求确认", "DB2.W40")); + list.add(new ItemDto(item_to_in_confirm_finish, "上料命令确认完毕", "DB2.W72")); + list.add(new ItemDto(item_to_confirm_finished, "确认完成", "DB2.W74")); + list.add(new ItemDto(item_to_pcsn, "批次号", "DB2.D84")); + list.add(new ItemDto(item_to_all_num, "上料总数量", "DB2.D232")); + list.add(new ItemDto(item_to_all_weight, "上料总重量", "DB2.D232")); + list.add(new ItemDto(item_to_del_task, "任务删除", "DB2.D232")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine/HailiangCleaningMachineDefination.java similarity index 70% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine/HailiangCleaningMachineDefination.java index 1a3e4a0c..fd637ef1 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine/HailiangCleaningMachineDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.hongxiang_conveyor; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -11,33 +11,34 @@ import java.util.LinkedList; import java.util.List; /** - * 烘箱设备对接位 + * 海亮清洗机 */ @Service -public class HongXiangStationDefination implements OpcDeviceDriverDefination { +public class HailiangCleaningMachineDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "hongxiang_conveyor"; + return "hailiang_cleaning_machine"; } @Override public String getDriverName() { - return "烘箱设备对接位"; + return "海亮-清洗机"; } @Override public String getDriverDescription() { - return "烘箱设备对接位"; + return "海亮-清洗机"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new HongXiangStationDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HailiangCleaningMachineDeviceDriver()).setDevice(device).setDriverDefination(this); + } @Override public Class getDeviceDriverType() { - return HongXiangStationDeviceDriver.class; + return HailiangCleaningMachineDeviceDriver.class; } @Override diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine/HailiangCleaningMachineDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine/HailiangCleaningMachineDeviceDriver.java new file mode 100644 index 00000000..921720d4 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine/HailiangCleaningMachineDeviceDriver.java @@ -0,0 +1,408 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮清洗机 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangCleaningMachineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); +// @Autowired +// ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int running = 0; //是否运行 + int prepare = 0; //是否准备 + int ready = 0; //是否就绪 + int order_finish = 0; //订单完成 + int error = 0; //报警信号 + int open_ready_time = 0; //开机准备时间(S) + int device_running_time = 0; //设备运转时间(S) + int await_time = 0; //待机时间(S) + int order = 0; //工单号 + int order_real_time = 0; //订单实时 + int is_start = 0; //是否开始 + int pause = 0; //是否暂停 + //出入库模式 + int operation_type = 0; + int last_running = 0; //是否运行 + int last_prepare = 0; //是否准备 + int last_ready = 0; //是否就绪 + int last_order_finish = 0; //订单完成 + int last_error = 0; //报警信号 + int last_open_ready_time = 0; //开机准备时间(S) + int last_device_running_time = 0; //设备运转时间(S) + int last_await_time = 0; //待机时间(S) + int last_order = 0; //工单号 + int last_order_real_time = 0; //订单实时 + int last_is_start = 0; //是否开始 + int last_pause = 0; //是否暂停 + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + running = this.itemProtocol.getItem_running(); + prepare = this.itemProtocol.getItem_prepare(); + ready = this.itemProtocol.getItem_ready(); + order_finish = this.itemProtocol.getItem_order_finish(); + error = this.itemProtocol.getItem_error(); + open_ready_time = this.itemProtocol.getItem_open_ready_time(); + device_running_time = this.itemProtocol.getItem_device_running_time(); + await_time = this.itemProtocol.getItem_await_time(); + order = this.itemProtocol.getItem_order(); + order_real_time = this.itemProtocol.getItem_order_real_time(); + is_start = this.itemProtocol.getItem_is_start(); + pause = this.itemProtocol.getItem_pause(); + if (running != last_running) { + logServer.deviceItemValue(this.device_code,"running" ,String.valueOf(running)); + logServer.deviceExecuteLog(this.device_code,"","","信号running:" + last_running + "->" + running); + } + if (prepare != last_prepare) { + logServer.deviceItemValue(this.device_code,"prepare" ,String.valueOf(prepare)); + logServer.deviceExecuteLog(this.device_code,"","","信号prepare:" + last_prepare + "->" + prepare); + } + if (ready != last_ready) { + logServer.deviceItemValue(this.device_code,"ready" ,String.valueOf(ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号ready:" + last_ready + "->" + ready); + } + if (order_finish != last_order_finish) { + logServer.deviceItemValue(this.device_code,"order_finish" ,String.valueOf(order_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_finish:" + last_order_finish + "->" + order_finish); + } + if (open_ready_time != last_open_ready_time) { + logServer.deviceItemValue(this.device_code,"open_ready_time" ,String.valueOf(open_ready_time)); + logServer.deviceExecuteLog(this.device_code,"","","信号open_ready_time:" + last_open_ready_time + "->" + open_ready_time); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + } + if (order_real_time != last_order_real_time) { + logServer.deviceItemValue(this.device_code,"order_real_time" ,String.valueOf(order_real_time)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_real_time:" + last_order_real_time + "->" + order_real_time); + } + if (is_start != last_is_start) { + logServer.deviceItemValue(this.device_code,"is_start" ,String.valueOf(is_start)); + logServer.deviceExecuteLog(this.device_code,"","","信号is_start:" + last_is_start + "->" + is_start); + } + if (pause != last_pause) { + logServer.deviceItemValue(this.device_code,"pause" ,String.valueOf(pause)); + logServer.deviceExecuteLog(this.device_code,"","","信号pause:" + last_pause + "->" + pause); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + }/* else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + }*/ else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + + if(!requireSucess){ + /* if ( mode == 1 && move != 0 && task > 0) { + logServer.deviceLogToacs(this.device_code,"","",device_code+":,move:"+move+",requireSucess:" + requireSucess + "开始申请任务"); + apply_task(); + }*/ + } + + + + } + last_running = running; //是否运行 + last_prepare = prepare; //是否准备 + last_ready = ready; //是否就绪 + last_order_finish = order_finish; //订单完成 + last_error = error; //报警信号 + last_open_ready_time = open_ready_time; //开机准备时间(S) + last_device_running_time = device_running_time; //设备运转时间(S) + last_await_time = await_time; //待机时间(S) + last_order = order; //工单号 + last_order_real_time = order_real_time; //订单实时 + last_is_start = is_start; //是否开始 + last_pause = pause; //是否暂停 + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + +/* public synchronized boolean apply_task() throws Exception { + Boolean flag = false; + //通过路由找到所有的目标设备 + //找到当前设备生产的物料,并且判断下个工序生产的物料相同 + //判断是否已经有前往这个工位的任务 + List list = routeLineService.getShortPathLinesByCode(this.device_code,"normal"); + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(this.device_code); + //查找当前工单对应的物料编号 + String cpbh = order.getMaterial_code(); + HailiangSpecialPourStationDeviceDriver hailiangSpecialPourStationDeviceDriver; + //遍历路由,找到对应所有的物料进行匹配 + for(int i=0;i getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_running, "是否运行", "DB1.X0.3")); + list.add(new ItemDto(item_prepare, "是否准备", "DB1.X0.5")); + list.add(new ItemDto(item_ready, "是否就绪", "DB1.X0.6")); + list.add(new ItemDto(item_order_finish, "订单完成", "DB1.X1.3")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W68")); + list.add(new ItemDto(item_open_ready_time, "开机准备时间(S)", "DB1.D144")); + list.add(new ItemDto(item_device_running_time, "设备运转时间(S)", "DB1.D148")); + list.add(new ItemDto(item_await_time, "待机时间(S)", "DB1.D152")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + list.add(new ItemDto(item_order_real_time, "订单实时", "DB1.D284")); + list.add(new ItemDto(item_is_start, "是否开始", "DB1.D288")); + list.add(new ItemDto(item_pause, "是否暂停", "DB1.D292")); + return list; + } + + //订单生产总量 + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB2.W76")); + list.add(new ItemDto(item_to_clear, "产量清零", "DB2.W78")); + list.add(new ItemDto(item_to_confirm_finished, "订单确认完成", "DB2.W80")); + list.add(new ItemDto(item_to_order, "工单号", "DB2.D160")); + list.add(new ItemDto(item_to_order_prod_num, "订单生产总量", "DB2.D224")); + list.add(new ItemDto(item_to_start_end, "开始结束", "DB2.D228")); + list.add(new ItemDto(item_to_pause, "暂停恢复", "DB2.D232")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine_storage_station/HailiangCleaningMachineStorageStationDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine_storage_station/HailiangCleaningMachineStorageStationDefination.java new file mode 100644 index 00000000..15050535 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine_storage_station/HailiangCleaningMachineStorageStationDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine_storage_station; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮清洗机储料仓 + */ +@Service +public class HailiangCleaningMachineStorageStationDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_cleaning_machine_storage_station"; + } + + @Override + public String getDriverName() { + return "海亮-清洗机储料仓"; + } + + @Override + public String getDriverDescription() { + return "海亮-清洗机储料仓"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangCleaningMachineStorageStationDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangCleaningMachineStorageStationDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine_storage_station/HailiangCleaningMachineStorageStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine_storage_station/HailiangCleaningMachineStorageStationDeviceDriver.java new file mode 100644 index 00000000..3be56959 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_cleaning_machine_storage_station/HailiangCleaningMachineStorageStationDeviceDriver.java @@ -0,0 +1,419 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine_storage_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.NDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pour_station.HailiangSpecialPourStationDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangCleaningMachineStorageStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode =0; + int running = 0; //是否运行 + int is_open = 0; //是否启动 + int error = 0; //报警信号 + int silo_weight = 0; //储料仓重量 + int full_number = 0; //储料仓总数量 + int silo_material_no = 0; //储料仓物物料号 + //出入库模式 + int operation_type = 0; + int last_running = 0; //是否运行 + int last_is_open = 0; //是否启动 + int last_error = 0; //报警信号 + int last_silo_weight = 0; //储料仓重量 + int last_full_number = 0; //储料仓总数量 + int last_silo_material_no = 0; //储料仓物物料号 + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + + int agvphase=0; + int index =0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getItem_error(); + running = this.itemProtocol.getItem_running(); + is_open = this.itemProtocol.getItem_is_open(); + silo_weight = this.itemProtocol.getItem_silo_weight(); + full_number = this.itemProtocol.getItem_full_number(); + silo_material_no = this.itemProtocol.getItem_silo_material_no(); + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (running != last_running) { + logServer.deviceItemValue(this.device_code,"running" ,String.valueOf(running)); + logServer.deviceExecuteLog(this.device_code,"","","信号running:" + last_running + "->" + running); + } + if (is_open != last_is_open) { + logServer.deviceItemValue(this.device_code,"is_open" ,String.valueOf(is_open)); + logServer.deviceExecuteLog(this.device_code,"","","信号is_open:" + last_is_open + "->" + is_open); + } + if (silo_weight != last_silo_weight) { + logServer.deviceItemValue(this.device_code,"silo_weight" ,String.valueOf(silo_weight)); + logServer.deviceExecuteLog(this.device_code,"","","信号silo_weight:" + last_silo_weight + "->" + silo_weight); + } + if (full_number != last_full_number) { + logServer.deviceItemValue(this.device_code,"full_number" ,String.valueOf(full_number)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_number:" + last_full_number + "->" + full_number); + } + if (silo_material_no != last_silo_material_no) { + logServer.deviceItemValue(this.device_code,"silo_material_no" ,String.valueOf(silo_material_no)); + logServer.deviceExecuteLog(this.device_code,"","","信号silo_material_no:" + last_silo_material_no + "->" + silo_material_no); + } + + } catch (Exception var17) { + return; + } + +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); + message = "信号量同步异常"; + //未联机 +// } else if (mode == 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "未联机"; + //有报警 +// } + if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + + if(!requireSucess){ + /* if ( mode == 1 && move != 0 && task > 0) { + logServer.deviceLogToacs(this.device_code,"","",device_code+":,move:"+move+",requireSucess:" + requireSucess + "开始申请任务"); + apply_task(); + }*/ + } + + if(agvphase == 0x0B || agvphase == 0x0F ) + { + if(error == 0 && ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("3"); + instructionService.update(inst); + writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + }else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因error:"+error+",inst"+inst); + + } + } + + if(agvphase == 0x0D || agvphase == 0x11){ + if(error == 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("4"); + instructionService.update(inst); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + }else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因error:"+error+",inst"+inst); + + } + } + + } + last_running = running; + last_is_open = is_open; //是否启动 + last_error = error; //报警信号 + last_silo_weight = silo_weight; //储料仓重量 + last_full_number = full_number; //储料仓总数量 + last_silo_material_no = silo_material_no; //储料仓物物料号 + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + + public synchronized boolean apply_task() throws Exception { + Boolean flag = false; + //通过路由找到所有的目标设备 + //找到当前设备生产的物料,并且判断下个工序生产的物料相同 + //判断是否已经有前往这个工位的任务 + List list = routeLineService.getShortPathLinesByCode(this.device_code,"normal"); + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(this.device_code); + //查找当前工单对应的物料编号 + String cpbh = order.getMaterial_code(); + HailiangSpecialPourStationDeviceDriver hailiangSpecialPourStationDeviceDriver; + //遍历路由,找到对应所有的物料进行匹配 + for(int i=0;i getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_mode, "模式", "DB1.W36")); + list.add(new ItemDto(item_running, "是否运行", "DB1.B2.0")); + list.add(new ItemDto(item_is_open, "是否启动", "DB1.B1.0")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W38")); + list.add(new ItemDto(item_silo_weight, "储料仓重量", "DB1.D84")); + list.add(new ItemDto(item_full_number, "储料仓总数量", "DB1.D164")); + list.add(new ItemDto(item_silo_material_no, "储料仓物料号", "DB1.D224")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open_weight, "储料仓开始称重", "DB2.W10")); + list.add(new ItemDto(item_to_feeding, "储料仓上料", "DB2.W42")); + list.add(new ItemDto(item_to_material_no, "储料仓料号", "DB2.D92")); + list.add(new ItemDto(item_to_dumping_num, "储料仓倒料数量", "DB2.D164")); + list.add(new ItemDto(item_to_peel, "储料仓去皮", "DB2.W364")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/HailiangElevatorWiringDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/HailiangElevatorWiringDefination.java new file mode 100644 index 00000000..0c3534c7 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/HailiangElevatorWiringDefination.java @@ -0,0 +1,73 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_elevator_wiring; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮-货梯对接线 + */ +@Service +public class HailiangElevatorWiringDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_elevator_wiring"; + } + + @Override + public String getDriverName() { + return "海亮-货梯对接线"; + } + + @Override + public String getDriverDescription() { + return "海亮-货梯对接线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangElevatorWiringDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangElevatorWiringDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "VW2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_move, "光电信号", "VW4")); + list.add(new ItemDto(ItemProtocol.item_action, "取放信号", "VW6")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "VW8")); + list.add(new ItemDto(ItemProtocol.item_task, "任务号", "VD10")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/HailiangElevatorWiringDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/HailiangElevatorWiringDeviceDriver.java new file mode 100644 index 00000000..85f5e01d --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/HailiangElevatorWiringDeviceDriver.java @@ -0,0 +1,252 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_elevator_wiring; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮-货梯对接线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangElevatorWiringDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int move = 0; + int task = 0; + int action = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_action = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getError(); + action = this.itemProtocol.getAction(); + move = this.itemProtocol.getMove(); + task = this.itemProtocol.getTask(); + hasGoods = this.itemProtocol.getMove(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code,"action" ,String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code,"","","信号action:" + last_action + "->" + action); + } + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + break; + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_action = action; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + } else if (type == 2) { + itemMap.put(to_target, command); + + } else if (type == 3) { + itemMap.put(to_task, command); + } + ReadUtil.write(itemMap, server); + + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/ItemProtocol.java new file mode 100644 index 00000000..1c7e841b --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_elevator_wiring/ItemProtocol.java @@ -0,0 +1,107 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_elevator_wiring; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_task = "task"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + public static String item_weight = "weight"; + + private HailiangElevatorWiringDeviceDriver driver; + + public ItemProtocol(HailiangElevatorWiringDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作状态", "VW2", Boolean.valueOf(true))); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_action, "取放信号", "VW6")); + list.add(new ItemDto(item_error, "报警信号", "VW8")); + list.add(new ItemDto(item_task, "任务号", "VD10")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "VW102", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "目标站", "VW104")); + list.add(new ItemDto(item_to_task, "任务号", "VD108")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/HailiangEngravingCacheDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/HailiangEngravingCacheDefination.java new file mode 100644 index 00000000..9b28f7a3 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/HailiangEngravingCacheDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮刻字缓存位 + */ +@Service +public class HailiangEngravingCacheDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_engraving_cache"; + } + + @Override + public String getDriverName() { + return "海亮-刻字缓存位"; + } + + @Override + public String getDriverDescription() { + return "海亮-刻字缓存位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangEngravingCacheDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangEngravingCacheDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/HailiangEngravingCacheDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/HailiangEngravingCacheDeviceDriver.java new file mode 100644 index 00000000..94fe4286 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/HailiangEngravingCacheDeviceDriver.java @@ -0,0 +1,427 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_machine.HailiangEngravingMachineDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station.HailiangPackerStationDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮刻字缓存位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangEngravingCacheDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + + String container; + + int move = 0;//光电信号 + int mode = 0;//模式 + //出入库模式 + int operation_type = 0; + int last_move = 0;//光电信号 + int last_mode = 0;//光电信号 + + + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + int agvphase = 0; + int index = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + move = this.itemProtocol.getItem_move();//光电信号 + mode = this.itemProtocol.getItem_mode();//模式 + if (mode != last_mode) { + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + if (move == 1) { + thingToNothing(); + } + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + + + /* if (mode == 2 && move != 0 && task > 0) { + + }*/ + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } /*else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } */ else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + if(agvphase == 0x03) + { + if(ObjectUtil.isNotEmpty(inst) && move != 0){ + inst.setExecute_status("1"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "move=" +move + ",等待反馈,inst:"+inst); + + } + } + + if(agvphase == 0x05){ + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("2"); + instructionService.update(inst); + writing("to_cache_write", "0"); + this.setMaterial(""); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + + } + } + + if(agvphase == 0x07){ + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("5"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + } + } + + if(agvphase == 0x09){ + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("6"); + instructionService.update(inst); + // TODO 指令中根据起始点位驱动类型判断空满 + String start_device_code = inst.getStart_device_code(); + log.warn("起点设备为:{}",start_device_code); + String next_device_code = inst.getNext_device_code(); + log.warn("终点设备为:{}",next_device_code); + Device start_device = deviceAppservice.findDeviceByCode(start_device_code); + Device next_device = deviceAppservice.findDeviceByCode(next_device_code); + if (start_device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver){ + writing("to_cache_write", "2"); + this.setMaterial(inst.getMaterial()); + next_device.setMaterial_type(inst.getMaterial()); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "起点位置刻字机,缓存位解锁成功"); + } + if (start_device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver){ + writing("to_cache_write", "1"); + this.setMaterial(""); + next_device.setMaterial_type(""); + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "起点位置包装机,缓存位解锁成功"); + } + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + + } + } + } + last_move = move ;//光电信号 + last_mode = mode ;//光电信号 + } + + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.setRequireSucess(false); + this.setApplySucess(false); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, value); + logServer.deviceExecuteLog(this.device_code,"","","下发信号:" + key + ",value:"+value); + ReadUtil.write(itemMap, server); + } + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("1"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/ItemProtocol.java new file mode 100644 index 00000000..6ede85ad --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_cache/ItemProtocol.java @@ -0,0 +1,73 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_move = "move";//光电信号 + public static String item_mode = "mode";//模式 + + // + public static String item_to_cache_write = "to_cache_write"; + + + + private HailiangEngravingCacheDeviceDriver driver; + + public ItemProtocol(HailiangEngravingCacheDeviceDriver driver) { + this.driver = driver; + } + + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_move, "光电信号", "DB1.W22")); + list.add(new ItemDto(item_mode, "模式", "DB1.B0.6")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_cache_write, "刻字缓存写", "DB2.W22")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/HailiangEngravingMachineDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/HailiangEngravingMachineDefination.java new file mode 100644 index 00000000..a8f4088b --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/HailiangEngravingMachineDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_machine; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮刻字机工位 + */ +@Service +public class HailiangEngravingMachineDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_engraving_machine"; + } + + @Override + public String getDriverName() { + return "海亮-刻字机工位"; + } + + @Override + public String getDriverDescription() { + return "海亮-刻字机工位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangEngravingMachineDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangEngravingMachineDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/HailiangEngravingMachineDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/HailiangEngravingMachineDeviceDriver.java new file mode 100644 index 00000000..76788b41 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/HailiangEngravingMachineDeviceDriver.java @@ -0,0 +1,857 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_machine; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache.HailiangEngravingCacheDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮刻字机工位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangEngravingMachineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + @Autowired + NDCAgvServiceImpl agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + String container; + + int status = 0;//线体状态 + int is_open = 0;//线体开机状态 + int is_running = 0;//刻字机运行状态 + int empty_req = 0;//空箱请求 + int move = 0;//有货 + int full_req = 0;//满箱请求 + int full_finish = 0;//满箱完成 + int order_finish = 0;//订单完成 + int engraving_prepare = 0;//刻字机准备 + int engraving_ready = 0;//刻字机就绪 + int line_ready = 0;//线体就绪 + int mode = 0;//模式 所有设备就绪 + int error = 0; //报警信号 + int order_now = 0; //订单实时 + int one_now = 0; //每框实时 + int task = 0; //任务号 + int port_full_num = 0; //出料口满框数量 + int lettering_silo_number = 0; //刻字机储料仓数量 + int open_ready_time = 0; //开机准备时间(S) + int device_running_time = 0; //设备运转时间(S) + int await_time = 0; //待机时间(S) + int order = 0; //工单号 + int heartbeat = 0; + + //出入库模式 + int operation_type = 0; + int last_status = 0;//线体状态 + int last_is_open = 0;//线体开机状态 + int last_is_running = 0;//刻字机运行状态 + int last_empty_req = 0;//空箱请求 + int last_move = 0;//有货 + int last_full_req = 0;//满箱请求 + int last_full_finish = 0;//满箱完成 + int last_order_finish = 0;//订单完成 + int last_engraving_prepare = 0;//刻字机准备 + int last_engraving_ready = 0;//刻字机就绪 + int last_line_ready = 0;//线体就绪 + int last_mode = 0;//模式 所有设备就绪 + int last_error = 0; //报警信号 + int last_order_now = 0; //订单实时 + int last_one_now = 0; //每框实时 + int last_task = 0; //任务号 + int last_port_full_num = 0; //出料口满框数量 + int last_lettering_silo_number = 0; //刻字机储料仓数量 + int last_open_ready_time = 0; //开机准备时间(S) + int last_device_running_time = 0; //设备运转时间(S) + int last_await_time = 0; //待机时间(S) + int last_order = 0; //工单号 + int last_heartbeat = 0; + + private long last_feedDeviceStatusTime = 0; + + int status_type = 0; + int last_status_type = 0; + + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + int agvphase = 0; + int index = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public synchronized void execute(){ + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getItem_mode();//模式 所有设备就绪 + status = this.itemProtocol.getItem_status();//线体状态 + is_open = this.itemProtocol.getItem_is_open();//线体开机状态 + is_running = this.itemProtocol.getItem_is_running();//刻字机运行状态 + empty_req = this.itemProtocol.getItem_empty_req();//空箱请求 + move = this.itemProtocol.getItem_move();//有货 + full_req = this.itemProtocol.getItem_full_req();//满箱请求 + full_finish = this.itemProtocol.getItem_full_finish();//满箱完成 + order_finish = this.itemProtocol.getItem_order_finish();//订单完成 + engraving_prepare = this.itemProtocol.getItem_engraving_prepare();//刻字机准备 + engraving_ready = this.itemProtocol.getItem_engraving_ready();//刻字机就绪 + line_ready = this.itemProtocol.getItem_line_ready();//线体就绪 + error = this.itemProtocol.getItem_error(); //报警信号 + order_now = this.itemProtocol.getItem_order_now(); //订单实时 + one_now = this.itemProtocol.getItem_one_now(); //每框实时 + task = this.itemProtocol.getItem_task(); //任务号 + port_full_num = this.itemProtocol.getItem_port_full_num(); //出料口满框数量 + lettering_silo_number = this.itemProtocol.getItem_lettering_silo_number(); //刻字机储料仓数量 + open_ready_time = this.itemProtocol.getItem_open_ready_time(); //开机准备时间(S) + device_running_time = this.itemProtocol.getItem_device_running_time(); //设备运转时间(S) + await_time = this.itemProtocol.getItem_await_time(); //待机时间(S) + order = this.itemProtocol.getItem_order(); //工单号 + if (mode != last_mode) { + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + thingToNothing(); + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (status != last_status) { + logServer.deviceItemValue(this.device_code,"status" ,String.valueOf(status)); + logServer.deviceExecuteLog(this.device_code,"","","信号status:" + last_status + "->" + status); + } + if (is_open != last_is_open) { + logServer.deviceItemValue(this.device_code,"is_open" ,String.valueOf(is_open)); + logServer.deviceExecuteLog(this.device_code,"","","信号is_open:" + last_is_open + "->" + is_open); + } + if (is_running != last_is_running) { + logServer.deviceItemValue(this.device_code,"is_running" ,String.valueOf(is_running)); + logServer.deviceExecuteLog(this.device_code,"","","信号is_running:" + last_is_running + "->" + is_running); + } + if (empty_req != last_empty_req) { + logServer.deviceItemValue(this.device_code,"empty_req" ,String.valueOf(empty_req)); + logServer.deviceExecuteLog(this.device_code,"","","信号empty_req:" + last_empty_req + "->" + empty_req); + } + if (full_req != last_full_req) { + logServer.deviceItemValue(this.device_code,"full_req" ,String.valueOf(full_req)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_req:" + last_full_req + "->" + full_req); + } + if (full_finish != last_full_finish) { + logServer.deviceItemValue(this.device_code,"full_finish" ,String.valueOf(full_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_finish:" + last_full_finish + "->" + full_finish); + } + if (order_finish != last_order_finish) { + logServer.deviceItemValue(this.device_code,"order_finish" ,String.valueOf(order_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_finish:" + last_order_finish + "->" + order_finish); + } + if (engraving_prepare != last_engraving_prepare) { + logServer.deviceItemValue(this.device_code,"engraving_prepare" ,String.valueOf(engraving_prepare)); + logServer.deviceExecuteLog(this.device_code,"","","信号engraving_prepare:" + last_engraving_prepare + "->" + engraving_prepare); + } + if (engraving_ready != last_engraving_ready) { + logServer.deviceItemValue(this.device_code,"engraving_ready" ,String.valueOf(engraving_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号engraving_ready:" + last_engraving_ready + "->" + engraving_ready); + } + if (line_ready != last_line_ready) { + logServer.deviceItemValue(this.device_code,"line_ready" ,String.valueOf(line_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_ready:" + last_line_ready + "->" + line_ready); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (order_now != last_order_now) { + logServer.deviceItemValue(this.device_code,"order_now" ,String.valueOf(order_now)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_now:" + last_order_now + "->" + order_now); + if (mode == 1 && order > 0){ + JSONObject map = new JSONObject(); + map.put("order",order); + map.put("real_qty",order_now); + try{ + acsToWmsService.feedOrderRealQty(map); + } catch (Exception e){ + log.error("工单数量反馈失败,设备{},原因{}",device_code,e.getMessage()); + } + } + } + if (one_now != last_one_now) { + logServer.deviceItemValue(this.device_code,"one_now" ,String.valueOf(one_now)); + logServer.deviceExecuteLog(this.device_code,"","","信号one_now:" + last_one_now + "->" + one_now); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code,"task" ,String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code,"","","信号task:" + last_task + "->" + task); + } + if (port_full_num != last_port_full_num) { + logServer.deviceItemValue(this.device_code,"port_full_num" ,String.valueOf(port_full_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号port_full_num:" + last_port_full_num + "->" + port_full_num); + } + if (lettering_silo_number != last_lettering_silo_number) { + logServer.deviceItemValue(this.device_code,"lettering_silo_number" ,String.valueOf(lettering_silo_number)); + logServer.deviceExecuteLog(this.device_code,"","","信号lettering_silo_number:" + last_lettering_silo_number + "->" + lettering_silo_number); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + } + + int realError = 0; + if (!this.itemProtocol.getIsonline()) { + status_type = 01; + } else { + status_type = 02; + if (error == 1 || error == 51) { + status_type = 05; + realError = error; + } else if (mode == 1 && order > 0) { + status_type = 03; + realError = 0; + } else if (mode == 0 && order > 0) { + realError = 0; + status_type = 04; + } + } + if (status_type != last_status_type) { + JSONObject map = new JSONObject(); + map.put("device_code", device_code); + map.put("status_type", "0" + status_type); + map.put("start_time", DateUtil.now()); + map.put("error_code", realError); + try { + acsToWmsService.feedDeviceStatusType(map); + last_status_type = status_type; + }catch (Exception e){ + log.error("设备状态反馈失败,设备{},原因{}",device_code,e.getMessage()); + } + } + + synchronized (this){ +// int realError = 0; +// long now_feedTime = System.currentTimeMillis(); +// if (now_feedTime - last_feedDeviceStatusTime >= 5000){ +// heartbeat = this.itemProtocol.getItem_heartbeat(); +// if (heartbeat == last_heartbeat){ +// status_type = 01; +// } else { +// status_type = 02; +// if (error == 1 || error == 51) { +// status_type = 05; +// realError = error; +// }else if (mode == 1 && order > 0) { +// status_type = 03; +// realError = 0; +// } else if (mode == 0 && order > 0) { +// status_type = 04; +// realError = 0; +// } +// } +// if (status_type != last_status_type) { +// JSONObject map = new JSONObject(); +// map.put("device_code", device_code); +// map.put("status_type", "0" + status_type); +// map.put("start_time", DateUtil.now()); +// map.put("error_code",realError); +// acsToWmsService.feedDeviceStatusType(map); +// last_status_type = status_type; +// } +// last_heartbeat = heartbeat; +// last_feedDeviceStatusTime = now_feedTime; +// } + } + + } catch (Exception var17) { + return; + } + +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else if (mode == 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "未联机"; +// //有报警 +// } else + if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + + if ( mode == 1 && order_finish == 1 && last_order_finish != order_finish && order > 0){ + ProduceshiftorderDto dto = new ProduceshiftorderDto(); + dto.setOrder_code(order + ""); + dto.setOrder_status("2"); + ProduceshiftorderDto deviceInfo = produceshiftorderService.findOrderByDeviceCode(this.device_code); + if(deviceInfo != null){ + if (StrUtil.isNotEmpty(deviceInfo.getExt_order_id())) { + String ext_order_id = deviceInfo.getExt_order_id(); + JSONObject param = new JSONObject(); + param.put("ext_order_id",ext_order_id); + acsToWmsService.feedbackOrderStatus(param); + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,对应的工单的外部标识:"+ext_order_id); + }else { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,对应的工单的没有外部标识"); + } + }else { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,对应的工单信息为空"); + } + produceshiftorderService.updateByOrderCode(dto); + this.writing("to_confirm_finished","1"); + this.writing("to_order", "0"); + this.writing("to_clear","1"); + this.writing("to_pause","1"); + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,任务确认完成,电器信号写入成功"); + }/*else { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,mode:"+mode + ",order_finish>"+ order_finish +",last_order_finish>"+last_order_finish + "order:" + order); + }*/ + + if(!requireSucess){ +// if ( move == 1 && mode == 1 && order > 0 && full_number>0 ) { + + if ( move == 1 && mode == 1 && full_req == 1 ) { +// if ( full_req == 1 ) { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,move:"+move+",requireSucess:" + requireSucess + "开始申请任务"); + + apply_task(); + }/* else { + logServer.deviceExecuteLog(this.device_code,"","","不满足下发满框请求任务条件,mode:"+mode+"move:"+move+"full_req:"+full_req); + + }*/ + + if (move == 0 && mode == 1 && empty_req == 1){ +// if (empty_req == 1) { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,move:"+move+",requireSucess:" + requireSucess + "开始申请空箱请求任务"); + apply_empty_task(); + }/*else { + logServer.deviceExecuteLog(this.device_code,"","","不满足下发空框请求任务条件,mode:"+mode+"move:"+move+"empty_req:"+empty_req); + + }*/ + + }else { + logServer.deviceExecuteLog(this.device_code,"","","是否请求成功:requireSucess:"+requireSucess); + } + + if(agvphase == 0x03) + { + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("1"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + + } + } + + if(agvphase == 0x05){ + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("2"); + instructionService.update(inst); + writing("to_cache_write", "0"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + + } + } + + if(agvphase == 0x07){ + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("5"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + } + } + + if(agvphase == 0x09){ + if(ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("6"); + instructionService.update(inst); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,inst为空"); + + } + } + + + } + last_status = status;//线体状态 + last_is_open = is_open;//线体开机状态 + last_is_running = is_running;//刻字机运行状态 + last_empty_req = empty_req;//空箱请求 + last_move = move;//有货 + last_full_req = full_req;//满箱请求 + last_full_finish = full_finish;//满箱完成 + last_order_finish = order_finish;//订单完成 + last_engraving_prepare = engraving_prepare;//刻字机准备 + last_engraving_ready = engraving_ready;//刻字机就绪 + last_line_ready = line_ready;//线体就绪 + last_mode = mode;//模式 所有设备就绪 + last_error = error; //报警信号 + last_order_now = order_now; //订单实时 + last_one_now = one_now; //每框实时 + last_task = task; //任务号 + last_port_full_num = port_full_num; //出料口满框数量 + last_lettering_silo_number = lettering_silo_number; //刻字机储料仓数量 + last_open_ready_time = open_ready_time; //开机准备时间(S) + last_device_running_time = device_running_time; //设备运转时间(S) + last_await_time = await_time; //待机时间(S) + last_order = order; //工单号 + last_heartbeat = heartbeat; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.setRequireSucess(false); + this.setApplySucess(false); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + public synchronized boolean apply_empty_task() { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + Boolean flag = false; + List list = routeLineService.getPathLinesByCode(this.device_code, "normal"); + if (ObjectUtil.isEmpty(list)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":未找到对应路由"); + throw new BadRequestException(this.device_code + ":未找到对应路由"); + } + HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver; + for (int i = 0; i < list.size(); i++) { + RouteLineDto dto = list.get(i); + String start_device_code = dto.getDevice_code(); + Device route_link_device = deviceAppservice.findDeviceByCode(start_device_code); + if (route_link_device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) route_link_device.getDeviceDriver(); + if (hailiangEngravingCacheDeviceDriver.getMove() != 1){ + continue; + } + int num = taskserver.querySameOriginTask(start_device_code); + if(num != 0){ + continue; + } + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + //onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_type("7"); + onedto.setTask_status("0"); + onedto.setPriority("1"); + onedto.setStart_device_code(start_device_code); + onedto.setStart_point_code(start_device_code); + onedto.setNext_device_code(this.getDevice().getDevice_code()); + onedto.setNext_point_code(this.getDevice().getDevice_code()); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + + try { + taskserver.create(onedto); + flag = true; + break; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务成功"); + } + } + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":专机生成任务成功"); + requireSucess = true; + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":条件不满足未找到起点设备"); + } + } + return true; + } + + public synchronized boolean apply_task() { + WQLObject runpointwo = WQLObject.getWQLObject("acs_device_runpoint"); + + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + Boolean flag = false; + List list = routeLineService.getShortPathLinesByCode(this.device_code, "normal"); + if (ObjectUtil.isEmpty(list)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":未找到对应路由"); + throw new BadRequestException(this.device_code + ":未找到对应路由"); + } + String link_device = this.getDevice().getExtraValue().get("link_device_code").toString(); + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(link_device); + if (ObjectUtil.isEmpty(order)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":关联设备" + link_device + "未找到对应设备工单"); + throw new BadRequestException(this.device_code + ":关联设备" + link_device + "未找到对应设备工单"); + } + if (order.getIs_needmove().equals("0")){ + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":关联设备" + link_device + "工单,不需要agv搬运"); + return false; + } + //查找当前工单对应的物料编号 + String cpbh = order.getMaterial_code(); + + HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver; + for (int i = 0; i < list.size(); i++) { + RouteLineDto dto = list.get(i); + String next_device_code = dto.getNext_device_code(); + Device route_link_device = deviceAppservice.findDeviceByCode(next_device_code); + + if (route_link_device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) route_link_device.getDeviceDriver(); + if (hailiangEngravingCacheDeviceDriver.getMove() != 0){ + continue; + } + int num = taskserver.querySameDestinationTask(next_device_code); + if(num != 0){ + continue; + } + //判断缓存位是否锁定 + JSONObject jsonObject = runpointwo.query("device_code = '" + next_device_code + "' and islock = '1'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(jsonObject)){ + continue; + } + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + //onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_type("6"); + onedto.setTask_status("0"); + onedto.setPriority("1"); + onedto.setMaterial(cpbh); + // TODO 任务中物料数量要不要赋值 + onedto.setQuantity(order.getQty() + ""); + onedto.setStart_device_code(this.getDevice().getDevice_code()); + onedto.setStart_point_code(this.getDevice().getDevice_code()); + onedto.setNext_device_code(next_device_code); + onedto.setNext_point_code(next_device_code); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + try { + taskserver.create(onedto); + //任务创建成功 锁定 + JSONObject map = new JSONObject(); + map.put("islock","1"); + map.put("update_by","auto"); + map.put("update_time", DateUtil.now()); + runpointwo.update(map,"device_code = '" + next_device_code + "'"); + flag = true; + break; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务成功"); + } + } + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":刻字机满料请求任务生成成功"); + requireSucess = true; + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":条件不满足未找到起点设备"); + } + } + return true; + } + + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, value); + logServer.deviceExecuteLog(this.device_code,"","","下发信号:" + key + ",value:"+value); + ReadUtil.write(itemMap, server); + } + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/ItemProtocol.java new file mode 100644 index 00000000..43289f20 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_engraving_machine/ItemProtocol.java @@ -0,0 +1,228 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_machine; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_status = "status";//线体状态 + public static String item_is_open = "is_open";//线体开机状态 + public static String item_is_running = "is_running";//刻字机运行状态 + public static String item_empty_req = "empty_req";//空箱请求 + public static String item_move = "move";//有货 + public static String item_full_req = "full_req";//满箱请求 + public static String item_full_finish = "full_finish";//满箱完成 + public static String item_order_finish = "order_finish";//订单完成 + public static String item_engraving_prepare = "engraving_prepare";//刻字机准备 + public static String item_engraving_ready = "engraving_ready";//刻字机就绪 + public static String item_line_ready = "line_ready";//线体就绪 + public static String item_mode = "mode";//模式 所有设备就绪 + public static String item_error = "error"; //报警信号 + public static String item_order_now = "order_now"; //订单实时 + public static String item_one_now = "one_now"; //每框实时 + public static String item_task = "task"; //任务号 + public static String item_port_full_num = "port_full_num"; //出料口满框数量 + public static String item_lettering_silo_number = "lettering_silo_number"; //刻字机储料仓数量 + public static String item_open_ready_time = "open_ready_time"; //开机准备时间(S) + public static String item_device_running_time = "device_running_time"; //设备运转时间(S) + public static String item_await_time = "await_time"; //待机时间(S) + public static String item_order = "order"; //工单号 + + //开机 + public static String item_to_open = "to_open"; + //AGV放空箱完成 + public static String item_to_agv_empty_finish = "to_agv_empty_finish"; + //刻字信息 + public static String item_to_engraving_info = "to_engraving_info"; + //产量清零 + public static String item_to_clear = "to_clear"; + //确认完成(订单完成状态置零) + public static String item_to_confirm_finished = "to_confirm_finished"; + //暂停 + public static String item_to_pause = "to_pause"; + //工单强制完成 + public static String item_to_order_compel_finished = "to_order_compel_finished"; + //订单生产总量 + public static String item_to_order_prod_num = "to_order_prod_num"; + //每框接料数量 + public static String item_to_one_box_num = "to_one_box_num"; + //任务号 + public static String item_to_task = "to_task"; + //刻字机倒料数量 + public static String item_to_dumping_num = "to_to_dumping_num"; + //工单号 + public static String item_to_order = "to_order"; + + + private HailiangEngravingMachineDeviceDriver driver; + + public ItemProtocol(HailiangEngravingMachineDeviceDriver driver) { + this.driver = driver; + } + + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_status() { + return this.getOpcIntegerValue(item_status); + } + + public int getItem_is_open() { + return this.getOpcIntegerValue(item_is_open); + } + + public int getItem_is_running() { + return this.getOpcIntegerValue(item_is_running); + } + + public int getItem_empty_req() { + return this.getOpcIntegerValue(item_empty_req); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_full_req() { + return this.getOpcIntegerValue(item_full_req); + } + + public int getItem_full_finish() { + return this.getOpcIntegerValue(item_full_finish); + } + + public int getItem_order_finish() { + return this.getOpcIntegerValue(item_order_finish); + } + + public int getItem_engraving_prepare() { + return this.getOpcIntegerValue(item_engraving_prepare); + } + + public int getItem_engraving_ready() { + return this.getOpcIntegerValue(item_engraving_ready); + } + + public int getItem_line_ready() { + return this.getOpcIntegerValue(item_line_ready); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_order_now() { + return this.getOpcIntegerValue(item_order_now); + } + + public int getItem_one_now() { + return this.getOpcIntegerValue(item_one_now); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + public int getItem_port_full_num() { + return this.getOpcIntegerValue(item_port_full_num); + } + + public int getItem_lettering_silo_number() { + return this.getOpcIntegerValue(item_lettering_silo_number); + } + + public int getItem_open_ready_time() { + return this.getOpcIntegerValue(item_open_ready_time); + } + + public int getItem_device_running_time() { + return this.getOpcIntegerValue(item_device_running_time); + } + + public int getItem_await_time() { + return this.getOpcIntegerValue(item_await_time); + } + + public int getItem_order() { + return this.getOpcIntegerValue(item_order); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_status, "线体状态", "DB1.B0.0")); + list.add(new ItemDto(item_is_open, "线体开机状态", "DB1.B0.1")); + list.add(new ItemDto(item_is_running, "刻字机运行状态", "DB1.B0.3")); + list.add(new ItemDto(item_empty_req, "空箱请求", "DB1.B0.5")); + list.add(new ItemDto(item_move, "光电信号", "DB1.B0.7")); + list.add(new ItemDto(item_full_req, "满箱请求", "DB1.B1.0")); + list.add(new ItemDto(item_full_finish, "满箱完成", "DB1.B1.1")); + list.add(new ItemDto(item_order_finish, "订单完成", "DB1.B1.2")); + list.add(new ItemDto(item_engraving_prepare, "刻字机准备", "DB1.B1.3")); + list.add(new ItemDto(item_engraving_ready, "刻字机就绪", "DB1.B1.4")); + list.add(new ItemDto(item_line_ready, "线体就绪", "DB1.B1.5")); + list.add(new ItemDto(item_mode, "模式", "DB1.B1.6")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_order_now, "订单实时", "DB1.D84")); + list.add(new ItemDto(item_one_now, "每框实时", "DB1.D88")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_port_full_num, "出料口满框数量", "DB1.D96")); + list.add(new ItemDto(item_lettering_silo_number, "刻字机储料仓数量", "DB1.D100")); + list.add(new ItemDto(item_open_ready_time, "开机准备时间", "DB1.D108")); + list.add(new ItemDto(item_device_running_time, "设备运转时间", "DB1.D112")); + list.add(new ItemDto(item_await_time, "待机时间", "DB1.D116")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB2.W4", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_agv_empty_finish, "AGV放空箱完成", "DB2.W8")); + list.add(new ItemDto(item_to_engraving_info, "刻字信息", "DB2.W10")); + list.add(new ItemDto(item_to_clear, "当前产量清零", "DB2.W12")); + list.add(new ItemDto(item_to_confirm_finished, "确认完成", "DB2.W14")); + list.add(new ItemDto(item_to_pause, "暂停", "DB2.W16")); + list.add(new ItemDto(item_to_order_compel_finished, "工单强制完成", "DB2.W82")); + list.add(new ItemDto(item_to_order_prod_num, "订单生产总量", "DB2.D84")); + list.add(new ItemDto(item_to_one_box_num, "每箱接料数量", "DB2.D88")); + list.add(new ItemDto(item_to_task, "任务号", "DB2.D92")); + list.add(new ItemDto(item_to_dumping_num, "刻字机倒料数量", "DB2.D100")); + list.add(new ItemDto(item_to_order, "工单号", "DB2.D160")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/HailiangFoldingDiscSmartDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/HailiangFoldingDiscSmartDefination.java new file mode 100644 index 00000000..53ecc5c8 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/HailiangFoldingDiscSmartDefination.java @@ -0,0 +1,74 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_foldingDisc_smart; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮-叠盘位Smart200 + */ +@Service +public class HailiangFoldingDiscSmartDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_foldingDisc_smart"; + } + + @Override + public String getDriverName() { + return "海亮-叠盘位Smart200"; + } + + @Override + public String getDriverDescription() { + return "海亮-叠盘位Smart200"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangFoldingDiscSmartDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangFoldingDiscSmartDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "VW2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_move, "光电信号", "VW4")); + list.add(new ItemDto(ItemProtocol.item_number, "数量", "VW6")); + list.add(new ItemDto(ItemProtocol.item_container_type, "托盘类型", "VW8")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "VW10")); + list.add(new ItemDto(ItemProtocol.item_task, "任务号", "VD12")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/HailiangFoldingDiscSmartDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/HailiangFoldingDiscSmartDeviceDriver.java new file mode 100644 index 00000000..825178de --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/HailiangFoldingDiscSmartDeviceDriver.java @@ -0,0 +1,257 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_foldingDisc_smart; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮-叠盘位Smart200 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangFoldingDiscSmartDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int move = 0; + int task = 0; + int number = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_number = 0; + int last_container_type = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getError(); + number = this.itemProtocol.getNumber(); + move = this.itemProtocol.getMove(); + task = this.itemProtocol.getTask(); + hasGoods = this.itemProtocol.getMove(); + container_type = this.itemProtocol.getContainer_type(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (number != last_number) { + logServer.deviceItemValue(this.device_code,"number" ,String.valueOf(number)); + logServer.deviceExecuteLog(this.device_code,"","","信号number:" + last_number + "->" + number); + } + if (container_type != last_container_type) { + logServer.deviceItemValue(this.device_code,"container_type" ,String.valueOf(container_type)); + logServer.deviceExecuteLog(this.device_code,"","","信号container_type:" + last_container_type + "->" + container_type); + } + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + break; + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_number = number; + last_container_type = container_type; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + } else if (type == 2) { + itemMap.put(to_target, command); + + } else if (type == 3) { + itemMap.put(to_task, command); + } + ReadUtil.write(itemMap, server); + + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/ItemProtocol.java new file mode 100644 index 00000000..64dd0920 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_foldingDisc_smart/ItemProtocol.java @@ -0,0 +1,113 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_foldingDisc_smart; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_number = "number"; + public static String item_container_type = "container_type"; + public static String item_error = "error"; + public static String item_task = "task"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + public static String item_weight = "weight"; + + private HailiangFoldingDiscSmartDeviceDriver driver; + + public ItemProtocol(HailiangFoldingDiscSmartDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getNumber() { + return this.getOpcIntegerValue(item_number); + } + + public int getContainer_type() { + return this.getOpcIntegerValue(item_container_type); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作状态", "VW2", Boolean.valueOf(true))); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_number, "数量", "VW6")); + list.add(new ItemDto(item_container_type, "托盘类型", "VW8")); + list.add(new ItemDto(item_error, "报警信号", "VW10")); + list.add(new ItemDto(item_task, "任务号", "VD12")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "VW52", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "目标站", "VW54")); + list.add(new ItemDto(item_to_task, "任务号", "VD58")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/HailiangPackerStationDefination.java similarity index 71% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/HailiangPackerStationDefination.java index e22c4a53..b72ab031 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/HailiangPackerStationDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.oven_manipulator; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -11,41 +11,40 @@ import java.util.LinkedList; import java.util.List; /** - * 烘箱-行架机械手 - * + * 海亮包装机工位 */ @Service -public class OvenGantryManipulatorDefination implements OpcDeviceDriverDefination { +public class HailiangPackerStationDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "oven_manipulator"; + return "hailiang_packer_station"; } @Override public String getDriverName() { - return "烘箱-行架机械手"; + return "海亮-包装机工位"; } @Override public String getDriverDescription() { - return "烘箱-行架机械手"; + return "海亮-包装机工位"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new OvenGantryManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HailiangPackerStationDeviceDriver()).setDevice(device).setDriverDefination(this); } @Override public Class getDeviceDriverType() { - return OvenGantryManipulatorDeviceDriver.class; + return HailiangPackerStationDeviceDriver.class; } @Override public List getFitDeviceTypes() { List types = new LinkedList(); - types.add(DeviceType.station); + types.add(DeviceType.conveyor); return types; } @@ -54,8 +53,6 @@ public class OvenGantryManipulatorDefination implements OpcDeviceDriverDefinatio return ItemProtocol.getReadableItemDtos(); } - - @Override public List getWriteableItemDtos() { return ItemProtocol.getWriteableItemDtos(); diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/HailiangPackerStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/HailiangPackerStationDeviceDriver.java new file mode 100644 index 00000000..817219ff --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/HailiangPackerStationDeviceDriver.java @@ -0,0 +1,794 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_cache.HailiangEngravingCacheDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮包装机工位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangPackerStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + + String container; + + int heartbeat = 0; + int packer_ready = 0;//包装机就绪 + int mode = 0;//模式 所有设备就绪 + int move = 0;//有货 + int order_finish = 0;//订单完成 + int lack_req = 0;//缺料请求 + int hopper_already = 0;//料斗已就位 + int req_task_empty = 0;//请求取空料斗 + int hopper_removed = 0;//料斗已取走 + int error = 0; //报警信号 + int order_now = 0; //订单实时 + int open_ready_time = 0; //开机准备时间(S) + int device_running_time = 0; //设备运转时间(S) + int await_time = 0; //待机时间(S) + int order = 0; //工单号 + //出入库模式 + int last_heartbeat = 0; + int operation_type = 0; + int last_packer_ready = 0;//包装机就绪 + int last_mode = 0;//模式 所有设备就绪 + int last_move = 0;//有货 + int last_order_finish = 0;//订单完成 + int last_lack_req = 0;//缺料请求 + int last_hopper_already = 0;//料斗已就位 + int last_req_task_empty = 0;//请求取空料斗 + int last_hopper_removed = 0;//料斗已取走 + int last_error = 0; //报警信号 + int last_order_now = 0; //订单实时 + int last_open_ready_time = 0; //开机准备时间(S) + int last_device_running_time = 0; //设备运转时间(S) + int last_await_time = 0; //待机时间(S) + int last_order = 0; //工单号 + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + + private long last_feedDeviceStatusTime = 0; + private long feedDeviceStatusTime = System.currentTimeMillis(); + + //请求成功标记 + Boolean requireSucess = false; + Boolean fullrequireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int status_type = 0; + int last_status_type = 0; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + int agvphase = 0; + int index = 0; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public synchronized void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + packer_ready = this.itemProtocol.getItem_packer_ready();//包装机就绪 + lack_req = this.itemProtocol.getItem_lack_req();//缺料请求 + hopper_already = this.itemProtocol.getItem_hopper_already();//料斗已就位 + req_task_empty = this.itemProtocol.getItem_req_task_empty();//请求取空料斗 + hopper_removed = this.itemProtocol.getItem_hopper_removed();//料斗已取走 + mode = this.itemProtocol.getItem_mode();//模式 所有设备就绪 + move = this.itemProtocol.getItem_move();//有货 + order_finish = this.itemProtocol.getItem_order_finish();//订单完成 + error = this.itemProtocol.getItem_error(); //报警信号 + order_now = this.itemProtocol.getItem_order_now(); //订单实时 + open_ready_time = this.itemProtocol.getItem_open_ready_time(); //开机准备时间(S) + device_running_time = this.itemProtocol.getItem_device_running_time(); //设备运转时间(S) + await_time = this.itemProtocol.getItem_await_time(); //待机时间(S) + order = this.itemProtocol.getItem_order(); //工单号 + if (mode != last_mode) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (packer_ready != last_packer_ready) { + logServer.deviceItemValue(this.device_code, "packer_ready", String.valueOf(packer_ready)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号packer_ready:" + last_packer_ready + "->" + packer_ready); + } + if (lack_req != last_lack_req) { + if (lack_req == 0) { + this.setRequireSucess(false); + } + logServer.deviceItemValue(this.device_code, "lack_req", String.valueOf(lack_req)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号lack_req:" + last_lack_req + "->" + lack_req); + } + if (hopper_already != last_hopper_already) { + logServer.deviceItemValue(this.device_code, "hopper_already", String.valueOf(hopper_already)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号hopper_already:" + last_hopper_already + "->" + hopper_already); + } + if (req_task_empty != last_req_task_empty) { + if (req_task_empty == 0) { + this.setFullrequireSucess(false); + } + logServer.deviceItemValue(this.device_code, "req_task_empty", String.valueOf(req_task_empty)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号req_task_empty:" + last_req_task_empty + "->" + req_task_empty); + } + if (hopper_removed != last_hopper_removed) { + logServer.deviceItemValue(this.device_code, "hopper_removed", String.valueOf(hopper_removed)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号hopper_removed:" + last_hopper_removed + "->" + hopper_removed); + } + + if (order_finish != last_order_finish) { + logServer.deviceItemValue(this.device_code, "order_finish", String.valueOf(order_finish)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号order_finish:" + last_order_finish + "->" + order_finish); + } + + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (order_now != last_order_now) { + logServer.deviceItemValue(this.device_code, "order_now", String.valueOf(order_now)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号order_now:" + last_order_now + "->" + order_now); + if (mode == 1 && order > 0) { + JSONObject map = new JSONObject(); + map.put("order", order); + map.put("real_qty", order_now); + try { + acsToWmsService.feedOrderRealQty(map); + } catch (Exception e) { + log.error("工单数量反馈失败,设备{},原因{}", device_code, e.getMessage()); + } + } + } + + if (order != last_order) { + logServer.deviceItemValue(this.device_code, "order", String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号order:" + last_order + "->" + order); + } + + + int realError = 0; + if (!this.itemProtocol.getIsonline()) { + status_type = 01; + } else { + status_type = 02; + if (error == 1 || error == 51) { + status_type = 05; + realError = error; + } else if (mode == 1 && order > 0) { + status_type = 03; + realError = 0; + } else if (mode == 0 && order > 0) { + realError = 0; + status_type = 04; + } + } + if (status_type != last_status_type) { + JSONObject map = new JSONObject(); + map.put("device_code", device_code); + map.put("status_type", "0" + status_type); + map.put("start_time", DateUtil.now()); + map.put("error_code", realError); + try { + acsToWmsService.feedDeviceStatusType(map); + last_status_type = status_type; + } catch (Exception e) { + log.error("设备状态反馈失败,设备{},原因{}", device_code, e.getMessage()); + } + } + synchronized (this) { +// int realError = 0; +// long now_feedTime = System.currentTimeMillis(); +// if (now_feedTime - last_feedDeviceStatusTime >= 5000){ +// heartbeat = this.itemProtocol.getItem_heartbeat(); +// if (heartbeat == last_heartbeat){ +// status_type = 01; +// } else { +// status_type = 02; +// if (error == 1 || error == 51) { +// status_type = 05; +// realError = error; +// }else if (mode == 1 && order > 0) { +// status_type = 03; +// realError = 0; +// } else if (mode == 0 && order > 0) { +// status_type = 04; +// realError = 0; +// } +// } +// if (status_type != last_status_type) { +// JSONObject map = new JSONObject(); +// map.put("device_code", device_code); +// map.put("status_type", "0" + status_type); +// map.put("error_code",realError); +// map.put("start_time", DateUtil.now()); +// acsToWmsService.feedDeviceStatusType(map); +// last_status_type = status_type; +// } +// last_heartbeat = heartbeat; +// last_feedDeviceStatusTime = now_feedTime; +// } + } + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 +// } else if (mode == 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "未联机"; +// //有报警 +// } else if (error != 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "有报警"; +// //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + if (mode == 1 && order_finish != last_order_finish && order_finish == 1 && order > 0) { + ProduceshiftorderDto dto = new ProduceshiftorderDto(); + dto.setOrder_code(order + ""); + dto.setOrder_status("2"); + ProduceshiftorderDto deviceInfo = produceshiftorderService.findOrderByDeviceCode(this.device_code); + if (deviceInfo != null) { + if (StrUtil.isNotEmpty(deviceInfo.getExt_order_id())) { + String ext_order_id = deviceInfo.getExt_order_id(); + JSONObject param = new JSONObject(); + param.put("ext_order_id", ext_order_id); + acsToWmsService.feedbackOrderStatus(param); + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单的外部标识:" + ext_order_id); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单的没有外部标识"); + } + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单信息为空"); + } + produceshiftorderService.updateByOrderCode(dto); + this.writing("to_confirm_finished", "1"); + this.writing("to_order", "0"); + this.writing("to_clear", "1"); + this.writing("to_pause", "1"); + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,任务确认完成,电器信号写入成功"); + } /*else { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":,order_finish>"+ order_finish +",last_order_finish>"+last_order_finish + "mode:" + mode + "order:" + order); + }*/ + + if (ObjectUtil.isEmpty(inst)) { + if (!requireSucess) { + if (mode == 1 && lack_req == 1 && move == 0) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,move:" + move + ",mode:" + mode + ",requireSucess:" + requireSucess + "开始申请缺料请求任务"); + apply_task(); + } + } + if (!fullrequireSucess) { + if (mode == 1 && req_task_empty == 1 && move == 1) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,move:" + move + ",mode:" + mode + ",fullrequireSucess:" + fullrequireSucess + "开始申请请求取走空料斗任务"); + apply_take_empty_task(); + } + } + } + + + if (agvphase == 0x03) { + //&& lack_req =1 缺料请求 先不判断 + /*if( move == 1 && error == 0 && ObjectUtil.isNotEmpty(inst)){*/ + inst.setExecute_status("1"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); + /* } else { + logServer.deviceLogToacs(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因move:"+move+",error:"+error+",inst"+inst); + + }*/ + } + + if (agvphase == 0x05) { + if (move == 0 && error == 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("2"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + writing("to_agv_take_finish", "1"); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈,原因move:" + move + ",error:" + error + ",inst" + inst); + } + } + + if (agvphase == 0x07) { + if (move == 0 && error == 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("5"); + instructionService.update(inst); + //writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈,原因move:" + move + ",error:" + error + ",inst" + inst); + + } + } + + if (agvphase == 0x09) { + if (move == 1 && error == 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("6"); + instructionService.update(inst); + writing("to_agv_release_finish", "1"); + byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0); + OneNDCSocketConnectionAutoRun.write(data); + String next_device_code = inst.getNext_device_code(); + Device next_device = deviceAppservice.findDeviceByCode(next_device_code); + next_device.setMaterial_type(inst.getMaterial()); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈,move:" + move + ",error:" + error + ",inst:" + inst); + + } + } + } + last_packer_ready = packer_ready;//包装机就绪 + last_lack_req = lack_req;//缺料请求 + last_hopper_already = hopper_already;//料斗已就位 + last_req_task_empty = req_task_empty;//请求取空料斗 + last_hopper_removed = hopper_removed;//料斗已取走 + last_move = move;//有货 + last_order_finish = order_finish;//订单完成 + last_mode = mode;//模式 所有设备就绪 + last_error = error; //报警信号 + last_order_now = order_now; //订单实时 + last_open_ready_time = open_ready_time; //开机准备时间(S) + last_device_running_time = device_running_time; //设备运转时间(S) + last_await_time = await_time; //待机时间(S) + last_order = order; //工单号 + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public synchronized boolean apply_take_empty_task() { + WQLObject runpointwo = WQLObject.getWQLObject("acs_device_runpoint"); + + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + Boolean flag = false; + List list = routeLineService.getShortPathLinesByCode(this.device_code, "normal"); + if (ObjectUtil.isEmpty(list)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":未找到对应路由"); + throw new BadRequestException(this.device_code + ":未找到对应路由"); + } + String link_device = this.getDevice().getExtraValue().get("link_device_code").toString(); + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(link_device); + if (ObjectUtil.isEmpty(order)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":关联设备" + link_device + "未找到对应设备工单"); + throw new BadRequestException(this.device_code + ":关联设备" + link_device + "未找到对应设备工单"); + } + HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver; + for (int i = 0; i < list.size(); i++) { + RouteLineDto dto = list.get(i); + String next_device_code = dto.getNext_device_code(); + Device route_link_device = deviceAppservice.findDeviceByCode(next_device_code); + if (route_link_device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) route_link_device.getDeviceDriver(); + if (hailiangEngravingCacheDeviceDriver.getMove() != 0) { + continue; + } + //querySameDestinationTask 查询是否有相同终点的任务 + int num = taskserver.querySameDestinationTask(next_device_code); + int numE = taskserver.querySameOriginTask(this.getDevice_code()); + if (num != 0 || numE != 0) { + continue; + } + //判断缓存位是否锁定 + JSONObject jsonObject = runpointwo.query("device_code = '" + next_device_code + "' and islock = '1'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(jsonObject)) { + logServer.deviceExecuteLog(this.device_code, "", "", "对应路由设备," + next_device_code + "已锁定"); + continue; + } + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + //onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_type("7"); + onedto.setTask_status("0"); + onedto.setPriority("1"); + onedto.setStart_device_code(this.getDevice().getDevice_code()); + onedto.setStart_point_code(this.getDevice().getDevice_code()); + onedto.setNext_device_code(next_device_code); + onedto.setNext_point_code(next_device_code); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + try { + taskserver.create(onedto); + //任务创建成功 锁定 + JSONObject map = new JSONObject(); + map.put("islock", "1"); + map.put("update_by", "auto"); + map.put("update_time", DateUtil.now()); + runpointwo.update(map, "device_code = '" + next_device_code + "'"); + flag = true; + break; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + } + } + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":取走空料斗任务创建成功"); + fullrequireSucess = true; + } else { + //如果都没有则调用mes接口申请入缓存线 + //生成任务 + //前往缓存线 + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":分配任务缓存线"); + } + } + return true; + } + + public synchronized boolean apply_task() { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + Boolean flag = false; + List list = routeLineService.getPathLinesByCode(this.device_code, "normal"); + if (ObjectUtil.isEmpty(list)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":未找到对应路由"); + throw new BadRequestException(this.device_code + ":未找到对应路由"); + } + String link_device = this.getDevice().getExtraValue().get("link_device_code").toString(); + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(link_device); + if (ObjectUtil.isEmpty(order)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":关联设备" + link_device + "未找到对应设备工单"); + throw new BadRequestException(this.device_code + ":关联设备" + link_device + "未找到对应设备工单"); + } + + if (StrUtil.isNotEmpty(order.getIs_needmove()) && order.getIs_needmove().equals("0")) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":关联设备" + link_device + "工单,不需要agv搬运"); + return false; + } + //查找当前工单对应的物料编号 + String cpbh = order.getMaterial_code(); + + HailiangEngravingCacheDeviceDriver hailiangEngravingCacheDeviceDriver; + for (int i = 0; i < list.size(); i++) { + RouteLineDto dto = list.get(i); + String start_device_code = dto.getDevice_code(); + Device route_link_device = deviceAppservice.findDeviceByCode(start_device_code); + if (route_link_device.getDeviceDriver() instanceof HailiangEngravingCacheDeviceDriver) { + hailiangEngravingCacheDeviceDriver = (HailiangEngravingCacheDeviceDriver) route_link_device.getDeviceDriver(); + if (hailiangEngravingCacheDeviceDriver.getMove() == 0 || hailiangEngravingCacheDeviceDriver.getMove() == 1) { + continue; + } + //querySameOriginTask 查询是否有相同起点的任务 + int num = taskserver.querySameOriginTask(start_device_code); + int numN = taskserver.querySameDestinationTask(this.getDevice_code()); + if (num != 0 || numN != 0) { + continue; + } + String material = route_link_device.getMaterial_type(); + if (StrUtil.isEmpty(material)) { + logServer.deviceExecuteLog(this.device_code, "", "", hailiangEngravingCacheDeviceDriver.getDevice_code() + ":缓存位物料为空"); + continue; + } + if (material.equals(cpbh)) { + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + //onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_type("7"); + onedto.setTask_status("0"); + onedto.setPriority("1"); + // TODO 任务中物料数量要不要赋值 + onedto.setQuantity(order.getQty() + ""); + onedto.setStart_device_code(start_device_code); + onedto.setStart_point_code(start_device_code); + onedto.setNext_device_code(this.getDevice().getDevice_code()); + onedto.setNext_point_code(this.getDevice().getDevice_code()); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + try { + taskserver.create(onedto); + flag = true; + break; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + } + } + } + + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":缺料请求任务生成成功"); + requireSucess = true; + } else { + //如果都没有则调用mes接口申请入缓存线 + //生成任务 + //前往缓存线 + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":分配任务缓存线"); + } + } + return true; + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, value); + logServer.deviceExecuteLog(this.device_code, "", "", "下发信号:" + key + ",value:" + value); + ReadUtil.write(itemMap, server); + } + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("1"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } + + @Override + public String toString() { + return ""; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/ItemProtocol.java new file mode 100644 index 00000000..dcf44f8f --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_packer_station/ItemProtocol.java @@ -0,0 +1,175 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_packer_ready = "packer_ready";//包装机就绪 + public static String item_mode = "mode";//模式 所有设备就绪 + public static String item_move = "move";//有货 + public static String item_order_finish = "order_finish";//订单完成 + public static String item_lack_req = "lack_req";//缺料请求 + public static String item_hopper_already = "hopper_already";//料斗已就位 + public static String item_req_task_empty = "req_task_empty";//请求取空料斗 + public static String item_hopper_removed = "hopper_removed";//料斗已取走 + public static String item_error = "error"; //报警信号 + public static String item_order_now = "order_now"; //订单实时 + public static String item_open_ready_time = "open_ready_time"; //开机准备时间(S) + public static String item_device_running_time = "device_running_time"; //设备运转时间(S) + public static String item_await_time = "await_time"; //待机时间(S) + public static String item_order = "order"; //工单号 + + //开机 + public static String item_to_open = "to_open"; + //AGV放货完成 + public static String item_to_agv_release_finish = "to_agv_release_finish"; + //AGV取货完成 + public static String item_to_agv_take_finish = "to_agv_take_finish"; + //产量清零 + public static String item_to_clear = "to_clear"; + //确认完成(订单完成状态置零) + public static String item_to_confirm_finished = "to_confirm_finished"; + //工单强制完成 + public static String item_to_order_compel_finished = "to_order_compel_finished"; + //订单生产总量 + public static String item_to_order_prod_num = "to_order_prod_num"; + //工单号 + public static String item_to_order = "to_order"; + + + private HailiangPackerStationDeviceDriver driver; + + public ItemProtocol(HailiangPackerStationDeviceDriver driver) { + this.driver = driver; + } + + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + + public int getItem_order_finish() { + return this.getOpcIntegerValue(item_order_finish); + } + + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_order_now() { + return this.getOpcIntegerValue(item_order_now); + } + + + public int getItem_open_ready_time() { + return this.getOpcIntegerValue(item_open_ready_time); + } + + public int getItem_device_running_time() { + return this.getOpcIntegerValue(item_device_running_time); + } + + public int getItem_await_time() { + return this.getOpcIntegerValue(item_await_time); + } + + public int getItem_order() { + return this.getOpcIntegerValue(item_order); + } + + public int getItem_packer_ready() { + return this.getOpcIntegerValue(item_packer_ready); + } + + public int getItem_lack_req() { + return this.getOpcIntegerValue(item_lack_req); + } + + public int getItem_hopper_already() { + return this.getOpcIntegerValue(item_hopper_already); + } + + public int getItem_req_task_empty() { + return this.getOpcIntegerValue(item_req_task_empty); + } + + public int getItem_hopper_removed() { + return this.getOpcIntegerValue(item_hopper_removed); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_packer_ready, "包装机就绪", "DB1.B0.5")); + list.add(new ItemDto(item_mode, "模式", "DB1.B0.6")); + list.add(new ItemDto(item_move, "光电信号", "DB1.B1.0")); + list.add(new ItemDto(item_order_finish, "订单完成", "DB1.B1.5")); + list.add(new ItemDto(item_lack_req, "缺料请求", "DB1.B2.0")); + list.add(new ItemDto(item_hopper_already, "料斗已到位", "DB1.B2.1")); + list.add(new ItemDto(item_req_task_empty, "请求取空料斗", "DB1.B2.6")); + list.add(new ItemDto(item_hopper_removed, "料斗已取走", "DB1.B2.7")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_order_now, "订单实时", "DB1.D84")); + list.add(new ItemDto(item_open_ready_time, "开机准备时间", "DB1.D108")); + list.add(new ItemDto(item_device_running_time, "设备运转时间", "DB1.D112")); + list.add(new ItemDto(item_await_time, "待机时间", "DB1.D116")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB2.W4", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_agv_release_finish, "AGV放货完成", "DB2.W6")); + list.add(new ItemDto(item_to_agv_take_finish, "AGV取货完成", "DB2.W8")); + list.add(new ItemDto(item_to_clear, "当前产量清零", "DB2.W12")); + list.add(new ItemDto(item_to_confirm_finished, "确认完成", "DB2.W14")); + list.add(new ItemDto(item_to_order_compel_finished, "工单强制完成", "DB2.W82")); + list.add(new ItemDto(item_to_order_prod_num, "订单生产总量", "DB2.D84")); + list.add(new ItemDto(item_to_order, "工单号", "DB2.D160")); + return list; + } + + @Override + public String toString() { + return "ItemProtocol{}"; + } +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/HailiangPaintLineDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/HailiangPaintLineDefination.java new file mode 100644 index 00000000..3be39726 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/HailiangPaintLineDefination.java @@ -0,0 +1,74 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_paint_line; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮-油漆线 + */ +@Service +public class HailiangPaintLineDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_paint_line"; + } + + @Override + public String getDriverName() { + return "海亮-油漆线"; + } + + @Override + public String getDriverDescription() { + return "海亮-油漆线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangPaintLineDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangPaintLineDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_move, "光电信号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_action, "取放信号", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "DB600.B6")); + list.add(new ItemDto(ItemProtocol.item_number, "数量", "DB600.B7")); + list.add(new ItemDto(ItemProtocol.item_task, "任务号", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/HailiangPaintLineDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/HailiangPaintLineDeviceDriver.java new file mode 100644 index 00000000..e178f203 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/HailiangPaintLineDeviceDriver.java @@ -0,0 +1,257 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_paint_line; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮-油漆线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangPaintLineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int move = 0; + int task = 0; + int action = 0; + int number = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_action = 0; + int last_number = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getError(); + action = this.itemProtocol.getAction(); + move = this.itemProtocol.getMove(); + number = this.itemProtocol.getNumber(); + task = this.itemProtocol.getTask(); + hasGoods = this.itemProtocol.getMove(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code,"action" ,String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code,"","","信号action:" + last_action + "->" + action); + } + if (number != last_number) { + logServer.deviceItemValue(this.device_code,"number" ,String.valueOf(number)); + logServer.deviceExecuteLog(this.device_code,"","","信号number:" + last_number + "->" + number); + } + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + break; + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_action = action; + last_number = number; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + } else if (type == 2) { + itemMap.put(to_target, command); + + } else if (type == 3) { + itemMap.put(to_task, command); + } + ReadUtil.write(itemMap, server); + + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/ItemProtocol.java similarity index 50% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/ItemProtocol.java index c963542a..6bbb6308 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/ItemProtocol.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_paint_line/ItemProtocol.java @@ -1,6 +1,5 @@ -package org.nl.acs.device_driver.basedriver.oven_manipulator; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_paint_line; -import cn.hutool.core.util.StrUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; @@ -12,34 +11,21 @@ import java.util.List; @Data public class ItemProtocol { - //心跳 public static String item_heartbeat = "heartbeat"; - //工作模式 public static String item_mode = "mode"; - //光电信号 public static String item_move = "move"; - //动作信号 public static String item_action = "action"; - //行走列 - public static String item_walk_y = "walk_y"; - //报警 public static String item_error = "error"; - //任务号 + public static String item_number = "number"; public static String item_task = "task"; - - //下发命令 public static String item_to_command = "to_command"; - //下发起始站 - public static String item_to_onset = "to_onset"; - //下发目标站 public static String item_to_target = "to_target"; - //下发任务号 public static String item_to_task = "to_task"; + public static String item_weight = "weight"; + private HailiangPaintLineDeviceDriver driver; - private OvenGantryManipulatorDeviceDriver driver; - - public ItemProtocol(OvenGantryManipulatorDeviceDriver driver) { + public ItemProtocol(HailiangPaintLineDeviceDriver driver) { this.driver = driver; } @@ -59,25 +45,41 @@ public class ItemProtocol { return this.getOpcIntegerValue(item_action); } - public int getWalk_y() { - return this.getOpcIntegerValue(item_walk_y); - } - public int getError() { return this.getOpcIntegerValue(item_error); } + public int getNumber() { + return this.getOpcIntegerValue(item_number); + } + public int getTask() { return this.getOpcIntegerValue(item_task); } + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } Boolean isonline; public int getOpcIntegerValue(String protocol) { Integer value = this.driver.getIntegeregerValue(protocol); if (value == null) { - // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); setIsonline(false); } else { setIsonline(true); @@ -87,40 +89,25 @@ public class ItemProtocol { } - public String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (StrUtil.isEmpty(value)) { - - } else { - return value; - } - return "0"; - } - public static List getReadableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); - list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); - list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); - list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4")); - list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); - list.add(new ItemDto(item_task, "任务号", "DB1.D6")); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); + list.add(new ItemDto(item_action, "取放信号", "DB600.B4")); + list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); + list.add(new ItemDto(item_number, "数量", "DB600.B7")); + list.add(new ItemDto(item_task, "任务号", "DB600.D8")); return list; } public static List getWriteableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); - list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); + list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "目标站", "DB601.W4")); + list.add(new ItemDto(item_to_task, "任务号", "DB601.D8")); return list; } - @Override - public String toString() { - return ""; - } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java similarity index 70% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java index bce3297e..73e03b4c 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/HailiangSmartplcTestDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.plug_pull_device_site; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -11,33 +11,34 @@ import java.util.LinkedList; import java.util.List; /** - * 插拔轴工位 + * 海亮迅捷plc测试 */ @Service -public class PlugPullDeviceSiteDefination implements OpcDeviceDriverDefination { +public class HailiangSmartplcTestDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "plug_pull_device_site"; + return "hailiang_smart_plc_test"; } @Override public String getDriverName() { - return "插拔轴工位"; + return "海亮-西门子plc测试"; } @Override public String getDriverDescription() { - return "插拔轴工位"; + return "海亮-西门子plc测试"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new PlugPullDeviceSiteDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HailiangSmartplcTestDeviceDriver()).setDevice(device).setDriverDefination(this); + } @Override public Class getDeviceDriverType() { - return PlugPullDeviceSiteDeviceDriver.class; + return HailiangSmartplcTestDeviceDriver.class; } @Override diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java new file mode 100644 index 00000000..2c79764a --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/HailiangSmartplcTestDeviceDriver.java @@ -0,0 +1,302 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangSmartplcTestDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int heartbeat = 0; + int mode =0; + int error =0; + int error_num =0; + int open_time =0; + int close_time =0; + int ready_time =0; + int running_time =0; + int error_time =0; + int voltage =0; + int temperature =0; + int current =0; + int material =0; + int lack_material =0; + int full_material =0; + int storage_qty =0; + int feeding_qty =0; + int blanking_qty =0; + int qualified_qty =0; + int unqualified_qty =0; + int finish =0; + int task =0; + int noload_electricity_consumption =0; + int prod_electricity_consumption =0; + int gas_consumption =0; + int water_consumption =0; + int oil_level =0; + int monthly_electricity_consumption =0; + int pause =0; + + + int last_mode =0; + int last_error =0; + int last_error_num =0; + int last_open_time =0; + int last_close_time =0; + int last_ready_time =0; + int last_running_time =0; + int last_error_time =0; + int last_voltage =0; + int last_temperature =0; + int last_current =0; + int last_material =0; + int last_lack_material =0; + int last_full_material =0; + int last_storage_qty =0; + int last_feeding_qty =0; + int last_blanking_qty =0; + int last_qualified_qty =0; + int last_unqualified_qty =0; + int last_finish =0; + int last_task =0; + int last_noload_electricity_consumption =0; + int last_prod_electricity_consumption =0; + int last_gas_consumption =0; + int last_water_consumption =0; + int last_oil_level =0; + int last_monthly_electricity_consumption =0; + int last_pause =0; + + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + + int agvphase=0; + int index =0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute(){ + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + error = this.itemProtocol.getItem_error(); + error_num = this.itemProtocol.getItem_error_num(); + open_time = this.itemProtocol.getItem_open_time(); + close_time = this.itemProtocol.getItem_close_time(); + ready_time = this.itemProtocol.getItem_ready_time(); + running_time = this.itemProtocol.getItem_running_time(); + error_time = this.itemProtocol.getItem_error_time(); + voltage = this.itemProtocol.getItem_voltage(); + temperature = this.itemProtocol.getItem_temperature(); + current = this.itemProtocol.getItem_current(); + material = this.itemProtocol.getItem_material(); + lack_material = this.itemProtocol.getItem_lack_material(); + full_material = this.itemProtocol.getItem_full_material(); + storage_qty = this.itemProtocol.getItem_storage_qty(); + feeding_qty = this.itemProtocol.getItem_feeding_qty(); + blanking_qty = this.itemProtocol.getItem_blanking_qty(); + qualified_qty = this.itemProtocol.getItem_qualified_qty(); + unqualified_qty = this.itemProtocol.getItem_unqualified_qty(); + finish = this.itemProtocol.getItem_finish(); + task = this.itemProtocol.getItem_task(); + noload_electricity_consumption = this.itemProtocol.getItem_noload_electricity_consumption(); + prod_electricity_consumption = this.itemProtocol.getItem_prod_electricity_consumption(); + gas_consumption = this.itemProtocol.getItem_gas_consumption(); + water_consumption = this.itemProtocol.getItem_water_consumption(); + oil_level = this.itemProtocol.getItem_oil_level(); + monthly_electricity_consumption = this.itemProtocol.getItem_monthly_electricity_consumption(); + pause = this.itemProtocol.getItem_pause(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code,"finish" ,String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号finish:" + last_finish + "->" + finish); + if(finish == 1){ + ProduceshiftorderDto deviceInfo = produceshiftorderService.findOrderByDeviceCode(this.device_code); + deviceInfo.setOrder_status("2"); + produceshiftorderService.updateByOrderCode(deviceInfo); + } + } + last_finish = finish; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/ItemProtocol.java new file mode 100644 index 00000000..ecc8e3d3 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_smart_plc_test/ItemProtocol.java @@ -0,0 +1,248 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_error = "error"; + public static String item_error_num = "error_num"; + public static String item_open_time = "open_time"; + public static String item_close_time = "close_time"; // + public static String item_ready_time = "ready_time"; // + public static String item_running_time = "running_time"; + public static String item_error_time = "error_time"; + public static String item_voltage = "voltage"; + public static String item_temperature = "temperature"; + public static String item_current = "current"; + public static String item_material = "material"; + public static String item_lack_material = "lack_material"; + public static String item_full_material = "full_material"; + public static String item_storage_qty = "storage_qty"; + public static String item_feeding_qty = "feeding_qty"; + public static String item_blanking_qty = "blanking_qty"; + public static String item_qualified_qty = "qualified_qty"; + public static String item_unqualified_qty = "unqualified_qty"; + public static String item_finish = "finish"; + public static String item_task = "task"; + public static String item_noload_electricity_consumption = "noload_electricity_consumption"; + public static String item_prod_electricity_consumption = "prod_electricity_consumption"; + public static String item_gas_consumption = "gas_consumption"; + public static String item_water_consumption = "water_consumption"; + public static String item_oil_level = "oil_level"; + public static String item_monthly_electricity_consumption = "monthly_electricity_consumption"; + public static String item_pause = "pause"; + + + + public static String item_to_heartbeat = "to_heartbeat";// + public static String item_to_command = "to_command";// + public static String item_to_feeding = "to_feeding";// + public static String item_to_task = "to_task";// + public static String item_to_pause= "to_pause";// + public static String item_to_clear = "to_clear";// + public static String item_to_finish = "to_finish";// + public static String item_to_open = "to_open";// + public static String item_to_close = "to_close";// + public static String item_to_material = "to_material";// + public static String item_to_qty = "to_qty";// + + + private HailiangSmartplcTestDeviceDriver driver; + + public ItemProtocol(HailiangSmartplcTestDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_error_num() { + return this.getOpcIntegerValue(item_error_num); + } + + public int getItem_open_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getItem_close_time() { + return this.getOpcIntegerValue(item_close_time); + } + + public int getItem_ready_time() { + return this.getOpcIntegerValue(item_ready_time); + } + + public int getItem_running_time() { + return this.getOpcIntegerValue(item_running_time); + } + + public int getItem_error_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getItem_voltage() { + return this.getOpcIntegerValue(item_voltage); + } + + public int getItem_temperature() { + return this.getOpcIntegerValue(item_temperature); + } + + public int getItem_current() { + return this.getOpcIntegerValue(item_current); + } + + public int getItem_material() { + return this.getOpcIntegerValue(item_material); + } + + public int getItem_lack_material() { + return this.getOpcIntegerValue(item_lack_material); + } + + public int getItem_full_material() { + return this.getOpcIntegerValue(item_full_material); + } + + public int getItem_storage_qty() { + return this.getOpcIntegerValue(item_storage_qty); + } + + public int getItem_feeding_qty() { + return this.getOpcIntegerValue(item_feeding_qty); + } + + public int getItem_blanking_qty() { + return this.getOpcIntegerValue(item_blanking_qty); + } + + public int getItem_qualified_qty() { + return this.getOpcIntegerValue(item_qualified_qty); + } + + public int getItem_unqualified_qty() { + return this.getOpcIntegerValue(item_unqualified_qty); + } + + public int getItem_finish() { + return this.getOpcIntegerValue(item_finish); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + public int getItem_noload_electricity_consumption() { + return this.getOpcIntegerValue(item_noload_electricity_consumption); + } + + public int getItem_prod_electricity_consumption() { + return this.getOpcIntegerValue(item_prod_electricity_consumption); + } + + public int getItem_gas_consumption() { + return this.getOpcIntegerValue(item_gas_consumption); + } + + public int getItem_water_consumption() { + return this.getOpcIntegerValue(item_water_consumption); + } + + public int getItem_oil_level() { + return this.getOpcIntegerValue(item_oil_level); + } + + public int getItem_monthly_electricity_consumption() { + return this.getOpcIntegerValue(item_monthly_electricity_consumption); + } + + public int getItem_pause() { + return this.getOpcIntegerValue(item_pause); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "模式", "VW2")); + list.add(new ItemDto(item_error, "故障", "VW4")); + list.add(new ItemDto(item_error_num, "故障次数", "VD6")); + list.add(new ItemDto(item_open_time, "开机时间", "VD8")); + list.add(new ItemDto(item_close_time, "关机时间", "VD12")); + list.add(new ItemDto(item_ready_time, "待机时间", "VD16")); + list.add(new ItemDto(item_running_time, "生产时间", "VD20")); + list.add(new ItemDto(item_error_time, "故障时间", "VD24")); + list.add(new ItemDto(item_temperature, "温度", "VD28")); + list.add(new ItemDto(item_voltage, "电压", "VD32")); + list.add(new ItemDto(item_current, "电流", "VD36")); + list.add(new ItemDto(item_material, "当前生产产品编号", "VD40")); + list.add(new ItemDto(item_lack_material, "生产缺料信号", "VD44")); + list.add(new ItemDto(item_full_material, "生产满料信号", "VD48")); + list.add(new ItemDto(item_storage_qty, "储料斗数量", "VD52")); + list.add(new ItemDto(item_feeding_qty, "上料数量", "VD56")); + list.add(new ItemDto(item_blanking_qty, "下料数量", "VD60")); + list.add(new ItemDto(item_qualified_qty, "当前生产合格品数量", "VD64")); + list.add(new ItemDto(item_unqualified_qty, "当前生产不合格数量", "VD68")); + list.add(new ItemDto(item_finish, "生产完成", "VD72")); + list.add(new ItemDto(item_task, "任务号", "VD76")); + list.add(new ItemDto(item_noload_electricity_consumption, "空载电能耗(未生产时)", "VD80")); + list.add(new ItemDto(item_prod_electricity_consumption, "生产电能耗", "VD84")); + list.add(new ItemDto(item_gas_consumption, "气压能耗", "VD88")); + list.add(new ItemDto(item_water_consumption, "水流量能耗", "VD92")); + list.add(new ItemDto(item_oil_level, "当前液压油位", "VD96")); + list.add(new ItemDto(item_monthly_electricity_consumption, "本月总电能耗", "VD100")); + list.add(new ItemDto(item_pause, "设备暂停", "VD104")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_heartbeat, "心跳", "VW200")); + list.add(new ItemDto(item_to_command, "下发命令", "VW202")); + list.add(new ItemDto(item_to_feeding, "下发命令", "VW204")); + list.add(new ItemDto(item_to_task, "任务号", "VW208")); + list.add(new ItemDto(item_to_pause, "生产暂停", "VW212")); + list.add(new ItemDto(item_to_clear, "当前产量清零", "VW216")); + list.add(new ItemDto(item_to_finish, "强制完成", "VW220")); + list.add(new ItemDto(item_to_open, "设备开机", "VW224")); + list.add(new ItemDto(item_to_close, "设备关机", "VW228")); + list.add(new ItemDto(item_to_material, "当前任务生产物料", "VW232")); + list.add(new ItemDto(item_to_qty, "当前任务生产数量", "VW236")); + return list; + } + + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/HailiangSpecialDeviceDefination.java similarity index 71% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/HailiangSpecialDeviceDefination.java index 322e715d..23ae5456 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/HailiangSpecialDeviceDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.paint_conveyor; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_device; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -11,34 +11,34 @@ import java.util.LinkedList; import java.util.List; /** - * 油漆线 + * 海亮专机设备 */ @Service -public class PaintConveyorDefination implements OpcDeviceDriverDefination { +public class HailiangSpecialDeviceDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "paint_conveyor"; + return "hailiang_special_device"; } @Override public String getDriverName() { - return "油漆线"; + return "海亮-专机设备"; } @Override public String getDriverDescription() { - return "油漆线"; + return "海亮-专机设备"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new PaintConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HailiangSpecialDeviceDriver()).setDevice(device).setDriverDefination(this); } @Override public Class getDeviceDriverType() { - return PaintConveyorDeviceDriver.class; + return HailiangSpecialDeviceDriver.class; } @Override diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/HailiangSpecialDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/HailiangSpecialDeviceDriver.java new file mode 100644 index 00000000..dc031788 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/HailiangSpecialDeviceDriver.java @@ -0,0 +1,630 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_device; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮专机设备 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangSpecialDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + /* int move = 0;*/ + int task = 0; + int is_open = 0; + int running = 0; + int finish = 0; + int all_ready = 0; + int order_compel_finish = 0; + int order = 0; + int now_order_prod_num = 0; + int full_number = 0; + int now_one_box_num = 0; + int storage_stock_num = 0; + int line_stock_num = 0; + int open_ready_time = 0; + int device_running_time = 0; + int await_time = 0; + int order_prod_allnum = 0; + int empty_is_lack = 0; //空箱位缺箱 + int device_is_running = 0; //专机运行状态 + int empty_is_finish = 0; //空位完成 + int full_ready_req_agv = 0; //满箱位就绪,请求AGV + int full_out = 0; //满箱已运出满箱位 + int device_prepare = 0; //专机准备中 + int device_ready = 0; //专机就绪 + int line_ready = 0; //线体就绪 + int device_online = 0; //专机联机 + //出入库模式 + int operation_type = 0; + int last_mode = 0; + int last_error = 0; + /* int last_move = 0;*/ + int last_task = 0; + int last_is_open = 0; + int last_running = 0; + int last_finish = 0; + int last_all_ready = 0; + int last_order_compel_finish = 0; + int last_order = 0; + int last_now_order_prod_num = 0; + int last_full_number = 0; + int last_now_one_box_num = 0; + int last_storage_stock_num = 0; + int last_line_stock_num = 0; + int last_open_ready_time = 0; + int last_device_running_time = 0; + int last_await_time = 0; + int last_order_prod_allnum = 0; + int last_empty_is_lack = 0; //空箱位缺箱 + int last_device_is_running = 0; //专机运行状态 + int last_empty_is_finish = 0; //空位完成 + int last_full_ready_req_agv = 0; //满箱位就绪,请求AGV + int last_full_out = 0; //满箱已运出满箱位 + int last_device_prepare = 0; //专机准备中 + int last_device_ready = 0; //专机就绪 + int last_line_ready = 0; //线体就绪 + int last_device_online = 0; //专机联机 + + //int heartbeat = 0; + //int last_heartbeat = 0; + //private long last_feedDeviceStatusTime = 0; + int status_type = 0; + int last_status_type = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public synchronized void execute(){ + String message = null; + try { + device_code = this.getDeviceCode(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + is_open = this.itemProtocol.getIsOpen(); + running = this.itemProtocol.getRunning(); + all_ready = this.itemProtocol.getAllReady(); + order = this.itemProtocol.getOrder(); + mode = this.itemProtocol.getItem_mode(); + finish = this.itemProtocol.getItem_finish(); + order_compel_finish = this.itemProtocol.getItem_order_compel_finish(); + now_order_prod_num = this.itemProtocol.getItem_now_order_prod_num(); + full_number = this.itemProtocol.getItem_full_number(); + now_one_box_num = this.itemProtocol.getItem_now_one_box_num(); + storage_stock_num = this.itemProtocol.getItem_storage_stock_num(); + line_stock_num = this.itemProtocol.getItem_line_stock_num(); + open_ready_time = this.itemProtocol.getItem_open_ready_time(); + device_running_time = this.itemProtocol.getItem_device_running_time(); + await_time = this.itemProtocol.getItem_await_time(); + order_prod_allnum = this.itemProtocol.getItem_order_prod_allnum(); + empty_is_lack = this.itemProtocol.getItem_empty_is_lack(); + device_is_running = this.itemProtocol.getItem_device_is_running(); + empty_is_finish = this.itemProtocol.getItem_empty_is_finish(); + full_ready_req_agv = this.itemProtocol.getItem_full_ready_req_agv(); + full_out = this.itemProtocol.getItem_full_out(); + device_prepare = this.itemProtocol.getItem_device_prepare(); + device_ready = this.itemProtocol.getItem_device_ready(); + line_ready = this.itemProtocol.getItem_line_ready(); + + + if (mode != last_mode) { + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (empty_is_lack != last_empty_is_lack) { + logServer.deviceItemValue(this.device_code,"empty_is_lack" ,String.valueOf(empty_is_lack)); + logServer.deviceExecuteLog(this.device_code,"","","信号empty_is_lack:" + last_empty_is_lack + "->" + empty_is_lack); + } + if (device_is_running != last_device_is_running) { + logServer.deviceItemValue(this.device_code,"device_is_running" ,String.valueOf(device_is_running)); + logServer.deviceExecuteLog(this.device_code,"","","信号device_is_running:" + last_device_is_running + "->" + device_is_running); + } + if (empty_is_finish != last_empty_is_finish) { + logServer.deviceItemValue(this.device_code,"empty_is_finish" ,String.valueOf(empty_is_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号empty_is_finish:" + last_empty_is_finish + "->" + empty_is_finish); + } + if (full_ready_req_agv != last_full_ready_req_agv) { + logServer.deviceItemValue(this.device_code,"full_ready_req_agv" ,String.valueOf(full_ready_req_agv)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_ready_req_agv:" + last_full_ready_req_agv + "->" + full_ready_req_agv); + } + if (full_out != last_full_out) { + logServer.deviceItemValue(this.device_code,"full_out" ,String.valueOf(full_out)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_out:" + last_full_out + "->" + full_out); + } + if (device_prepare != last_device_prepare) { + logServer.deviceItemValue(this.device_code,"device_prepare" ,String.valueOf(device_prepare)); + logServer.deviceExecuteLog(this.device_code,"","","信号device_prepare:" + last_device_prepare + "->" + device_prepare); + } + if (device_ready != last_device_ready) { + logServer.deviceItemValue(this.device_code,"device_ready" ,String.valueOf(device_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号device_ready:" + last_device_ready + "->" + device_ready); + } + if (line_ready != last_line_ready) { + logServer.deviceItemValue(this.device_code,"line_ready" ,String.valueOf(line_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_ready:" + last_line_ready + "->" + line_ready); + } + if (device_online != last_device_online) { + logServer.deviceItemValue(this.device_code,"device_online" ,String.valueOf(device_online)); + logServer.deviceExecuteLog(this.device_code,"","","信号device_online:" + last_device_online + "->" + device_online); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code,"task" ,String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code,"","","信号task:" + last_task + "->" + task); + } + + if (is_open != last_is_open) { + logServer.deviceItemValue(this.device_code,"is_open" ,String.valueOf(is_open)); + logServer.deviceExecuteLog(this.device_code,"","","信号is_open:" + last_is_open + "->" + is_open); + } + if (running != last_running) { + logServer.deviceItemValue(this.device_code,"running" ,String.valueOf(running)); + logServer.deviceExecuteLog(this.device_code,"","","信号running:" + last_running + "->" + running); + } + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code,"finish" ,String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号finish:" + last_finish + "->" + finish); + } + if (all_ready != last_all_ready) { + logServer.deviceItemValue(this.device_code,"all_ready" ,String.valueOf(all_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号all_ready:" + last_all_ready + "->" + all_ready); + } + if (order_compel_finish != last_order_compel_finish) { + logServer.deviceItemValue(this.device_code,"order_compel_finish" ,String.valueOf(order_compel_finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_compel_finish:" + last_order_compel_finish + "->" + order_compel_finish); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + } + if (now_order_prod_num != last_now_order_prod_num) { + logServer.deviceItemValue(this.device_code,"now_order_prod_num" ,String.valueOf(now_order_prod_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号now_order_prod_num:" + last_now_order_prod_num + "->" + now_order_prod_num); + JSONObject map = new JSONObject(); + if (mode == 1 && order > 0) { + map.put("order", order); + map.put("real_qty", now_order_prod_num); + try { + acsToWmsService.feedOrderRealQty(map); + } catch (Exception e){ + log.error("工单数量反馈失败,设备{},原因{}",device_code,e.getMessage()); + } + } + } + if (full_number != last_full_number) { + logServer.deviceItemValue(this.device_code,"full_number" ,String.valueOf(full_number)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_number:" + last_full_number + "->" + full_number); + } + if (now_one_box_num != last_now_one_box_num) { + logServer.deviceItemValue(this.device_code,"now_one_box_num" ,String.valueOf(now_one_box_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号now_one_box_num:" + last_now_one_box_num + "->" + now_one_box_num); + } + if (storage_stock_num != last_storage_stock_num) { + logServer.deviceItemValue(this.device_code,"storage_stock_num" ,String.valueOf(storage_stock_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号storage_stock_num:" + last_storage_stock_num + "->" + storage_stock_num); + } + if (line_stock_num != last_line_stock_num) { + logServer.deviceItemValue(this.device_code,"line_stock_num" ,String.valueOf(line_stock_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_stock_num:" + last_line_stock_num + "->" + line_stock_num); + } + if (open_ready_time != last_open_ready_time) { + logServer.deviceItemValue(this.device_code,"open_ready_time" ,String.valueOf(open_ready_time)); + logServer.deviceExecuteLog(this.device_code,"","","信号open_ready_time:" + last_open_ready_time + "->" + open_ready_time); + } + + if (order_prod_allnum != last_order_prod_allnum) { + logServer.deviceItemValue(this.device_code,"order_prod_allnum" ,String.valueOf(order_prod_allnum)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_prod_allnum:" + last_order_prod_allnum + "->" + order_prod_allnum); + } + + int realError = 0; + if (!this.itemProtocol.getIsonline()) { + status_type = 01; + } else { + status_type = 02; + if (error == 1 || error == 51) { + status_type = 05; + realError = error; + } else if (mode == 1 && order > 0) { + status_type = 03; + realError = 0; + } else if (mode == 0 && order > 0) { + realError = 0; + status_type = 04; + } + } + if (status_type != last_status_type) { + JSONObject map = new JSONObject(); + map.put("device_code", device_code); + map.put("status_type", "0" + status_type); + map.put("start_time", DateUtil.now()); + map.put("error_code", realError); + try { + acsToWmsService.feedDeviceStatusType(map); + last_status_type = status_type; + }catch (Exception e){ + log.error("设备状态反馈失败,设备{},原因{}",device_code,e.getMessage()); + } + } +// synchronized (this) { +// int realError = 0; +// long now_feedTime = System.currentTimeMillis(); +// if (now_feedTime - last_feedDeviceStatusTime >= 5000) { +// heartbeat = this.itemProtocol.getHeartbeat(); +// if (heartbeat == last_heartbeat) { +// status_type = 01; +// } else { +// status_type = 02; +// if (error == 1 || error == 51) { +// status_type = 05; +// realError = error; +// } else if (mode == 1 && order > 0) { +// status_type = 03; +// realError = 0; +// } else if (mode == 0 && order > 0) { +// realError = 0; +// status_type = 04; +// } +// } +// if (status_type != last_status_type) { +// JSONObject map = new JSONObject(); +// map.put("device_code", device_code); +// map.put("status_type", "0" + status_type); +// map.put("start_time", DateUtil.now()); +// map.put("error_code", realError); +// acsToWmsService.feedDeviceStatusType(map); +// last_status_type = status_type; +// } +// last_feedDeviceStatusTime = now_feedTime; +// last_heartbeat = heartbeat; +// } +// } + + } catch (Exception var17) { + return; + } + if (1 != 1) { +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); + message = "信号量同步异常"; + //未联机 +// } else if (mode == 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "未联机"; + //有报警 +// } else if (error != 0) { +// this.setIsonline(false); +// this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + if (mode == 1 && finish != last_finish && finish == 1 && order > 0) { + ProduceshiftorderDto dto = new ProduceshiftorderDto(); + dto.setOrder_code(order + ""); + dto.setOrder_status("2"); + ProduceshiftorderDto deviceInfo = produceshiftorderService.findOrderByDeviceCode(this.device_code); + if (deviceInfo != null) { + if (StrUtil.isNotEmpty(deviceInfo.getExt_order_id())) { + String ext_order_id = deviceInfo.getExt_order_id(); + JSONObject param = new JSONObject(); + param.put("ext_order_id", ext_order_id); + acsToWmsService.feedbackOrderStatus(param); + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单的外部标识:" + ext_order_id); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单的没有外部标识"); + } + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单信息为空"); + } + produceshiftorderService.updateByOrderCode(dto); + this.writing("to_confirm_finished", "1"); + this.writing("to_order", "0"); + this.writing("to_clear", "1"); + this.writing("to_pause", "1"); + }/* else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,finish>" + finish + ",last_finish>" + last_finish + "mode:" + mode + "order:" + order); + }*/ + } + last_mode = mode; + last_error = error; + /* last_move = move;*/ + last_task = task; + last_is_open = is_open; + last_running = running; + last_finish = finish; + last_all_ready = all_ready; + last_order_compel_finish = order_compel_finish; + last_order = order; + last_now_order_prod_num = now_order_prod_num; + last_full_number = full_number; + last_now_one_box_num = now_one_box_num; + last_storage_stock_num = storage_stock_num; + last_line_stock_num = line_stock_num; + last_open_ready_time = open_ready_time; + last_device_running_time = device_running_time; + last_await_time = await_time; + last_order_prod_allnum = order_prod_allnum; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + + } + + public void writing(String param, String value) { + String to_param = 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_param, Integer.parseInt(value)); + ReadUtil.write(itemMap, server); + logServer.deviceExecuteLog(this.device_code, "", "", "下发信号:" + param + ":" + value); + } + + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/ItemProtocol.java new file mode 100644 index 00000000..c62bdc0b --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_device/ItemProtocol.java @@ -0,0 +1,270 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_device; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; //心跳 + public static String item_mode = "mode"; //模式 + public static String item_is_open = "is_open";// 线体是否启动 + public static String item_running = "running"; //是否运行 + public static String item_finish = "finish";// 订单完成 + public static String item_all_ready = "all_ready"; //所有设备就绪 + public static String item_order_compel_finish = "order_compel_finish"; // 订单强制完成 + public static String item_order = "order"; //订单号 + public static String item_error = "error"; //报警信号 + public static String item_task = "task"; //任务号 + public static String item_now_order_prod_num = "now_order_prod_num"; //当前生产总量 + public static String item_full_number = "full_number"; //出料口满框数量 + public static String item_now_one_box_num = "now_one_prod_num"; //每框数量 + public static String item_storage_stock_num = "storage_stock_num"; //储料仓库存数量 + public static String item_line_stock_num = "line_stock_num"; //线体库存数量 + public static String item_open_ready_time = "open_ready_time";//开机准备时间(S) + public static String item_device_running_time = "device_running_time";//设备运行时间(S) + public static String item_await_time = "await_time";//待机时间(S) + public static String item_order_prod_allnum = "order_prod_allnum";//订单生产总量 + + public static String item_empty_is_lack = "empty_is_lack"; //空箱位缺箱 + public static String item_device_is_running = "device_is_running"; //专机运行状态 + public static String item_empty_is_finish = "empty_is_finish"; //空位完成 + public static String item_full_ready_req_agv = "full_ready_req_agv"; //满箱位就绪,请求AGV + public static String item_full_out = "full_out"; //满箱已运出满箱位 + public static String item_device_prepare = "device_prepare"; //专机准备中 + public static String item_device_ready = "device_ready"; //专机就绪 + public static String item_line_ready = "line_ready"; //线体就绪 + + + //开机 + public static String item_to_open = "to_open"; + //产量清零 + public static String item_to_clear = "to_clear"; + //确认完成(订单完成状态置零) + public static String item_to_confirm_finished = "to_confirm_finished"; + //暂停 + public static String item_to_pause = "to_pause"; + //工单强制完成 + public static String item_to_order_compel_finished = "to_order_compel_finished"; + //订单生产总量 + public static String item_to_order_prod_num = "to_order_prod_num"; + //每框接料数量 + public static String item_to_one_box_num = "to_one_box_num"; + //倒料数量 + public static String item_to_out_num = "to_out_num"; + //工单号 + public static String item_to_order = "to_order"; + //agvAGV空位就绪 + public static String item_to_empty_ready = "to_empty_ready"; + //agvAGV满位就绪 + public static String item_to_full_ready = "to_full_ready"; + //agvAGV取货完成 + public static String item_to_pick_finish = "to_pick_finish"; + //任务号 + public static String item_to_task = "to_task"; + + private HailiangSpecialDeviceDriver driver; + + public ItemProtocol(HailiangSpecialDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getIsOpen() { + return this.getOpcIntegerValue(item_is_open); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getRunning() { + return this.getOpcIntegerValue(item_running); + } + + public int getAllReady() { + return this.getOpcIntegerValue(item_all_ready); + } + + public int getOrder() { + return this.getOpcIntegerValue(item_order); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_finish() { + return this.getOpcIntegerValue(item_finish); + } + + public int getItem_order_compel_finish() { + return this.getOpcIntegerValue(item_order_compel_finish); + } + + public int getItem_now_order_prod_num() { + return this.getOpcIntegerValue(item_now_order_prod_num); + } + + public int getItem_full_number() { + return this.getOpcIntegerValue(item_full_number); + } + + public int getItem_now_one_box_num() { + return this.getOpcIntegerValue(item_now_one_box_num); + } + + public int getItem_storage_stock_num() { + return this.getOpcIntegerValue(item_storage_stock_num); + } + + public int getItem_line_stock_num() { + return this.getOpcIntegerValue(item_line_stock_num); + } + + public int getItem_open_ready_time() { + return this.getOpcIntegerValue(item_open_ready_time); + } + + public int getItem_device_running_time() { + return this.getOpcIntegerValue(item_device_running_time); + } + + public int getItem_await_time() { + return this.getOpcIntegerValue(item_await_time); + } + + public int getItem_order_prod_allnum() { + return this.getOpcIntegerValue(item_order_prod_allnum); + } + + public int getItem_empty_is_lack() { + return this.getOpcIntegerValue(item_empty_is_lack); + } + + public int getItem_device_is_running() { + return this.getOpcIntegerValue(item_device_is_running); + } + + public int getItem_empty_is_finish() { + return this.getOpcIntegerValue(item_empty_is_finish); + } + + public int getItem_full_ready_req_agv() { + return this.getOpcIntegerValue(item_full_ready_req_agv); + } + + public int getItem_full_out() { + return this.getOpcIntegerValue(item_full_out); + } + + public int getItem_device_prepare() { + return this.getOpcIntegerValue(item_device_prepare); + } + + public int getItem_device_ready() { + return this.getOpcIntegerValue(item_device_ready); + } + + public int getItem_line_ready() { + return this.getOpcIntegerValue(item_line_ready); + } + + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static String getField_desc(String item) { + String field_desc = ""; + List readlist = getReadableItemDtos(); + List writelist = getWriteableItemDtos(); + for (int i = 0; i < readlist.size(); i++) { + ItemDto dto = readlist.get(i); +// if(){ +// +// } + } + return field_desc; + } + + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_is_open, "线体是否启动", "DB1.B0.1")); + list.add(new ItemDto(item_device_is_running, "专机运行状态", "DB1.B0.3")); + list.add(new ItemDto(item_empty_is_lack, "空箱位缺箱", "DB1.B0.5")); + list.add(new ItemDto(item_running, "是否运行", "DB1.B0.6")); + list.add(new ItemDto(item_empty_is_finish, "空位完成", "DB1.B0.7")); + list.add(new ItemDto(item_full_out, "满箱已运出满箱位", "DB1.B1.1")); + list.add(new ItemDto(item_finish, "订单完成", "DB1.B1.2")); + list.add(new ItemDto(item_device_prepare, "专机准备中", "DB1.B1.3")); + list.add(new ItemDto(item_device_ready, "专机就绪", "DB1.B1.4")); + list.add(new ItemDto(item_line_ready, "线体就绪", "DB1.B1.5")); + list.add(new ItemDto(item_all_ready, "所有设备就绪", "DB1.B1.6")); + list.add(new ItemDto(item_mode, "手自动状态", "DB1.B1.7", Boolean.valueOf(true))); + list.add(new ItemDto(item_order_compel_finish, "订单强制完成", "DB1.B2.0")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_now_order_prod_num, "当前生产总量", "DB1.D84")); + list.add(new ItemDto(item_now_one_box_num, "每框箱数量", "DB1.D88")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_full_number, "出料口满框数量", "DB1.D96")); + list.add(new ItemDto(item_storage_stock_num, "储料仓库存数量", "DB1.D100")); + list.add(new ItemDto(item_line_stock_num, "线体库存数量", "DB1.D104")); + list.add(new ItemDto(item_open_ready_time, "开机准备时间(S)", "DB1.D108")); + list.add(new ItemDto(item_device_running_time, "设备运行时间(S)", "DB1.D112")); + list.add(new ItemDto(item_await_time, "待机时间(S)", "DB1.D116")); + list.add(new ItemDto(item_order_prod_allnum, "订单生产总量", "DB1.D120")); + list.add(new ItemDto(item_full_ready_req_agv, "满箱位就绪,请求AGV", "DB1.B1.0")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB2.W4", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_clear, "当前产量清零", "DB2.W12")); + list.add(new ItemDto(item_to_confirm_finished, "确认完成", "DB2.W14")); + list.add(new ItemDto(item_to_pause, "暂停", "DB2.W16")); + list.add(new ItemDto(item_to_order_compel_finished, "工单强制完成", "DB2.W82")); + list.add(new ItemDto(item_to_order_prod_num, "订单生产总量", "DB2.D84")); + list.add(new ItemDto(item_to_one_box_num, "每箱接料数量", "DB2.D88")); + list.add(new ItemDto(item_to_out_num, "倒料数量", "DB2.D96")); + list.add(new ItemDto(item_to_order, "工单号", "DB2.D160")); + list.add(new ItemDto(item_to_empty_ready, "AGV空位就绪", "DB2.W6")); + list.add(new ItemDto(item_to_full_ready, "AGV满位就绪", "DB2.W8")); + list.add(new ItemDto(item_to_pick_finish, "AGV取货完成", "DB2.W10")); + list.add(new ItemDto(item_to_task, "任务号", "DB2.D92")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/HailiangSpecialEmptyStationDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/HailiangSpecialEmptyStationDefination.java new file mode 100644 index 00000000..272b9d6c --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/HailiangSpecialEmptyStationDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_empty_station; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮专机设备空框位 + */ +@Service +public class HailiangSpecialEmptyStationDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_special_empty_station"; + } + + @Override + public String getDriverName() { + return "海亮-专机设备空框位"; + } + + @Override + public String getDriverDescription() { + return "海亮-专机设备空框位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangSpecialEmptyStationDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangSpecialEmptyStationDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/HailiangSpecialEmptyStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/HailiangSpecialEmptyStationDeviceDriver.java new file mode 100644 index 00000000..265676fb --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/HailiangSpecialEmptyStationDeviceDriver.java @@ -0,0 +1,434 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_empty_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.NDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮专机设备空框位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangSpecialEmptyStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + + String container; + + int agvphase = 0; + int index = 0; + String device_code; + + int mode = 0; + int status = 0; + int move = 0; + int finish = 0; + int allready = 0; + int order = 0; + int error = 0; + int task = 0; + int running = 0; + //出入库模式 + int operation_type = 0; + int last_mode = 0; + int last_status = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_all_ready = 0; + int last_order = 0; + int last_finish = 0; + int last_running = 0; + + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + error = this.itemProtocol.getError(); + move = this.itemProtocol.getMove(); + status = this.itemProtocol.getStatus(); + task = this.itemProtocol.getTask(); + allready = this.itemProtocol.getAllReady(); + mode = this.itemProtocol.getMode(); + finish = this.itemProtocol.getFinish(); + order = this.itemProtocol.getOrder(); + hasGoods = this.itemProtocol.getMove(); + running = this.itemProtocol.getRunning(); + if (mode != last_mode) { + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + if (move == 1) { + thingToNothing(); + } + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (status != last_status) { + logServer.deviceItemValue(this.device_code,"status" ,String.valueOf(status)); + logServer.deviceExecuteLog(this.device_code,"","","信号status:" + last_status + "->" + status); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code,"task" ,String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code,"","","信号task:" + last_task + "->" + task); + } + if (running != last_running) { + logServer.deviceItemValue(this.device_code,"running" ,String.valueOf(running)); + logServer.deviceExecuteLog(this.device_code,"","","信号running:" + last_running + "->" + running); + + } + if (allready != last_all_ready) { + logServer.deviceItemValue(this.device_code,"allready" ,String.valueOf(allready)); + logServer.deviceExecuteLog(this.device_code,"","","信号allready:" + last_all_ready + "->" + allready); + + } + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code,"finish" ,String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号finish:" + last_finish + "->" + finish); + + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + + } + + if (mode == 2 && move != 0 && task > 0) { + + } + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + //请求放空箱 + if(agvphase == 0x13 || agvphase == 0x17 ) + { + if(error == 0 && move== 1 && ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("5"); + instructionService.update(inst); + writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + }else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因move:"+move+",error:"+error+",inst"+inst); + } + } + //放空箱完成 + if(agvphase == 0x15 || agvphase == 0x19){ + if(error == 0 && move== 1 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("6"); + instructionService.update(inst); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + }else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因move:"+move+",error:"+error+",inst"+inst); + } + } + } + last_mode = mode; + last_status = status; + last_error = error; + last_move = move; + last_task = task; + last_all_ready = allready; + last_finish = finish; + last_order = order; + last_running = running; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.setRequireSucess(false); + this.setApplySucess(false); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/ItemProtocol.java new file mode 100644 index 00000000..06eac95a --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_empty_station/ItemProtocol.java @@ -0,0 +1,109 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_empty_station; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_running = "running"; + public static String item_status = "status"; + public static String item_finish = "finish"; + public static String item_all_ready = "all_ready"; + public static String item_order = "order"; + public static String item_error = "error"; + public static String item_task = "task"; + + public static String item_to_agv_ready = "to_agv_ready"; + + public static String item_to_agv_finish = "to_agv_finish"; + + private HailiangSpecialEmptyStationDeviceDriver driver; + + public ItemProtocol(HailiangSpecialEmptyStationDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getRunning() { + return this.getOpcIntegerValue(item_running); + } + + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getFinish() { return this.getOpcIntegerValue(item_finish);} + + public int getAllReady() { return this.getOpcIntegerValue(item_all_ready);} + + public int getOrder() { return this.getOpcIntegerValue(item_order);} + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_mode, "是否启动", "DB1.B0.1")); + list.add(new ItemDto(item_status, "手自动状态", "DB1.B0.0", Boolean.valueOf(true))); + list.add(new ItemDto(item_move, "光电开关信号(取反)", "DB1.B0.5")); + list.add(new ItemDto(item_running, "空位运行", "DB1.B0.6")); + list.add(new ItemDto(item_finish, "是否完成", "DB1.B0.7")); + list.add(new ItemDto(item_all_ready, "所有设备就绪", "DB1.B1.6")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_agv_ready, "AGV就绪", "DB2.W6", Boolean.valueOf(true))); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/SiemensOneFloorAGVConveyorDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/HailiangSpecialFullStationDefination.java similarity index 70% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/SiemensOneFloorAGVConveyorDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/HailiangSpecialFullStationDefination.java index 4969f916..72a50925 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/SiemensOneFloorAGVConveyorDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/HailiangSpecialFullStationDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.siemens_onefloor_agv_conveyor; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_full_station; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -11,41 +11,40 @@ import java.util.LinkedList; import java.util.List; /** - * 西门子-输送机驱动 - * + * 海亮专机设备满框位 */ @Service -public class SiemensOneFloorAGVConveyorDefination implements OpcDeviceDriverDefination { +public class HailiangSpecialFullStationDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "siemens_onefloor_agv_conveyor"; + return "hailiang_special_full_station"; } @Override public String getDriverName() { - return "西门子-1LAGV-输送机驱动"; + return "海亮-专机设备满框位"; } @Override public String getDriverDescription() { - return "西门子-1LAGV-输送机驱动"; + return "海亮-专机设备满框位"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new SiemensOneFloorAGVConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HailiangSpecialFullStationDeviceDriver()).setDevice(device).setDriverDefination(this); } @Override public Class getDeviceDriverType() { - return SiemensOneFloorAGVConveyorDeviceDriver.class; + return HailiangSpecialFullStationDeviceDriver.class; } @Override public List getFitDeviceTypes() { List types = new LinkedList(); - types.add(DeviceType.station); + types.add(DeviceType.conveyor); return types; } @@ -54,8 +53,6 @@ public class SiemensOneFloorAGVConveyorDefination implements OpcDeviceDriverDefi return ItemProtocol.getReadableItemDtos(); } - - @Override public List getWriteableItemDtos() { return ItemProtocol.getWriteableItemDtos(); diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/HailiangSpecialFullStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/HailiangSpecialFullStationDeviceDriver.java new file mode 100644 index 00000000..22c14992 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/HailiangSpecialFullStationDeviceDriver.java @@ -0,0 +1,673 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_full_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.NDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_auto_cache_line.HailiangAutoCacheLineDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine_storage_station.HailiangCleaningMachineStorageStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pour_station.HailiangSpecialPourStationDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮专机设备满框位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangSpecialFullStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int move = 0; + int status = 0; + int finish = 0; + int allready = 0; + int order = 0; + int error = 0; + int task = 0; + int full_number = 0; + //出入库模式 + int operation_type = 0; + int last_mode = 0; + int last_status = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_all_ready = 0; + int last_order = 0; + int last_finish = 0; + int last_full_number = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + int agvphase = 0; + int index = 0; + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + error = this.itemProtocol.getError(); + move = this.itemProtocol.getMove(); + task = this.itemProtocol.getTask(); + allready = this.itemProtocol.getAllReady(); + mode = this.itemProtocol.getMode(); + finish = this.itemProtocol.getFinish(); + order = this.itemProtocol.getOrder(); + hasGoods = this.itemProtocol.getMove(); + full_number = this.itemProtocol.getFull_number(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + + } + if (status != last_status) { + logServer.deviceItemValue(this.device_code, "status", String.valueOf(status)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号status:" + last_status + "->" + status); + + } + if (full_number != last_full_number) { + logServer.deviceItemValue(this.device_code, "full_number", String.valueOf(full_number)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号full_number:" + last_full_number + "->" + full_number); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + if (allready != last_all_ready) { + logServer.deviceItemValue(this.device_code, "allready", String.valueOf(allready)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号allready:" + last_all_ready + "->" + allready); + } + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code, "finish", String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号finish:" + last_finish + "->" + finish); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code, "order", String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号order:" + last_order + "->" + order); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + + } catch (Exception var17) { + return; + } + +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 +// } else if (error != 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "有报警"; +// //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + + if (!requireSucess) { +// if ( move == 1 && mode == 1 && order > 0 && full_number>0 ) { + + if (move == 1 && mode == 1) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,move:" + move + ",requireSucess:" + requireSucess + "开始申请任务"); + apply_task(); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,move:" + move + ",requireSucess:" + requireSucess + "申请任务失败,不符合条件"); + } + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "是否请求成功:requireSucess:" + requireSucess); + + } + + if (agvphase == 0x03 || agvphase == 0x07) { + if (move == 1 && error == 0 && allready == 1 && full_number > 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("1"); + instructionService.update(inst); + writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈,原因move:" + move + ",error:" + error + ",inst" + inst + ",allready:" + allready + ",full_number:" + full_number); + + + } + } + + if (agvphase == 0x05 || agvphase == 0x09) { + if (move == 0 && error == 0 && allready == 1 && full_number > 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("2"); + instructionService.update(inst); + writing("to_agv_finish", "1"); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + inst = null; + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "反馈成功"); + + } else { + logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + agvphase + "等待反馈,原因move:" + move + ",error:" + error + ",inst" + inst + ",allready:" + allready + ",full_number:" + full_number); + + + } + } + + } + last_mode = mode; + last_status = status; + last_error = error; + last_move = move; + last_task = task; + last_all_ready = allready; + last_finish = finish; + last_order = order; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code, "", "", "光电信号切换,刷新请求标记:" + this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + + public synchronized boolean apply_task() { + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + Boolean flag = false; + //通过路由找到所有的目标设备 + //找到当前设备生产的物料,并且判断下个工序生产的物料相同 + //判断是否已经有前往这个工位的任务 + List list = routeLineService.getShortPathLinesByCode(this.device_code, "normal"); + if (ObjectUtil.isEmpty(list)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":未找到对应路由"); + throw new BadRequestException(this.device_code + ":未找到对应路由"); + } + //link_device tw 满料位设备关联的设备tw + String link_device = this.getDevice().getExtraValue().get("link_device_code").toString(); + //empty_device 满料位对应的空料位 + String empty_device = this.getDevice().getExtraValue().get("empty_device_code").toString(); + //通过满料位设备关联的设备tw查找订单 + ProduceshiftorderDto order = produceshiftorderService.findOrderByDeviceCode(link_device); + if (ObjectUtil.isEmpty(order)) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":关联设备" + link_device + "未找到对应设备工单"); + throw new BadRequestException(this.device_code + ":关联设备" + link_device + "未找到对应设备工单"); + } + //判断是否需要agv搬运 + if (order.getIs_needmove().equals("0")) { + requireSucess = true; + logServer.deviceExecuteLog(this.device_code, "", "", "不需要agv搬运,工单号:" + order.getOrder_code()); + return true; + } + //查找当前工单对应的物料编号 + String cpbh = order.getMaterial_code(); + HailiangSpecialPourStationDeviceDriver hailiangSpecialPourStationDeviceDriver; + HailiangCleaningMachineStorageStationDeviceDriver hailiangCleaningMachineStorageStationDeviceDriver; + HailiangAutoCacheLineDeviceDriver hailiangAutoCacheLineDeviceDriver; + String clear_storage_device = null; + //遍历路由,找到对应所有的物料进行匹配 + for (int i = 0; i < list.size(); i++) { + RouteLineDto dto = list.get(i); + //找到路由对应工位 清洗机设备编号 + String route_device_code = dto.getNext_device_code(); + Device route_link_device = deviceAppservice.findDeviceByCode(route_device_code); + //找到路由工位对应设备 + String route_link_device_code = (String) route_link_device.getExtraValue().get("link_device_code"); + if (StrUtil.isEmpty(route_link_device_code)) { + continue; + } + //找到路由工位对应设备对应的工单 + ProduceshiftorderDto route_order = produceshiftorderService.findOrderByDeviceCode(route_link_device_code); + //找到对应设备工单 + if (ObjectUtil.isNotEmpty(route_order)) { + //找到生产产品一样的设备 + if (StrUtil.equals(route_order.getMaterial_code(), cpbh)) { + //所有到这个倒料位上任务的总数量 + int allnum = taskserver.queryAllTaskMaterialQty(route_link_device_code); + //查询此工位是否需要补料 + //获取此工位允许的最大上料数量 + int max_num = Integer.parseInt(route_link_device.getExtraValue().get("max_num").toString()); + //判断设备是专机倒料位 + if (route_link_device.getDeviceDriver() instanceof HailiangSpecialPourStationDeviceDriver) { + hailiangSpecialPourStationDeviceDriver = (HailiangSpecialPourStationDeviceDriver) route_link_device.getDeviceDriver(); + if (hailiangSpecialPourStationDeviceDriver.getMode() != 1) { + continue; + } + //获取储料仓库存数量 + int stock_num = hailiangSpecialPourStationDeviceDriver.getStorage_stock_num(); + //此款数量+储料仓库存数量 < 下工序允许最大数量 则通过 + if (allnum + full_number + stock_num < max_num) { + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_status("0"); + onedto.setPriority("101"); + onedto.setAgv_system_type("1"); + onedto.setTask_type("1"); + onedto.setStart_device_code(this.getDevice().getDevice_code()); + onedto.setStart_point_code(this.getDevice().getDevice_code()); + onedto.setPut_device_code(route_device_code); + onedto.setPut_point_code(route_device_code); + onedto.setNext_point_code(empty_device); + onedto.setNext_device_code(empty_device); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + + try { + taskserver.create(onedto); + flag = true; + break; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务成功"); + } else { + //打印日志 + continue; + } + } + + } else if (route_link_device.getDeviceDriver() instanceof HailiangAutoCacheLineDeviceDriver) { + JSONObject json = new JSONObject(); + json.put("device_code", device_code); + json.put("type", "1"); + HttpResponse httpResponse = acsToWmsService.applyInCacheLineTask(json); + JSONObject jsonObject = JSONObject.parseObject(httpResponse.body()); + String ext_task_id = jsonObject.getString("ext_task_id"); + String task_code = jsonObject.getString("task_code"); + String start_device_code = jsonObject.getString("start_device_code"); + String put_device_code = jsonObject.getString("put_device_code"); + String next_device_code = jsonObject.getString("next_device_code"); + String task_type = jsonObject.getString("task_type"); + String barcodeArr = jsonObject.getString("barcodeArr"); + String[] barcodeArrs = barcodeArr.split("\\,"); + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + onedto.setExt_task_id(ext_task_id); + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_status("0"); + onedto.setPriority("101"); + onedto.setAgv_system_type("1"); + onedto.setTask_type(task_type); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setTask_code(task_code); + onedto.setStart_device_code(start_device_code); + onedto.setStart_point_code(start_device_code); + onedto.setPut_device_code(put_device_code); + onedto.setPut_point_code(put_device_code); + onedto.setNext_point_code(next_device_code); + onedto.setNext_device_code(next_device_code); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + try { + taskserver.create(onedto); + flag = true; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + } + } else { + //清洗倒料位是没有工单的 + if (route_link_device.getDeviceDriver() instanceof HailiangCleaningMachineStorageStationDeviceDriver) { + //优先判断是否有相同的物料 + //优先找相同的物料的倒料位,然后判断最大重量是否可放,如果都没有则找个空的位置 + //需要在这个驱动中设置允许最大重量,如果当前重量超过了,则不能倒料 + hailiangCleaningMachineStorageStationDeviceDriver = (HailiangCleaningMachineStorageStationDeviceDriver) route_link_device.getDeviceDriver(); + String material = route_link_device.getMaterial(); + int maxWeight = Integer.parseInt(route_link_device.getExtraValue().get("max_weight").toString()); + //此处需要考虑已有任务的情况 + if (StrUtil.equals(material, cpbh) && hailiangCleaningMachineStorageStationDeviceDriver.getSilo_weight() < maxWeight) { + clear_storage_device = route_link_device.getDevice_code(); + //直接生成任务 + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_status("0"); + onedto.setAgv_system_type("1"); + onedto.setTask_type("1"); + onedto.setPriority("101"); + onedto.setStart_device_code(this.getDevice().getDevice_code()); + onedto.setStart_point_code(this.getDevice().getDevice_code()); + onedto.setPut_device_code(route_device_code); + onedto.setPut_point_code(route_device_code); + onedto.setNext_point_code(empty_device); + onedto.setNext_device_code(empty_device); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + + try { + taskserver.create(onedto); + route_link_device.setMaterial(cpbh); + hailiangCleaningMachineStorageStationDeviceDriver.setMaterial(cpbh); + flag = true; + break; + } catch (Exception e) { + route_link_device.setMaterial(""); + hailiangCleaningMachineStorageStationDeviceDriver.setMaterial(""); + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务成功"); + break; + } + } + } + } + + if (StrUtil.isEmpty(clear_storage_device)) { + //表示没有该物料工位 直接寻找空位倒料 + for (int i = 0; i < list.size(); i++) { + RouteLineDto dto = list.get(i); + //找到路由对应工位 + String route_device_code = dto.getNext_device_code(); + Device route_link_device = deviceAppservice.findDeviceByCode(route_device_code); + if (route_link_device.getDeviceDriver() instanceof HailiangCleaningMachineStorageStationDeviceDriver) { + hailiangCleaningMachineStorageStationDeviceDriver = (HailiangCleaningMachineStorageStationDeviceDriver) route_link_device.getDeviceDriver(); + //寻找空位倒料 + String material = route_link_device.getMaterial(); + if (StrUtil.isEmpty(material)) { + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_status("0"); + onedto.setPriority("101"); + onedto.setAgv_system_type("1"); + onedto.setTask_type("1"); + onedto.setStart_device_code(this.getDevice().getDevice_code()); + onedto.setStart_point_code(this.getDevice().getDevice_code()); + onedto.setPut_device_code(route_device_code); + onedto.setPut_point_code(route_device_code); + onedto.setNext_point_code(empty_device); + onedto.setNext_device_code(empty_device); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + try { + taskserver.create(onedto); + //将当前工单物料赋给对应的清洗路由工位 + route_link_device.setMaterial(cpbh); + hailiangCleaningMachineStorageStationDeviceDriver.setMaterial(cpbh); + flag = true; + break; + } catch (Exception e) { + route_link_device.setMaterial(""); + hailiangCleaningMachineStorageStationDeviceDriver.setMaterial(""); + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + break; + } + } + } + } + + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":专机生成任务成功"); + requireSucess = true; + } else { + //如果都没有则调用mes接口申请入缓存线 + //生成任务 + //前往缓存线 + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":分配任务缓存线"); + } + } + return true; + } + + public synchronized boolean applyInCacheLineTask() throws Exception { + Boolean flag = false; + + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":专机生成任务成功"); + requireSucess = true; + } else { + //如果都没有则调用mes接口申请入缓存线 + //生成任务 + //前往缓存线 + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":分配任务缓存线"); + } + + return true; + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/ItemProtocol.java new file mode 100644 index 00000000..8613344b --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_full_station/ItemProtocol.java @@ -0,0 +1,110 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_full_station; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_status = "status"; + public static String item_finish = "finish"; + public static String item_all_ready = "all_ready"; + public static String item_order = "order"; + public static String item_error = "error"; + public static String item_task = "task"; + public static String item_full_number = "full_number"; + + public static String item_to_agv_ready = "to_agv_ready"; + + public static String item_to_agv_finish = "to_agv_finish"; + + private HailiangSpecialFullStationDeviceDriver driver; + + public ItemProtocol(HailiangSpecialFullStationDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getFinish() { return this.getOpcIntegerValue(item_finish);} + + public int getAllReady() { return this.getOpcIntegerValue(item_all_ready);} + + public int getOrder() { return this.getOpcIntegerValue(item_order);} + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getFull_number() { + return this.getOpcIntegerValue(item_full_number); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + //System.out.println(driver.getDevice_code()+":" + protocol+"数据同步异常"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_mode, "是否启动", "DB1.B0.1")); + list.add(new ItemDto(item_move, "光电开关信号", "DB1.B1.0")); + list.add(new ItemDto(item_status, "手自动状态", "DB1.B0.0", Boolean.valueOf(true))); + list.add(new ItemDto(item_finish, "是否完成", "DB1.B0.7")); + list.add(new ItemDto(item_all_ready, "所有设备就绪", "DB1.B1.6")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + list.add(new ItemDto(item_full_number, "出料口满框数量", "DB1.D96")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_agv_ready, "AGV就绪", "DB2.W8", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_agv_finish, "AGV完成", "DB2.W10", Boolean.valueOf(true))); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/HailiangSpecialPickStationDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/HailiangSpecialPickStationDefination.java new file mode 100644 index 00000000..41cfb8d0 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/HailiangSpecialPickStationDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pick_station; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮专机设备接框位 + */ +@Service +public class HailiangSpecialPickStationDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_special_pick_station"; + } + + @Override + public String getDriverName() { + return "海亮-专机设备接框位"; + } + + @Override + public String getDriverDescription() { + return "海亮-专机设备接框位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangSpecialPickStationDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangSpecialPickStationDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/HailiangSpecialPickStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/HailiangSpecialPickStationDeviceDriver.java new file mode 100644 index 00000000..455ab532 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/HailiangSpecialPickStationDeviceDriver.java @@ -0,0 +1,409 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pick_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮专机设备接框位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangSpecialPickStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int status = 0; + int error = 0; + int task = 0; + int finish = 0; + int order = 0; + int full_number = 0; + //出入库模式 + int operation_type = 0; + int last_mode = 0; + int last_status = 0; + int last_error = 0; + int last_task = 0; + int last_finish = 0; + int last_order = 0; + int last_full_number = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute(){ + String message = null; + try { + device_code = this.getDeviceCode(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + mode = this.itemProtocol.getMode(); + status = this.itemProtocol.getStatus(); + order = this.itemProtocol.getOrder(); + finish = this.itemProtocol.getFinish(); + full_number = this.itemProtocol.getFull_number(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (status != last_status) { + logServer.deviceItemValue(this.device_code,"status" ,String.valueOf(status)); + logServer.deviceExecuteLog(this.device_code,"","","信号status:" + last_status + "->" + status); + + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code,"task" ,String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code,"","","信号task:" + last_task + "->" + task); + + } + if (full_number != last_full_number) { + logServer.deviceItemValue(this.device_code,"full_number" ,String.valueOf(full_number)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_number:" + last_full_number + "->" + full_number); + } + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code,"finish" ,String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号finish:" + last_finish + "->" + finish); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + +/* if (mode == 2 && move != 0 && task > 0) { + + }*/ + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + //申请任务 + + break; + case 3: + + break; + case 4: + //叫料 + + break; + case 5: + //申请空盘 + /* if (move == 0 && !requireSucess) { + apply_OutEmpty(); + }*/ + break; + case 6: + //申请入库 + /* if (move != 0 && !applySucess) { + instruction_apply(); + } + if (move != 0 && !requireSucess) { + apply_InEmpty(); + }*/ + break; + } + + + } + last_mode = mode; + last_status = status; + last_error = error; + last_task = task; + last_full_number = full_number; + last_finish = finish; + last_order = order; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) {} + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/ItemProtocol.java new file mode 100644 index 00000000..8077d51f --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pick_station/ItemProtocol.java @@ -0,0 +1,97 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pick_station; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_finish = "finish"; + public static String item_order = "order"; + public static String item_error = "error"; + public static String item_full_number = "full_number"; + public static String item_task = "task"; + public static String item_status = "status"; + + public static String item_to_agv_ready = "to_agv_ready"; + + public static String item_to_agv_finish = "to_agv_finish"; + + + private HailiangSpecialPickStationDeviceDriver driver; + + public ItemProtocol(HailiangSpecialPickStationDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getFinish() { return this.getOpcIntegerValue(item_finish);} + + public int getOrder() { return this.getOpcIntegerValue(item_order);} + + public int getFull_number() { return this.getOpcIntegerValue(item_full_number);} + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_mode, "是否启动", "DB1.B0.1")); + list.add(new ItemDto(item_status, "手自动状态", "DB1.B0.0", Boolean.valueOf(true))); + list.add(new ItemDto(item_finish, "是否完成", "DB1.B0.7")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_full_number, "出料口满框数量", "DB1.D96")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/HailiangSpecialPourStationDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/HailiangSpecialPourStationDefination.java new file mode 100644 index 00000000..8be432df --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/HailiangSpecialPourStationDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pour_station; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮专机设备倒料位 + */ +@Service +public class HailiangSpecialPourStationDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_special_pour_station"; + } + + @Override + public String getDriverName() { + return "海亮-专机设备倒料位"; + } + + @Override + public String getDriverDescription() { + return "海亮-专机设备倒料位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangSpecialPourStationDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangSpecialPourStationDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/HailiangSpecialPourStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/HailiangSpecialPourStationDeviceDriver.java new file mode 100644 index 00000000..23ca505d --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/HailiangSpecialPourStationDeviceDriver.java @@ -0,0 +1,519 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pour_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.auto.run.NDCSocketConnectionAutoRun; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.WcsConfig; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮专机设备倒料位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangSpecialPourStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + private Date instruction_require_time = new Date(); + private int instruction_require_time_out = 3000; + int mode = 0; + int error = 0; + int task = 0; + int status = 0; + int running = 0; + int finish = 0; + int all_ready = 0; + int storage_stock_num = 0; + int line_stock_num = 0; + int order = 0; + int full_number = 0; + //出入库模式 + int operation_type = 0; + int last_mode = 0; + int last_error = 0; + int last_task = 0; + int last_status = 0; + int last_running = 0; + int last_finish = 0; + int last_all_ready = 0; + int last_storage_stock_num = 0; + int last_line_stock_num = 0; + int last_order = 0; + int last_full_number = 0; + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + private Date instruction_apply_time = new Date(); + int agvphase=0; + int index =0; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute(){ + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + status = this.itemProtocol.getStatus(); + running = this.itemProtocol.getRunning(); + finish = this.itemProtocol.getFinish(); + all_ready = this.itemProtocol.getAllReady(); + storage_stock_num = this.itemProtocol.getStorage_stock_num(); + line_stock_num = this.itemProtocol.getLine_stock_num(); + order = this.itemProtocol.getOrder(); + full_number = this.itemProtocol.getFull_number(); + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code,"task" ,String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code,"","","信号task:" + last_task + "->" + task); + + } + if (full_number != last_full_number) { + logServer.deviceItemValue(this.device_code,"full_number" ,String.valueOf(full_number)); + logServer.deviceExecuteLog(this.device_code,"","","信号full_number:" + last_full_number + "->" + full_number); + } + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code,"finish" ,String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号finish:" + last_finish + "->" + finish); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (status != last_status) { + logServer.deviceItemValue(this.device_code,"status" ,String.valueOf(status)); + logServer.deviceExecuteLog(this.device_code,"","","信号status:" + last_status + "->" + status); + } + if (storage_stock_num != last_storage_stock_num) { + logServer.deviceItemValue(this.device_code,"storage_stock_num" ,String.valueOf(storage_stock_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号storage_stock_num:" + last_storage_stock_num + "->" + storage_stock_num); + } + if (all_ready != last_all_ready) { + logServer.deviceItemValue(this.device_code,"all_ready" ,String.valueOf(all_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号all_ready:" + last_all_ready + "->" + all_ready); + } + if (line_stock_num != last_line_stock_num) { + logServer.deviceItemValue(this.device_code,"line_stock_num" ,String.valueOf(line_stock_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_stock_num:" + last_line_stock_num + "->" + line_stock_num); + } + if (running != last_running) { + logServer.deviceItemValue(this.device_code,"running" ,String.valueOf(running)); + logServer.deviceExecuteLog(this.device_code,"","","信号running:" + last_running + "->" + running); + } + + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + if(!requireSucess){ + if ( mode == 1) { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":requireSucess:" + requireSucess + "开始申请任务"); + applyOutCacheLineTask(); + } else { + logServer.deviceExecuteLog(this.device_code,"","",device_code+":requireSucess:" + requireSucess + "申请任务失败,不符合条件"); + } + } else { + logServer.deviceExecuteLog(this.device_code,"","","是否请求成功:requireSucess:"+requireSucess); + + } + + if(agvphase == 0x0B || agvphase == 0x0F ) + { + if(error == 0 && ObjectUtil.isNotEmpty(inst)){ + inst.setExecute_status("3"); + instructionService.update(inst); + writing("to_agv_ready", "1"); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + NDCSocketConnectionAutoRun.write(data); + agvphase = 0; + index = 0; + }else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因error:"+error+",inst"+inst); + + } + } + + if(agvphase == 0x0D || agvphase == 0x11){ + if(error == 0 && ObjectUtil.isNotEmpty(inst)) { + inst.setExecute_status("4"); + instructionService.update(inst); + writing("item_to_pour_num", inst.getQuantity()); + byte[] data = agvService.sendAgvTwoModeInst(agvphase, index, 0); + agvphase = 0; + index = 0; + }else { + logServer.deviceExecuteLog(this.device_code,"","","agvphase:" + agvphase + "等待反馈,原因error:"+error+",inst"+inst); + } + } + + } + last_mode = mode; + last_error = error; + last_task = task; + last_status = status; + last_running = running; + last_finish = finish; + last_all_ready = all_ready; + last_storage_stock_num = storage_stock_num; + last_line_stock_num = line_stock_num; + last_order = order; + last_full_number = full_number; + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public synchronized boolean applyOutCacheLineTask(){ + Date date = new Date(); + if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + Boolean flag = false; + Device device = deviceAppservice.findDeviceByCode(device_code); + Integer min_num = Integer.parseInt(device.getExtraValue().get("min_num")+""); + if (storage_stock_num < min_num ){ + JSONObject json = new JSONObject(); + json.put("device_code",device_code); + json.put("type","2"); + HttpResponse httpResponse = acsToWmsService.applyOutCacheLineTask(json); + String body = httpResponse.body(); + JSONObject jsonObject = JSONObject.parseObject(body); + String ext_task_id = jsonObject.getString("ext_task_id"); + String task_code = jsonObject.getString("task_code"); + String start_device_code = jsonObject.getString("start_device_code"); + String put_device_code = jsonObject.getString("put_device_code"); + String next_device_code = jsonObject.getString("next_device_code"); + String task_type = jsonObject.getString("task_type"); + TaskDto onedto = new TaskDto(); + String now = DateUtil.now(); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setQuantity(String.valueOf(full_number)); + onedto.setCreate_by(this.getDevice().getDevice_code()); + onedto.setUpdate_by(this.getDevice().getDevice_code()); + onedto.setRoute_plan_code("normal"); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + onedto.setTask_code("-" + taskcode); + onedto.setTask_status("0"); + onedto.setPriority("101"); + onedto.setAgv_system_type("1"); + onedto.setTask_type(task_type); + onedto.setExt_task_id(ext_task_id); + onedto.setTask_id(IdUtil.simpleUUID()); + onedto.setTask_code(task_code); + onedto.setStart_device_code(start_device_code); + onedto.setStart_point_code(start_device_code); + onedto.setPut_device_code(put_device_code); + onedto.setPut_point_code(put_device_code); + onedto.setNext_point_code(next_device_code); + onedto.setNext_device_code(next_device_code); + onedto.setUpdate_time(now); + onedto.setCreate_time(now); + try { + taskserver.create(onedto); + flag = true; + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + } + //生成任务成功 + if (flag) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":专机生成任务成功"); + requireSucess = true; + } else { + //如果都没有则调用mes接口申请入缓存线 + //生成任务 + //前往缓存线 + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":分配任务缓存线"); + } + } + + return true; + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) {} + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + + public void writing(int command, int target, int task) { + + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + itemMap.put(to_target, target); + itemMap.put(to_task, task); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + + + } + + public boolean instruction_apply() throws Exception { + return false; + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + public void apply_OutEmpty() { + + } + + public synchronized boolean apply_InEmpty() throws Exception { + return false; + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/ItemProtocol.java new file mode 100644 index 00000000..35f49297 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_special_pour_station/ItemProtocol.java @@ -0,0 +1,109 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_pour_station; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_status = "status"; + public static String item_running = "running"; + public static String item_finish = "finish"; + public static String item_all_ready = "all_ready"; + public static String item_storage_stock_num = "storage_stock_num"; + public static String item_line_stock_num = "line_stock_num"; + public static String item_order = "order"; + public static String item_error = "error"; + public static String item_full_number = "full_number"; + public static String item_task = "task"; + + public static String item_to_pour_num = "to_item_pour_num"; + + private HailiangSpecialPourStationDeviceDriver driver; + + public ItemProtocol(HailiangSpecialPourStationDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getRunning() { return this.getOpcIntegerValue(item_running);} + + public int getFinish() { return this.getOpcIntegerValue(item_finish);} + + public int getAllReady() { return this.getOpcIntegerValue(item_all_ready);} + + public int getOrder() { return this.getOpcIntegerValue(item_order);} + + public int getFull_number() { return this.getOpcIntegerValue(item_full_number);} + public int getLine_stock_num() { return this.getOpcIntegerValue(item_line_stock_num);} + public int getStorage_stock_num() { return this.getOpcIntegerValue(item_storage_stock_num);} + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB1.W82")); + list.add(new ItemDto(item_mode, "是否启动", "DB1.B0.1")); + list.add(new ItemDto(item_status, "手自动状态", "DB1.B0.0", Boolean.valueOf(true))); + list.add(new ItemDto(item_running, "是否运行", "DB1.B0.6")); + list.add(new ItemDto(item_all_ready, "所有设备就绪", "DB1.B1.6")); + list.add(new ItemDto(item_error, "报警信号", "DB1.W4")); + list.add(new ItemDto(item_full_number, "出料口满框数量", "DB1.D96")); + list.add(new ItemDto(item_storage_stock_num, "储料仓库存数量", "DB1.D100")); + list.add(new ItemDto(item_line_stock_num, "线体库存数量", "DB1.D104")); + list.add(new ItemDto(item_task, "任务号", "DB1.D92")); + list.add(new ItemDto(item_order, "工单号", "DB1.D160")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_pour_num, "倒料数量", "DB2.D96")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/HailiangStackingStationDefination.java similarity index 71% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/HailiangStackingStationDefination.java index 1dbce627..b04d6c2d 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/HailiangStackingStationDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.hongxiang_device; +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_stacking_station; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -11,33 +11,34 @@ import java.util.LinkedList; import java.util.List; /** - * 烘箱工位 + * 海亮机械手码垛工位/巷道 */ @Service -public class HongXiangConveyorDefination implements OpcDeviceDriverDefination { +public class HailiangStackingStationDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "hongxiang_device"; + return "hailiang_stacking_station"; } @Override public String getDriverName() { - return "烘箱工位"; + return "海亮-码垛工位/巷道"; } @Override public String getDriverDescription() { - return "烘箱工位"; + return "海亮-码垛工位/巷道"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new HongXiangConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HailiangStackingStationDriver()).setDevice(device).setDriverDefination(this); + } @Override public Class getDeviceDriverType() { - return HongXiangConveyorDeviceDriver.class; + return HailiangStackingStationDriver.class; } @Override diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/HailiangStackingStationDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/HailiangStackingStationDriver.java new file mode 100644 index 00000000..bb416fb9 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/HailiangStackingStationDriver.java @@ -0,0 +1,437 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_stacking_station; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮机械手码垛工位/巷道 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangStackingStationDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + + + //线体状态 + int mode = 0; + int last_mode = 0; + //线体开机状态 + int line_power_status = 0; + int last_line_power_status = 0; + //线体就绪 + int line_ready = 0; + int last_line_ready = 0; + //所有设备就绪 + int all_ready = 0; + int last_all_ready = 0; + //线体故障 + int line_error = 0; + int last_line_error = 0; + //巷道有货请求 + int lane_stock_req = 0; + int last_lane_stock_req = 0; + //订单完成 + int finish = 0; + int last_finish = 0; + //巷道1托盘满托 + int lane1_tray_full = 0; + int last_lane1_tray_full = 0; + //巷道2托盘满托 + int lane2_tray_full = 0; + int last_lane2_tray_full = 0; + //巷道1托盘位允许放货 + int lane1_allow_put = 0; + int last_lane1_allow_put = 0; + //巷道2托盘位允许放货 + int lane2_allow_put = 0; + int last_lane2_allow_put = 0; + //巷道故障 + int lane_error = 0; + int last_lane_error = 0; + //巷道1号托盘当前码垛箱数 + int lane1_tray_current_num = 0; + int last_lane1_tray_current_num = 0; + //巷道2号托盘当前码垛箱数 + int lane2_tray_current_num = 0; + int last_lane2_tray_current_num = 0; + //巷道1号托盘模板 + int lane1_tray_template = 0; + int last_lane1_tray_template = 0; + //巷道2号托盘模板 + int lane2_tray_template = 0; + int last_lane2_tray_template = 0; + //订单实时 + int order_now = 0; + int last_order_now = 0; + //托盘实时 + int tray_now = 0; + int last_tray_now = 0; + //码盘巷道工单号 + int order = 0; + int last_order = 0; + + + //出入库模式 + int operation_type = 0; + + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + line_power_status = this.itemProtocol.getLine_power_status(); + line_ready = this.itemProtocol.getLine_ready(); + all_ready = this.itemProtocol.getAll_ready(); + line_error = this.itemProtocol.getLine_error(); + lane_stock_req = this.itemProtocol.getLane_stock_req(); + finish = this.itemProtocol.getFinish(); + lane1_tray_full = this.itemProtocol.getLane1_tray_full(); + lane2_tray_full = this.itemProtocol.getLane2_tray_full(); + lane1_allow_put = this.itemProtocol.getLane1_allow_put(); + lane2_allow_put = this.itemProtocol.getLane2_allow_put(); + lane_error = this.itemProtocol.getLane_error(); + lane1_tray_current_num = this.itemProtocol.getLane1_tray_current_num(); + lane2_tray_current_num = this.itemProtocol.getLane2_tray_current_num(); + lane1_tray_template = this.itemProtocol.getLane1_tray_template(); + lane2_tray_template = this.itemProtocol.getLane2_tray_template(); + order_now = this.itemProtocol.getOrder_now(); + tray_now = this.itemProtocol.getTray_now(); + order = this.itemProtocol.getOrder(); + + if (mode != last_mode) { + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (line_power_status != last_line_power_status) { + logServer.deviceItemValue(this.device_code,"line_power_status" ,String.valueOf(line_power_status)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_power_status:" + last_line_power_status + "->" + line_power_status); + } + if (line_ready != last_line_ready) { + logServer.deviceItemValue(this.device_code,"line_ready" ,String.valueOf(line_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_ready:" + last_line_ready + "->" + line_ready); + } + if (all_ready != last_all_ready) { + logServer.deviceItemValue(this.device_code,"all_ready" ,String.valueOf(all_ready)); + logServer.deviceExecuteLog(this.device_code,"","","信号all_ready:" + last_all_ready + "->" + all_ready); + } + if (line_error != last_line_error) { + logServer.deviceItemValue(this.device_code,"line_error" ,String.valueOf(line_error)); + logServer.deviceExecuteLog(this.device_code,"","","信号line_error:" + last_line_error + "->" + line_error); + } + if (lane_stock_req != last_lane_stock_req) { + logServer.deviceItemValue(this.device_code,"lane_stock_req" ,String.valueOf(lane_stock_req)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane_stock_req:" + last_lane_stock_req + "->" + lane_stock_req); + } + if (finish != last_finish) { + logServer.deviceItemValue(this.device_code,"finish" ,String.valueOf(finish)); + logServer.deviceExecuteLog(this.device_code,"","","信号finish:" + last_finish + "->" + finish); + } + if (lane1_tray_full != last_lane1_tray_full) { + logServer.deviceItemValue(this.device_code,"lane1_tray_full" ,String.valueOf(lane1_tray_full)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane1_tray_full:" + last_lane1_tray_full + "->" + lane1_tray_full); + } + if (lane2_tray_full != last_lane2_tray_full) { + logServer.deviceItemValue(this.device_code,"lane2_tray_full" ,String.valueOf(lane2_tray_full)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane2_tray_full:" + last_lane2_tray_full + "->" + lane2_tray_full); + } + if (lane1_allow_put != last_lane1_allow_put) { + logServer.deviceItemValue(this.device_code,"lane1_allow_put" ,String.valueOf(lane1_allow_put)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane1_allow_put:" + last_lane1_allow_put + "->" + lane1_allow_put); + } + if (lane2_allow_put != last_lane2_allow_put) { + logServer.deviceItemValue(this.device_code,"lane2_allow_put" ,String.valueOf(lane2_allow_put)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane2_allow_put:" + last_lane2_allow_put + "->" + lane2_allow_put); + } + if (lane_error != last_lane_error) { + logServer.deviceItemValue(this.device_code,"lane_error" ,String.valueOf(lane_error)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane_error:" + last_lane_error + "->" + lane_error); + } + if (lane1_tray_current_num != last_lane1_tray_current_num) { + logServer.deviceItemValue(this.device_code,"lane1_tray_current_num" ,String.valueOf(lane1_tray_current_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane1_tray_current_num:" + last_lane1_tray_current_num + "->" + lane1_tray_current_num); + } + if (lane2_tray_current_num != last_lane2_tray_current_num) { + logServer.deviceItemValue(this.device_code,"lane2_tray_current_num" ,String.valueOf(lane2_tray_current_num)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane2_tray_current_num:" + last_lane2_tray_current_num + "->" + lane2_tray_current_num); + } + if (lane1_tray_template != last_lane1_tray_template) { + logServer.deviceItemValue(this.device_code,"lane1_tray_template" ,String.valueOf(lane1_tray_template)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane1_tray_template:" + last_lane1_tray_template + "->" + lane1_tray_template); + } + if (lane2_tray_template != last_lane2_tray_template) { + logServer.deviceItemValue(this.device_code,"lane2_tray_template" ,String.valueOf(lane2_tray_template)); + logServer.deviceExecuteLog(this.device_code,"","","信号lane2_tray_template:" + last_lane2_tray_template + "->" + lane2_tray_template); + } + if (order_now != last_order_now) { + logServer.deviceItemValue(this.device_code,"order_now" ,String.valueOf(order_now)); + logServer.deviceExecuteLog(this.device_code,"","","信号order_now:" + last_order_now + "->" + order_now); + } + if (tray_now != last_tray_now) { + logServer.deviceItemValue(this.device_code,"tray_now" ,String.valueOf(tray_now)); + logServer.deviceExecuteLog(this.device_code,"","","信号tray_now:" + last_tray_now + "->" + tray_now); + } + if (order != last_order) { + logServer.deviceItemValue(this.device_code,"order" ,String.valueOf(order)); + logServer.deviceExecuteLog(this.device_code,"","","信号order:" + last_order + "->" + order); + } + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + }/* else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + }*/ else if (lane_error != 0 || line_error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + + if (mode == 1 && finish == 1 && finish != last_finish && order > 0){ + ProduceshiftorderDto dto = new ProduceshiftorderDto(); + dto.setOrder_code(order + ""); + dto.setOrder_status("2"); + ProduceshiftorderDto deviceInfo = produceshiftorderService.findOrderByDeviceCode(this.device_code); + if (deviceInfo != null) { + if (StrUtil.isNotEmpty(deviceInfo.getExt_order_id())) { + String ext_order_id = deviceInfo.getExt_order_id(); + JSONObject param = new JSONObject(); + param.put("ext_order_id", ext_order_id); + acsToWmsService.feedbackOrderStatus(param); + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单的外部标识:" + ext_order_id); + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单的没有外部标识"); + } + } else { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":,对应的工单信息为空"); + } + produceshiftorderService.updateByOrderCode(dto); + this.writing("to_confirm_finished","1"); + } + } + + last_mode = mode; + last_line_power_status = line_power_status; + last_line_ready = line_ready; + last_all_ready = all_ready; + last_line_error = line_error; + last_lane_stock_req = lane_stock_req; + last_finish = finish; + last_lane1_tray_full = lane1_tray_full; + last_lane2_tray_full = lane2_tray_full; + last_lane1_allow_put = lane1_allow_put; + last_lane2_allow_put = lane2_allow_put; + last_lane_error = lane_error; + last_lane1_tray_current_num = lane1_tray_current_num; + last_lane2_tray_current_num = lane2_tray_current_num; + last_lane1_tray_template = lane1_tray_template; + last_lane2_tray_template = lane2_tray_template; + last_order_now = order_now; + last_tray_now = tray_now; + last_order = order; + + } + + public boolean exe_error() { +// if (this.error == 0) { +// return true; +// } else { +// log.debug("设备报警"); +// return false; +// } + return true; + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } + + + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/ItemProtocol.java new file mode 100644 index 00000000..15a0fdac --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_stacking_station/ItemProtocol.java @@ -0,0 +1,228 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_stacking_station; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + //线体状态 + public static String item_mode = "mode"; + //线体开机状态 + public static String item_line_power_status = "line_power_status"; + //线体就绪 + public static String item_line_ready = "line_ready"; + //所有设备就绪 + public static String item_all_ready = "all_ready"; + //线体故障 + public static String item_line_error = "line_error"; + //巷道有货请求 + public static String item_lane_stock_req = "lane_stock_req"; + //订单完成 + public static String item_finish = "finish"; + //巷道1托盘满托 + public static String item_lane1_tray_full = "lane1_tray_full"; + //巷道2托盘满托 + public static String item_lane2_tray_full = "lane2_tray_full"; + //巷道1托盘位允许放货 + public static String item_lane1_allow_put = "lane1_allow_put"; + //巷道2托盘位允许放货 + public static String item_lane2_allow_put = "lane2_allow_put"; + //巷道故障 + public static String item_lane_error = "lane_error"; + //巷道1号托盘当前码垛箱数 + public static String item_lane1_tray_current_num = "lane1_tray_current_num"; + //巷道2号托盘当前码垛箱数 + public static String item_lane2_tray_current_num = "lane2_tray_current_num"; + //巷道1号托盘模板 + public static String item_lane1_tray_template = "lane1_tray_template"; + //巷道2号托盘模板 + public static String item_lane2_tray_template = "lane2_tray_template"; + //订单实时 + public static String item_order_now = "order_now"; + //托盘实时 + public static String item_tray_now = "tray_now"; + //码盘巷道工单号 + public static String item_order = "order"; + + + + //设备开关 + public static String item_to_open = "to_open"; + //码盘信息 + public static String item_to_tray_info = "to_tray_info"; + //当前产量清零 + public static String item_to_clear = "to_clear"; + //确认完成(订单完成状态置零) + public static String item_to_confirm_finished = "to_confirm_finished"; + //巷道箱子长 + public static String item_to_lane_box_l = "to_lane_box_l"; + //巷道箱子宽 + public static String item_to_lane_box_w = "to_lane_box_w"; + //巷道箱子高 + public static String item_to_lane_box_h = "to_lane_box_h"; + //巷道1号托盘强制满托 + public static String item_to_lane1_tray_compel_full = "to_lane1_tray_compel_full"; + //巷道2号托盘强制满托 + public static String item_to_lane2_tray_compel_full = "to_lane2_tray_compel_full"; + //巷道禁用 + public static String item_to_lane_off = "to_lane_off"; + //工单强制完成 + public static String item_to_compel_finish = "to_compel_finish"; + //订单生产总量 + public static String item_to_order_prod_num = "to_order_prod_num"; + //托盘总量 + public static String item_to_tray_num = "to_tray_num"; + //工单号 + public static String item_to_order = "to_order"; + + + private HailiangStackingStationDriver driver; + + public ItemProtocol(HailiangStackingStationDriver driver) { + this.driver = driver; + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + public int getLine_power_status() { + return this.getOpcIntegerValue(item_line_power_status); + } + public int getLine_ready () { + return this.getOpcIntegerValue(item_line_ready); + } + public int getAll_ready() { + return this.getOpcIntegerValue(item_all_ready); + } + public int getLine_error() { + return this.getOpcIntegerValue(item_line_error); + } + public int getLane_stock_req() { + return this.getOpcIntegerValue(item_lane_stock_req); + } + public int getFinish() { + return this.getOpcIntegerValue(item_finish); + } + public int getLane1_tray_full () { + return this.getOpcIntegerValue(item_lane1_tray_full); + } + public int getLane2_tray_full () { + return this.getOpcIntegerValue(item_lane2_tray_full); + } + public int getLane1_allow_put() { + return this.getOpcIntegerValue(item_lane1_allow_put); + } + public int getLane2_allow_put() { + return this.getOpcIntegerValue(item_lane2_allow_put); + } + public int getLane_error() { + return this.getOpcIntegerValue(item_lane_error); + } + public int getLane1_tray_current_num() { + return this.getOpcIntegerValue(item_lane1_tray_current_num); + } + public int getLane2_tray_current_num () { + return this.getOpcIntegerValue(item_lane2_tray_current_num); + } + public int getLane1_tray_template() { + return this.getOpcIntegerValue(item_lane1_tray_template); + } + public int getLane2_tray_template() { + return this.getOpcIntegerValue(item_lane2_tray_template); + } + public int getOrder_now() { + return this.getOpcIntegerValue(item_order_now); + } + public int getTray_now() { + return this.getOpcIntegerValue(item_tray_now); + } + public int getOrder() { + return this.getOpcIntegerValue(item_order); + } + + + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static String getField_desc(String item) { + String field_desc = ""; + List readlist = getReadableItemDtos(); + List writelist = getWriteableItemDtos(); + for (int i = 0; i < readlist.size(); i++) { + ItemDto dto = readlist.get(i); +// if(){ +// +// } + } + return field_desc; + } + + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_mode, "线体状态", "DB1.B0.0")); + list.add(new ItemDto(item_line_power_status, "线体开机状态", "DB1.B0.1")); + list.add(new ItemDto(item_line_ready, "线体就绪", "DB1.B2.1")); + list.add(new ItemDto(item_all_ready, "所有设备就绪", "DB1.B2.2")); + list.add(new ItemDto(item_line_error, "线体故障", "DB1.W4")); + list.add(new ItemDto(item_lane_stock_req, "巷道有货请求", "DB1.B1.1")); + list.add(new ItemDto(item_finish, "订单完成", "DB1.B2.3")); + list.add(new ItemDto(item_lane1_tray_full, "巷道1号托盘满托", "DB1.B2.5")); + list.add(new ItemDto(item_lane2_tray_full, "巷道2号托盘满托", "DB1.B2.6")); + list.add(new ItemDto(item_lane1_allow_put, "巷道1号托盘位允许放货", "DB1.B3.1")); + list.add(new ItemDto(item_lane2_allow_put, "巷道2号托盘位允许放货", "DB1.B3.2")); + list.add(new ItemDto(item_lane_error, "巷道error", "DB1.W10")); + list.add(new ItemDto(item_lane1_tray_current_num, "巷道1号托盘当前码垛箱数", "DB1.W64")); + list.add(new ItemDto(item_lane2_tray_current_num, "巷道2号托盘当前码垛箱数", "DB1.W66")); + list.add(new ItemDto(item_lane1_tray_template, "巷道1号托盘模板", "DB1.W72")); + list.add(new ItemDto(item_lane2_tray_template, "巷道2号托盘模板", "DB1.DW74")); + list.add(new ItemDto(item_order_now, "订单实时", "DB1.DW84")); + list.add(new ItemDto(item_tray_now, "托盘实时", "DB1.DW88")); + list.add(new ItemDto(item_order, "工单号", "DB1.DW156")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_open, "设备开关", "DB2.W4")); + list.add(new ItemDto(item_to_tray_info, "码盘信息", "DB2.W12")); + list.add(new ItemDto(item_to_clear, "当前产量清零", "DB2.W16")); + list.add(new ItemDto(item_to_confirm_finished, "订单确认完成", "DB2.W20")); + list.add(new ItemDto(item_to_lane_box_l, "巷道箱子长", "DB2.W28")); + list.add(new ItemDto(item_to_lane_box_w, "巷道箱子宽", "DB2.W30")); + list.add(new ItemDto(item_to_lane_box_h, "巷道箱子高", "DB2.W32")); + list.add(new ItemDto(item_to_lane1_tray_compel_full, "巷道1号托盘强制满托", "DB2.W40")); + list.add(new ItemDto(item_to_lane2_tray_compel_full, "巷道2号托盘强制满托", "DB2.W42")); + list.add(new ItemDto(item_to_lane_off, "巷道禁用", "DB2.W48")); + list.add(new ItemDto(item_to_compel_finish, "工单强制完成", "DB2.W80")); + list.add(new ItemDto(item_to_order_prod_num, "订单生产总量", "DB2.DW84")); + list.add(new ItemDto(item_to_tray_num, "托盘总量", "DB2.DW88")); + list.add(new ItemDto(item_to_order, "工单号", "DB2.DW156")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/HailiangThreestationSmartDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/HailiangThreestationSmartDefination.java new file mode 100644 index 00000000..f9a28640 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/HailiangThreestationSmartDefination.java @@ -0,0 +1,75 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_threeStation_smart; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮-三工位Smart200 + */ +@Service +public class HailiangThreestationSmartDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_threestation_smart"; + } + + @Override + public String getDriverName() { + return "海亮-三工位Smart200"; + } + + @Override + public String getDriverDescription() { + return "海亮-三工位Smart200"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangThreestationSmartDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangThreestationSmartDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "VW2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_move, "光电信号", "VW4")); + list.add(new ItemDto(ItemProtocol.item_action, "取放信号", "VW6")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "VW8")); + list.add(new ItemDto(ItemProtocol.item_number, "数量", "VW10")); + list.add(new ItemDto(ItemProtocol.item_container_type, "托盘类型", "VW12")); + list.add(new ItemDto(ItemProtocol.item_task, "任务号", "VD14")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/HailiangThreestationSmartDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/HailiangThreestationSmartDeviceDriver.java new file mode 100644 index 00000000..dfcd4154 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/HailiangThreestationSmartDeviceDriver.java @@ -0,0 +1,266 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_threeStation_smart; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海亮-三工位Smart200 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangThreestationSmartDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + String container_type_desc; + String last_container_type_desc; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int move = 0; + int task = 0; + int action = 0; + int number = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_action = 0; + int last_number = 0; + int last_container_type = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //物料 + String material; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getError(); + action = this.itemProtocol.getAction(); + move = this.itemProtocol.getMove(); + number = this.itemProtocol.getNumber(); + container_type = this.itemProtocol.getContainer_type(); + task = this.itemProtocol.getTask(); + hasGoods = this.itemProtocol.getMove(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code,"move" ,String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code,"","","信号move:" + last_move + "->" + move); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code,"action" ,String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code,"","","信号action:" + last_action + "->" + action); + } + if (container_type != last_container_type) { + logServer.deviceItemValue(this.device_code,"container_type" ,String.valueOf(container_type)); + logServer.deviceExecuteLog(this.device_code,"","","信号container_type:" + last_container_type + "->" + container_type); + } + if (number != last_number) { + logServer.deviceItemValue(this.device_code,"number" ,String.valueOf(number)); + logServer.deviceExecuteLog(this.device_code,"","","信号number:" + last_number + "->" + number); + } + + } catch (Exception var17) { + return; + } + + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + break; + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_action = action; + last_number = number; + last_container_type = container_type; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + } else if (type == 2) { + itemMap.put(to_target, command); + + } else if (type == 3) { + itemMap.put(to_task, command); + } + ReadUtil.write(itemMap, server); + + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/ItemProtocol.java new file mode 100644 index 00000000..c7ad6d31 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_threeStation_smart/ItemProtocol.java @@ -0,0 +1,119 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_threeStation_smart; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_number = "number"; + public static String item_container_type = "container_type"; + public static String item_task = "task"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + public static String item_weight = "weight"; + + private HailiangThreestationSmartDeviceDriver driver; + + public ItemProtocol(HailiangThreestationSmartDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getNumber() { + return this.getOpcIntegerValue(item_number); + } + + public int getContainer_type() { + return this.getOpcIntegerValue(item_container_type); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "VW0")); + list.add(new ItemDto(item_mode, "工作状态", "VW2", Boolean.valueOf(true))); + list.add(new ItemDto(item_move, "光电信号", "VW4")); + list.add(new ItemDto(item_action, "取放信号", "VW6")); + list.add(new ItemDto(item_error, "报警信号", "VW8")); + list.add(new ItemDto(item_number, "数量", "VW10")); + list.add(new ItemDto(item_container_type, "托盘类型", "VW12")); + list.add(new ItemDto(item_task, "任务号", "VD14")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "VW102", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "目标站", "VW104")); + list.add(new ItemDto(item_to_task, "任务号", "VD108")); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/HailiangHailiangxjplcTestDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/HailiangHailiangxjplcTestDeviceDriver.java new file mode 100644 index 00000000..1b8347d3 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/HailiangHailiangxjplcTestDeviceDriver.java @@ -0,0 +1,286 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_xj_plc_test; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮清洗机储料仓 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HailiangHailiangxjplcTestDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int heartbeat = 0; + int mode =0; + int error =0; + int error_num =0; + int open_time =0; + int close_time =0; + int ready_time =0; + int running_time =0; + int error_time =0; + int voltage =0; + int temperature =0; + int current =0; + int material =0; + int lack_material =0; + int full_material =0; + int storage_qty =0; + int feeding_qty =0; + int blanking_qty =0; + int qualified_qty =0; + int unqualified_qty =0; + int finish =0; + int task =0; + int noload_electricity_consumption =0; + int prod_electricity_consumption =0; + int gas_consumption =0; + int water_consumption =0; + int oil_level =0; + int monthly_electricity_consumption =0; + int pause =0; + + + int last_mode =0; + int last_error =0; + int last_error_num =0; + int last_open_time =0; + int last_close_time =0; + int last_ready_time =0; + int last_running_time =0; + int last_error_time =0; + int last_voltage =0; + int last_temperature =0; + int last_current =0; + int last_material =0; + int last_lack_material =0; + int last_full_material =0; + int last_storage_qty =0; + int last_feeding_qty =0; + int last_blanking_qty =0; + int last_qualified_qty =0; + int last_unqualified_qty =0; + int last_finish =0; + int last_task =0; + int last_noload_electricity_consumption =0; + int last_prod_electricity_consumption =0; + int last_gas_consumption =0; + int last_water_consumption =0; + int last_oil_level =0; + int last_monthly_electricity_consumption =0; + int last_pause =0; + + + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + //请求成功标记 + Boolean requireSucess = false; + //申请指令成功标记 + Boolean applySucess = false; + String inst_message; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag = 0; + + + int agvphase=0; + int index =0; + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute(){ + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + error = this.itemProtocol.getItem_error(); + error_num = this.itemProtocol.getItem_error_num(); + open_time = this.itemProtocol.getItem_open_time(); + close_time = this.itemProtocol.getItem_close_time(); + ready_time = this.itemProtocol.getItem_ready_time(); + running_time = this.itemProtocol.getItem_running_time(); + error_time = this.itemProtocol.getItem_error_time(); + voltage = this.itemProtocol.getItem_voltage(); + temperature = this.itemProtocol.getItem_temperature(); + current = this.itemProtocol.getItem_current(); + material = this.itemProtocol.getItem_material(); + lack_material = this.itemProtocol.getItem_lack_material(); + full_material = this.itemProtocol.getItem_full_material(); + storage_qty = this.itemProtocol.getItem_storage_qty(); + feeding_qty = this.itemProtocol.getItem_feeding_qty(); + blanking_qty = this.itemProtocol.getItem_blanking_qty(); + qualified_qty = this.itemProtocol.getItem_qualified_qty(); + unqualified_qty = this.itemProtocol.getItem_unqualified_qty(); + finish = this.itemProtocol.getItem_finish(); + task = this.itemProtocol.getItem_task(); + noload_electricity_consumption = this.itemProtocol.getItem_noload_electricity_consumption(); + prod_electricity_consumption = this.itemProtocol.getItem_prod_electricity_consumption(); + gas_consumption = this.itemProtocol.getItem_gas_consumption(); + water_consumption = this.itemProtocol.getItem_water_consumption(); + oil_level = this.itemProtocol.getItem_oil_level(); + monthly_electricity_consumption = this.itemProtocol.getItem_monthly_electricity_consumption(); + pause = this.itemProtocol.getItem_pause(); + + if (mode != last_mode) { + this.setRequireSucess(false); + logServer.deviceItemValue(this.device_code,"mode" ,String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code,"","","信号mode:" + last_mode + "->" + mode); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code,"error" ,String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code,"","","信号error:" + last_error + "->" + error); + } + } + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + logServer.deviceExecuteLog(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess); + + this.setRequireSucess(false); + this.setApplySucess(false); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.setInst_message(null); + this.setContainer(null); + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + } + + public void writing(String key, String value) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + key; + 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); + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/HailiangxjplcTestDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/HailiangxjplcTestDefination.java new file mode 100644 index 00000000..6a7411af --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/HailiangxjplcTestDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_xj_plc_test; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮迅捷plc测试 + */ +@Service +public class HailiangxjplcTestDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_xj_plc_test"; + } + + @Override + public String getDriverName() { + return "海亮-海亮迅捷plc测试"; + } + + @Override + public String getDriverDescription() { + return "海亮-海亮迅捷plc测试"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HailiangHailiangxjplcTestDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HailiangHailiangxjplcTestDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/ItemProtocol.java new file mode 100644 index 00000000..0dfa78ba --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hailiang_one/hailiang_xj_plc_test/ItemProtocol.java @@ -0,0 +1,248 @@ +package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_xj_plc_test; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_error = "error"; + public static String item_error_num = "error_num"; + public static String item_open_time = "open_time"; + public static String item_close_time = "close_time"; // + public static String item_ready_time = "ready_time"; // + public static String item_running_time = "running_time"; + public static String item_error_time = "error_time"; + public static String item_voltage = "voltage"; + public static String item_temperature = "temperature"; + public static String item_current = "current"; + public static String item_material = "material"; + public static String item_lack_material = "lack_material"; + public static String item_full_material = "full_material"; + public static String item_storage_qty = "storage_qty"; + public static String item_feeding_qty = "feeding_qty"; + public static String item_blanking_qty = "blanking_qty"; + public static String item_qualified_qty = "qualified_qty"; + public static String item_unqualified_qty = "unqualified_qty"; + public static String item_finish = "finish"; + public static String item_task = "task"; + public static String item_noload_electricity_consumption = "noload_electricity_consumption"; + public static String item_prod_electricity_consumption = "prod_electricity_consumption"; + public static String item_gas_consumption = "gas_consumption"; + public static String item_water_consumption = "water_consumption"; + public static String item_oil_level = "oil_level"; + public static String item_monthly_electricity_consumption = "monthly_electricity_consumption"; + public static String item_pause = "pause"; + + + + public static String item_to_heartbeat = "to_heartbeat";// + public static String item_to_command = "to_command";// + public static String item_to_feeding = "to_feeding";// + public static String item_to_task = "to_task";// + public static String item_to_pause= "to_pause";// + public static String item_to_clear = "to_clear";// + public static String item_to_finish = "to_finish";// + public static String item_to_open = "to_open";// + public static String item_to_close = "to_close";// + public static String item_to_material = "to_material";// + public static String item_to_qty = "to_qty";// + + + private HailiangHailiangxjplcTestDeviceDriver driver; + + public ItemProtocol(HailiangHailiangxjplcTestDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_error_num() { + return this.getOpcIntegerValue(item_error_num); + } + + public int getItem_open_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getItem_close_time() { + return this.getOpcIntegerValue(item_close_time); + } + + public int getItem_ready_time() { + return this.getOpcIntegerValue(item_ready_time); + } + + public int getItem_running_time() { + return this.getOpcIntegerValue(item_running_time); + } + + public int getItem_error_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getItem_voltage() { + return this.getOpcIntegerValue(item_voltage); + } + + public int getItem_temperature() { + return this.getOpcIntegerValue(item_temperature); + } + + public int getItem_current() { + return this.getOpcIntegerValue(item_current); + } + + public int getItem_material() { + return this.getOpcIntegerValue(item_material); + } + + public int getItem_lack_material() { + return this.getOpcIntegerValue(item_lack_material); + } + + public int getItem_full_material() { + return this.getOpcIntegerValue(item_full_material); + } + + public int getItem_storage_qty() { + return this.getOpcIntegerValue(item_storage_qty); + } + + public int getItem_feeding_qty() { + return this.getOpcIntegerValue(item_feeding_qty); + } + + public int getItem_blanking_qty() { + return this.getOpcIntegerValue(item_blanking_qty); + } + + public int getItem_qualified_qty() { + return this.getOpcIntegerValue(item_qualified_qty); + } + + public int getItem_unqualified_qty() { + return this.getOpcIntegerValue(item_unqualified_qty); + } + + public int getItem_finish() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_task() { + return this.getOpcIntegerValue(item_task); + } + + public int getItem_noload_electricity_consumption() { + return this.getOpcIntegerValue(item_noload_electricity_consumption); + } + + public int getItem_prod_electricity_consumption() { + return this.getOpcIntegerValue(item_prod_electricity_consumption); + } + + public int getItem_gas_consumption() { + return this.getOpcIntegerValue(item_gas_consumption); + } + + public int getItem_water_consumption() { + return this.getOpcIntegerValue(item_water_consumption); + } + + public int getItem_oil_level() { + return this.getOpcIntegerValue(item_oil_level); + } + + public int getItem_monthly_electricity_consumption() { + return this.getOpcIntegerValue(item_monthly_electricity_consumption); + } + + public int getItem_pause() { + return this.getOpcIntegerValue(item_pause); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "45203")); + list.add(new ItemDto(item_mode, "模式", "45205")); + list.add(new ItemDto(item_error, "故障", "45207")); + list.add(new ItemDto(item_error_num, "故障次数", "45209")); + list.add(new ItemDto(item_open_time, "开机时间", "45213")); + list.add(new ItemDto(item_close_time, "关机时间", "45217")); + list.add(new ItemDto(item_ready_time, "待机时间", "45221")); + list.add(new ItemDto(item_running_time, "生产时间", "45225")); + list.add(new ItemDto(item_error_time, "故障时间", "45229")); + list.add(new ItemDto(item_temperature, "温度", "45233")); + list.add(new ItemDto(item_voltage, "电压", "45237")); + list.add(new ItemDto(item_current, "电流", "45241")); + list.add(new ItemDto(item_material, "当前生产产品编号", "45245")); + list.add(new ItemDto(item_lack_material, "生产缺料信号", "45249")); + list.add(new ItemDto(item_full_material, "生产满料信号", "45253")); + list.add(new ItemDto(item_storage_qty, "储料斗数量", "45257")); + list.add(new ItemDto(item_feeding_qty, "上料数量", "45261")); + list.add(new ItemDto(item_blanking_qty, "下料数量", "45265")); + list.add(new ItemDto(item_qualified_qty, "当前生产合格品数量", "45269")); + list.add(new ItemDto(item_unqualified_qty, "当前生产不合格数量", "45273")); + list.add(new ItemDto(item_finish, "生产完成", "45277")); + list.add(new ItemDto(item_task, "任务号", "45281")); + list.add(new ItemDto(item_noload_electricity_consumption, "空载电能耗(未生产时)", "45285")); + list.add(new ItemDto(item_prod_electricity_consumption, "生产电能耗", "45289")); + list.add(new ItemDto(item_gas_consumption, "气压能耗", "45293")); + list.add(new ItemDto(item_water_consumption, "水流量能耗", "452967")); + list.add(new ItemDto(item_oil_level, "当前液压油位", "45301")); + list.add(new ItemDto(item_monthly_electricity_consumption, "本月总电能耗", "45305")); + list.add(new ItemDto(item_pause, "设备暂停", "45309")); + + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_heartbeat, "心跳", "45703")); + list.add(new ItemDto(item_to_command, "下发命令", "45705")); + list.add(new ItemDto(item_to_feeding, "下发命令", "45707")); + list.add(new ItemDto(item_to_task, "任务号", "45711")); + list.add(new ItemDto(item_to_pause, "生产暂停", "45715")); + list.add(new ItemDto(item_to_clear, "当前产量清零", "45719")); + list.add(new ItemDto(item_to_finish, "强制完成", "45723")); + list.add(new ItemDto(item_to_open, "设备开机", "45727")); + list.add(new ItemDto(item_to_close, "设备关机", "45731")); + list.add(new ItemDto(item_to_material, "当前任务生产物料", "45735")); + list.add(new ItemDto(item_to_qty, "当前任务生产数量", "45739")); + return list; + } + + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java deleted file mode 100644 index 886c2d85..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/HongXiangStationDeviceDriver.java +++ /dev/null @@ -1,230 +0,0 @@ -package org.nl.acs.device_driver.basedriver.hongxiang_conveyor; - -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 烘箱对接位 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class HongXiangStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver , DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); - @Autowired - AgvService agvService = SpringContextHolder.getBean(AgvService.class); - - private Date instruction_require_time = new Date(); - private Date instruction_finished_time = new Date(); - private Date instruction_apply_time = new Date(); - private int instruction_require_time_out = 3000; - - public int heartbeat = 0; - public int mode = 0; - public int move = 0; - public int action = 0; - public int error = 0; - public int door = 0; - public int temperature = 0; - public int countdown = 0; - public int finish = 0; - public int task = 0; - public int error1 = 0; - public int material = 0; - public int consumption = 0; - public int voltageA = 0; - public int voltageB = 0; - public int voltageC = 0; - public int currentA = 0; - public int currentB = 0; - public int currentC = 0; - - public int last_heartbeat = 0; - public int last_mode = 0; - public int last_move = 0; - public int last_action = 0; - public int last_error = 0; - public int last_door = 0; - public int last_temperature = 0; - public int last_countdown = 0; - public int last_finish = 0; - public int last_task = 0; - public int last_error1 = 0; - public int last_material = 0; - public int last_consumption = 0; - public int last_voltageA = 0; - public int last_voltageB = 0; - public int last_voltageC = 0; - public int last_currentA = 0; - public int last_currentB = 0; - public int last_currentC = 0; - - Boolean isonline = true; - - Boolean iserror = false; - - //1-执行任务;2-取货完成;3-放货完成; - int flag; - - String device_code; - - @Override - public Device getDevice() { - return this.device; - } - - //请求成功标记 - Boolean requireSucess = false; - - @Override - public void execute() { - String message = null; - - device_code = this.getDeviceCode(); - - } - - - public synchronized boolean instruction_apply(String container_code) throws Exception { - Date date = new Date(); - if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_apply_time = date; - requireSucess = true; - return true; - } - } - - protected void thingToNothing() { - this.setRequireSucess(false); - } - - public void writing(int command) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command; - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command, command); - this.control(itemMap); - } - - //将扩展表中的字符串数据转换成集合 - public List getExtraDeviceCodes(String extraName) { - String extraValue = (String) this.getDevice().getExtraValue().get(extraName); - if (StrUtil.isEmpty(extraValue)){ - return new ArrayList<>(); - } - String devicesString = extraValue.substring(1, extraValue.length() - 1); - List devicesList = new ArrayList<>(); - String[] devices = devicesString.split(","); - for (int i = 0; i < devices.length; i++) { - String s = devices[i].replace("\"", "").replace("\"", ""); - devicesList.add(s); - } - return devicesList; - } - - public void writing(String param, String value) { - - String to_param = 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_param, value); -// itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - } - - public void writing(int type, int command) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_command; - String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_target; - String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_task; - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - if (type == 1) { - itemMap.put(to_command, command); - log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command); - } else if (type == 2) { - itemMap.put(to_target, command); - log.info("设备:" + device_code + ",下发PLC信号" + to_target + ",value:" + command); - - } else if (type == 3) { - itemMap.put(to_task, command); - log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); - } - - this.control(itemMap); - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String move = ""; - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", "联机"); - jo.put("action", action); - jo.put("isOnline", true); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("task", this.getTask()); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/ItemProtocol.java deleted file mode 100644 index 46f385f1..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_conveyor/ItemProtocol.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.nl.acs.device_driver.basedriver.hongxiang_conveyor; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - public static String item_action = "action"; - - public static String item_to_command = "to_command"; - - private HongXiangStationDeviceDriver driver; - - public ItemProtocol(HongXiangStationDeviceDriver driver) { - this.driver = driver; - } - - - public int getItem_action(){ - return this.getOpcIntegerValue(item_action); - }; - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - - list.add(new ItemDto(item_action, "动作信号", "450")); - - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "226")); - return list; - } - - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java deleted file mode 100644 index 286cdce1..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java +++ /dev/null @@ -1,376 +0,0 @@ -package org.nl.acs.device_driver.basedriver.hongxiang_device; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.core.bean.WQLObject; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 烘箱工位 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); - @Autowired - AgvService agvService = SpringContextHolder.getBean(AgvService.class); - - private Date instruction_require_time = new Date(); - private Date instruction_finished_time = new Date(); - private Date instruction_apply_time = new Date(); - private int instruction_require_time_out = 3000; - - public int heartbeat = 0; - public int mode = 0; - public int move = 0; - public int action = 0; - public int error = 0; - public int door = 0; - public int temperature = 0; - public int to_temperature = 0; - public int countdown_house = 0; - public int countdown_min = 0; - public int countdown_sec = 0; - public int finish = 0; - public int task = 0; - public int error1 = 0; - public int material = 0; - public int consumption = 0; - public float voltageA = 0; - public float voltageB = 0; - public float voltageC = 0; - public float currentA = 0; - public float currentB = 0; - public float currentC = 0; - - public int last_heartbeat = 0; - public int last_mode = 0; - public int last_move = 0; - public int last_action = 0; - public int last_error = 0; - public int last_door = 0; - public int last_temperature = 0; - public int last_countdown_house = 0; - public int last_countdown_min = 0; - public int last_countdown_sec = 0; - public int last_finish = 0; - public int last_task = 0; - public int last_error1 = 0; - public int last_material = 0; - public int last_consumption = 0; - public float last_voltageA = 0; - public float last_voltageB = 0; - public float last_voltageC = 0; - public float last_currentA = 0; - public float last_currentB = 0; - public float last_currentC = 0; - - Boolean isonline = true; - - Boolean iserror = false; - - //1-执行任务;2-取货完成;3-放货完成; - int flag; - - String device_code; - - String message = null; - - - @Override - public Device getDevice() { - return this.device; - } - - //请求成功标记 - Boolean requireSucess = false; - - @Override - public void execute() { - - device_code = this.getDeviceCode(); - heartbeat = this.itemProtocol.getItem_heartbeat(); - mode = this.itemProtocol.getItem_mode(); - move = this.itemProtocol.getItem_move(); - action = this.itemProtocol.getItem_action(); - error = this.itemProtocol.getItem_error(); - door = this.itemProtocol.getItem_door(); - temperature = this.itemProtocol.getItem_temperature(); - countdown_house = this.itemProtocol.getItem_countdown_house(); - countdown_min = this.itemProtocol.getItem_countdown_min(); - countdown_sec = this.itemProtocol.getItem_countdown_sec(); - finish = this.itemProtocol.getItem_finish(); - task = this.itemProtocol.getItem_task(); - error1 = this.itemProtocol.getItem_error1(); - material = this.itemProtocol.getItem_material(); - consumption = this.itemProtocol.getItem_consumption(); - voltageA = this.itemProtocol.getItem_voltageA(); - voltageB = this.itemProtocol.getItem_voltageB(); - voltageC = this.itemProtocol.getItem_voltageC(); - currentA = this.itemProtocol.getItem_currentA(); - currentB = this.itemProtocol.getItem_currentB(); - currentC = this.itemProtocol.getItem_currentC(); - to_temperature = this.itemProtocol.getItem_to_temperature(); - if(door != last_door){ - logServer.deviceExecuteLog(this.device_code, "", "", "信号door:" + last_door + "->" + door); - } - if (mode != last_mode) { - //this.setRequireSucess(false); - } - if (move != last_move) { - if (move == 0) { - thingToNothing(); - } - } - if (finish != last_finish) { - if (finish == 1) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为requireSucess:" + requireSucess); - requireSucess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为requireSucess:" + requireSucess); - } - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_finish + "->" + finish); - } - if (mode == 0) { - this.setIsonline(false); - message = "有报警"; - //无报警 - } else if (error != 0) { - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - if (move == 0 && last_move == 1) { - //requireSucess = false; - } - - if (finish == 1 && !requireSucess) { - //烘箱完成反馈LMS - apply_finish(); - } - } - - last_mode = mode; - last_move = move; - last_action = action; - last_error = error; - last_door = door; - last_temperature = temperature; - last_countdown_house = countdown_house; - last_countdown_min = countdown_min; - last_countdown_sec = countdown_sec; - last_finish = finish; - last_task = task; - last_error1 = error1; - last_material = material; - last_consumption = consumption; - last_voltageA = voltageA; - last_voltageB = voltageB; - last_voltageC = voltageC; - last_currentA = currentA; - last_currentB = currentB; - last_currentC = currentC; - } - - - protected void thingToNothing() { - //this.setRequireSucess(false); - } - - public void writing(int command) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command; - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command, command); - this.control(itemMap); - } - - //将扩展表中的字符串数据转换成集合 - public List getExtraDeviceCodes(String extraName) { - String extraValue = (String) this.getDevice().getExtraValue().get(extraName); - if (StrUtil.isEmpty(extraValue)) { - return new ArrayList<>(); - } - String devicesString = extraValue.substring(1, extraValue.length() - 1); - List devicesList = new ArrayList<>(); - String[] devices = devicesString.split(","); - for (int i = 0; i < devices.length; i++) { - String s = devices[i].replace("\"", "").replace("\"", ""); - devicesList.add(s); - } - return devicesList; - } - - public void writing(String param, String value) { - - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + param; - - Map itemMap = new HashMap(); - - itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void writing(int type, int command) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_command; - String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_target; - String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_task; - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - if (type == 1) { - itemMap.put(to_command, command); - log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command); - } else if (type == 2) { - itemMap.put(to_target, command); - log.info("设备:" + device_code + ",下发PLC信号" + to_target + ",value:" + command); - - } else if (type == 3) { - itemMap.put(to_task, command); - log.info("设备:" + device_code + ",下发PLC信号" + to_task + ",value:" + command); - } - - this.control(itemMap); - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String move = ""; - if (this.getMode() == 0) { - mode = "未联机"; - } else if (this.getMode() == 1) { - mode = "联机"; - } else if (this.getMode() == 2) { - mode = "联机"; - } - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("requireSucess", requireSucess); - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("temperature", temperature); - jo.put("finish", finish); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("countdown_house", countdown_house); - jo.put("countdown_min", countdown_min); - jo.put("countdown_sec", countdown_sec); - jo.put("door", door); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("task", this.getTask()); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } - - public synchronized boolean apply_finish() { - Date date = new Date(); - if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_apply_time = date; - message = "烘箱完成反馈LMS..."; - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("3"); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - logServer.deviceExecuteLog(this.device_code, "", "", "烘拷完成,请求参数:"+JSON.toJSONString(applyLabelingAndBindingRequest)); - if (applyLabelingAndBindingResponse.getstatus() == 200) { - requireSucess = true; - message = "烘箱完成反馈LMS成功..."; - logServer.deviceExecuteLog(this.device_code, "", "", "烘拷完成请求成功,响应参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - } else { - requireSucess = true; - message = "烘箱完成反馈LMS失败,"+String.valueOf(applyLabelingAndBindingResponse); - logServer.deviceExecuteLog(this.device_code, "", "", "烘拷完成请求失败,响应参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - } - return true; - } - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java deleted file mode 100644 index 95e82150..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.nl.acs.device_driver.basedriver.hongxiang_device; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - public static String item_heartbeat = "heartbeat"; - public static String item_mode = "mode"; - public static String item_move = "move"; - public static String item_action = "action"; - public static String item_error = "error"; - public static String item_door = "door"; - public static String item_temperature = "temperature"; - //恒温倒计时 - public static String item_countdown_house = "countdown_house"; - public static String item_countdown_min = "countdown_min"; - public static String item_countdown_sec = "countdown_sec"; - - public static String item_finish = "finish"; - public static String item_task = "task"; - public static String item_error1 = "error1"; - public static String item_material = "material"; - public static String item_consumption = "consumption"; - public static String item_voltageA = "voltageA"; - public static String item_voltageB = "voltageB"; - public static String item_voltageC = "voltageC"; - public static String item_currentA = "currentA"; - public static String item_currentB = "currentB"; - public static String item_currentC = "currentC"; - - - public static String item_to_command = "to_command"; - public static String item_to_open_door = "to_open_door"; - public static String item_to_close_door = "to_close_door"; - public static String item_to_temperature = "to_temperature"; - public static String item_to_material = "to_material"; - public static String item_to_time_house = "to_time_house"; - public static String item_to_time_min = "to_time_min"; - public static String item_to_time_sec = "to_time_sec"; - - public static String item_to_task = "to_task"; - - - private HongXiangConveyorDeviceDriver driver; - - public ItemProtocol(HongXiangConveyorDeviceDriver driver) { - this.driver = driver; - } - - public int getItem_heartbeat(){ - return this.getOpcIntegerValue(item_heartbeat); - } ; - public int getItem_mode(){ - return this.getOpcIntegerValue(item_mode); - } ; - public int getItem_move(){ - return this.getOpcIntegerValue(item_move); - } ; - public int getItem_action(){ - return this.getOpcIntegerValue(item_action); - }; - public int getItem_error(){ - return this.getOpcIntegerValue(item_error); - } ; - public int getItem_door(){ - return this.getOpcIntegerValue(item_door); - } ; - public int getItem_temperature(){ - return this.getOpcIntegerValue(item_temperature); - } ; - public int getItem_countdown_house(){ - return this.getOpcIntegerValue(item_countdown_house); - } ; - public int getItem_countdown_min(){ - return this.getOpcIntegerValue(item_countdown_min); - } ; - public int getItem_countdown_sec(){ - return this.getOpcIntegerValue(item_countdown_sec); - } ; - public int getItem_finish(){ - return this.getOpcIntegerValue(item_finish); - } ; - public int getItem_task(){ - return this.getOpcIntegerValue(item_task); - } ; - public int getItem_error1(){ - return this.getOpcIntegerValue(item_error1); - } ; - public int getItem_material(){ - return this.getOpcIntegerValue(item_material); - } ; - public int getItem_consumption(){ - return this.getOpcIntegerValue(item_consumption); - } ; - public float getItem_voltageA(){ - return this.getOpcFloatValue(item_voltageA); - } ; - public float getItem_voltageB(){ - return this.getOpcFloatValue(item_voltageB); - } ; - public float getItem_voltageC(){ - return this.getOpcFloatValue(item_voltageC); - } ; - public float getItem_currentA(){ - return this.getOpcFloatValue(item_currentA); - } ; - public float getItem_currentB(){ - return this.getOpcFloatValue(item_currentB); - } ; - public float getItem_currentC(){ - return this.getOpcFloatValue(item_currentC); - } ; - - public int getItem_to_temperature(){ - return this.getOpcIntegerValue(item_to_temperature); - } ; - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public float getOpcFloatValue(String protocol) { - Float value = this.driver.getDoubleValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0L; - - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "251")); - list.add(new ItemDto(item_mode, "工作模式", "7990")); - list.add(new ItemDto(item_move, "光电信号", "550")); - list.add(new ItemDto(item_door, "门状态", "450")); - list.add(new ItemDto(item_temperature, "工位温度", "7991")); - list.add(new ItemDto(item_countdown_house, "恒温倒计时(时)", "80500")); - list.add(new ItemDto(item_countdown_min, "恒温倒计时(分)", "80502")); - list.add(new ItemDto(item_countdown_sec, "恒温倒计时(秒)", "80504")); - list.add(new ItemDto(item_finish, "烘干完成", "8025")); - list.add(new ItemDto(item_action, "取放信号", "450")); - list.add(new ItemDto(item_task, "任务号", "220")); - list.add(new ItemDto(item_error, "故障", "8055")); - list.add(new ItemDto(item_error1, "故障1", "216")); - list.add(new ItemDto(item_material, "物料", "223")); - list.add(new ItemDto(item_consumption, "电能耗", "8092")); - list.add(new ItemDto(item_voltageA, "A相电压", "8080")); - list.add(new ItemDto(item_voltageB, "B相电压", "8082")); - list.add(new ItemDto(item_voltageC, "C相电压", "8084")); - list.add(new ItemDto(item_currentA, "A相电流", "8086")); - list.add(new ItemDto(item_currentB, "B相电流", "8088")); - list.add(new ItemDto(item_currentC, "C相电流", "8090")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "40226")); - list.add(new ItemDto(item_to_open_door, "开门", "00111")); - list.add(new ItemDto(item_to_close_door, "关门", "00112")); - list.add(new ItemDto(item_to_temperature, "生产温度", "48100")); - list.add(new ItemDto(item_to_material, "生产物料", "40229")); - list.add(new ItemDto(item_to_time_house, "生产时间(时)", "48771")); - list.add(new ItemDto(item_to_time_min, "生产时间(分)", "48770")); - list.add(new ItemDto(item_to_task, "任务号", "40232")); - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java deleted file mode 100644 index 0e613938..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java +++ /dev/null @@ -1,991 +0,0 @@ -package org.nl.acs.device_driver.basedriver.oven_manipulator; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.basedriver.hongxiang_conveyor.HongXiangStationDeviceDriver; -import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.lamp_three_color.LampThreecolorDeviceDriver; -import org.nl.acs.device_driver.basedriver.photoelectric_inspection_site.PhotoelectricInspectionSiteDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 烘箱-行架机械手 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); - @Autowired - RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); - @Autowired - TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl"); - @Autowired - DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - - //工作模式 - int mode = 0; - int last_mode = 0; - //光电信号 - int move = 0; - int last_move = 0; - //动作信号 - int action = 0; - int last_action = 0; - //行走列 - int walk_y = 0; - int last_walk_y = 0; - //报警信号 - int error = 0; - int last_error = 0; - //任务号 - int task = 0; - int last_task = 0; - - int heartbeat = 0; - int last_heartbeat = 0; - - - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - - private int instruction_finished_time_out; - - int branchProtocol = 0; - - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 - int now_steps_type = 0; - String notCreateTaskMessage = ""; - String notCreateInstMessage = ""; - String feedMessage = ""; - - - @Override - public Device getDevice() { - return this.device; - } - - - @Override - public void execute() { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - action = this.itemProtocol.getAction(); - walk_y = this.itemProtocol.getWalk_y(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - heartbeat = this.itemProtocol.getHeartbeat(); -// if(heartbeat != last_heartbeat){ -// logServer.deviceExecuteLog(this.device_code, "", "", "heartbeat:" + last_heartbeat + "->" + heartbeat); -// } - if (mode != last_mode) { - if (mode == 2) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号复位前requireSuccess:" + requireSucess); - this.setRequireSucess(false); - logServer.deviceExecuteLog(this.device_code, "", "", "信号复位后requireSuccess:" + requireSucess); -// if (move == 0 && task == 0 && action == 0 && this.getNow_steps_type() != 0){ -// logServer.deviceExecuteLog(this.device_code, "", "", "当前执行步骤复位前:" + this.getNow_steps_type()); -// this.setNow_steps_type(0); -// logServer.deviceExecuteLog(this.device_code, "", "", "当前执行步骤复位后:" + this.getNow_steps_type()); -// } - feedMessage = ""; - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - message = null; - } - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (action != last_action) { - logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (walk_y != last_walk_y) { - logServer.deviceItemValue(this.device_code, "walk_y", String.valueOf(walk_y)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号walk_y:" + last_walk_y + "->" + walk_y); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - - //更改任务状态 - if (task > 0) { - //inst_message - Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst1 != null) { - if (StrUtil.equals(inst1.getInstruction_status(), "0")) { - inst1.setInstruction_status("1"); - inst1.setExecute_device_code(this.device_code); - instructionService.update(inst1); - } - } - } - - //申请取货 - if (mode == 3 && action == 1 && move == 0 && task > 0) { - Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task)); - if (ObjectUtil.isNotEmpty(inst2)) { - String start_device_code = inst2.getStart_device_code(); - Device device = deviceAppService.findDeviceByCode(start_device_code); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); - //hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - int mode = hongXiangConveyorDeviceDriver.getMode(); - int door = hongXiangConveyorDeviceDriver.getDoor(); - int action = hongXiangConveyorDeviceDriver.getAction(); - int error1 = hongXiangConveyorDeviceDriver.getError1(); - int move = hongXiangConveyorDeviceDriver.getMove(); - if (mode == 1 && door == 1 && action == 1 && error1 == 0 && move == 1) { - if (this.getNow_steps_type() == 2) { - this.writing("to_command", "2"); - this.setNow_steps_type(3); - } else { - //logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为下发电气信号(now_steps_type!=2)"); - } - } else { - if (this.getNow_steps_type() == 2) { - feedMessage = "烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code(); - if (mode != 1) { - feedMessage = feedMessage + "工作模式(mode)信号未联机,"; - } - if (door != 1) { - feedMessage = feedMessage + "门状态(door)信号未开门,"; - } - if (action != 1) { - feedMessage = feedMessage + "允许取放(action)信号未允许取放,"; - } - if (move != 1) { - feedMessage = feedMessage + "取货位光电信号(move)不应该为无货状态,"; - } - if (error1 != 0) { - feedMessage = feedMessage + "故障(error1)信号出现故障,故障值:" + error1 + "。"; - } - } - } - } else { - if (this.getNow_steps_type() == 2) { - this.writing("to_command", "2"); - this.setNow_steps_type(3); - } else { - //logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为下发电气信号(now_steps_type!=2)\")"); - } - } - } - } else { - if (this.getNow_steps_type() == 2) { - feedMessage = "行架机械手:"; - if (mode != 3) { - feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; - } - if (action != 1) { - feedMessage = feedMessage + "动作信号(action)不为取货中状态,"; - } - if (move != 0) { - feedMessage = feedMessage + "光电信号(move)不为无货状态,"; - } - if (task == 0) { - feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; - } - } - } - - //取货完成关闭烘箱门 - if (mode == 3 && action == 2 && move == 1 && task > 0) { - Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task)); - if (ObjectUtil.isNotEmpty(inst2)) { - String start_device_code = inst2.getStart_device_code(); - Device device = deviceAppService.findDeviceByCode(start_device_code); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing("to_close_door", "1"); - } - if (this.getNow_steps_type() == 3) { - this.writing("to_command", "3"); - this.setNow_steps_type(4); - } else { - //logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为允许取货(now_steps_type!=3)"); - } - } - } else { - if (this.getNow_steps_type() == 3) { - feedMessage = "行架机械手:"; - if (mode != 3) { - feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; - } - if (action != 2) { - feedMessage = feedMessage + "动作信号(action)不为取货完成状态,"; - } - if (move != 1) { - feedMessage = feedMessage + "光电信号(move)不为有货状态,"; - } - if (task == 0) { - feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; - } - } - } - - //申请放货 - if (mode == 3 && action == 3 && move == 1 && task > 0) { - Instruction instructionDto = instructionService.findByCode(String.valueOf(task)); - String next_device_code = instructionDto.getNext_device_code(); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - PhotoelectricInspectionSiteDeviceDriver photoelectricInspectionSiteDeviceDriver; - if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); - //hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - int mode = hongXiangConveyorDeviceDriver.getMode(); - int door = hongXiangConveyorDeviceDriver.getDoor(); - int action = hongXiangConveyorDeviceDriver.getAction(); - int error1 = hongXiangConveyorDeviceDriver.getError1(); - int move = hongXiangConveyorDeviceDriver.getMove(); - if (mode == 1 && door == 1 && action == 1 && error1 == 0 && move == 0) { - if (this.getNow_steps_type() == 4) { - this.writing("to_command", "4"); - this.setNow_steps_type(5); - } else { - feedMessage = "未反馈电气信号原因:当前步骤不为允许放货(now_steps_type!=4)"; - //logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为允许放货(now_steps_type!=4)"); - } - } else { - if (this.getNow_steps_type() == 4) { - feedMessage = "烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code(); - if (mode != 1) { - feedMessage = feedMessage + "工作模式(mode)信号未联机,"; - } - if (door != 1) { - feedMessage = feedMessage + "门状态(door)信号未开门,"; - } - if (action != 1) { - feedMessage = feedMessage + "允许取放(action)信号未允许取放,"; - } - if (move != 0) { - feedMessage = feedMessage + "放货位光电信号不应该为有货状态"; - } - if (error1 != 0) { - feedMessage = feedMessage + "故障(error1)信号出现故障。"; - } - } - } - } else { - if (this.getNow_steps_type() == 4) { - this.writing("to_command", "4"); - this.setNow_steps_type(5); - } else { - //logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为允许放货(now_steps_type!=4)"); - } - - } - } else { - if (this.getNow_steps_type() == 4) { - feedMessage = "行架机械手:"; - if (mode != 3) { - feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; - } - if (action != 3) { - feedMessage = feedMessage + "动作信号(action)不为放货中状态,"; - } - if (move != 1) { - feedMessage = feedMessage + "光电信号(move)不为有货状态,"; - } - if (task == 0) { - feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; - } - } - } - - //放货完成 - if (mode == 3 && action == 4 && move == 0 && task > 0) { - Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst2 != null) { - if (StrUtil.equals(inst2.getInstruction_status(), "1")) { - try { - finish_instruction(inst2); - } catch (Exception e) { - e.printStackTrace(); - } - TaskDto taskDto = taskserver.findByCode(inst2.getTask_code()); - - String next_device_code = inst2.getNext_device_code(); - //String start_device_code = taskDto.getStart_device_code(); - //Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - LampThreecolorDeviceDriver lampThreecolorDeviceDriver; -// if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { -// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver(); -// hongXiangConveyorDeviceDriver.writing("to_close_door", "1"); -// } - if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing("to_close_door", "1"); - if (StrUtil.isNotEmpty(taskDto.getOven_time())) { - //下发烘箱时间 - int time = Integer.parseInt(taskDto.getOven_time()); - int hours = (time % (60 * 60 * 24)) / (60 * 60); - int minutes = (time % (60 * 60)) / 60; - hongXiangConveyorDeviceDriver.writing("to_time_house", String.valueOf(hours)); - hongXiangConveyorDeviceDriver.writing("to_time_min", String.valueOf(minutes)); - } - } - - if (nextDevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextDevice.getDeviceDriver(); -// hongXiangConveyorDeviceDriver.writing("to_close_door", "1"); - - if(!StrUtil.startWith(taskDto.getTask_code(), "-")){ - if(ObjectUtil.isNotEmpty(nextDevice.getExtraValue().get("link_three_lamp"))){ - String lamp = nextDevice.getExtraValue().get("link_three_lamp").toString(); - Device lampDevice = deviceAppService.findDeviceByCode(lamp); - if(ObjectUtil.isEmpty(lampDevice)){ - return; - } - if (lampDevice.getDeviceDriver() instanceof LampThreecolorDeviceDriver) { - lampThreecolorDeviceDriver = (LampThreecolorDeviceDriver) lampDevice.getDeviceDriver(); - logServer.deviceExecuteLog(lampDevice.getDeviceDriver().getDeviceCode(), "", "", "下发报警灯"+ lamp +"报警信号"); - lampThreecolorDeviceDriver.writing("to_command","1"); - } - } - } - - } - - if (this.getNow_steps_type() == 5) { - this.writing("to_command", "5"); - this.setNow_steps_type(6); - this.setNow_steps_type(0); - feedMessage = ""; - } else { - //logServer.deviceExecuteLog(this.device_code, "", "", "未反馈电气信号原因:当前步骤不为放货完成(now_steps_type!=5)"); - } -// this.writing("to_onset", "0"); -// this.writing("to_target", "0"); -// this.writing("to_task", "0"); - } - } - } else { - if (this.getNow_steps_type() == 5) { - feedMessage = "行架机械手:"; - if (mode != 3) { - feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; - } - if (action != 4) { - feedMessage = feedMessage + "动作信号(action)不为放货完成状态,"; - } - if (move != 0) { - feedMessage = feedMessage + "光电信号(move)不为无货状态,"; - } - if (task == 0) { - feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; - } - } - } - - } catch (Exception var17) { - var17.printStackTrace(); - feedMessage = var17.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage()+ ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol) ); - - } - -// if (!this.itemProtocol.getIsonline()) { -// this.setIsonline(false); -// this.setIserror(true); -// message = "信号量同步异常"; -// //未联机 -// } else - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - //有报警 - } else if (error != 0) { - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - message = ""; - Instruction instruction = null; - List toInstructions; - - //行架机械手申请任务 - if (mode == 2 && move == 0 && task == 0 && !requireSucess) { - boolean res = applyTask(); - if (res){ - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - feedMessage = ""; - } - } else { - if (mode == 2) { - //if (!requireSucess) { - String remark = "未查找任务原因为:"; - if (mode != 2) { - remark = remark + "工作模式(mode)不是待机状态,"; - } - if (move != 0) { - remark = remark + "光电信号(move)为有货状态,"; - } - if (task != 0) { - remark = remark + "当前上报任务号(task)应该为0,"; - } - if (requireSucess) { - remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; - } - this.setNotCreateTaskMessage(remark); - //} - } - } - - } - last_mode = mode; - last_move = move; - last_action = action; - last_walk_y = walk_y; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - } - - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - - /** - * 申请任务 - * - * @param - */ - public synchronized boolean applyTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - //抓取工位 - List getDeviceCodeList = this.getExtraDeviceCodes("get_device_code"); - //放货工位 - List putDeviceCodeList = this.getExtraDeviceCodes("put_device_code"); - TaskDto task = null; - for (int i = 0; i < getDeviceCodeList.size(); i++) { - String startDeviceCode = getDeviceCodeList.get(i); - List taskDtos = taskserver.queryTaskByDeviceCodeAndStatus(startDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - TaskDto taskDto = taskDtos.get(0); - Instruction instruction = instructionService.findByTaskcodeAndStatus(taskDto.getTask_code()); - String start_device_code = instruction.getStart_device_code(); - String next_device_code = instruction.getNext_device_code(); - Device nextdevice = deviceAppService.findDeviceByCode(next_device_code); - Device startdevice = deviceAppService.findDeviceByCode(start_device_code); - PhotoelectricInspectionSiteDeviceDriver photoelectricInspectionSiteDeviceDriver; - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - if (startdevice.getDeviceDriver() instanceof PhotoelectricInspectionSiteDeviceDriver) { - photoelectricInspectionSiteDeviceDriver = (PhotoelectricInspectionSiteDeviceDriver) startdevice.getDeviceDriver(); - if (photoelectricInspectionSiteDeviceDriver.getMove() != 1) { - notCreateInstMessage = "手动创建指令未下发电气信号原因->取货位-烘箱对接位:" + photoelectricInspectionSiteDeviceDriver.getDevice_code() + "无货,无法下发指令!指令号:"+instruction.getInstruction_code(); - return false; - } - } - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMove() != 1) { - notCreateInstMessage = "手动创建指令未下发电气信号原因->取货位-烘箱对接位:" + standardInspectSiteDeviceDriver.getDevice_code() + "无货,无法下发指令!指令号:"+instruction.getInstruction_code(); - return false; - } - } - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - if (hongXiangConveyorDeviceDriver.getMode() == 0 || hongXiangConveyorDeviceDriver.getMove() == 0) { - notCreateInstMessage = "手动创建指令未下发电气信号原因->取货位-烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code() + "未联机或无货,无法下发指令!指令号:"+instruction.getInstruction_code(); - return false; - } - } - - if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMove() != 0) { - notCreateInstMessage = "手动创建指令未下发电气信号原因->放货位-烘箱对接位:" + standardInspectSiteDeviceDriver.getDevice_code() + "有货,无法下发指令!指令号:"+instruction.getInstruction_code(); - return false; - } - } - if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextdevice.getDeviceDriver(); - if (hongXiangConveyorDeviceDriver.getMode() == 0 || hongXiangConveyorDeviceDriver.getMove() == 1) { - notCreateInstMessage = "手动创建指令未下发电气信号原因->放货位-烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code() + "未联机或者有货,无法下发指令!指令号:"+instruction.getInstruction_code(); - return false; - } - } - //判断关联的同一列烘箱设备是否都关门 都关门返回false,有一个不关门就返回true - boolean isCloseDoor = this.judgeCloseDoor(start_device_code, next_device_code); - //未关门结束 - if (isCloseDoor) { - return false; - } - instruction.setInstruction_status("1"); - instruction.setUpdate_time(DateUtil.now()); - instructionService.update(instruction); - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))) { - throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!"); - } - if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))) { - throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"); - } - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - this.writing("to_onset", start_addr); - this.writing("to_target", next_addr); - this.writing("to_task", instruction.getInstruction_code()); - this.writing("to_command", "1"); - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing("to_open_door","1"); - } - if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing("to_open_door","1"); - } - this.setNow_steps_type(2); - this.setRequireSucess(true); - return true; - } else { - List taskDtoList = taskserver.queryTaskByDeviceCode(startDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtoList)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtoList = this.sortTask(taskDtoList); - task = taskDtoList.get(0); - } - if (ObjectUtil.isNotEmpty(task)) break; - } - } - if (!ObjectUtil.isEmpty(task)) { - Device nextdevice = deviceAppService.findDeviceByCode(task.getNext_device_code()); - Device startdevice = deviceAppService.findDeviceByCode(task.getStart_device_code()); - PhotoelectricInspectionSiteDeviceDriver photoelectricInspectionSiteDeviceDriver; - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - if (startdevice.getDeviceDriver() instanceof PhotoelectricInspectionSiteDeviceDriver) { - photoelectricInspectionSiteDeviceDriver = (PhotoelectricInspectionSiteDeviceDriver) startdevice.getDeviceDriver(); - if (photoelectricInspectionSiteDeviceDriver.getMove() != 1) { - notCreateInstMessage = "就绪任务未创建指令原因->取货位-烘箱对接位:" + photoelectricInspectionSiteDeviceDriver.getDevice_code() + "光电无货,无法生成指令!"; - return false; - } - } - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMove() != 1) { - notCreateInstMessage = "就绪任务未创建指令原因->取货位-烘箱对接位:" + standardInspectSiteDeviceDriver.getDevice_code() + "光电无货,无法生成指令!"; - return false; - } - } - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - if (hongXiangConveyorDeviceDriver.getMode() == 0 || hongXiangConveyorDeviceDriver.getMove() == 0) { - notCreateInstMessage = "就绪任务未创建指令原因->取货位-烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code() + "光电无货,无法生成指令!"; - return false; - } - } - - if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextdevice.getDeviceDriver(); - if (hongXiangConveyorDeviceDriver.getMode() == 0 || hongXiangConveyorDeviceDriver.getMove() == 1) { - notCreateInstMessage = "就绪任务未创建指令原因->放货位-烘箱:" + hongXiangConveyorDeviceDriver.getDevice_code() + "光电有货,无法生成指令!"; - return false; - } - } - if (nextdevice.getDeviceDriver() instanceof PhotoelectricInspectionSiteDeviceDriver) { - photoelectricInspectionSiteDeviceDriver = (PhotoelectricInspectionSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (photoelectricInspectionSiteDeviceDriver.getMove() != 0) { - notCreateInstMessage = "就绪任务未创建指令原因->放货位-烘箱对接位:" + photoelectricInspectionSiteDeviceDriver.getDevice_code() + "光电有货,无法生成指令!"; - return false; - } - } - if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMove() != 0) { - notCreateInstMessage = "就绪任务未创建指令原因->放货位-烘箱对接位:" + standardInspectSiteDeviceDriver.getDevice_code() + "光电有货,无法生成指令!"; - return false; - } - } - String taskid = task.getTask_id(); - String taskcode = task.getTask_code(); - String vehiclecode = task.getVehicle_code(); - String priority = task.getPriority(); - String start_point_code = task.getStart_point_code(); - String start_device_code = task.getStart_device_code(); - String route_plan_code = task.getRoute_plan_code(); - String next_point_code = task.getNext_point_code(); - String next_device_code = task.getNext_device_code(); - - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(task.getRemark()); - instdto.setMaterial(task.getMaterial()); - instdto.setQuantity(task.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - - //判断关联的同一列烘箱设备是否都关门 都关门返回false,有一个不关门就返回true - boolean isCloseDoor = this.judgeCloseDoor(instdto.getStart_device_code(), instdto.getNext_device_code()); - //如果未关门结束 - if (isCloseDoor) { - return false; - } - - try { - instructionService.create(instdto); - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); - return false; - } - //创建指令后修改任务状态 - task.setTask_status("1"); - task.setUpdate_time(DateUtil.now()); - taskserver.update(task); - - Device startDevice = deviceAppService.findDeviceByCode(instdto.getStart_device_code()); - Device nextDevice = deviceAppService.findDeviceByCode(instdto.getNext_device_code()); - if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))) { - notCreateInstMessage = "设备:" + startDevice.getDevice_code() + "未设置电气调度号!"; - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "设备:" + startDevice.getDevice_code() + "未设置电气调度号!"); - throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!"); - } - if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))) { - notCreateInstMessage = "设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"; - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"); - throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!"); - } - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - this.writing("to_onset", start_addr); - this.writing("to_target", next_addr); - this.writing("to_task", instdto.getInstruction_code()); - this.writing("to_command", "1"); - //HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - } - if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - hongXiangConveyorDeviceDriver.writing("to_open_door", "1"); - } - this.setNow_steps_type(2); - this.setRequireSucess(true); - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - } else { - notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; - } - return true; - } - } - - public boolean exe_business() { - return true; - } - - public synchronized boolean finish_instruction(Instruction inst) throws Exception { - instructionService.finish(inst); - return true; - } - - public void writing(String param, String value) { - - String to_param = 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_param, Integer.parseInt(value)); -// itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void executing(Server server, Map itemMap) { - this.control(itemMap); - } - - //判断取货位或放货位为烘箱设备时关联的同一列烘箱设备是否有开门 - public boolean judgeCloseDoor(String start_device_code, String next_device_code) { - Boolean isClose = false; - - try { - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - if (ObjectUtil.isEmpty(startDevice)) { - throw new BadRequestException("设备号:" + start_device_code + "不存在!"); - } - if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver(); - List deviceCodes = hongXiangConveyorDeviceDriver.getExtraDeviceCodes("link_device_code"); - if (ObjectUtil.isNotEmpty(deviceCodes)) { - for (String deviceCode : deviceCodes) { - Device linkDevice = deviceAppService.findDeviceByCode(deviceCode); - if (ObjectUtil.isEmpty(linkDevice)) { - throw new BadRequestException("设备:" + start_device_code + "关联设备->" + deviceCode + "为空!"); - } - if (linkDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) linkDevice.getDeviceDriver(); - //判断关联设备是否开门 - if (hongXiangConveyorDeviceDriver.getDoor() == 1) { - isClose = true; - notCreateInstMessage = start_device_code + "关联设备->" + deviceCode + "烘箱门未关闭!"; - break; - } - } - } - return isClose; - } - } - if (ObjectUtil.isEmpty(nextDevice)) { - throw new BadRequestException("设备号:" + next_device_code + "不存在!"); - } - if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); - List deviceCodes = hongXiangConveyorDeviceDriver.getExtraDeviceCodes("link_device_code"); - if (ObjectUtil.isNotEmpty(deviceCodes)) { - for (String deviceCode : deviceCodes) { - Device linkDevice = deviceAppService.findDeviceByCode(deviceCode); - if (ObjectUtil.isEmpty(linkDevice)) { - throw new BadRequestException("设备:" + next_device_code + "关联设备->" + deviceCode + "为空!"); - } - if (linkDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) linkDevice.getDeviceDriver(); - //判断关联设备是否开门 - if (hongXiangConveyorDeviceDriver.getDoor() == 1) { - isClose = true; - notCreateInstMessage = next_device_code + "关联设备->" + deviceCode + "烘箱门未关闭!"; - break; - } - } - } - return isClose; - } - } - } catch (Exception e) { - isClose = true; - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "检查烘箱是否关门时出现异常:" + e.getMessage()); - notCreateInstMessage = "检查烘箱是否关门时出现异常:" + e.getMessage(); - } - return isClose; - } - - public void writing(int command) { - Map itemMap = new HashMap(); - this.control(itemMap); - } - - //将扩展表中的字符串数据转换成集合 - public List getExtraDeviceCodes(String extraName) { - String extraValue = (String) this.getDevice().getExtraValue().get(extraName); - if (StrUtil.isEmpty(extraValue)) { - return new ArrayList<>(); - } - String devicesString = extraValue.substring(1, extraValue.length() - 1); - List devicesList = new ArrayList<>(); - String[] devices = devicesString.split(","); - for (int i = 0; i < devices.length; i++) { - String s = devices[i].replace("\"", "").replace("\"", ""); - devicesList.add(s); - } - return devicesList; - } - - public List sortTask(List taskDtos) { - Collections.sort(taskDtos, new Comparator() { - @Override - public int compare(TaskDto t1, TaskDto t2) { - //优先级从大到小 - int i = t2.getPriority().compareTo(t1.getPriority()); - //如果优先级相等 - if (i == 0) { - //时间从早到晚 - i = t1.getCreate_time().compareTo(t2.getCreate_time()); - } - return i; - } - }); - return taskDtos; - } - - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String action = ""; - String walk_y = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - } else if (this.getMove() == 1) { - move = "有货"; - } - - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("requireSucess", requireSucess); - if (this.getAction() == 1) { - action = "取货中"; - } else if (this.getAction() == 2) { - action = "取货完成"; - } else if (this.getAction() == 3) { - action = "放货中"; - } else if (this.getAction() == 4) { - action = "放货完成"; - } - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("task", task); - jo.put("walk_y", walk_y); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("notCreateTaskMessage", notCreateTaskMessage); - jo.put("notCreateInstMessage", notCreateInstMessage); - jo.put("feedMessage", feedMessage); - jo.put("driver_type", "siemens_conveyor"); - jo.put("is_click", true); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - -// public void writing(int type, int command) { -// String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() -// + "." + ItemProtocol.item_to_material_code; -// String opcservcerid = this.getDevice().getOpc_server_id(); -// Server server = ReadUtil.getServer(opcservcerid); -// Map itemMap = new HashMap(); -// if (type == 2) { -// itemMap.put(to_material_code, command); -// } -// this.control(itemMap); -// -// } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/Test.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/Test.java deleted file mode 100644 index 5aba10e1..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/Test.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.nl.acs.device_driver.basedriver.oven_manipulator; - -import java.text.DecimalFormat; - -public class Test { - public static String beautifyTime(double second) { - if (second <= 0) return "0"; - final String[] units = new String[]{"秒", "分钟", "小时"}; - int digitGroups = (int) (Math.log10(second) / Math.log10(60)); - String value = "0"; - if(digitGroups<3) { - value = new DecimalFormat("#,##0.#").format(second / Math.pow(60, digitGroups)) + "" + units[digitGroups]; - }else if(digitGroups >= 3) { - //如果超过了小时的表达范围则,则转换为天,小时,分,秒格式 - - value = secondToDate(second); - } - - return value; - } - - public static String secondToDate(double second) { - Long time = new Long(new Double(second).longValue()); - String strTime = null; - Long days = time / (60 * 60 * 24); - Long hours = (time % (60 * 60 * 24)) / (60 * 60); - Long minutes = (time % (60 * 60)) / 60; - Long seconds = time % 60; - if (days > 0) { - strTime = days + "天" + hours + "小时" + minutes + "分钟"; - } else if (hours > 0) { - strTime = hours + "小时" + minutes + "分钟"; - } else if (minutes > 0) { - strTime = minutes + "分钟" + seconds + "秒"; - } else { - strTime = second + "秒"; - } - return strTime; - } - - - public static void main(String[] args) { - - Long time = new Long(new Double(7500).longValue()); - Long hours = (time % (60 * 60 * 24)) / (60 * 60); - Long minutes = (time % (60 * 60)) / 60; - Long seconds = time % 60; - System.out.println(hours); - System.out.println(minutes); - System.out.println(seconds); - - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/ItemProtocol.java deleted file mode 100644 index 8707e77c..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/ItemProtocol.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.nl.acs.device_driver.basedriver.paint_conveyor; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - public static String item_heartbeat = "heartbeat"; - public static String item_mode = "mode"; - public static String item_move = "move"; - public static String item_action = "action"; - public static String item_error = "error"; - public static String item_number = "number"; - public static String item_task = "task"; - - - public static String item_to_target = "to_target";// - public static String item_to_command = "to_command";// - public static String item_to_task = "to_task";// - - - private PaintConveyorDeviceDriver driver; - - public ItemProtocol(PaintConveyorDeviceDriver driver) { - this.driver = driver; - } - - public int getItem_heartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getItem_mode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getItem_move() { - return this.getOpcIntegerValue(item_move); - } - - public int getItem_action() { - return this.getOpcIntegerValue(item_action); - } - - public int getItem_error() { - return this.getOpcIntegerValue(item_error); - } - - public int getItem_number() { - return this.getOpcIntegerValue(item_number); - } - - public int getItem_task() { - return this.getOpcIntegerValue(item_task); - } - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "D0000000")); - list.add(new ItemDto(item_mode, "模式", "D0000004")); - list.add(new ItemDto(item_move, "光电信号", "D0000008")); - list.add(new ItemDto(item_action, "取放信号", "D0000012")); - list.add(new ItemDto(item_error, "故障", "D0000016")); - list.add(new ItemDto(item_number, "数量", "D0000020")); - list.add(new ItemDto(item_task, "任务号", "D0000024")); - - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "D00000102")); - list.add(new ItemDto(item_to_target , "下发目标站", "D00000106")); - list.add(new ItemDto(item_to_task, "任务号", "D00000110")); - return list; - } - - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java deleted file mode 100644 index 64bca676..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/paint_conveyor/PaintConveyorDeviceDriver.java +++ /dev/null @@ -1,303 +0,0 @@ -package org.nl.acs.device_driver.basedriver.paint_conveyor; - -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * 油漆线 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class PaintConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); - @Autowired - AgvService agvService = SpringContextHolder.getBean(AgvService.class); - - private Date instruction_require_time = new Date(); - private Date instruction_finished_time = new Date(); - private Date instruction_apply_time = new Date(); - private int instruction_require_time_out = 3000; - - int heartbeat = 0; - int mode = 0; - int move = 0; - int action = 0; - int error = 0; - int number = 0; - int task = 0; - - Boolean isonline = true; - - Boolean iserror = false; - - //1-执行任务;2-取货完成;3-放货完成; - int flag; - - int last_mode = 0; - int last_move = 0; - int last_error = 0; - - String device_code; - - @Override - public Device getDevice() { - return this.device; - } - - //请求成功标记 - Boolean requireSucess = false; - - @Override - public void execute() { - String message = null; - - device_code = this.getDeviceCode(); - heartbeat = this.itemProtocol.getItem_heartbeat(); - mode = this.itemProtocol.getItem_mode(); - move = this.itemProtocol.getItem_move(); - action = this.itemProtocol.getItem_action(); - error = this.itemProtocol.getItem_error(); - number = this.itemProtocol.getItem_number(); - task = this.itemProtocol.getItem_task(); - - - if (mode != last_mode) { - this.setRequireSucess(false); - } - if (move != last_move) { - if (move == 0) { - thingToNothing(); - } - } - if (error != last_error) { - } - - - if (!this.itemProtocol.getIsonline()) { - this.setIsonline(false); - this.setIserror(true); - message = "信号量同步异常"; - //未联机 - } else if (mode == 0) { - this.setIsonline(false); - this.setIserror(true); - message = "未联机"; - //有报警 - } else if (error != 0) { - this.setIsonline(false); - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - JSONObject jo = new JSONObject(); - switch (mode) { - case 1: - log.debug("设备运转模式:等待工作"); - break; - case 5: - //下料位申请空盘 - if (move == 0 && !requireSucess) { - //向LMS发送请求,发送终点和托盘类型 - jo.put("type","3"); - jo.put("point_code",device_code); - jo.put("vehicle_num","10"); - String result = acsToWmsService.applyTaskToWms(jo); - JSONObject res_jo = JSONObject.parseObject(result); - if (res_jo.getString("status").equals("200")){ - requireSucess = true; - } - } - case 6: - //下料位满拖申请 - if (move == 1 && !requireSucess) { - //向LMS发送请求,发送起点 - jo.put("type","7"); - jo.put("point_code",device_code); - String result = acsToWmsService.applyTaskToWms(jo); - JSONObject res_jo = JSONObject.parseObject(result); - if (res_jo.getString("status").equals("200")){ - requireSucess = true; - } - } - case 7: - //上料位满拖申请 - if (move == 0 && !requireSucess) { - //向LMS发送请求,发送起点 - jo.put("type","4"); - jo.put("point_code",device_code); - String result = acsToWmsService.applyTaskToWms(jo); - JSONObject res_jo = JSONObject.parseObject(result); - if (res_jo.getString("status").equals("200")){ - requireSucess = true; - } - } - break; - case 8: - if (move == 1 && !requireSucess) { - //上料位空托入库 - jo.put("type", "5"); - jo.put("point_code", device_code); - jo.put("vehicle_num", number); - String result = acsToWmsService.applyTaskToWms(jo); - JSONObject res_jo = JSONObject.parseObject(result); - if (res_jo.getString("status").equals("200")){ - requireSucess = true; - } - break; - } - case 9: - if (move == 1 && !requireSucess) { - //强制满垛入库 - jo.put("type", "5"); - jo.put("point_code", device_code); - jo.put("vehicle_num", number); - String result = acsToWmsService.applyTaskToWms(jo); - JSONObject res_jo = JSONObject.parseObject(result); - if (res_jo.getString("status").equals("200")){ - requireSucess = true; - } - break; - } - } - switch (flag) { - //取货完成 - case 1: - writing(2); - break; - //放货完成 - case 2: - writing(3); - break; - - } - } - - last_mode = mode; - last_move = move; - last_error = error; - } - - - public synchronized boolean instruction_apply(String container_code) throws Exception { - Date date = new Date(); - if (date.getTime() - this.instruction_apply_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_apply_time = date; - requireSucess = true; - return true; - } - } - - protected void thingToNothing() { - - } - - public void writing(int command) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command, command); - this.control(itemMap); - } - - public void writing(String key, String value) { - String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + key; - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command, value); - this.control(itemMap); - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String move = ""; - if (this.getMode() == 0) { - mode = "未联机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "联机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("task", this.getTask()); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java deleted file mode 100644 index 68656c28..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.nl.acs.device_driver.basedriver.plug_pull_device_site; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - //1/0 手动/自动 - public static String item_mode = "mode"; - //0/1 半自动/全自动 - public static String item_action = "action"; - //0/1 远程/本地控制 - public static String item_control = "control"; - //2 运行中 - //1 急停/故障 - //0 待机中 - public static String item_status = "status"; - //1 机头上有轴 - public static String item_move = "move"; - //1/0 穿轴中/穿轴完成 - public static String item_plug_finish = "plug_finish"; - //1/0 把轴中/拔轴完成 - public static String item_pull_finish = "pull_finish"; - //3寸轴穿轴次数 - public static String item_3plug_times = "3plug_times"; - //6寸轴穿轴次数 - public static String item_6plug_times = "6plug_times"; - //3寸轴拔轴次数 - public static String item_3pull_times = "3pull_times"; - //6寸轴拔轴次数 - public static String item_6pull_times = "6pull_times"; - //穿轴总次数 - public static String item_plug_alltimes = "plug_alltimes"; - //拔轴总次数 - public static String item_pull_alltimes = "pull_alltimes"; - - - //1 全自动启动 - public static String item_to_command = "to_command"; - //0/1 穿轴/拔轴 - public static String item_to_type = "to_type"; - //3/6 轴尺寸 - public static String item_to_size = "to_size"; - - - private PlugPullDeviceSiteDeviceDriver driver; - - public ItemProtocol(PlugPullDeviceSiteDeviceDriver driver) { - this.driver = driver; - } - - public int getItem_mode(){ - return this.getOpcIntegerValue(item_mode); - } ; - public int getItem_move(){ - return this.getOpcIntegerValue(item_move); - } ; - public int getItem_action(){ - return this.getOpcIntegerValue(item_action); - }; - public int getItem_control(){ - return this.getOpcIntegerValue(item_control); - } ; - public int getItem_status(){ - return this.getOpcIntegerValue(item_status); - } ; - public int getItem_plug_finish(){ - return this.getOpcIntegerValue(item_plug_finish); - } ; - public int getItem_pull_finish(){ - return this.getOpcIntegerValue(item_pull_finish); - } ; - public int getItem_3plug_times(){ - return this.getOpcIntegerValue(item_3plug_times); - } ; - public int getItem_6plug_times(){ - return this.getOpcIntegerValue(item_6plug_times); - } ; - public int getItem_3pull_times(){ - return this.getOpcIntegerValue(item_3pull_times); - } ; - public int getItem_6pull_times(){ - return this.getOpcIntegerValue(item_6pull_times); - } ; - public int getItem_plug_alltimes(){ - return this.getOpcIntegerValue(item_plug_alltimes); - } ; - public int getItem_pull_alltimes(){ - return this.getOpcIntegerValue(item_pull_alltimes); - } ; - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public float getOpcFloatValue(String protocol) { - Float value = this.driver.getDoubleValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_mode, "工作模式", "30243")); - list.add(new ItemDto(item_action, "半自动/全自动", "30245")); - list.add(new ItemDto(item_control, "远程控制", "30254")); - list.add(new ItemDto(item_status, "状态", "30181")); - list.add(new ItemDto(item_move, "机头上有轴", "30252")); - list.add(new ItemDto(item_plug_finish, "穿轴完成", "30249")); - list.add(new ItemDto(item_pull_finish, "拔轴完成", "30250")); - list.add(new ItemDto(item_3plug_times, "3寸轴穿轴次数", "30231")); - list.add(new ItemDto(item_6plug_times, "6寸轴穿轴次数", "30235")); - list.add(new ItemDto(item_3pull_times, "3寸轴拔轴次数", "30233")); - list.add(new ItemDto(item_6pull_times, "6寸轴拔轴次数", "30237")); - list.add(new ItemDto(item_plug_alltimes, "穿轴总次数", "30239")); - list.add(new ItemDto(item_pull_alltimes, "拔轴总次数", "30241")); - - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "40246")); - list.add(new ItemDto(item_to_type, "类型", "40244")); - list.add(new ItemDto(item_to_size, "尺寸", "40247")); - - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java deleted file mode 100644 index a46c5200..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/PlugPullDeviceSiteDeviceDriver.java +++ /dev/null @@ -1,239 +0,0 @@ -package org.nl.acs.device_driver.basedriver.plug_pull_device_site; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.core.bean.WQLObject; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 插拔轴工位 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class PlugPullDeviceSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); - @Autowired - AgvService agvService = SpringContextHolder.getBean(AgvService.class); - - private Date instruction_require_time = new Date(); - private Date instruction_finished_time = new Date(); - private Date instruction_apply_time = new Date(); - private int instruction_require_time_out = 3000; - - public int mode = 0; - public int move = 0; - public int action = 0; - public int status = 0; - public int control = 0; - public int plug_finish = 0; - public int pull_finish = 0; - public int plug3_times = 0; - public int plug6_times = 0; - public int pull3_times = 0; - public int pull6_times = 0; - public int plug_alltimes = 0; - public int pull_alltimes = 0; - - public int last_mode = 0; - public int last_move = 0; - public int last_action = 0; - public int last_status = 0; - public int last_control = 0; - public int last_plug_finish = 0; - public int last_pull_finish = 0; - - - Boolean isonline = true; - - Boolean iserror = false; - - //1-执行任务;2-取货完成;3-放货完成; - int flag; - - String device_code; - - @Override - public Device getDevice() { - return this.device; - } - - //请求成功标记 - Boolean requireSucess = false; - - @Override - public void execute() { - String message = null; - - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getItem_mode(); - move = this.itemProtocol.getItem_move(); - action = this.itemProtocol.getItem_action(); - status = this.itemProtocol.getItem_status(); - control = this.itemProtocol.getItem_control(); - plug_finish = this.itemProtocol.getItem_plug_finish(); - pull_finish = this.itemProtocol.getItem_pull_finish(); - plug3_times = this.itemProtocol.getItem_3plug_times(); - plug6_times = this.itemProtocol.getItem_6plug_times(); - pull3_times = this.itemProtocol.getItem_3pull_times(); - pull6_times = this.itemProtocol.getItem_6pull_times(); - plug_alltimes = this.itemProtocol.getItem_plug_alltimes(); - pull_alltimes = this.itemProtocol.getItem_pull_alltimes(); - - - - - if (status != 1) { - this.setIsonline(false); - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - - - } - - last_mode = mode; - last_move = move; - last_action = action; - } - - - protected void thingToNothing() { - //this.setRequireSucess(false); - } - - public void writing(List list) { - - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - this.control(itemMap); - } - - //将扩展表中的字符串数据转换成集合 - public List getExtraDeviceCodes(String extraName) { - String extraValue = (String) this.getDevice().getExtraValue().get(extraName); - if (StrUtil.isEmpty(extraValue)) { - return new ArrayList<>(); - } - String devicesString = extraValue.substring(1, extraValue.length() - 1); - List devicesList = new ArrayList<>(); - String[] devices = devicesString.split(","); - for (int i = 0; i < devices.length; i++) { - String s = devices[i].replace("\"", "").replace("\"", ""); - devicesList.add(s); - } - return devicesList; - } - - - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String move = ""; - if (this.getMode() == 0) { - mode = "未联机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "联机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("isOnline", this.getIsonline()); - jo.put("isError", this.getIserror()); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - - } - - public void writing(String param, String value) { - - String to_param = 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_param, value); -// itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - } - - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java deleted file mode 100644 index 32616f25..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/ItemProtocol.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor; - -import cn.hutool.core.util.StrUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - //心跳 - public static String item_heartbeat = "heartbeat"; - //工作模式 - public static String item_mode = "mode"; - //光电信号 - public static String item_move = "move"; - //托盘方向 - public static String item_carrier_direction = "carrier_direction"; - //报警 - public static String item_error = "error"; - //任务号 - public static String item_task = "task"; - - //下发命令 - public static String item_to_command = "to_command"; - //下发目标站 - public static String item_to_target = "to_target"; - //下发托盘类型 - public static String item_to_container_type = "to_container_type"; - //下发任务号 - public static String item_to_task = "to_task"; - //困扎次数 - public static String item_to_strap_times = "to_strap_times"; - //木箱长度 - public static String item_to_length = "to_length"; - //木箱宽度 - public static String item_to_weight = "to_weight"; - //木箱高度 - public static String item_to_height = "to_height"; - - - private SiemensConveyorDeviceDriver driver; - - public ItemProtocol(SiemensConveyorDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getCarrier_direction() { - return this.getOpcIntegerValue(item_carrier_direction); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - public int getTo_command() { - return this.getOpcIntegerValue(item_to_command); - } - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (StrUtil.isEmpty(value)) { - - } else { - return value; - } - return "0"; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); - list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); - list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4")); - list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); - list.add(new ItemDto(item_task, "任务号", "DB600.D10")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); - list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB601.W6")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); - list.add(new ItemDto(item_to_strap_times, "困扎次数", "DB601.W12")); - list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); - list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); - list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java deleted file mode 100644 index e2eb3f95..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java +++ /dev/null @@ -1,964 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.nl.acs.AcsConfig; -import org.nl.acs.agv.server.NDCAgvService; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.ScannerDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_scanner.StandardScannerDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.dto.RouteLineDto; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.core.bean.WQLObject; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 西门子-输送机驱动 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - @Autowired - NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); - //当前指令 - Instruction inst = null; - - //工作模式 - int mode = 0; - int last_mode = 0; - //光电信号 - int move = 0; - int last_move = 0; - //托盘方向 - int carrier_direction = 0; - int last_carrier_direction = 0; - //报警信号 - int error = 0; - int last_error = 0; - //任务号 - int task = 0; - int last_task = 0; - int agvphase = 0; - String task_code = null; - int to_command = 0; - - int phase = 0; - int index = 0; - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - private Date require_apply_labeling_time = new Date(); - private Date require_apply_strangulation_time = new Date(); - private Date require_empty_in_time = new Date(); - private Date require_empty_out_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - boolean requireApplyLabelingSuccess = false; - boolean requireApplyLaStrangulationSuccess = false; - boolean requireEmptyInSuccess = false; - boolean requireEmptyOutSuccess = false; - boolean requiresShipDeviceUpdate = true; - private int instruction_finished_time_out; - - int branchProtocol = 0; - String inst_message; - String last_inst_message; - int heartbeat = 0; - int last_heartbeat = 0; - //当前指令 - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - String vehicle_code; - String last_vehicle_code; - - @Override - public Device getDevice() { - return this.device; - } - - - @Override - public void execute() { - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - carrier_direction = this.itemProtocol.getCarrier_direction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - to_command = this.itemProtocol.getTo_command(); - heartbeat = this.itemProtocol.getHeartbeat(); -// if(heartbeat != last_heartbeat){ -// logServer.deviceExecuteLog(this.device_code, "", "", "heartbeat:" + last_heartbeat + "->" + heartbeat); -// } - if (mode != last_mode) { - if (mode == 2) { - requireSucess = false; - requireApplyLabelingSuccess = false; - requireApplyLaStrangulationSuccess = false; - requireEmptyInSuccess = false; - requireEmptyOutSuccess = false; - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记"); - } - if(mode == 6){ - requireEmptyInSuccess = false; - } - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - message = null; - if (move == 0 ) { - inst_message = null; - this.clearWrite(); - } - if(move == 0 && last_move == 1 ){ - last_vehicle_code = vehicle_code; - last_inst_message = inst_message; - if ("true".equals(this.device.getExtraValue().get("ship_device_update"))) { - this.requiresShipDeviceUpdate = false; - } - } - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (carrier_direction != last_carrier_direction) { - logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - - if (move != 0 && task > 0 ) { -// logServer.deviceExecuteLog(device_code, "", "", "输送线任务开始反馈任务状态,指令号:" + task); - //inst_message - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst != null) { - inst_message = "当前指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); - vehicle_code = inst.getVehicle_code(); - task_code = inst.getTask_code(); - if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); - } - if (StrUtil.equals(inst.getInstruction_status(), "1")) { - if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - vehicle_code = inst.getVehicle_code(); - inst.setExecute_device_code(this.device_code); - finish_instruction(); - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); - } else { - - - } - - } - } else { - message = "输送线任务反馈状态,查询不到指令号:" + task +"指令已完成"; - inst_message = null; - } - } - - } catch (Exception var17) { - var17.printStackTrace(); - logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage()+ ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol) ); - } - - if("true".equals(this.device.getExtraValue().get("ship_device_update"))){ - if(ObjectUtil.equal(this.getDevice().getExtraValue().get("noIdleRequest"),"true")){ - if (!requiresShipDeviceUpdate && move == 0) { - this.shipDeviceUpdate(); - } - } else { - if (mode ==2 && !requiresShipDeviceUpdate && move == 0) { - this.shipDeviceUpdate(); - } - } - } - - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - //有报警 - - } else { - this.setIsonline(true); - this.setIserror(false); - if (error != 0) { - this.setIserror(true); - message = "有报警"; - } - - Instruction instruction = null; - List toInstructions; - - switch (mode) { - case 1: - log.debug("设备运转模式:等待工作"); - break; - case 2: - //申请任务 - if (move > 0 && !requireSucess) { - instruction_require(); - } - - break; - case 4: - //申请捆扎 - if (move > 0 ) { - applyLaStrangulation(); - } - break; - case 5: - //申请贴标 - if (move > 0 && !requireSucess) { - applyLabeling(); - - } - break; - case 6: - //空托盘满垛入库申请 - if (move > 0 && !requireEmptyInSuccess) { - emptyIn(); - } - if (move > 0 && !requireSucess) { - instruction_require(); - } - break; - case 7: - //空盘出库申请 - if (move == 0 && !requireSucess) { - emptyOut(); - } - break; - case 8: - //申请AGV任务 - if (move == 1 && !requireSucess) { - applyAgvTask(); - } - break; - - } - } - last_mode = mode; - last_move = move; - last_carrier_direction = carrier_direction; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - } - - private void shipDeviceUpdate() { - JSONObject param = new JSONObject() {{ - put("device_code", device_code); - }}; - logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,参数:"+param); - HttpResponse response = acsToWmsService.shipDeviceUpdate(param); - if (response == null || response.getStatus() == 200) { - logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,接口返回:"+response.body()); - this.requiresShipDeviceUpdate = true; - } - } - - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - public void clearWrite() { - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", "0"); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", "0"); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "0"); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", "0"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_length"); - map5.put("value", "0"); - list.add(map5); - Map map6 = new HashMap(); - map6.put("code", "to_weight"); - map6.put("value", "0"); - list.add(map6); - Map map7 = new HashMap(); - map7.put("code", "to_height"); - map7.put("value", "0"); - list.add(map7); - this.writing(list); - message = null; - vehicle_code = null; - } - - public boolean exe_business() { - return true; - } - - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); - return true; - } - - - protected void thingToNothing() throws Exception { - requireSucess = false; - } - - - public void writing(String param, String value) { - - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + param; - Map itemMap = new HashMap(); - - itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void executing(Server server, Map itemMap) { - this.control(itemMap); - } - - public void writing(int command) { - Map itemMap = new HashMap(); - this.control(itemMap); - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String carrier_direction = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } else if (this.getMode() == 4) { - mode = "申请捆扎中"; - } else if (this.getMode() == 5) { - mode = "申请贴标中"; - } else if (this.getMode() == 6) { - mode = "申请空盘入库中"; - } else if (this.getMode() == 7) { - mode = "申请空盘出库中"; - } else if (this.getMode() == 8) { - mode = "申请AGV任务中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - - if (this.carrier_direction == 1) { - carrier_direction = "正转"; - } else if (this.carrier_direction == 2) { - carrier_direction = "反转"; - } - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("carrier_direction", carrier_direction); - jo.put("task", task); - jo.put("last_task", last_task); - jo.put("task_code", task_code); - jo.put("inst_message", this.inst_message); - jo.put("last_inst_message", this.last_inst_message); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("is_click", true); - jo.put("requireSucess", requireSucess); - jo.put("driver_type", "siemens_conveyor"); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - public void writing(List list) { - - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - this.control(itemMap); - - } - - - /** - * 请求指令 - */ - public synchronized boolean instruction_require() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - //判断是否存在起点相同 任务状态就绪的任务 - TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); - if (!ObjectUtil.isEmpty(taskdto)) { -// if (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { -// return false; -// } - //需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 - Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); - if (ObjectUtil.isNotEmpty(inst)) { - List list = new ArrayList(); - Map map = new HashMap(); - - if (StrUtil.isNotEmpty(taskdto.getTo_z())) { - if (StrUtil.equals(taskdto.getTo_z(), "01")) { - map.put("code", "to_target"); - map.put("value", "102"); - } else if (StrUtil.equals(taskdto.getTo_z(), "02")) { - map.put("code", "to_target"); - map.put("value", "201"); - } else if (StrUtil.equals(taskdto.getTo_z(), "03")) { - map.put("code", "to_target"); - map.put("value", "301"); - } - } - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); -// if (task != Integer.parseInt(inst.getInstruction_code())) { -// this.writing(list); -// message = "重新下发电气信号"; -// logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); -// } - message = "下发电气任务号成功"; - requireSucess = true; - return true; - } - - // type 5 输送任务 - if (!StrUtil.equals(taskdto.getTask_type(), "5")) { - return false; - } - String taskid = taskdto.getTask_id(); - String taskcode = taskdto.getTask_code(); - String vehiclecode = taskdto.getVehicle_code(); - String priority = taskdto.getPriority(); - String start_point_code = taskdto.getStart_point_code(); - String start_device_code = taskdto.getStart_device_code(); - String route_plan_code = taskdto.getRoute_plan_code(); - String next_device_code = ""; - - /** - * 开始平均分配 - */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; - } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_coevice_code; - } - //校验路由关系 - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new RuntimeException("路由不通!"); - } - - Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); - Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); - String next_point_code; - if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(taskdto.getRemark()); - instdto.setMaterial(taskdto.getMaterial()); - instdto.setQuantity(taskdto.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - try { - instructionService.create(instdto); - } catch (Exception e) { - e.printStackTrace(); - log.error("指令创建失败!",e.getMessage()); - return false; - } - //创建指令后修改任务状态 - taskdto.setTask_status("1"); - taskserver.update(taskdto); - requireSucess = true; - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", instdto.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); -// if (task != Integer.parseInt(inst.getInstruction_code())) { -// this.writing(list); -// message = "重新下发电气信号"; -// logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); -// } - } else { - //如果不存在则直接找对应指令 - Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); - if (ObjectUtil.isEmpty(inst)) { - return false; - } - //当起点为行架任务的时候不需要请求下发 - if (StrUtil.equals(inst.getInstruction_type(), "6")) { - return false; - } - Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - } - return true; - } - } - - //申请贴标 - public synchronized void applyLabeling() { - Date date = new Date(); - if (date.getTime() - this.require_apply_labeling_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_apply_labeling_time = date; - String vehicle_code = ""; - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "异常"); - message = "申请贴标电气设备任务号:" + task + "异常"; - throw new RuntimeException("任务号为空!"); - } - if (StrUtil.isEmpty(vehicle_code)) { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "未找到载具号"); - message = "申请贴标电气设备任务号:" + task + "未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("1"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,请求参数:"+JSON.toJSONString(applyLabelingAndBindingRequest)); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - - if (applyLabelingAndBindingResponse.getstatus() == 200) { - message = "申请贴标成功"; - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "5"); - list.add(map); - this.writing(list); - this.writing(list); - message = "申请贴标下发电气信号成功"; - requireApplyLabelingSuccess = true; - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - - } else { - message = "申请贴标失败," + applyLabelingAndBindingResponse.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - } - } - } - - //申请捆扎 - @SneakyThrows - public synchronized void applyLaStrangulation() { - Date date = new Date(); - if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_apply_strangulation_time = date; - String vehicle_code = ""; - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - if(ObjectUtil.isEmpty(instruction)){ - message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; - return ; -// throw new RuntimeException("该电气任务号未找到对应指令!"); - } - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); - message = "申请捆扎电气设备任务号:" + task + "异常"; - return ; -// throw new RuntimeException("任务号为空!"); - } - if (StrUtil.isEmpty(vehicle_code)) { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); - message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; - return ; -// throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("2"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - logServer.deviceExecuteLog(this.device_code, "", "", "申请捆扎,请求参数:"+JSON.toJSONString(applyLabelingAndBindingRequest)); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - if (applyLabelingAndBindingResponse.getstatus() == 200) { - if (ObjectUtil.isNotEmpty(applyLabelingAndBindingResponse.getData())) { - Map datas = applyLabelingAndBindingResponse.getData(); - String length = datas.get("box_length").toString(); - String width = datas.get("box_width").toString(); - String box_high = datas.get("box_high").toString(); - String bundle_times = datas.get("bundle_times").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_length"); - map.put("value", length); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_weight"); - map2.put("value", width); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_height"); - map3.put("value", box_high); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", bundle_times); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_command"); - map5.put("value", "4"); - list.add(map5); - this.writing(list); -// this.writing(list); - logServer.deviceExecuteLog(this.device_code, "", "", "申请捆扎,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - message = "申请捆扎成功"; - requireSucess = true; - } else { - message = "未返回尺寸信息"; - logServer.deviceExecuteLog(this.device_code, "", "", "申请捆扎,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - } - - } else { - message = applyLabelingAndBindingResponse.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "申请捆扎,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - } - - } - } - - public synchronized void emptyIn() { - Date date = new Date(); - if (date.getTime() - this.require_empty_in_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_in_time = date; - - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘入库任务中..."; - - if(taskserver.querySameOriginTask(this.device_code) > 0 ){ - message = "已存在空盘出库任务不再请求"; - return; - } - - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "2"); - String str = acsToWmsService.applyTaskToWms(apply); - logServer.deviceExecuteLog(this.device_code, "", "", "申请空盘入库,请求参数:"+JSON.toJSONString(apply)); - - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘入库接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘入库成功"; - requireEmptyInSuccess = true; - } else { - message = "申请空盘入库失败," + jo.get("message").toString(); - } - } - - } - } - } - - public synchronized void applyAgvTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.instruction_require_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - Instruction instruction = instructionService.findByCode(String.valueOf(task)); - if(ObjectUtil.isEmpty(instruction)){ - message = "指令号"+task+"未找到对应指令"; - return; - } - if(StrUtil.isEmpty(instruction.getVehicle_code())){ - message = "指令号"+task+"未找到对应木箱号"; - return; - } - message = "申请AGV搬运任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "4"); - apply.put("vehicle_code", instruction.getVehicle_code()); - - String str = acsToWmsService.applyTaskToWms(apply); - logServer.deviceExecuteLog(this.device_code, "", "", "申请AGV任务,请求参数:"+apply); - - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请AGV搬运任务接口不通"; - requireSucess = true; - } else { - if (jo.getInteger("status") == 200) { - message = "申请AGV搬运任务成功"; - logServer.deviceExecuteLog(this.device_code, "", "", "申请AGV任务,返回参数:"+jo); - requireSucess = true; - } else { - requireSucess = true; - message = "申请AGV搬运任务失败," + jo.get("message").toString(); - } - } - - } - } - } - - public synchronized void emptyOut() { - Date date = new Date(); - if (date.getTime() - this.require_empty_out_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_out_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - if(taskserver.querySameDestinationTask(this.device_code) > 0 ){ - message = "已存在空盘出库任务不再请求"; - return; - } - message = "申请空盘出库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "3"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘出库接口不通"; - requireSucess = true; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘出库成功"; - requireSucess = true; - } else { - requireSucess = true; - message = "申请空盘出库失败," + jo.get("message").toString(); - } - } - - } - } - } - - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java deleted file mode 100644 index 6d64f74c..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; - -import cn.hutool.core.util.StrUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - //心跳 - public static String item_heartbeat = "heartbeat"; - //工作模式 - public static String item_mode = "mode"; - //光电信号 - public static String item_move = "move"; - //托盘方向 - public static String item_carrier_direction = "carrier_direction"; - //报警 - public static String item_error = "error"; - //任务号 - public static String item_task = "task"; - - //下发命令 - public static String item_to_command = "to_command"; - //下发目标站 - public static String item_to_target = "to_target"; - //下发托盘类型 - public static String item_to_container_type = "to_container_type"; - //下发任务号 - public static String item_to_task = "to_task"; - //困扎次数 - public static String item_to_strap_times = "to_strap_times"; - //木箱长度 - public static String item_to_length = "to_length"; - //木箱宽度 - public static String item_to_weight = "to_weight"; - //木箱高度 - public static String item_to_height = "to_height"; - - - private SiemensConveyorCkkDeviceDriver driver; - - public ItemProtocol(SiemensConveyorCkkDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getCarrier_direction() { - return this.getOpcIntegerValue(item_carrier_direction); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (StrUtil.isEmpty(value)) { - - } else { - return value; - } - return "0"; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); - list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); - list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4")); - list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); - list.add(new ItemDto(item_task, "任务号", "DB600.D10")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); - list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB601.W6")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); - list.add(new ItemDto(item_to_strap_times, "困扎次数", "DB601.W12")); - list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); - list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); - list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java deleted file mode 100644 index 248dc8fa..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; - -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceType; -import org.springframework.stereotype.Service; - -import java.util.LinkedList; -import java.util.List; - -/** - * 西门子-输送机驱动 - * - */ -@Service -public class SiemensConveyorCkkDefination implements OpcDeviceDriverDefination { - @Override - public String getDriverCode() { - return "siemens_conveyor_ckk"; - } - - @Override - public String getDriverName() { - return "西门子-输送机驱动-出库口"; - } - - @Override - public String getDriverDescription() { - return "西门子-输送机驱动-出库口"; - } - - @Override - public DeviceDriver getDriverInstance(Device device) { - return (new SiemensConveyorCkkDeviceDriver()).setDevice(device).setDriverDefination(this); - - } - - @Override - public Class getDeviceDriverType() { - return SiemensConveyorCkkDeviceDriver.class; - } - - @Override - public List getFitDeviceTypes() { - List types = new LinkedList(); - types.add(DeviceType.station); - return types; - } - - @Override - public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); - } - - - - @Override - public List getWriteableItemDtos() { - return ItemProtocol.getWriteableItemDtos(); - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java deleted file mode 100644 index e147b749..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java +++ /dev/null @@ -1,921 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.nl.acs.AcsConfig; -import org.nl.acs.agv.server.NDCAgvService; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.dto.RouteLineDto; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.core.bean.WQLObject; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 西门子-输送机驱动-出库口 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class SiemensConveyorCkkDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - @Autowired - NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); - //当前指令 - Instruction inst = null; - - //工作模式 - int mode = 0; - int last_mode = 0; - //光电信号 - int move = 0; - int last_move = 0; - //托盘方向 - int carrier_direction = 0; - int last_carrier_direction = 0; - //报警信号 - int error = 0; - int last_error = 0; - //任务号 - int task = 0; - int last_task = 0; - int agvphase = 0; - String task_code = null; - int heartbeat = 0; - int last_heartbeat = 0; - int phase = 0; - int index = 0; - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - private Date require_apply_labeling_time = new Date(); - private Date require_apply_strangulation_time = new Date(); - private Date require_empty_in_time = new Date(); - private Date require_empty_out_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - boolean requireApplyLabelingSuccess = false; - boolean requireApplyLaStrangulationSuccess = false; - boolean requireEmptyInSuccess = false; - boolean requireEmptyOutSuccess = false; - boolean requiresShipDeviceUpdate = true; - private int instruction_finished_time_out; - - int branchProtocol = 0; - String inst_message; - String last_inst_message; - - //当前指令 - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - String vehicle_code; - String last_vehicle_code; - - @Override - public Device getDevice() { - return this.device; - } - - - @Override - public void execute() { - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - carrier_direction = this.itemProtocol.getCarrier_direction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - heartbeat = this.itemProtocol.getHeartbeat(); -// if(heartbeat != last_heartbeat){ -// logServer.deviceExecuteLog(this.device_code, "", "", "heartbeat:" + last_heartbeat + "->" + heartbeat); -// } - if (mode != last_mode) { - if (mode == 2) { - requireSucess = false; - requireApplyLabelingSuccess = false; - requireApplyLaStrangulationSuccess = false; - requireEmptyInSuccess = false; - requireEmptyOutSuccess = false; - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记"); - } - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - message = null; - if (move == 0 ) { - inst_message = null; - requireSucess = false; - this.clearWrite(); - } - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (carrier_direction != last_carrier_direction) { - logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - - if (move != 0 && task > 0) { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst != null) { - inst_message = "当前指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); - vehicle_code = inst.getVehicle_code(); - task_code = inst.getTask_code(); - if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); - } - if (StrUtil.equals(inst.getInstruction_status(), "1")) { - if (!StrUtil.equals(inst.getExecute_code(), this.device_code)) { - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } - } - } else { -// logServer.deviceExecuteLog(device_code, "", "", "输送线任务开始反馈任务状态,反馈失败,查询不到指令号:" + task); - message = "输送线任务反馈状态,查询不到指令号:" + task +"指令已完成"; - inst_message = null; - } - } - - } catch (Exception var17) { - var17.printStackTrace(); - inst_message = var17.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - } - -// if (!this.itemProtocol.getIsonline()) { -// this.setIsonline(false); -// this.setIserror(true); -// message = "信号量同步异常"; -// //未联机 -// } else - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - - } else { - this.setIsonline(true); - this.setIserror(false); - - if (error != 0) { - this.setIserror(true); - message = "有报警"; - } - - Instruction instruction = null; - List toInstructions; - - - switch (mode) { - case 1: - log.debug("设备运转模式:等待工作"); - break; - case 2: - //申请任务 - if (move > 0 && !requireSucess) { - try { - instruction_require(); - } catch (Exception e) { - e.printStackTrace(); - } - } - break; - case 4: - break; - case 5: - break; - case 6: - break; - case 7: - break; - case 8: - break; - } - } - last_mode = mode; - last_move = move; - last_carrier_direction = carrier_direction; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - } - - private void shipDeviceUpdate() { - JSONObject param = new JSONObject() {{ - put("device_code", device_code); - }}; - - HttpResponse response = acsToWmsService.shipDeviceUpdate(param); - if (response == null || response.getStatus() == 200) { - this.requiresShipDeviceUpdate = true; - } - } - - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - public void clearWrite() { - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", "0"); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", "0"); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "0"); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", "0"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_length"); - map5.put("value", "0"); - list.add(map5); - Map map6 = new HashMap(); - map6.put("code", "to_weight"); - map6.put("value", "0"); - list.add(map6); - Map map7 = new HashMap(); - map7.put("code", "to_height"); - map7.put("value", "0"); - list.add(map7); - this.writing(list); - message = null; - vehicle_code = null; - } - - public boolean exe_business() { - return true; - } - - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); -// requireSucess = false; - return true; - } - - - protected void thingToNothing() throws Exception { - requireSucess = false; - } - - - public void writing(String param, String value) { - - String to_param = 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_param, Integer.parseInt(value)); -// itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void executing(Server server, Map itemMap) { - this.control(itemMap); - } - - public void writing(int command) { - - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - this.control(itemMap); - - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String carrier_direction = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } else if (this.getMode() == 4) { - mode = "申请捆扎中"; - } else if (this.getMode() == 5) { - mode = "申请贴标中"; - } else if (this.getMode() == 6) { - mode = "申请空盘入库中"; - } else if (this.getMode() == 7) { - mode = "申请空盘出库中"; - } else if (this.getMode() == 8) { - mode = "申请AGV任务中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - - if (this.carrier_direction == 1) { - carrier_direction = "正转"; - } else if (this.carrier_direction == 2) { - carrier_direction = "反转"; - } - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("carrier_direction", carrier_direction); - jo.put("task", task); - jo.put("last_task", last_task); - jo.put("task_code", task_code); - -// jo.put("barcode", barcode); -// jo.put("last_task", last_task); - jo.put("inst_message", this.inst_message); - jo.put("last_inst_message", this.last_inst_message); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("is_click", true); - jo.put("requireSucess", requireSucess); - jo.put("driver_type", "siemens_conveyor"); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - public void writing(List list) { - -// String opcservcerid = this.getDevice().getOpc_server_id(); -// Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - this.control(itemMap); - - } - - - /** - * 请求指令 - */ - public synchronized boolean instruction_require() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - if (ObjectUtil.isEmpty(instruction)) { - //instruction = instructionService.findByCode(String.valueOf(task)); - message ="任务号:"+task +"未找到对应立库指令,请检查"; - return false; - } - if(StrUtil.equals(instruction.getInstruction_status(),"1")){ - if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - vehicle_code = inst.getVehicle_code(); - inst.setExecute_device_code(this.device_code); - try { - finish_instruction(); - } catch (Exception e) { - e.printStackTrace(); - } - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); - } - } - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请输送任务电气设备任务号:" + task + "异常"); - message = "申请输送任务电气设备任务号:" + task + "异常"; - return false; - } - - //判断是否存在起点相同 任务状态就绪的任务 - TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); - if (!ObjectUtil.isEmpty(taskdto)) { -// if (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { -// return false; -// } - //需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 - Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); - if (ObjectUtil.isNotEmpty(inst)) { - List list = new ArrayList(); - Map map = new HashMap(); - - if (StrUtil.isNotEmpty(taskdto.getTo_z())) { - if (StrUtil.equals(taskdto.getTo_z(), "01")) { - map.put("code", "to_target"); - map.put("value", "102"); - } else if (StrUtil.equals(taskdto.getTo_z(), "02")) { - map.put("code", "to_target"); - map.put("value", "201"); - } else if (StrUtil.equals(taskdto.getTo_z(), "03")) { - map.put("code", "to_target"); - map.put("value", "301"); - } - } - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - message = "重新下发电气信号"; - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - message = "下发电气任务号成功"; - requireSucess = true; - return true; - } - - // type 5 输送任务 - if (!StrUtil.equals(taskdto.getTask_type(), "5")) { - return false; - } - String taskid = taskdto.getTask_id(); - String taskcode = taskdto.getTask_code(); - String vehiclecode = taskdto.getVehicle_code(); - String priority = taskdto.getPriority(); - String start_point_code = taskdto.getStart_point_code(); - String start_device_code = taskdto.getStart_device_code(); - String route_plan_code = taskdto.getRoute_plan_code(); - String next_device_code = ""; - - /** - * 开始平均分配 - */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; - } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_coevice_code; - } - //校验路由关系 - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new RuntimeException("路由不通!"); - } - - Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); - Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); - String next_point_code; - if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(taskdto.getRemark()); - instdto.setMaterial(taskdto.getMaterial()); - instdto.setQuantity(taskdto.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - try { - instructionService.create(instdto); - } catch (Exception e) { - e.printStackTrace(); - log.error("指令创建失败!",e.getMessage()); - return false; - } - //创建指令后修改任务状态 - taskdto.setTask_status("1"); - taskserver.update(taskdto); - requireSucess = true; - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", instdto.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - message = "重新下发电气信号"; - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - } else { - //如果不存在则直接找对应指令 - Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); - if (ObjectUtil.isEmpty(inst)) { - return false; - } - - Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - requireSucess = true; - } - return true; - } - } - - //申请贴标 - public synchronized void applyLabeling() { - Date date = new Date(); - if (date.getTime() - this.require_apply_labeling_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_apply_labeling_time = date; - String vehicle_code = ""; - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "异常"); - message = "申请贴标电气设备任务号:" + task + "异常"; - throw new RuntimeException("任务号为空!"); - } - if (StrUtil.isEmpty(vehicle_code)) { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "未找到载具号"); - message = "申请贴标电气设备任务号:" + task + "未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("1"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - - if (applyLabelingAndBindingResponse.getstatus() == 200) { - message = "申请贴标成功"; - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "5"); - list.add(map); - this.writing(list); - this.writing(list); - message = "申请贴标下发电气信号成功"; - requireApplyLabelingSuccess = true; - } else { - message = "申请贴标失败," + applyLabelingAndBindingResponse.getMessage(); - } - } - } - - //申请捆扎 - @SneakyThrows - public synchronized void applyLaStrangulation() { - Date date = new Date(); - if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_apply_strangulation_time = date; - String vehicle_code = ""; - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - if(ObjectUtil.isEmpty(instruction)){ - message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; - throw new RuntimeException("该电气任务号未找到对应指令!"); - } - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); - message = "申请捆扎电气设备任务号:" + task + "异常"; - throw new RuntimeException("任务号为空!"); - } - if (StrUtil.isEmpty(vehicle_code)) { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); - message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("2"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - if (applyLabelingAndBindingResponse.getstatus() == 200) { - if (ObjectUtil.isNotEmpty(applyLabelingAndBindingResponse.getData())) { - Map datas = applyLabelingAndBindingResponse.getData(); - String length = datas.get("box_length").toString(); - String width = datas.get("box_width").toString(); - String box_high = datas.get("box_high").toString(); - String bundle_times = datas.get("bundle_times").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_length"); - map.put("value", length); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_weight"); - map2.put("value", width); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_height"); - map3.put("value", box_high); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", bundle_times); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_command"); - map5.put("value", "4"); - list.add(map5); - this.writing(list); -// this.writing(list); - - message = "申请捆扎成功"; - requireSucess = true; - } else { - message = "未返回尺寸信息"; - } - - } else { - message = applyLabelingAndBindingResponse.getMessage(); - } - - } - } - - public synchronized void emptyIn() { - Date date = new Date(); - if (date.getTime() - this.require_empty_in_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_in_time = date; - - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘入库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "2"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘入库接口不通"; - requireEmptyInSuccess = true; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘入库成功"; - requireEmptyInSuccess = true; - } else { - requireEmptyInSuccess = true; - message = "申请空盘入库失败," + jo.get("message").toString(); - } - } - - } - } - } - - public synchronized void applyAgvTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.instruction_require_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - Instruction instruction = instructionService.findByCode(String.valueOf(task)); - if(ObjectUtil.isEmpty(instruction)){ - message = "指令号"+task+"未找到对应指令"; - return; - } - message = "申请AGV搬运任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "4"); - apply.put("vehicle_code", instruction.getVehicle_code()); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请AGV搬运任务接口不通"; - requireSucess = true; - } else { - if (jo.getInteger("status") == 200) { - message = "申请AGV搬运任务成功"; - requireSucess = true; - } else { - requireSucess = true; - message = "申请AGV搬运任务失败," + jo.get("message").toString(); - } - } - - } - } - } - - public synchronized void emptyOut() { - Date date = new Date(); - if (date.getTime() - this.require_empty_out_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_out_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘出库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "3"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘出库接口不通"; - requireSucess = true; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘出库成功"; - requireSucess = true; - } else { - requireSucess = true; - message = "申请空盘出库失败," + jo.get("message").toString(); - } - } - - } - } - } - - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/ItemProtocol.java deleted file mode 100644 index baa5e9a7..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/ItemProtocol.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling; - -import cn.hutool.core.util.StrUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - //心跳 - public static String item_heartbeat = "heartbeat"; - //工作模式 - public static String item_mode = "mode"; - //光电信号 - public static String item_move = "move"; - //托盘方向 - public static String item_carrier_direction = "carrier_direction"; - //报警 - public static String item_error = "error"; - //任务号 - public static String item_task = "task"; - //重量 - public static String item_weight = "weight"; - - //下发命令 - public static String item_to_command = "to_command"; - //下发目标站 - public static String item_to_target = "to_target"; - //下发托盘类型 - public static String item_to_container_type = "to_container_type"; - //下发任务号 - public static String item_to_task = "to_task"; - //困扎次数 - public static String item_to_strap_times = "to_strap_times"; - //木箱长度 - public static String item_to_length = "to_length"; - //木箱宽度 - public static String item_to_weight = "to_weight"; - //木箱高度 - public static String item_to_height = "to_height"; - - - private SiemensConveyorLabelingDeviceDriver driver; - - public ItemProtocol(SiemensConveyorLabelingDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getCarrier_direction() { - return this.getOpcIntegerValue(item_carrier_direction); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - public int getWeight() { - return this.getOpcIntegerValue(item_weight); - } - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (StrUtil.isEmpty(value)) { - - } else { - return value; - } - return "0"; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB101.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB101.B152")); - list.add(new ItemDto(item_move, "光电信号", "DB101.B153")); - list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB101.B154")); - list.add(new ItemDto(item_error, "报警信号", "DB101.B156")); - list.add(new ItemDto(item_task, "任务号", "DB101.D160")); - list.add(new ItemDto(item_weight, "重量", "DB101.D160")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "DB102.W152")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W154")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB102.D158")); - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java deleted file mode 100644 index 20f246cc..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDefination.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling; - -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceType; -import org.springframework.stereotype.Service; - -import java.util.LinkedList; -import java.util.List; - -/** - * 西门子-输送机驱动-贴标 - * - */ -@Service -public class SiemensConveyorLabelingDefination implements OpcDeviceDriverDefination { - @Override - public String getDriverCode() { - return "siemens_conveyor_labeling"; - } - - @Override - public String getDriverName() { - return "西门子-输送机驱动-贴标"; - } - - @Override - public String getDriverDescription() { - return "西门子-输送机驱动-贴标"; - } - - @Override - public DeviceDriver getDriverInstance(Device device) { - return (new SiemensConveyorLabelingDeviceDriver()).setDevice(device).setDriverDefination(this); - - } - - @Override - public Class getDeviceDriverType() { - return SiemensConveyorLabelingDeviceDriver.class; - } - - @Override - public List getFitDeviceTypes() { - List types = new LinkedList(); - types.add(DeviceType.station); - return types; - } - - @Override - public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); - } - - - - @Override - public List getWriteableItemDtos() { - return ItemProtocol.getWriteableItemDtos(); - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java deleted file mode 100644 index 705a8abd..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_labeling/SiemensConveyorLabelingDeviceDriver.java +++ /dev/null @@ -1,931 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.nl.acs.AcsConfig; -import org.nl.acs.agv.server.NDCAgvService; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.dto.RouteLineDto; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.core.bean.WQLObject; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** 西门子-输送机驱动-贴标 */ -@Slf4j -@Data -@RequiredArgsConstructor -public class SiemensConveyorLabelingDeviceDriver extends AbstractOpcDeviceDriver - implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - - @Autowired DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); - @Autowired TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - - @Autowired ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); - - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - @Autowired NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); - // 当前指令 - Instruction inst = null; - int heartbeat = 0; - int last_heartbeat = 0; - // 工作模式 - int mode = 0; - int last_mode = 0; - // 光电信号 - int move = 0; - int last_move = 0; - // 托盘方向 - int carrier_direction = 0; - int last_carrier_direction = 0; - // 报警信号 - int error = 0; - int last_error = 0; - // 任务号 - int task = 0; - int weight = 0; - int last_task = 0; - int agvphase = 0; - - int phase = 0; - int index = 0; - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - private Date require_apply_labeling_time = new Date(); - private Date require_apply_strangulation_time = new Date(); - private Date require_empty_in_time = new Date(); - private Date require_empty_out_time = new Date(); - - private int instruction_require_time_out =3000; - // 行架机械手申请任务成功标识 - boolean requireSucess = false; - boolean requireApplyLabelingSuccess = false; - boolean requireApplyLaStrangulationSuccess = false; - boolean requireEmptyInSuccess = false; - boolean requireEmptyOutSuccess = false; - private int instruction_finished_time_out; - - int branchProtocol = 0; - String inst_message; - - // 当前指令 - - // 暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - String vehicle_code; - - @Override - public Device getDevice() { - return this.device; - } - - @Override - public void execute() { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - carrier_direction = this.itemProtocol.getCarrier_direction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - weight = this.itemProtocol.getWeight(); - heartbeat = this.itemProtocol.getHeartbeat(); -// if(heartbeat != last_heartbeat){ -// logServer.deviceExecuteLog(this.device_code, "", "", "heartbeat:" + last_heartbeat + "->" + heartbeat); -// } - if (mode != last_mode) { - if (mode == 2) { - requireSucess = false; - requireApplyLabelingSuccess = false; - requireApplyLaStrangulationSuccess = false; - requireEmptyInSuccess = false; - requireEmptyOutSuccess = false; - logServer.deviceExecuteLog(this.device_code, "", "", "复位请求标记成功!"); - } - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - if (move == 0 && mode == 2) { - this.clearWrite(); - } - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (carrier_direction != last_carrier_direction) { - logServer.deviceItemValue( - this.device_code, "carrier_direction", String.valueOf(carrier_direction)); - logServer.deviceExecuteLog( - this.device_code, - "", - "", - "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog( - this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - - if (mode == 2 && move != 0 && task > 0) { - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈任务状态,指令号:" + task); - // inst_message - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst != null) { - inst_message = - "指令号:" - + inst.getInstruction_code() - + " " - + inst.getStart_point_code() - + "->" - + inst.getNext_point_code() - + " 载具号:" - + inst.getVehicle_code(); - if (StrUtil.equals(inst.getInstruction_status(), "1") - && StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - vehicle_code = inst.getVehicle_code(); - finish_instruction(); - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); - } else if (StrUtil.equals(inst.getInstruction_status(), "0") - && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - instructionService.update(inst); - logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); - } else { - logServer.deviceExecuteLog( - device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈失败任务状态不为就绪或者执行中状态,指令号:" + task); - } - } else { -// logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈任务状态,反馈失败,查询不到指令号:" + task); - } - } - - } catch (Exception var17) { - var17.printStackTrace(); - inst_message = var17.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - } - - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - } else { - this.setIsonline(true); - this.setIserror(false); - if (error != 0) { - this.setIserror(true); - message = "有报警"; - } - message = ""; - Instruction instruction = null; - List toInstructions; - - switch (mode) { - case 1: - log.debug("设备运转模式:等待工作"); - break; - case 2: - // 申请任务 - if (move > 0 && !requireSucess) { - instruction_require(); - } - break; - case 4: - // 申请捆扎 - if (move > 0 && !requireSucess) { - applyLaStrangulation(); - } - break; - case 5: - // 申请贴标 - if (move > 0 && !requireSucess) { - applyLabeling(); - } - break; - case 6: - // 空托盘满垛入库申请 - if (move > 0 && !requireEmptyInSuccess) { - emptyIn(); - } - if (move > 0 && !requireSucess) { - instruction_require(); - } - break; - case 7: - // 空盘出库申请 - if (move == 0 && !requireEmptyOutSuccess) { - emptyOut(); - } - break; - case 8: - // 申请AGV任务 - if (move == 0 && !requireSucess) { - applyAgvTask(); - } - break; - } - } - last_mode = mode; - last_move = move; - last_carrier_direction = carrier_direction; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - - } - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - public void clearWrite() { - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", "0"); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", "0"); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "0"); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", "0"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_length"); - map5.put("value", "0"); - list.add(map5); - Map map6 = new HashMap(); - map6.put("code", "to_weight"); - map6.put("value", "0"); - list.add(map6); - Map map7 = new HashMap(); - map7.put("code", "to_height"); - map7.put("value", "0"); - list.add(map7); - this.writing(list); - message = null; - vehicle_code = null; - } - - public boolean exe_business() { - return true; - } - - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); - // requireSucess = false; - return true; - } - - protected void thingToNothing() throws Exception { - requireSucess = false; - } - - public void writing(String param, String value) { - - String to_param = - 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_param, Integer.parseInt(value)); - // itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - logServer.deviceExecuteLog( - device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void executing(Server server, Map itemMap) { - this.control(itemMap); - } - - public void writing(int command) { - - // String opcservcerid = this.getDevice().getOpc_server_id(); - // Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - this.control(itemMap); - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String carrier_direction = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } else if (this.getMode() == 4) { - mode = "申请捆扎中"; - } else if (this.getMode() == 5) { - mode = "申请贴标中"; - } else if (this.getMode() == 6) { - mode = "申请空盘入库中"; - } else if (this.getMode() == 7) { - mode = "申请空盘出库中"; - } else if (this.getMode() == 8) { - mode = "申请AGV任务中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - String requireApplyLabelingSuccess = "0"; - if (this.requireApplyLabelingSuccess) { - requireApplyLabelingSuccess = "1"; - } - String requireApplyLaStrangulationSuccess = "0"; - if (this.requireApplyLaStrangulationSuccess) { - requireApplyLaStrangulationSuccess = "1"; - } - jo.put("requireApplyLabelingSuccess", requireApplyLabelingSuccess); - jo.put("requireApplyLaStrangulationSuccess", requireApplyLaStrangulationSuccess); - - if (this.carrier_direction == 1) { - carrier_direction = "正转"; - } else if (this.carrier_direction == 2) { - carrier_direction = "反转"; - } - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("carrier_direction", carrier_direction); - jo.put("task", task); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("is_click", true); - jo.put("requireSucess", requireSucess); - jo.put("driver_type", "siemens_conveyor"); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - public void writing(List list) { - - // String opcservcerid = this.getDevice().getOpc_server_id(); - // Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = - this.getDevice().getOpc_server_code() - + "." - + this.getDevice().getOpc_plc_code() - + "." - + this.getDevice().getDevice_code() - + "." - + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - this.control(itemMap); - } - - /** 请求指令 */ - public synchronized boolean instruction_require() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() - < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - // 判断是否存在起点相同 任务状态就绪的任务 - TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); - if (!ObjectUtil.isEmpty(taskdto)) { - // if - // (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { - // return false; - // } - // 需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 - Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); - if (ObjectUtil.isNotEmpty(inst)) { - List list = new ArrayList(); - Map map = new HashMap(); - - if (StrUtil.isNotEmpty(taskdto.getTo_z())) { - if (StrUtil.equals(taskdto.getTo_z(), "01")) { - map.put("code", "to_target"); - map.put("value", "102"); - } else if (StrUtil.equals(taskdto.getTo_z(), "02")) { - map.put("code", "to_target"); - map.put("value", "201"); - } else if (StrUtil.equals(taskdto.getTo_z(), "03")) { - map.put("code", "to_target"); - map.put("value", "301"); - } - } - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog( - device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - message = "下发电气任务号成功"; - requireSucess = true; - return true; - } - - // type 5 输送任务 - if (!StrUtil.equals(taskdto.getTask_type(), "5")) { - return false; - } - String taskid = taskdto.getTask_id(); - String taskcode = taskdto.getTask_code(); - String vehiclecode = taskdto.getVehicle_code(); - String priority = taskdto.getPriority(); - String start_point_code = taskdto.getStart_point_code(); - String start_device_code = taskdto.getStart_device_code(); - String route_plan_code = taskdto.getRoute_plan_code(); - String next_device_code = ""; - - /** 开始平均分配 */ - String this_coevice_code = - taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { - List shortPathsList = - routeLineService.getShortPathLines( - start_device_code, taskdto.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; - } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_coevice_code; - } - // 校验路由关系 - List shortPathsList = - routeLineService.getShortPathLines( - start_device_code, next_device_code, route_plan_code); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new RuntimeException("路由不通!"); - } - - Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); - Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); - String next_point_code; - if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(taskdto.getRemark()); - instdto.setMaterial(taskdto.getMaterial()); - instdto.setQuantity(taskdto.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - try { - instructionService.create(instdto); - } catch (Exception e) { - e.printStackTrace(); - log.error("指令创建异常!"); - return false; - } - // 创建指令后修改任务状态 - taskdto.setTask_status("1"); - taskserver.update(taskdto); - requireSucess = true; - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", instdto.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - } else { - // 如果不存在则直接找对应指令 - Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); - if (ObjectUtil.isEmpty(inst)) { - return false; - } - // 当起点为行架任务的时候不需要请求下发 - if (StrUtil.equals(inst.getInstruction_type(), "6")) { - return false; - } - Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); - String next_addr = nextdevice.getExtraValue().get("address").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", next_addr); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - this.writing(list); - if (task != Integer.parseInt(inst.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); - } - } - return true; - } - } - - // 申请贴标 - public synchronized void applyLabeling() { - Date date = new Date(); - if (date.getTime() - this.require_apply_labeling_time.getTime() - < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_apply_labeling_time = date; - String vehicle_code = ""; - if (weight == 0) { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备重量:" + weight + "异常"); - message = "申请贴标电气设备重量:" + weight + "异常"; - throw new RuntimeException("重量为空!"); - } - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - if (ObjectUtil.isEmpty(instruction)) { - instruction = instructionService.findByCode(String.valueOf(task)); - } - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "异常"); - message = "申请贴标电气设备任务号:" + task + "异常"; - throw new RuntimeException("任务号为空!"); - } - if (StrUtil.isEmpty(vehicle_code)) { - logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "未找到载具号"); - message = "申请贴标电气设备任务号:" + task + "未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = - WQLObject.getWQLObject("acs_storage_cell") - .query("storage_code ='" + this.device_code + "'") - .uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = - (String) device_json.get("parent_storage_code") == null - ? this.device_code - : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("1"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - applyLabelingAndBindingRequest.setWeight(String.valueOf((float) weight / 100)); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = - acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,请求参数:"+JSON.toJSONString(applyLabelingAndBindingRequest)); - - if (applyLabelingAndBindingResponse.getstatus() == 200) { - message = "申请贴标成功"; - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "5"); - list.add(map); - this.writing(list); - this.writing(list); - message = "申请贴标下发电气信号成功"; - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - requireSucess = true; - } else { - message = "申请贴标失败," + applyLabelingAndBindingResponse.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "申请贴标,返回参数:"+JSON.toJSONString(applyLabelingAndBindingResponse)); - - } - } - } - - // 申请捆扎 - public synchronized void applyLaStrangulation() { - Date date = new Date(); - if (date.getTime() - this.require_apply_strangulation_time.getTime() - < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_apply_strangulation_time = date; - String vehicle_code = ""; - if (task > 0) { - Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); - vehicle_code = instruction.getVehicle_code(); - } else { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); - message = "申请捆扎电气设备任务号:" + task + "异常"; - throw new RuntimeException("任务号为空!"); - } - if (StrUtil.isEmpty(vehicle_code)) { - logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); - message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; - throw new RuntimeException("载具号为空!"); - } - ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = - new ApplyLabelingAndBindingRequest(); - JSONObject device_json = - WQLObject.getWQLObject("acs_storage_cell") - .query("storage_code ='" + this.device_code + "'") - .uniqueResult(0); - String start_point_code = null; - if (!ObjectUtil.isEmpty(device_json)) { - start_point_code = - (String) device_json.get("parent_storage_code") == null - ? this.device_code - : (String) device_json.get("parent_storage_code"); - } - applyLabelingAndBindingRequest.setDevice_code(start_point_code); - applyLabelingAndBindingRequest.setType("2"); - applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); - ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = - acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); - if (applyLabelingAndBindingResponse.getstatus() == 200) { - if (ObjectUtil.isNotEmpty(applyLabelingAndBindingResponse.getData())) { - Map datas = applyLabelingAndBindingResponse.getData(); - String length = datas.get("box_length").toString(); - String width = datas.get("box_width").toString(); - String box_high = datas.get("box_high").toString(); - String bundle_times = datas.get("bundle_times").toString(); - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_length"); - map.put("value", length); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_weight"); - map2.put("value", width); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_height"); - map3.put("value", box_high); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", bundle_times); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_command"); - map5.put("value", "4"); - list.add(map5); - this.writing(list); - this.writing(list); - message = "申请贴标成功"; - requireSucess = true; - } else { - message = "未返回尺寸信息"; - } - - } else { - message = applyLabelingAndBindingResponse.getMessage(); - } - } - } - - public synchronized void emptyIn() { - Date date = new Date(); - if (date.getTime() - this.require_empty_in_time.getTime() - < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_in_time = date; - - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘入库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "2"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘入库接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘入库成功"; - requireEmptyInSuccess = true; - } else { - requireEmptyInSuccess = false; - message = "申请空盘入库失败," + jo.get("message").toString(); - } - } - } - } - } - - public synchronized void applyAgvTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() - < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.instruction_require_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请AGV搬运任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "1"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请AGV搬运任务接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请AGV搬运任务成功"; - requireEmptyOutSuccess = true; - } else { - requireEmptyOutSuccess = false; - message = "申请AGV搬运任务失败," + jo.get("message").toString(); - } - } - } - } - } - - public synchronized void emptyOut() { - Date date = new Date(); - if (date.getTime() - this.require_empty_out_time.getTime() - < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return; - } else { - this.require_empty_out_time = date; - if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { - message = "申请空盘出库任务中..."; - JSONObject apply = new JSONObject(); - apply.put("device_code", device_code); - apply.put("type", "3"); - String str = acsToWmsService.applyTaskToWms(apply); - JSONObject jo = JSON.parseObject(str); - if (ObjectUtil.isEmpty(jo)) { - message = "申请空盘出库接口不通"; - } else { - if (jo.getInteger("status") == 200) { - message = "申请空盘出库成功"; - requireEmptyOutSuccess = true; - } else { - requireEmptyOutSuccess = false; - message = "申请空盘出库失败," + jo.get("message").toString(); - } - } - } - } - } -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/ItemProtocol.java deleted file mode 100644 index acef45db..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/ItemProtocol.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_onefloor_agv_conveyor; - -import cn.hutool.core.util.StrUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - //心跳 - public static String item_heartbeat = "heartbeat"; - //工作模式 - public static String item_mode = "mode"; - //光电信号 - public static String item_move = "move"; - //托盘方向 - public static String item_carrier_direction = "carrier_direction"; - //报警 - public static String item_error = "error"; - //任务号 - public static String item_task = "task"; - - //下发命令 - public static String item_to_command = "to_command"; - //下发目标站 - public static String item_to_target = "to_target"; - //下发托盘类型 - public static String item_to_container_type = "to_container_type"; - //下发任务号 - public static String item_to_task = "to_task"; - //困扎次数 - public static String item_to_strap_times = "to_strap_times"; - //木箱长度 - public static String item_to_length = "to_length"; - //木箱宽度 - public static String item_to_weight = "to_weight"; - //木箱高度 - public static String item_to_height = "to_height"; - - - private SiemensOneFloorAGVConveyorDeviceDriver driver; - - public ItemProtocol(SiemensOneFloorAGVConveyorDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getCarrier_direction() { - return this.getOpcIntegerValue(item_carrier_direction); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - public int getTo_command() { - return this.getOpcIntegerValue(item_to_command); - } - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (StrUtil.isEmpty(value)) { - - } else { - return value; - } - return "0"; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_mode, "工作模式", "DB101.B152")); - list.add(new ItemDto(item_move, "光电信号", "DB101.B153")); - list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB101.B154")); - list.add(new ItemDto(item_error, "报警信号", "DB101.B156")); - list.add(new ItemDto(item_task, "任务号", "DB101.D160")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command, "下发命令", "DB102.W152")); - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/SiemensOneFloorAGVConveyorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/SiemensOneFloorAGVConveyorDeviceDriver.java deleted file mode 100644 index 91b62d7d..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_onefloor_agv_conveyor/SiemensOneFloorAGVConveyorDeviceDriver.java +++ /dev/null @@ -1,343 +0,0 @@ -package org.nl.acs.device_driver.basedriver.siemens_onefloor_agv_conveyor; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.nl.acs.AcsConfig; -import org.nl.acs.agv.server.NDCAgvService; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; -import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.dto.RouteLineDto; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.system.service.ParamService; -import org.nl.modules.wql.core.bean.WQLObject; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 西门子-1LAGV-输送机驱动 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class SiemensOneFloorAGVConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); - @Autowired - RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - @Autowired - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - @Autowired - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); - @Autowired - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - @Autowired - NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); - //当前指令 - Instruction inst = null; - int heartbeat = 0; - int last_heartbeat = 0; - //工作模式 - int mode = 0; - int last_mode = 0; - //光电信号 - int move = 0; - int last_move = 0; - //托盘方向 - int carrier_direction = 0; - int last_carrier_direction = 0; - //报警信号 - int error = 0; - int last_error = 0; - //任务号 - int task = 0; - int last_task = 0; - int agvphase = 0; - String task_code = null; - int to_command = 0; - - int phase = 0; - int index = 0; - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - private Date require_apply_labeling_time = new Date(); - private Date require_apply_strangulation_time = new Date(); - private Date require_empty_in_time = new Date(); - private Date require_empty_out_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - boolean requireApplyLabelingSuccess = false; - boolean requireApplyLaStrangulationSuccess = false; - boolean requireEmptyInSuccess = false; - boolean requireEmptyOutSuccess = false; - boolean requiresShipDeviceUpdate = true; - private int instruction_finished_time_out; - - int branchProtocol = 0; - String inst_message; - String last_inst_message; - - //当前指令 - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - String vehicle_code; - String last_vehicle_code; - - @Override - public Device getDevice() { - return this.device; - } - - - @Override - public void execute() { - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - carrier_direction = this.itemProtocol.getCarrier_direction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - to_command = this.itemProtocol.getTo_command(); - - } catch (Exception var17) { - var17.printStackTrace(); - inst_message = var17.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); - } - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - - } else { - this.setIsonline(true); - this.setIserror(false); - if (error != 0) { - this.setIserror(true); - message = "有报警"; - } - - } - last_mode = mode; - last_move = move; - last_carrier_direction = carrier_direction; - last_error = error; - last_task = task; - } - - - - public void clearWrite() { - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_target"); - map.put("value", "0"); - list.add(map); - Map map2 = new HashMap(); - map2.put("code", "to_task"); - map2.put("value", "0"); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_command"); - map3.put("value", "0"); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_strap_times"); - map4.put("value", "0"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_length"); - map5.put("value", "0"); - list.add(map5); - Map map6 = new HashMap(); - map6.put("code", "to_weight"); - map6.put("value", "0"); - list.add(map6); - Map map7 = new HashMap(); - map7.put("code", "to_height"); - map7.put("value", "0"); - list.add(map7); - this.writing(list); - message = null; - vehicle_code = null; - } - - public boolean exe_business() { - return true; - } - - public synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); -// requireSucess = false; - return true; - } - - - protected void thingToNothing() throws Exception { - requireSucess = false; - } - - - public void writing(String param, String value) { - - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + param; - Map itemMap = new HashMap(); - - itemMap.put(to_param, Integer.parseInt(value)); - this.control(itemMap); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public void executing(Server server, Map itemMap) { - this.control(itemMap); - } - - public void writing(int command) { - - Map itemMap = new HashMap(); - this.control(itemMap); - - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String carrier_direction = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } else if (this.getMode() == 4) { - mode = "申请捆扎中"; - } else if (this.getMode() == 5) { - mode = "申请贴标中"; - } else if (this.getMode() == 6) { - mode = "申请空盘入库中"; - } else if (this.getMode() == 7) { - mode = "申请空盘出库中"; - } else if (this.getMode() == 8) { - mode = "申请AGV任务中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - - if (this.carrier_direction == 1) { - carrier_direction = "正转"; - } else if (this.carrier_direction == 2) { - carrier_direction = "反转"; - } - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("carrier_direction", carrier_direction); - jo.put("task", task); - jo.put("last_task", last_task); - jo.put("task_code", task_code); - jo.put("inst_message", this.inst_message); - jo.put("last_inst_message", this.last_inst_message); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("is_click", true); - jo.put("requireSucess", requireSucess); - jo.put("driver_type", "siemens_conveyor"); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - public void writing(List list) { - - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - this.control(itemMap); - - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/ItemProtocol.java deleted file mode 100644 index f566a162..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/ItemProtocol.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.nl.acs.device_driver.basedriver.slit_two_manipulator; - -import cn.hutool.core.util.StrUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - - //心跳 - public static String item_heartbeat = "heartbeat"; - //工作模式 - public static String item_mode = "mode"; - //设备状态 - public static String item_status = "status"; - //前工位光电信号 - public static String item_move1 = "move1"; - //后工位光电信号 - public static String item_move2 = "move2"; - //前工位动作信号 - public static String item_action1 = "action1"; - //后工位动作信号 - public static String item_action2 = "action2"; - //行走列 - public static String item_walk_y = "walk_y"; - //报警信号 - public static String item_error = "error"; - //任务类型 - public static String item_type = "type"; - //前工位任务号 - public static String item_task1 = "task1"; - //后工位任务号 - public static String item_task2 = "task2"; - - - //前工位下发命令 - public static String item_to_command1 = "to_command1"; - //前工位下发起始站 - public static String item_to_onset1 = "to_onset1"; - //前工位下发目标站 - public static String item_to_target1 = "to_target1"; - //前工位下发任务号 - public static String item_to_task1 = "to_task1"; - //后工位下发命令 - public static String item_to_command2 = "to_command2"; - //后工位下发起始站 - public static String item_to_onset2 = "to_onset2"; - //后工位下发目标站 - public static String item_to_target2 = "to_target2"; - //后工位下发任务号 - public static String item_to_task2 = "to_task2"; - //任务类型 1前工位 2后工位 3双工位 - public static String item_to_type = "to_type"; - - - private SlitTwoManipulatorDeviceDriver driver; - - public ItemProtocol(SlitTwoManipulatorDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getStatus() { - return this.getOpcIntegerValue(item_status); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getMove1() { - return this.getOpcIntegerValue(item_move1); - } - - public int getMove2() { - return this.getOpcIntegerValue(item_move2); - } - - public int getAction1() { - return this.getOpcIntegerValue(item_action1); - } - - public int getAction2() { - return this.getOpcIntegerValue(item_action2); - } - - public int getWalk_y() { - return this.getOpcIntegerValue(item_walk_y); - } - - public int getType() { - return this.getOpcIntegerValue(item_type); - } - - public int getTask1() { - return this.getOpcIntegerValue(item_task1); - } - - public int getTask2() { - return this.getOpcIntegerValue(item_task2); - } - - public int getTo_command1() { - return this.getOpcIntegerValue(item_to_command1); - } - - public int getTo_command2() { - return this.getOpcIntegerValue(item_to_command2); - } - - //是否有货 - public int hasGoods(int move) { - return move; - } - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - - } - - public String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (StrUtil.isEmpty(value)) { - - } else { - return value; - } - return "0"; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); - list.add(new ItemDto(item_status, "设备状态", "DB1.B2")); - list.add(new ItemDto(item_move1, "前工位光电信号", "DB1.B3")); - list.add(new ItemDto(item_move2, "后工位光电信号", "DB1.B4")); - list.add(new ItemDto(item_action1, "前工位动作信号", "DB1.B5")); - list.add(new ItemDto(item_action2, "后工位动作信号", "DB2.B6")); - list.add(new ItemDto(item_walk_y, "行走列", "DB1.B7")); - list.add(new ItemDto(item_error, "报警信号", "DB1.B8")); - list.add(new ItemDto(item_type, "任务类型", "DB1.B9")); - list.add(new ItemDto(item_task1, "前工位任务号", "DB1.D10")); - list.add(new ItemDto(item_task2, "后工位任务号", "DB1.D14")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDto(item_to_command1, "前工位下发命令", "DB2.W0")); - list.add(new ItemDto(item_to_onset1, "前工位下发起始站", "DB2.W2")); - list.add(new ItemDto(item_to_target1, "前工位下发目标站", "DB2.W4")); - list.add(new ItemDto(item_to_task1, "前工位下发任务号", "DB2.D6")); - list.add(new ItemDto(item_to_command2, "后工位下发命令", "DB2.W10")); - list.add(new ItemDto(item_to_onset2, "后工位下发起始站", "DB2.W12")); - list.add(new ItemDto(item_to_target2, "后工位下发目标站", "DB2.W14")); - list.add(new ItemDto(item_to_task2, "后工位下发任务号", "DB2.D16")); - list.add(new ItemDto(item_to_type, "下发任务类型", "DB2.W20")); - return list; - } - - @Override - public String toString() { - return ""; - } - -} - diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDefination.java deleted file mode 100644 index c0dc36f8..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDefination.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.nl.acs.device_driver.basedriver.slit_two_manipulator; - -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceType; -import org.springframework.stereotype.Service; - -import java.util.LinkedList; -import java.util.List; - -/** - * 分切双工位行架机械手 - * - */ -@Service -public class SlitTwoManipulatorDefination implements OpcDeviceDriverDefination { - @Override - public String getDriverCode() { - return "slit_two_manipulator"; - } - - @Override - public String getDriverName() { - return "分切双工位-行架机械手"; - } - - @Override - public String getDriverDescription() { - return "分切双工位-行架机械手"; - } - - @Override - public DeviceDriver getDriverInstance(Device device) { - return (new SlitTwoManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); - - } - - @Override - public Class getDeviceDriverType() { - return SlitTwoManipulatorDeviceDriver.class; - } - - @Override - public List getFitDeviceTypes() { - List types = new LinkedList(); - types.add(DeviceType.station); - return types; - } - - @Override - public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); - } - - @Override - public List getWriteableItemDtos() { - return ItemProtocol.getWriteableItemDtos(); - } - -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java deleted file mode 100644 index a36d2574..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/slit_two_manipulator/SlitTwoManipulatorDeviceDriver.java +++ /dev/null @@ -1,1490 +0,0 @@ -package org.nl.acs.device_driver.basedriver.slit_two_manipulator; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.modules.common.exception.BadRequestException; -import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.*; - -/** - * 分切双工位行架机械手 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - @Autowired - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - @Autowired - DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); - @Autowired - RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); - @Autowired - TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - @Autowired - AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl"); - @Autowired - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - //分切行架机械手是否禁用 0否 1是 - private int is_disable = 0; - - //工作模式 - int mode = 0; - int last_mode = 0; - //设备状态 - int status = 0; - int last_status = 0; - //前后工位光电信号 - int move1 = 0; - int last_move1 = 0; - int move2 = 0; - int last_move2 = 0; - //前后工位动作信号 - int action1 = 0; - int last_action1 = 0; - int action2 = 0; - int last_action2 = 0; - //报警信号 - int error = 0; - int last_error = 0; - //行走列 - int walk_y = 0; - int last_walk_y = 0; - //任务类型 - int type = 0; - int last_type = 0; - //前后工位任务号 - int task1 = 0; - int last_task1 = 0; - int task2 = 0; - int last_task2 = 0; - int to_command1 = 0; - int to_command2 = 0; - - Boolean isonline = true; - //前工位申请任务请求标记 - Boolean requireSucess = false; - - int hasGoods = 0; - String message = null; - Boolean iserror = false; - - int branchProtocol = 0; - - int heartbeat = 0; - int last_heartbeat = 0; - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - //前工位任务执行当前步骤 - //0未执行 1更改指令状态 2下发电气任务信息 3前工位允许取货 4前工位取货完成 5前工位允许放货 6放货完成 - int now_steps_type1 = 0; - //后工位当前执行步骤 - //0未执行 1更改指令状态 2下发电气任务信息 3后工位允许取货4后工位取货完成 5后工位允许放货 6放货完成 - int now_steps_type2 = 0; - //双工位任务当前执行步骤 - //0未执行 1更改指令状态 2下发电气任务信息 3后工位允许取货 4后工位取货完成 5前工位允许取货 6前工位取货完成 7后工位允许放货 8后工位放货完成 9前工位允许放货 10前工位放货完成 - int now_steps_type3 = 0; - - String device_code; - - - //请求超时时间 - private int instruction_require_time_out = 3000; - - - //后工位申请任务请求时间 - private Date instruction_require_time = new Date(); - //前工位申请任务请求时间 - private Date instruction_head_time = new Date(); - - String notCreateTaskMessage = ""; - String notCreateInstMessage = ""; - String feedMessage = ""; - - - @Override - public Device getDevice() { - return this.device; - } - - - @Override - public synchronized void execute() { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - status = this.itemProtocol.getStatus(); - move1 = this.itemProtocol.getMove1(); - move2 = this.itemProtocol.getMove2(); - action1 = this.itemProtocol.getAction1(); - action2 = this.itemProtocol.getAction2(); - walk_y = this.itemProtocol.getWalk_y(); - error = this.itemProtocol.getError(); - type = this.itemProtocol.getType(); - task1 = this.itemProtocol.getTask1(); - task2 = this.itemProtocol.getTask2(); - to_command1 = this.itemProtocol.getTo_command1(); - to_command2 = this.itemProtocol.getTo_command2(); - heartbeat = this.itemProtocol.getHeartbeat(); -// if(heartbeat != last_heartbeat){ -// logServer.deviceExecuteLog(this.device_code, "", "", "heartbeat:" + last_heartbeat + "->" + heartbeat); -// } - if (mode != last_mode) { - if (mode == 2) { - logServer.deviceExecuteLog(device_code, "", "", "开始请求标记复位`此时请求标记值为:" + requireSucess); - requireSucess = false; - logServer.deviceExecuteLog(device_code, "", "", "请求标记复位成功`此时请求标记值为:" + requireSucess); -// if (task1 == 0 && task2 == 0 && type == 0) { -// logServer.deviceExecuteLog(device_code, "", "", "开始复位当前执行步骤"); -// this.setNow_steps_type1(0); -// this.setNow_steps_type2(0); -// this.setNow_steps_type3(0); -// logServer.deviceExecuteLog(device_code, "", "", "复位当前执行步骤成功"); -// } - feedMessage = ""; - notCreateTaskMessage = ""; - notCreateInstMessage = ""; - } - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (type != last_type) { - logServer.deviceItemValue(this.device_code, "type", String.valueOf(type)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号type:" + last_type + "->" + type); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (status != last_status) { - logServer.deviceItemValue(this.device_code, "status", String.valueOf(status)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号status:" + last_status + "->" + status); - } - if (move1 != last_move1) { - logServer.deviceItemValue(this.device_code, "move1", String.valueOf(move1)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move1:" + last_move1 + "->" + move1); - } - if (move2 != last_move2) { - logServer.deviceItemValue(this.device_code, "move2", String.valueOf(move2)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move2:" + last_move2 + "->" + move2); - } - if (action1 != last_action1) { - logServer.deviceItemValue(this.device_code, "action1", String.valueOf(action1)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action1:" + last_action1 + "->" + action1); - } - if (action2 != last_action2) { - logServer.deviceItemValue(this.device_code, "action2", String.valueOf(action2)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action2:" + last_action2 + "->" + action2); - } - if (walk_y != last_walk_y) { - logServer.deviceItemValue(this.device_code, "walk_y", String.valueOf(walk_y)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号walk_y:" + last_walk_y + "->" + walk_y); - } - if (task1 != last_task1) { - logServer.deviceItemValue(this.device_code, "task1", String.valueOf(task1)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task1:" + last_task1 + "->" + task1); - } - if (task2 != last_task2) { - logServer.deviceItemValue(this.device_code, "task2", String.valueOf(task2)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task2:" + last_task2 + "->" + task2); - } - - //单任务 前工位任务更新指令状态 - if (task1 > 0 && type == 1) { - Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1)); - if (inst1 != null) { - if (StrUtil.equals(inst1.getInstruction_status(), "0")) { - //当前执行步骤为更新任务状态 - inst1.setInstruction_status("1"); - inst1.setExecute_device_code(this.getDevice_code()); - instructionService.update(inst1); - } - } - } - - //单任务 后工位任务更新指令状态 - if (task2 > 0 && type == 2) { - //inst_message - Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task2)); - if (inst2 != null) { - if (StrUtil.equals(inst2.getInstruction_status(), "0")) { - //当前指令更新状态 - now_steps_type2 = 1; - inst2.setInstruction_status("1"); - inst2.setExecute_device_code(this.device_code); - instructionService.update(inst2); - } - } - } - - //双任务更新指令状态 - if (task2 > 0 && task1 > 0 && type == 3) { - //inst_message - Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task1)); - if (inst2 != null) { - if (StrUtil.equals(inst2.getInstruction_status(), "0")) { - //当前指令更新状态 - inst2.setInstruction_status("1"); - inst2.setExecute_device_code(this.device_code); - instructionService.update(inst2); - } - } - } - - //双任务/单任务 后工位取空时判断动作信号,并反馈 - if (mode == 3 && action2 == 1 && move2 == 0 && task2 > 0) { - Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task2)); - String start_device_code = inst1.getStart_device_code(); - Device startDevice = deviceAppservice.findDeviceByCode(start_device_code); - if (ObjectUtil.isEmpty(startDevice)) { - feedMessage = "后工位取货位:" + start_device_code + "为空!"; - logServer.deviceExecuteLog(this.getDeviceCode(), "", "", "后工位取货位:" + start_device_code + "为空!"); - throw new BadRequestException("后工位取货位:" + start_device_code + "为空!"); - } - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; - if (startDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) startDevice.getDeviceDriver(); - int move = siemensConveyorDeviceDriver.getMove(); - int mode = siemensConveyorDeviceDriver.getMode(); - if (mode == 2 && move == 1) { - if (to_command2 != 2) { - this.writing("to_command2", "2"); - } - if (type == 2) { - this.setNow_steps_type2(3); - } else if (type == 3) { - this.setNow_steps_type3(3); - } - } else { - log.warn("后工位取货位无货,取货位:{},mode:{},move:{}", start_device_code, mode, move); - if (this.getNow_steps_type2() == 2 || this.getNow_steps_type3() == 2) { - feedMessage = "后工位未取货原因-->取货位:" + siemensConveyorDeviceDriver.getDevice_code(); - if (mode != 2) { - feedMessage += "工作模式不为待机(mode != 2),"; - } - if (move != 1) { - feedMessage += "光电信号不应该为无货状态(move != 1)"; - } - } - } - } - } else { - if (this.getNow_steps_type2() == 2 || this.getNow_steps_type3() == 2) { - feedMessage = "后工位未取货原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action2 != 1) { - feedMessage += "后工位动作信号不为取货中(action2 != 1),"; - } - if (move2 != 0) { - feedMessage += "后工位光电信号应该为0(move2 != 0),"; - } - if (task2 == 0) { - feedMessage += "后工位没有任务号(task2 == 0)"; - } - } - } - - //单任务/或双任务 后工位收到取货完成信号并反馈 - if (mode == 3 && action2 == 2 && move2 == 1 && task2 > 0) { - if (to_command2 != 3) { - this.writing("to_command2", "3"); - } - if (type == 2) { - this.setNow_steps_type2(4); - } - if (type == 3) { - this.setNow_steps_type3(4); - } - } else { - if (this.getNow_steps_type2() == 3 || this.getNow_steps_type3() == 3) { - feedMessage = "后工位取货完成后未反馈原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action2 != 2) { - feedMessage += "后工位动作信号未取货完成(action2 != 2),"; - } - if (move2 == 0) { - feedMessage += "后工位光电信号不应该为0(move2 == 0),"; - } - if (task2 == 0) { - feedMessage += "后工位没有任务号(task2 == 0)"; - } - } - } - - //单任务/双任务 前工位取货时判断动作信号并反馈 - if (mode == 3 && action1 == 1 && move1 == 0 && task1 > 0) { - if (to_command1 != 2) { - this.writing("to_command1", "2"); - } - if (type == 1) { - this.setNow_steps_type1(3); - } else if (type == 3) { - this.setNow_steps_type3(5); - } - } else { - if (this.getNow_steps_type1() == 2 || this.getNow_steps_type3() == 4) { - feedMessage = "前工位未取货原因:"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action1 != 1) { - feedMessage += "前工位动作信号不为取货中(action2 != 1),"; - } - if (move1 != 0) { - feedMessage += "前工位光电信号应该为0(move2 != 0),"; - } - if (task1 == 0) { - feedMessage += "前工位没有任务号(task2 == 0)"; - } - } - } - - //单任务/双任务 前工位取货完成并反馈 - if (mode == 3 && action1 == 2 && move1 == 1 && task1 > 0) { - if (to_command1 != 3) { - this.writing("to_command1", "3"); - } - if (type == 1) { - this.setNow_steps_type1(4); - } - if (type == 3) { - this.setNow_steps_type3(6); - } - } else { - if (this.getNow_steps_type1() == 3 || this.getNow_steps_type3() == 5) { - feedMessage = "前工位取货完成后未反馈原因"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action1 != 2) { - feedMessage += "前工位动作信号未取货完成(action2 != 2),"; - } - if (move1 == 0) { - feedMessage += "前工位光电信号不应该为无货状态(move2 == 0),"; - } - if (task1 == 0) { - feedMessage += "前工位没有任务号(task2 == 0)"; - } - } - } - - - //单任务/双任务 后工位放货时判断信号并反馈 - if (mode == 3 && action2 == 3 && move2 == 1 && task2 > 0) { - if (to_command2 != 4) { - this.writing("to_command2", "4"); - } - if (type == 2) { - this.setNow_steps_type2(5); - } else if (type == 3) { - this.setNow_steps_type3(7); - } - } else { - if (this.getNow_steps_type2() == 4 || this.getNow_steps_type3() == 6) { - feedMessage = "后工位未放货原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action2 != 3) { - feedMessage += "后工位动作信号不为放货中(action2 != 3),"; - } - if (move2 == 0) { - feedMessage += "后工位光电信号为不应该为0(move2 == 0),"; - } - if (task2 == 0) { - feedMessage += "后工位没有任务号(task2 == 0)"; - } - } - } - - //单任务 后工位放货完成 任务完成 - if (mode == 3 && action2 == 4 && move2 == 0 && task2 > 0 && type == 2) { - //inst_message - Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task2)); - if (inst2 != null) { - if (StrUtil.equals(inst2.getInstruction_status(), "1")) { - finish_instruction(inst2); - if (to_command2 != 5) { - this.writing("to_command2", "5"); - } - this.setNow_steps_type2(6); - this.setNow_steps_type2(0); - } - } - } else { - if (this.getNow_steps_type2() == 5) { - feedMessage = "单任务后工位放货完成后未反馈原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action2 != 4) { - feedMessage += "后工位动作信号未放货完成(action2 != 4),"; - } - if (move2 != 0) { - feedMessage += "后工位光电信号应该为无货状态(move2 != 0),"; - } - if (task2 == 0) { - feedMessage += "后工位没有任务号(task2 == 0),"; - } - if (type != 2) { - feedMessage += "不是后工位单任务(type != 2)"; - } - } - } - - //双任务 后工位反馈任务完成 并反馈 - if (mode == 3 && action2 == 4 && move2 == 0 && task1 > 0 && task2 > 0 && type == 3) { - if (to_command2 != 5) { - this.writing("to_command2", "5"); - } - this.setNow_steps_type3(8); - } else { - if (this.getNow_steps_type3() == 7) { - feedMessage = "双任务后工位放货完成后未反馈原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action2 != 4) { - feedMessage += "后工位动作信号未放货完成(action2 != 4),"; - } - if (move2 != 0) { - feedMessage += "后工位光电信号不应该为有货状态(move2 != 0),"; - } - if (task1 == 0) { - feedMessage += "前工位没有任务号(task1 == 0),"; - } - if (task2 == 0) { - feedMessage += "后工位没有任务号(task2 == 0),"; - } - if (type != 3) { - feedMessage += "不是双任务(type != 3)"; - } - } - } - - //单任务/双任务 前工位放货时判断放货位光电信号 - if (mode == 3 && action1 == 3 && move1 == 1 && task1 > 0) { - Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1)); - String next_device_code = ""; - if (type == 1) { - next_device_code = inst1.getNext_device_code(); - } else if (type == 3) { - next_device_code = inst1.getNext_device_code2(); - } - Device nextDevice = deviceAppservice.findDeviceByCode(next_device_code); - if (ObjectUtil.isEmpty(nextDevice)) { - feedMessage = "前工位放货位:" + next_device_code + "为空!"; - throw new BadRequestException("前工位放货位:" + next_device_code + "为空!"); - } - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; - if (nextDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) nextDevice.getDeviceDriver(); - int move = siemensConveyorDeviceDriver.getMove(); - int mode = siemensConveyorDeviceDriver.getMode(); - if (move == 1 && mode == 2) { - if (to_command1 != 4) { - this.writing("to_command1", "4"); - } - if (type == 1) { - this.setNow_steps_type1(5); - } else if (type == 3) { - this.setNow_steps_type3(9); - } - } else { -// log.warn("后工位放货位有货,放货位:{},mode:{},move:{}", next_device_code, mode, move); - if (this.getNow_steps_type1() == 4 || this.getNow_steps_type3() == 8) { - feedMessage = "前工位未放货原因-->"; - if (mode != 2) { - feedMessage += "前工位放货位工作模式不为待机状态(mode != 2),"; - } - if (move == 0) { - feedMessage += "前工位放货位不应该为无货状态(move == 0)"; - } - } - } - } - } else { - if (this.getNow_steps_type1() == 4 || this.getNow_steps_type3() == 8) { - feedMessage = "前工位未放货原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action1 != 3) { - feedMessage += "前工位动作信号不为放货中(action1 != 3),"; - } - if (move1 == 0) { - feedMessage += "前工位光电信号不应为无货状态(move1 == 0),"; - } - if (task1 == 0) { - feedMessage += "前工位没有任务号(task1 == 0),"; - } - } - } - - - //单任务前工位放货完成 任务完成 - if (mode == 3 && action1 == 4 && move1 == 0 && task1 > 0 && type == 1) { - //inst_message - Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1)); - if (inst1 != null) { - if (StrUtil.equals(inst1.getInstruction_status(), "1")) { - this.finish_instruction(inst1); - if (to_command1 != 5) { - this.writing("to_command1", "5"); - } - this.setNow_steps_type1(6); - this.setNow_steps_type1(0); - } - } - } else { - if (this.getNow_steps_type1() == 5) { - feedMessage = "单任务前工位放货完成后未反馈原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action1 != 4) { - feedMessage += "前工位动作信号未放货完成(action1 != 4),"; - } - if (move1 != 0) { - feedMessage += "前工位光电信号为不应为有货状态(move1 != 0),"; - } - if (task1 == 0) { - feedMessage += "前工位没有任务号(task1 == 0),"; - } - if (type != 1) { - feedMessage += "不为前工位单任务(type != 1)"; - } - } - } - - - //双工位 任务完成 前工位反馈4 - if (mode == 3 && action1 == 4 && move1 == 0 && task1 > 0 && task2 > 0 && type == 3) { - //inst_message - Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task1)); - if (inst1 != null) { - if (StrUtil.equals(inst1.getInstruction_status(), "1")) { - this.finish_instruction(inst1); - if (to_command1 != 5) { - this.writing("to_command1", "5"); - } - this.setNow_steps_type3(10); - this.setNow_steps_type3(0); - } - } - } else { - if (this.getNow_steps_type3() == 9) { - feedMessage = "双任务前工位放货完成后未反馈原因-->"; - if (mode != 3) { - feedMessage += "行架工作模式不为运行中(mode != 3),"; - } - if (action1 != 4) { - feedMessage += "前工位动作信号未放货完成(action1 != 4),"; - } - if (move1 != 0) { - feedMessage += "前工位光电信号为不应为有货状态(move1 != 0),"; - } - if (task1 == 0) { - feedMessage += "前工位没有任务(task1 == 0),"; - } - if (task2 == 0) { - feedMessage += "后工位没有任务号(task2 == 0),"; - } - if (type != 3) { - feedMessage += "不是双任务(type != 3)"; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - feedMessage = e.getMessage(); - System.out.println("11111111:"+e.getMessage()); - logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + e.getMessage()+ ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol) ); - } - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - //有报警 - } else if (error != 0) { - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - switch (mode) { - case 1: - log.debug("设备运转模式:等待工作"); - return; - case 2: - //申请任务 - if (mode == 2 && move1 == 0 && move2 == 0 && action1 == 0 && action2 == 0 && task1 == 0 && task2 == 0 && !requireSucess) { - //获取关联设备驱动信息 判断关联设备是否禁用 - String link_device_code = String.valueOf(this.getDevice().getExtraValue().get("link_device_code")); - Device device = deviceAppservice.findDeviceByCode(link_device_code); - SlitTwoManipulatorDeviceDriver slitTwoManipulatorDeviceDriver; - if (device.getDeviceDriver() instanceof SlitTwoManipulatorDeviceDriver) { - slitTwoManipulatorDeviceDriver = (SlitTwoManipulatorDeviceDriver) device.getDeviceDriver(); - //如果禁用 - if (slitTwoManipulatorDeviceDriver.getIs_disable() == 1) { - boolean flag = false; - try { - //就去走关联设备异常取放货工位的任务 任务生成成功返回true 就不会走下面正常生成任务的逻辑 - flag = instruction_require2(); - } catch (Exception e) { - flag = false; - } - if (flag) { - break; - } - } - } - //没有生成异常取放货工位的任务 就生成正常关联取放货工位的任务 - boolean res = instruction_require(); - if (res) { - feedMessage = ""; - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - } - } else { - - if (!requireSucess) { - String remark = ""; - if (mode != 2) { - remark = remark + "行架工作模式不为待机(mode != 2),"; - } - if (move1 != 0) { - remark = remark + "前工位光电信号不应该为有货状态(move1 != 0),"; - } - if (move2 != 0) { - remark = remark + "后工位光电信号不应该为有货状态(move2 != 0),"; - } - if (action1 != 0) { - remark = remark + "前工位动作信号不为0(action1 != 0),"; - } - if (action2 != 0) { - remark = remark + "后工位动作信号不为0(action2 != 0),"; - } - if (task1 != 0) { - remark = remark + "前工位存在任务号(task1 != 0),"; - } - if (task2 != 0) { - remark = remark + "后工位存在任务号(task2 != 0),"; - } - this.setNotCreateTaskMessage(remark); - } - } - break; - case 3: - break; - } - - } - last_mode = mode; - last_error = error; - last_status = status; - last_move1 = move1; - last_move2 = move2; - last_action1 = action1; - last_action2 = action2; - last_walk_y = walk_y; - last_type = type; - last_task1 = task1; - last_task2 = task2; - last_heartbeat = heartbeat; - } - - //关联设备异常申请任务 - public synchronized boolean instruction_require2() { - Boolean flag = false; - Date date = new Date(); - if (date.getTime() - this.instruction_head_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_head_time); - return false; - } else { - this.instruction_head_time = date; - //前工位取货关联设备 - List getDeviceCodeList = this.getExtraDeviceCodes("error_head_get_device_code"); - //后工位取货关联设备 - List backGetDeviceCodeList = this.getExtraDeviceCodes("error_back_get_device_code"); - TaskDto taskDto = null; - //遍历前工位取货点设备 - for (String getDeviceCode : getDeviceCodeList) { - //去任务表中查询是否有前工位关联设备的重新创建指令的任务 - List taskDtos = taskserver.queryTaskByStartAndIntStatus(getDeviceCode); - //如果有 - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList); - return flag; - } else { - //去任务表中查询是否有前工位关联设备的就绪状态下的任务 - taskDtos = taskserver.queryTaskByStartDeviceCode(getDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - break; - } - } - } - //如果任务表中起点1或起点2中 无前工位取货点关联设备 - //就去查询任务表中查找起点1或起点2为后工位取货点关联设备的任务 - if (ObjectUtil.isEmpty(taskDto)) { - for (String backGetDeviceCode : backGetDeviceCodeList) { - //去任务表中查询是否有前工位关联设备的重新创建指令的任务 - List taskDtos = taskserver.queryTaskByNextAndIntStatus(backGetDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList); - return flag; - } else { - //去任务表中查询是否有后工位关联设备的就绪状态下的任务 - taskDtos = taskserver.queryTaskByBackDeviceCode(backGetDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - break; - } - } - } - } - if (!ObjectUtil.isEmpty(taskDto)) { - flag = this.executeReadyBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList); - if (flag) { - notCreateInstMessage = ""; - } - } else { - notCreateTaskMessage = ""; - notCreateInstMessage = "未找到关联设备禁用的任务!"; - } - } - return flag; - } - - //正常申请任务 - public synchronized boolean instruction_require() { - boolean flag = false; - Date date = new Date(); - if (date.getTime() - this.instruction_head_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_head_time); - return false; - } else { - this.instruction_head_time = date; - //前工位取货关联设备 - List getDeviceCodeList = this.getExtraDeviceCodes("head_get_device_code"); - //后工位取货关联设备 - List backGetDeviceCodeList = this.getExtraDeviceCodes("back_get_device_code"); - TaskDto taskDto = null; - //遍历前工位取货点设备 - for (String getDeviceCode : getDeviceCodeList) { - //去任务表中查询是否有前工位关联设备的重新创建指令的任务 - List taskDtos = taskserver.queryTaskByStartAndIntStatus(getDeviceCode); - //如果有 - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList); - return flag; - } else { - //去任务表中查询是否有前工位关联设备的就绪状态下的任务 - taskDtos = taskserver.queryTaskByStartDeviceCode(getDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - break; - } - } - } - //如果任务表中起点1或起点2中 无前工位取货点关联设备 - //就去查询任务表中查找起点1或起点2为后工位取货点关联设备的任务 - if (ObjectUtil.isEmpty(taskDto)) { - for (String backGetDeviceCode : backGetDeviceCodeList) { - //去任务表中查询是否有前工位关联设备的重新创建指令的任务 - List taskDtos = taskserver.queryTaskByNextAndIntStatus(backGetDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - flag = this.executeBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList); - return flag; - } else { - //去任务表中查询是否有后工位关联设备的就绪状态下的任务 - taskDtos = taskserver.queryTaskByBackDeviceCode(backGetDeviceCode); - if (ObjectUtil.isNotEmpty(taskDtos)) { - //按照优先级排序 优先级相等按照创建时间排序 - taskDtos = this.sortTask(taskDtos); - taskDto = taskDtos.get(0); - break; - } - } - } - } - - if (!ObjectUtil.isEmpty(taskDto)) { - flag = this.executeReadyBusiness(taskDto, getDeviceCodeList, backGetDeviceCodeList); - if (flag) { - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - } - } else { - notCreateTaskMessage = ""; - notCreateInstMessage = "未找到正常关联设备的任务!"; - } - } - return flag; - } - - //执行重新生成指令的任务 - public synchronized boolean executeBusiness(TaskDto taskDto, List getDeviceCodeList, List backGetDeviceCodeList) { - boolean flag = false; - //任务类型 1.前工位任务 2.后工位任务 3.双工位任务 - String type = ""; - //获取指令信息 - Instruction instructionDto = instructionService.findByTaskcodeAndStatus(taskDto.getTask_code()); - //获取指令表中的取货点1 - String start_device_code = instructionDto.getStart_device_code(); - //获取指令表中的取货点2 - String start_device_code2 = instructionDto.getStart_device_code2(); - //获取指令表中的放货点1 - String next_device_code = instructionDto.getNext_device_code(); - //获取指令表中的放货点2 - String next_device_code2 = instructionDto.getNext_device_code2(); - //判断任务点位是否配置电气信号 - Device startDevice = deviceAppservice.findDeviceByCode(start_device_code); - Device startDevice2 = deviceAppservice.findDeviceByCode(start_device_code2); - Device nextDevice = deviceAppservice.findDeviceByCode(next_device_code); - Device nextDevice2 = deviceAppservice.findDeviceByCode(next_device_code2); - //如果指令表中的取货点1和取货点2 都不为空 则说明时下双工位任务 - if (StrUtil.isNotEmpty(start_device_code2) && StrUtil.isNotEmpty(start_device_code)) { - this.isSetAddress(startDevice); - this.isSetAddress(nextDevice); - this.isSetAddress(startDevice2); - this.isSetAddress(nextDevice2); - type = "3"; - } else { - //判断指令表中的起点1 是否是前工位/后工位取货点的关联设备 - int headGetIndex = getDeviceCodeList.indexOf(start_device_code); - int backGetIndex = backGetDeviceCodeList.indexOf(start_device_code); - if (headGetIndex != -1) { - //前工位 - type = "1"; - } else if (backGetIndex != -1) { - //后工位 - type = "2"; - } - this.isSetAddress(startDevice); - this.isSetAddress(nextDevice); - } - - //修改指令状态 - instructionDto.setInstruction_status("1"); - instructionDto.setUpdate_time(DateUtil.now()); - try { - instructionService.update(instructionDto); - if (StrUtil.equals(type, "1")) { - this.setNow_steps_type1(1); - } - if (StrUtil.equals(type, "2")) { - this.setNow_steps_type2(1); - } - if (StrUtil.equals(type, "3")) { - this.setNow_steps_type3(1); - } - flag = true; - } catch (Exception e) { - logServer.deviceExecuteLog(device_code, "", instructionDto.getInstruction_code(), "执行重新生成指令的任务失败,原因->" + e.getMessage()); - } - - //下发电气信号 - this.sendSignalType(instructionDto, type); - - //请求任务成功 - requireSucess = true; - return flag; - } - - //执行就绪状态下的任务 - public synchronized boolean executeReadyBusiness(TaskDto taskDto, List getDeviceCodeList, List backGetDeviceCodeList) { - boolean flag = false; - //任务类型 1.前工位任务 2.后工位任务 3.双工位任务 - String type = ""; - //获取任务表中的取货点1 - String start_device_code = taskDto.getStart_device_code(); - //获取任务表中的取货点2 - String start_device_code2 = taskDto.getStart_device_code2(); - //获取任务表中的放货点1 - String next_device_code = taskDto.getNext_device_code(); - //获取任务表中的放货点2 - String next_device_code2 = taskDto.getNext_device_code2(); - //判断任务点位是否配置电气信号 - Device startDevice = deviceAppservice.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppservice.findDeviceByCode(next_device_code); - Device startDevice2 = deviceAppservice.findDeviceByCode(start_device_code2); - Device nextDevice2 = deviceAppservice.findDeviceByCode(next_device_code2); - logServer.deviceExecuteLog(this.getDeviceCode(), "", "", "" + - "执行就绪状态下的任务生成指令时:起点1为:" + start_device_code + "起点2为:" + start_device_code2 + ",任务信息为:" + taskDto.toString()); - //如果指令表中的取货点1和取货点2 都不为空 则说明时下双工位任务 - if (StrUtil.isNotEmpty(start_device_code2) && StrUtil.isNotEmpty(start_device_code)) { - type = "3"; - logServer.deviceExecuteLog(this.getDeviceCode(), "", "", "" + - "执行就绪状态下的任务生成指令时:起点1为:" + start_device_code + "起点2为:" + start_device_code2 + - "type值为:" + type + ",任务信息为:" + taskDto.toString()); - //判断四个点位是否都设置电气值 - this.isSetAddress(startDevice); - this.isSetAddress(nextDevice); - this.isSetAddress(startDevice2); - this.isSetAddress(nextDevice2); - } else { - //判断指令表中的起点1 是否是前工位/后工位取货点的关联设备 - int headGetIndex = getDeviceCodeList.indexOf(start_device_code); - int backGetIndex = backGetDeviceCodeList.indexOf(start_device_code); - if (headGetIndex != -1) { - type = "1"; //前工位 - } else if (backGetIndex != -1) { - type = "2"; //后工位 - } - logServer.deviceExecuteLog(this.getDeviceCode(), "", "", "" + - "执行就绪状态下的任务生成指令时:起点1为:" + start_device_code + "起点2为:" + start_device_code2 - + "type值为:" + type + ",任务信息为:" + taskDto.toString()); - //判断单任务下的两个点位是否都设置电气值 - this.isSetAddress(startDevice); - this.isSetAddress(nextDevice); - } - - String taskid = taskDto.getTask_id(); - String taskcode = taskDto.getTask_code(); - String vehiclecode = taskDto.getVehicle_code(); - String priority = taskDto.getPriority(); - String start_point_code = taskDto.getStart_point_code(); - String next_point_code = taskDto.getNext_point_code(); - String start_point_code2 = taskDto.getStart_point_code2(); - String next_point_code2 = taskDto.getNext_point_code2(); - String route_plan_code = taskDto.getRoute_plan_code(); - String remark = taskDto.getRemark(); - String material = taskDto.getMaterial(); - String quantity = taskDto.getQuantity(); - - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(remark); - instdto.setMaterial(material); - instdto.setQuantity(quantity); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - instdto.setStart_device_code2(start_device_code2); - instdto.setStart_point_code2(start_point_code2); - instdto.setNext_device_code2(next_device_code2); - instdto.setNext_point_code2(next_point_code2); - - try { - logServer.deviceExecuteLog(this.getDeviceCode(), "", "", "" + - "执行就绪状态下的任务生成指令时:起点1为:" + start_device_code + "起点2为:" + start_device_code2 - + "type值为:" + type + ",创建指令信息为:" + instdto.toString()); - instructionService.create(instdto); - flag = true; - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(device_code, "", instdto.getInstruction_code(), "指令创建失败,原因->" + e.getMessage()); - } - - //创建指令后修改任务状态 - taskDto.setTask_status("1"); - taskDto.setUpdate_time(DateUtil.now()); - taskserver.update(taskDto); - - //下发电气信号 - this.sendSignalType(instdto, type); - - //请求任务成功 - requireSucess = true; - return flag; - } - - //下发电气信号 - public synchronized void sendSignalType(Instruction dto, String type) { - logServer.deviceExecuteLog(this.getDeviceCode(), "", "", "开始下发电气信号,即下发电气指令信息为:" - + dto.toString() + ",type = " + type); - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - Device startDevice = deviceAppservice.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppservice.findDeviceByCode(next_device_code); - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - List list = new ArrayList(); - if (StrUtil.equals(type, "1")) { - Map map1 = new HashMap(); - map1.put("code", "to_onset1"); - map1.put("value", start_addr); - list.add(map1); - Map map2 = new HashMap(); - map2.put("code", "to_target1"); - map2.put("value", next_addr); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_task1"); - map3.put("value", dto.getInstruction_code()); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_type"); - map4.put("value", "1"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_command1"); - map5.put("value", "1"); - list.add(map5); - HashMap map6 = new HashMap() {{ - put("code", "to_command2"); - put("value", "0"); - }}; - list.add(map6); - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "下发前工位任务"); - this.setNow_steps_type1(2); - } else if (StrUtil.equals(type, "2")) { - Map map1 = new HashMap(); - map1.put("code", "to_onset2"); - map1.put("value", start_addr); - list.add(map1); - Map map2 = new HashMap(); - map2.put("code", "to_target2"); - map2.put("value", next_addr); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_task2"); - map3.put("value", dto.getInstruction_code()); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_type"); - map4.put("value", "2"); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_command2"); - map5.put("value", "1"); - list.add(map5); - HashMap map6 = new HashMap() {{ - put("code", "to_command1"); - put("value", "0"); - }}; - list.add(map6); - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "下发后工位任务"); - this.setNow_steps_type2(2); - } else if (StrUtil.equals(type, "3")) { - String start_device_code2 = dto.getStart_device_code2(); - String next_device_code2 = dto.getNext_device_code2(); - Device startDevice2 = deviceAppservice.findDeviceByCode(start_device_code2); - Device nextDevice2 = deviceAppservice.findDeviceByCode(next_device_code2); - String start_addr2 = startDevice2.getExtraValue().get("address").toString(); - String next_addr2 = nextDevice2.getExtraValue().get("address").toString(); - - - Map map1 = new HashMap(); - map1.put("code", "to_onset1"); - map1.put("value", start_addr2); - list.add(map1); - Map map2 = new HashMap(); - map2.put("code", "to_target1"); - map2.put("value", next_addr2); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code", "to_task1"); - map3.put("value", dto.getInstruction_code()); - list.add(map3); - Map map4 = new HashMap(); - map4.put("code", "to_onset2"); - map4.put("value", start_addr); - list.add(map4); - Map map5 = new HashMap(); - map5.put("code", "to_target2"); - map5.put("value", next_addr); - list.add(map5); - Map map6 = new HashMap(); - map6.put("code", "to_task2"); - map6.put("value", dto.getInstruction_code()); - list.add(map6); - Map map7 = new HashMap(); - map7.put("code", "to_type"); - map7.put("value", "3"); - list.add(map7); - Map map8 = new HashMap(); - map8.put("code", "to_command1"); - map8.put("value", "1"); - list.add(map8); - Map map9 = new HashMap(); - map9.put("code", "to_command2"); - map9.put("value", "1"); - list.add(map9); - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "下发双工位任务"); - - this.setNow_steps_type3(2); - } - - if (task1 != Integer.parseInt(dto.getInstruction_code()) || task2 != Integer.parseInt(dto.getInstruction_code())) { - this.writing(list); - logServer.deviceExecuteLog(device_code, "", "", dto.getInstruction_code() + "再次下发电气信号"); - } - - } - - //判断点位是否设置电气值 - public void isSetAddress(Device device) { - if (ObjectUtil.isEmpty(device.getExtraValue().get("address"))) { - logServer.deviceExecuteLog(device_code, "", "task1:" + task1 + ",task2:" + task2, "设备:" + device.getDevice_code() + "未设置电气调度号!"); - notCreateInstMessage = "设备:" + device.getDevice_code() + "未设置电气调度号!"; - throw new BadRequestException("设备:" + device.getDevice_code() + "未设置电气调度号!"); - } - } - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - public void writing(String param, String value) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + param; - Map itemMap = new HashMap(); - itemMap.put(to_param, Integer.parseInt(value)); - - this.control(itemMap); - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); - } - - public boolean exe_business() { - return true; - } - - protected void executing(Instruction instruction) { - this.executing(1, instruction, ""); - } - - public void executing(int command, Instruction instruction, String appendMessage) { - - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - this.control(itemMap); - - } - - - public synchronized boolean finish_instruction(Instruction inst) throws Exception { - instructionService.finish(inst); - return true; - } - - - public void executing(Server server, Map itemMap) { - this.control(itemMap); - } - - public void writing1(int command) { - String to_command1 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command1; - - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command1, command); - this.control(itemMap); - - } - - public void writing2(int command) { - String to_command2 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command2; - - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_command2, command); - this.control(itemMap); - - } - - public void writing(int type, int command) { - //String opcservcerid = this.getDevice().getOpc_server_id(); -//Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - this.control(itemMap); - } - - public void writing(List list) { - -// String opcservcerid = this.getDevice().getOpc_server_id(); -// Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - for (int i = 0; i < list.size(); i++) { - Object ob = list.get(i); - JSONObject json = (JSONObject) JSONObject.toJSON(ob); - if (!StrUtil.isEmpty(json.getString("value"))) { - String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + json.getString("code"); - itemMap.put(to_param, json.getString("value")); - } - } - logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); - this.control(itemMap); - } - - - //将扩展表中的字符串数组数据转换成集合 - public List getExtraDeviceCodes(String extraName) { - String extraValue = (String) this.getDevice().getExtraValue().get(extraName); - if (StrUtil.isEmpty(extraValue)) { - return new ArrayList<>(); - } - String devicesString = extraValue.substring(1, extraValue.length() - 1); - List devicesList = new ArrayList<>(); - String[] devices = devicesString.split(","); - for (int i = 0; i < devices.length; i++) { - String s = devices[i].replace("\"", "").replace("\"", ""); - devicesList.add(s); - } - return devicesList; - } - - public List sortTask(List taskDtos) { - Collections.sort(taskDtos, new Comparator() { - @Override - public int compare(TaskDto t1, TaskDto t2) { - //优先级从大到小 - int i = t2.getPriority().compareTo(t1.getPriority()); - //如果优先级相等 - if (i == 0) { - //时间从早到晚 - i = t1.getCreate_time().compareTo(t2.getCreate_time()); - } - return i; - } - }); - return taskDtos; - } - - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String move_1 = ""; - String move_2 = ""; - String action1 = ""; - String action2 = ""; - String walk_y = ""; - String mode = ""; - String status = ""; - String is_disable = ""; - - - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getStatus() == 0) { - status = "0"; - } else if (this.getStatus() == 1) { - status = "待机"; - } else if (this.getStatus() == 2) { - status = "生产中"; - } else if (this.getStatus() == 3) { - status = "故障"; - } - - if (this.getMove1() == 0) { - move_1 = "无货"; - } else if (this.getMove1() == 1) { - move_1 = "有货"; - } - - if (this.getMove2() == 0) { - move_2 = "无货"; - } else if (this.getMove2() == 1) { - move_2 = "有货"; - } - - if (this.getAction1() == 1) { - action1 = "取货中"; - } else if (this.getAction1() == 2) { - action1 = "取货完成"; - } else if (this.getAction1() == 3) { - action1 = "放货中"; - } else if (this.getAction1() == 4) { - action1 = "放货完成"; - } - - if (this.getAction2() == 1) { - action2 = "取货中"; - } else if (this.getAction2() == 2) { - action2 = "取货完成"; - } else if (this.getAction2() == 3) { - action2 = "放货中"; - } else if (this.getAction2() == 4) { - action2 = "放货完成"; - } - - if (this.getWalk_y() == 0) { - walk_y = "原位"; - } else if (this.getWalk_y() == 2) { - walk_y = "非原位"; - } - - if (this.getIs_disable() == 0) { - is_disable = "正常"; - } else if (this.getIs_disable() == 1) { - is_disable = "禁用"; - } - - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("requireSucess", requireSucess); - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("status", status); - jo.put("move_1", move_1); - jo.put("move_2", move_2); - jo.put("action_1", action1); - jo.put("action_2", action2); - jo.put("walk_y", walk_y); - jo.put("error", this.getError()); - jo.put("task1", this.getTask1()); - jo.put("task2", this.getTask2()); - jo.put("isOnline", this.getIsonline()); - jo.put("isError", this.getIserror()); - jo.put("is_disable1", this.getIs_disable()); - jo.put("is_disable", is_disable); - jo.put("message", this.messageInfo(type)); - jo.put("is_click", true); - jo.put("driver_type", "slit_two_manipulator"); - jo.put("notCreateTaskMessage", notCreateTaskMessage); - jo.put("notCreateInstMessage", notCreateInstMessage); - jo.put("feedMessage", feedMessage); - return jo; - } - - public String messageInfo(int type) { - String set_type = ""; - JSONObject map = new JSONObject(); - if (type == 1) { - set_type = String.valueOf(now_steps_type1); - map.put("0", "前工位单任务未执行"); - map.put("1", "前工位单任务改变指令状态"); - map.put("2", "前工位单任务下发电气任务信息"); - map.put("3", "单任务前工位允许取货"); - map.put("4", "单任务前工位取货完成"); - map.put("5", "单任务前工位允许放货"); - map.put("6", "单任务前工位放货完成"); - } else if (type == 2) { - set_type = String.valueOf(now_steps_type2); - map.put("0", "后工位单任务未执行"); - map.put("1", "后工位单任务改变指令状态"); - map.put("2", "后工位单任务下发电气任务信息"); - map.put("3", "单任务后工位允许取货"); - map.put("4", "单任务后工位取货完成"); - map.put("5", "单任务后工位允许放货"); - map.put("6", "单任务后工位放货完成"); - } else if (type == 3) { - set_type = String.valueOf(now_steps_type3); - map.put("0", "双任务未执行"); - map.put("1", "双任务改变指令状态"); - map.put("2", "双任务下发电气任务信息"); - map.put("3", "双任务后工位允许取货"); - map.put("4", "双任务后工位取货完成"); - map.put("5", "双任务前工位允许取货"); - map.put("6", "双任务前工位取货完成"); - map.put("7", "双任务后工位允许放货"); - map.put("8", "双任务后工位放货完成"); - map.put("9", "双任务前工位允许放货"); - map.put("10", "双任务前工位放货完成"); - } else { - return "未执行任务"; - } - return map.getString(set_type); - } - - @Override - public void setDeviceStatus(JSONObject data) { - String is_disable = data.getString("is_disable"); - if (StrUtil.isNotEmpty(is_disable)) { - this.setIs_disable(Integer.parseInt(is_disable)); - } - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/HaiLiangCoatingDefination.java similarity index 53% rename from wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDefination.java rename to wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/HaiLiangCoatingDefination.java index 465f0a75..bd12db8a 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDefination.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/HaiLiangCoatingDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.basedriver.siemens_conveyor; +package org.nl.acs.device_driver.hailiang.hailiang_coating; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device_driver.DeviceDriver; @@ -7,54 +7,61 @@ import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceType; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** - * 西门子-输送机驱动 - * + * 海亮裹膜机 */ @Service -public class SiemensConveyorDefination implements OpcDeviceDriverDefination { +public class HaiLiangCoatingDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "siemens_conveyor"; + return "lamp_three_color"; } @Override public String getDriverName() { - return "西门子-输送机驱动"; + return "标准版-三色灯"; } @Override public String getDriverDescription() { - return "西门子-输送机驱动"; + return "标准版-三色灯"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new SiemensConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new HaiLiangCoatingDeviceDriver()).setDevice(device).setDriverDefination(this); } @Override public Class getDeviceDriverType() { - return SiemensConveyorDeviceDriver.class; + return HaiLiangCoatingDeviceDriver.class; } @Override public List getFitDeviceTypes() { List types = new LinkedList(); - types.add(DeviceType.station); + types.add(DeviceType.conveyor); return types; } @Override public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); + return getReadableItemDtos2(); } - + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", true)); + list.add(new ItemDto(ItemProtocol.item_action, "动作信号", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "DB600.B4")); + return list; + } @Override public List getWriteableItemDtos() { diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/HaiLiangCoatingDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/HaiLiangCoatingDeviceDriver.java new file mode 100644 index 00000000..174b1075 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/HaiLiangCoatingDeviceDriver.java @@ -0,0 +1,155 @@ +package org.nl.acs.device_driver.hailiang.hailiang_coating; + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮-裹膜机驱动 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HaiLiangCoatingDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + String devicecode; + int mode = 0; + int action = 0; + int error = 0; + int move = 0; + int task = 0; + int last_action = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + protected boolean hasGoods = false; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + + String device_code = this.getDevice().getDevice_code(); + mode = this.itemProtocol.getMode(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + if (mode != last_mode) { + } + if (action != last_action) { + } + if (error != last_error) { + } + last_action = action; + last_mode = mode; + last_error = error; + //message = StringFormatUtl.format("设备报警:{}", new Object[]{}); + +// String manual_create_task = this.getDevice().getExtraValue().get("manual_create_task").toString(); + + + } + + public synchronized String getStatus() { + JSONObject jo = new JSONObject(); + + if (action == 1) { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "OPEN"); + + } else if (action == 2) { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "CLOSE"); + + } else { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "ERROR"); + } + return jo.toString(); + } + + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_inspect_site.ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + //log.info("下发PLC信号:{},{}", to_command, command); + System.out.println("设备:" + devicecode + ",下发PLC信号:" + to_command + ",value:" + command); + } + + public synchronized void OpenOrClose(String type) { + + writing(Integer.parseInt(type)); + + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/ItemProtocol.java new file mode 100644 index 00000000..cce09b05 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_coating/ItemProtocol.java @@ -0,0 +1,72 @@ +package org.nl.acs.device_driver.hailiang.hailiang_coating; + +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ItemProtocol { + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_to_command = "to_command"; + + + private HaiLiangCoatingDeviceDriver driver; + + public ItemProtocol(HaiLiangCoatingDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + //log.error("读取错误!"); + } else { + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB51.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB51.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_action, "动作信号", "DB51.B2")); + list.add(new ItemDto(item_error, "报警信号", "DB51.B4")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "DB52.W2", Boolean.valueOf(true))); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/HaiLiangLabelingDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/HaiLiangLabelingDefination.java new file mode 100644 index 00000000..971bf41c --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/HaiLiangLabelingDefination.java @@ -0,0 +1,70 @@ +package org.nl.acs.device_driver.hailiang.hailiang_labeling; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮贴标机驱动 + */ +@Service +public class HaiLiangLabelingDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_labeling"; + } + + @Override + public String getDriverName() { + return "海亮-贴标机"; + } + + @Override + public String getDriverDescription() { + return "海亮-贴标机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HaiLiangLabelingDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HaiLiangLabelingDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "V100.1", true)); + list.add(new ItemDto(ItemProtocol.item_action, "动作信号", "V100.0")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "VB101")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/HaiLiangLabelingDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/HaiLiangLabelingDeviceDriver.java new file mode 100644 index 00000000..1c9547fc --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/HaiLiangLabelingDeviceDriver.java @@ -0,0 +1,87 @@ +package org.nl.acs.device_driver.hailiang.hailiang_labeling; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.opc.Device; +import org.openscada.opc.lib.da.Server; + +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮贴标机驱动 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HaiLiangLabelingDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + String devicecode; + int mode = 0; + int action = 0; + int error = 0; + int move = 0; + int last_action = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int branchProtocol = 0; + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public void execute() { + String message = null; + + String device_code = this.getDevice().getDevice_code(); + mode = this.itemProtocol.getMode(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + if (mode != last_mode) { + } + if (action != last_action) { + } + if (error != last_error) { + } + // 打印就绪 + if (mode == 1 && error == 0) { + + } + + //打印完成 + if (action == 1) { + + } + last_action = action; + last_mode = mode; + last_error = error; + + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_inspect_site.ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + log.info("下发PLC信号:{},{}", to_command, command); + System.out.println("设备:" + devicecode + ",下发PLC信号:" + to_command + ",value:" + command); + } + + public synchronized void OpenOrClose(String type) { + writing(Integer.parseInt(type)); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/ItemProtocol.java new file mode 100644 index 00000000..455eb8a6 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_labeling/ItemProtocol.java @@ -0,0 +1,66 @@ +package org.nl.acs.device_driver.hailiang.hailiang_labeling; + +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ItemProtocol { + public static String item_mode = "mode"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_to_command = "to_command"; + + + private HaiLiangLabelingDeviceDriver driver; + + public ItemProtocol(HaiLiangLabelingDeviceDriver driver) { + this.driver = driver; + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + //log.error("读取错误!"); + } else { + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_mode, "工作状态", "V100.1", Boolean.valueOf(true))); + list.add(new ItemDto(item_action, "动作信号", "V100.0")); + list.add(new ItemDto(item_error, "报警信号", "VB101")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "V102.0", Boolean.valueOf(true))); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_lettering/HaiLiangLetteringDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_lettering/HaiLiangLetteringDefination.java new file mode 100644 index 00000000..6214d2f0 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_lettering/HaiLiangLetteringDefination.java @@ -0,0 +1,50 @@ +package org.nl.acs.device_driver.hailiang.hailiang_lettering; + +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.DeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 海亮刻字机驱动 + */ +@Service +public class HaiLiangLetteringDefination implements DeviceDriverDefination { + @Override + public String getDriverCode() { + return "hailiang_lettering"; + } + + @Override + public String getDriverName() { + return "海亮-激光刻字机"; + } + + @Override + public String getDriverDescription() { + return "海亮-激光刻字机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HaiLiangLetteringDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HaiLiangLetteringDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_lettering/HaiLiangLetteringDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_lettering/HaiLiangLetteringDeviceDriver.java new file mode 100644 index 00000000..00a8feb2 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_lettering/HaiLiangLetteringDeviceDriver.java @@ -0,0 +1,121 @@ +package org.nl.acs.device_driver.hailiang.hailiang_lettering; + +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; + + +/** + * + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HaiLiangLetteringDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + Integer hasGoods = 0; + int error = 0; + Boolean iserror = false; + Boolean islock = false; + + int branchProtocol = 0; + int last_branchProtocol = 0; + //是否需要输入物料 + String input_material = "0"; + //备注 + String remark = ""; + //数量 + String qty = ""; + //是否在线 + Boolean is_online = true; + //批次 + String batch = ""; + //物料 + String material = ""; + //目标点位 + String purpose = ""; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + boolean requireSucess = false; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + // 1取货完成 2放货完成 3进入区域 4离开区域 + private int flag; + + //人工确认信号 默认0 agv到达后请求置1 等人工确认后变为2 反馈agv后继续为0 + private int manua_confirm = 0; + + String devicecode; + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + + String message; + + // 1就绪 2下发刻字 3 刻字完成 + int status; + + int mode = 2; + + int move; + + int action; + + int ioaction; + + @Override + public void execute() { + hasGoods = this.getDevice().getHas_goods(); + material = this.getDevice().getMaterial_type(); + batch = this.getDevice().getBatch(); + devicecode = this.getDeviceCode(); + if (branchProtocol != last_branchProtocol) { + requireSucess = false; + } + switch (branchProtocol) { + case 1: + break; + //呼叫请求 + case 2: + + break; + //响应生成任务 + case 3: + + break; + } + } + + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/HaiLiangPackingDefination.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/HaiLiangPackingDefination.java new file mode 100644 index 00000000..a48b487f --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/HaiLiangPackingDefination.java @@ -0,0 +1,71 @@ +package org.nl.acs.device_driver.hailiang.hailiang_packing; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 包装机驱动 + */ +@Service +public class HaiLiangPackingDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lamp_three_color"; + } + + @Override + public String getDriverName() { + return "标准版-三色灯"; + } + + @Override + public String getDriverDescription() { + return "标准版-三色灯"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new HaiLiangPackingDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return HaiLiangPackingDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", true)); + list.add(new ItemDto(ItemProtocol.item_action, "动作信号", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "DB600.B4")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/HaiLiangPackingDeviceDriver.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/HaiLiangPackingDeviceDriver.java new file mode 100644 index 00000000..a1f63ee9 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/HaiLiangPackingDeviceDriver.java @@ -0,0 +1,155 @@ +package org.nl.acs.device_driver.hailiang.hailiang_packing; + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.opc.Device; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 海亮-包装机驱动 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class HaiLiangPackingDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + String devicecode; + int mode = 0; + int action = 0; + int error = 0; + int move = 0; + int task = 0; + int last_action = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + protected boolean hasGoods = false; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + + String device_code = this.getDevice().getDevice_code(); + mode = this.itemProtocol.getMode(); + action = this.itemProtocol.getAction(); + error = this.itemProtocol.getError(); + if (mode != last_mode) { + } + if (action != last_action) { + } + if (error != last_error) { + } + last_action = action; + last_mode = mode; + last_error = error; + //message = StringFormatUtl.format("设备报警:{}", new Object[]{}); + +// String manual_create_task = this.getDevice().getExtraValue().get("manual_create_task").toString(); + + + } + + public synchronized String getStatus() { + JSONObject jo = new JSONObject(); + + if (action == 1) { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "OPEN"); + + } else if (action == 2) { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "CLOSE"); + + } else { + jo.put("name", this.getDevice().getDevice_code()); + jo.put("status", "ERROR"); + } + return jo.toString(); + } + + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_inspect_site.ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + log.info("下发PLC信号:{},{}", to_command, command); + System.out.println("设备:" + devicecode + ",下发PLC信号:" + to_command + ",value:" + command); + } + + public synchronized void OpenOrClose(String type) { + + writing(Integer.parseInt(type)); + + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/ItemProtocol.java b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/ItemProtocol.java new file mode 100644 index 00000000..e9040600 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/device_driver/hailiang/hailiang_packing/ItemProtocol.java @@ -0,0 +1,72 @@ +package org.nl.acs.device_driver.hailiang.hailiang_packing; + +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ItemProtocol { + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_to_command = "to_command"; + + + private HaiLiangPackingDeviceDriver driver; + + public ItemProtocol(HaiLiangPackingDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + //log.error("读取错误!"); + } else { + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB51.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB51.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_action, "动作信号", "DB51.B2")); + list.add(new ItemDto(item_error, "报警信号", "DB51.B4")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "DB52.W2", Boolean.valueOf(true))); + return list; + } + +} + diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index b3019007..62c53390 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -104,4 +104,20 @@ public interface AcsToWmsService { // 输送线有货变成无货时向lms请求 HttpResponse shipDeviceUpdate(JSONObject param); + + /** + * 向wms订单实时数量 + * + * @param param + * @return + */ + HttpResponse feedOrderRealQty(JSONObject param); + + /** + * 向wms反馈设备状态 + * + * @param param + * @return + */ + HttpResponse feedDeviceStatusType(JSONObject param); } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 71e96405..7416fb50 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -17,6 +17,8 @@ import org.nl.acs.device.service.DeviceService; import org.nl.acs.ext.wms.data.*; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.modules.system.service.ParamService; @@ -28,6 +30,8 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor @Slf4j public class AcsToWmsServiceImpl implements AcsToWmsService { + @Autowired + ProduceshiftorderService produceshiftorderService; @Autowired ParamService paramService; @@ -47,8 +51,8 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { public String token; - private String log_file_type="log_file_type"; - private String log_type="ACS请求LMS"; + private String log_file_type = "log_file_type"; + private String log_type = "ACS请求LMS"; @Override public String applyTaskToWms(JSONObject jo) { @@ -71,7 +75,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { //网络不通 // //System.out.println(msg); } - if(ObjectUtil.isEmpty(result2)){ + if (ObjectUtil.isEmpty(result2)) { log.info("applyTaskToWms-----输出参数{}", "返回结果为空"); return null; } @@ -472,7 +476,6 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } - @Override public UpdateLKTaskResponse updateLKTaskRequest(UpdateLKTaskRequest param) { try { @@ -529,4 +532,84 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } return null; } + + @Override + public HttpResponse feedOrderRealQty(JSONObject param) { + try { + MDC.put(log_file_type, log_type); + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + String order_code = param.getString("order"); + ProduceshiftorderDto produceshiftorderDto = produceshiftorderService.findByCode(order_code); + if (ObjectUtil.isEmpty(produceshiftorderDto)) { + return null; + } + if (!produceshiftorderDto.getOrder_status().equals("2") || !produceshiftorderDto.getOrder_status().equals("3")) { + String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + // TODO 还没向地址表中添加 feedDeviceStatusType + AddressDto addressDto = addressService.findByCode("feedOrderRealQty"); + String methods_url = addressDto.getMethods_url(); + String url = wmsUrl + methods_url; + HttpResponse result = null; + log.info("feedOrderRealQty----请求参数{}", param); + try { + result = HttpRequest.post(url) + .body(String.valueOf(param)) + .execute(); + String type = ""; + if (result.getStatus() == 200) { + type = "info"; + } else { + type = "error"; + } + log.info("feedOrderRealQty----返回参数{}", result); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + System.out.println(msg); + } + return result; + } + } + return null; + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public HttpResponse feedDeviceStatusType(JSONObject param) { + try { + MDC.put(log_file_type, log_type); + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + // TODO 还没向地址表中添加 feedDeviceStatusType + AddressDto addressDto = addressService.findByCode("feedDeviceStatusType"); + String methods_url = addressDto.getMethods_url(); + String url = wmsUrl + methods_url; + HttpResponse result = null; + log.info("feedbackOrderStatus----请求参数{}", param); + try { + result = HttpRequest.post(url) + .body(String.valueOf(param)) + .execute(); + String type = ""; + if (result.getStatus() == 200) { + type = "info"; + } else { + type = "error"; + } + log.info("feedDeviceStatusType----返回参数{}", result); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + System.out.println(msg); + } + return result; + } + return null; + }finally { + MDC.remove(log_file_type); + } + + } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java index a0970345..5cd3f9c8 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java @@ -7,8 +7,6 @@ import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.device.address.service.AddressService; -import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.ext.wms.AcsUtil; import org.nl.acs.ext.wms.RespUtil; @@ -265,40 +263,41 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { //请求放空盘 @Override public Resp putEmptyPallet(putEmptyPalletRequest requestParam) throws Exception { - try { +// try { MDC.put(log_file_type, log_type); log.info("请求放空盘-----输入参数{}", JSON.toJSONString(requestParam)); String device_code = requestParam.getDeviceId(); String type = requestParam.getType(); DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); Device device = appService.findDeviceByCode(device_code); - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; - JSONObject result = new JSONObject(); - result.put("code", "0"); - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if(StrUtil.equals(type,"1")){ - if((siemensConveyorDeviceDriver.getMode() ==2 || siemensConveyorDeviceDriver.getMode() ==7 )&& siemensConveyorDeviceDriver.getMove() ==0){ - result.put("result", "true"); - result.put("comment", ""); - } else { - result.put("result", "false"); - result.put("comment", "当前设备光电信号:"+siemensConveyorDeviceDriver.getMove()+",工作模式:"+siemensConveyorDeviceDriver.getMode()); - } - } else if(StrUtil.equals(type,"2")){ - siemensConveyorDeviceDriver.writing("to_command","3"); - siemensConveyorDeviceDriver.writing("to_command","3"); - - result.put("result", "true"); - result.put("comment", ""); - } - - } - log.info("请求放空盘-----输出参数{}", result); - return RespUtil.getResp(result.toString(), new DeviceStatusResponse()); - } finally { - MDC.remove(log_file_type); - } +// SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; +// JSONObject result = new JSONObject(); +// result.put("code", "0"); +// if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { +// siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); +// if(StrUtil.equals(type,"1")){ +//// if((siemensConveyorDeviceDriver.getMode() ==2 || siemensConveyorDeviceDriver.getMode() ==7 )&& siemensConveyorDeviceDriver.getMove() ==0){ +//// result.put("result", "true"); +//// result.put("comment", ""); +//// } else { +//// result.put("result", "false"); +//// result.put("comment", "当前设备光电信号:"+siemensConveyorDeviceDriver.getMove()+",工作模式:"+siemensConveyorDeviceDriver.getMode()); +//// } +// } else if(StrUtil.equals(type,"2")){ +//// siemensConveyorDeviceDriver.writing("to_command","3"); +//// siemensConveyorDeviceDriver.writing("to_command","3"); +// +// result.put("result", "true"); +// result.put("comment", ""); +// } +// +// } +// log.info("请求放空盘-----输出参数{}", result); +// return RespUtil.getResp(result.toString(), new DeviceStatusResponse()); +// } finally { +// MDC.remove(log_file_type); +// } + return null; } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index b4bc7789..4cb0efb0 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -10,17 +10,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.common.IDriverService; -import org.nl.acs.common.StandardOrdinarySiteDevice; import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.CargoLiftConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.empty_vehicle_stacking_position.EmptyVehicleStackingPositionDeviceDriver; -import org.nl.acs.device_driver.basedriver.hongxiang_conveyor.HongXiangStationDeviceDriver; -import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.lamp_three_color.LampThreecolorDeviceDriver; -import org.nl.acs.device_driver.basedriver.plug_pull_device_site.PlugPullDeviceSiteDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; -import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDefination; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.ext.wms.data.*; import org.nl.acs.ext.wms.liKuData.Resp; @@ -170,16 +161,16 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (ObjectUtil.isEmpty(device)) { throw new Exception("未找到对应设备:" + device_code); } - HongXiangStationDeviceDriver hongXiangStationDeviceDriver; - LampThreecolorDeviceDriver lampThreecolorDeviceDriver; - if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { - hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); - hongXiangStationDeviceDriver.writing(code, value); - } - if (device.getDeviceDriver() instanceof LampThreecolorDeviceDriver) { - lampThreecolorDeviceDriver = (LampThreecolorDeviceDriver) device.getDeviceDriver(); - lampThreecolorDeviceDriver.writing(code, value); - } +// HongXiangStationDeviceDriver hongXiangStationDeviceDriver; +// LampThreecolorDeviceDriver lampThreecolorDeviceDriver; +// if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { +// hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); +// hongXiangStationDeviceDriver.writing(code, value); +// } +// if (device.getDeviceDriver() instanceof LampThreecolorDeviceDriver) { +// lampThreecolorDeviceDriver = (LampThreecolorDeviceDriver) device.getDeviceDriver(); +// lampThreecolorDeviceDriver.writing(code, value); +// } } @@ -201,10 +192,10 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONArray backja = new JSONArray(); JSONArray datas = JSONArray.parseArray(jsonObject); - //AGV烘箱对接位 - HongXiangStationDeviceDriver hongXiangStationDeviceDriver; - //烘箱工位 - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; +// //AGV烘箱对接位 +// HongXiangStationDeviceDriver hongXiangStationDeviceDriver; +// //烘箱工位 +// HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; //货梯对接线-带扫码器 StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; @@ -214,49 +205,49 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { for (int i = 0; i < datas.size(); i++) { JSONObject jo = new JSONObject(); - JSONObject data = datas.getJSONObject(i); - String parent_device_code = data.getString("device_code"); - String device_code = ""; - JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + parent_device_code + "'").uniqueResult(0); - if (!ObjectUtil.isEmpty(device_json)) { - device_code = (String) device_json.get("parent_storage_code") == null ? parent_device_code : (String) device_json.get("storage_code"); - } - Device device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device)) { - throw new Exception("未找到对应设备:" + parent_device_code); - } - - if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { - hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", parent_device_code); - jo.put("mode", hongXiangStationDeviceDriver.getMode()); - jo.put("move", hongXiangStationDeviceDriver.getMove()); - - } else if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", parent_device_code); - jo.put("mode", hongXiangConveyorDeviceDriver.getMode()); - jo.put("move", hongXiangConveyorDeviceDriver.getMove()); - jo.put("countdown_house", hongXiangConveyorDeviceDriver.getCountdown_house()); - jo.put("countdown_min", hongXiangConveyorDeviceDriver.getCountdown_min()); - jo.put("countdown_sec", hongXiangConveyorDeviceDriver.getCountdown_sec()); - //温度需要除以10 - jo.put("temperature", hongXiangConveyorDeviceDriver.getTo_temperature()/10); - jo.put("now_temperature", hongXiangConveyorDeviceDriver.getTemperature()/10); - - jo.put("door", hongXiangConveyorDeviceDriver.getDoor()); - jo.put("finish", hongXiangConveyorDeviceDriver.getFinish()); - jo.put("task", hongXiangConveyorDeviceDriver.getTask()); - jo.put("error", hongXiangConveyorDeviceDriver.getError()); - } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { - standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); - jo.put("device_code", parent_device_code); - jo.put("move", standardCoveyorControlWithScannerDeviceDriver.getMove()); - jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); - jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); - } else { - jo.put("device_code", parent_device_code); - } +// JSONObject data = datas.getJSONObject(i); +// String parent_device_code = data.getString("device_code"); +// String device_code = ""; +// JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + parent_device_code + "'").uniqueResult(0); +// if (!ObjectUtil.isEmpty(device_json)) { +// device_code = (String) device_json.get("parent_storage_code") == null ? parent_device_code : (String) device_json.get("storage_code"); +// } +// Device device = deviceAppService.findDeviceByCode(device_code); +// if (ObjectUtil.isEmpty(device)) { +// throw new Exception("未找到对应设备:" + parent_device_code); +// } +// +// if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { +// hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); +// jo.put("device_code", parent_device_code); +// jo.put("mode", hongXiangStationDeviceDriver.getMode()); +// jo.put("move", hongXiangStationDeviceDriver.getMove()); +// +// } else if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { +// hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); +// jo.put("device_code", parent_device_code); +// jo.put("mode", hongXiangConveyorDeviceDriver.getMode()); +// jo.put("move", hongXiangConveyorDeviceDriver.getMove()); +// jo.put("countdown_house", hongXiangConveyorDeviceDriver.getCountdown_house()); +// jo.put("countdown_min", hongXiangConveyorDeviceDriver.getCountdown_min()); +// jo.put("countdown_sec", hongXiangConveyorDeviceDriver.getCountdown_sec()); +// //温度需要除以10 +// jo.put("temperature", hongXiangConveyorDeviceDriver.getTo_temperature()/10); +// jo.put("now_temperature", hongXiangConveyorDeviceDriver.getTemperature()/10); +// +// jo.put("door", hongXiangConveyorDeviceDriver.getDoor()); +// jo.put("finish", hongXiangConveyorDeviceDriver.getFinish()); +// jo.put("task", hongXiangConveyorDeviceDriver.getTask()); +// jo.put("error", hongXiangConveyorDeviceDriver.getError()); +// } else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { +// standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); +// jo.put("device_code", parent_device_code); +// jo.put("move", standardCoveyorControlWithScannerDeviceDriver.getMove()); +// jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); +// jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); +// } else { +// jo.put("device_code", parent_device_code); +// } backja.add(jo); } JSONObject resultJson = new JSONObject(); @@ -333,128 +324,128 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { resultJson.put("message", "未找到对应的设备:"+device_code); return resultJson; } - PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; - if (device.getDeviceDriver() instanceof PlugPullDeviceSiteDeviceDriver) { - plugPullDeviceSiteDeviceDriver = (PlugPullDeviceSiteDeviceDriver) device.getDeviceDriver(); - // 0 穿轴 1拔轴 - if(StrUtil.equals(type,"1")){ - - if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求拔轴,当前设备工作模式未自动"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求拔轴,当前设备未全自动"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求拔轴,当前设备未待机"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求拔轴,当前设备未远程控制"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getMove() != 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求拔轴,当前设备有轴"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 - && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==0 - && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code","to_size"); - map.put("value",size); - list.add(map); - Map map2 = new HashMap(); - map2.put("code","to_type"); - map2.put("value",type); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); - list.add(map3); - plugPullDeviceSiteDeviceDriver.writing(list); - - } else { - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "当前设备状态不满足下发条件"); - return resultJson; - } - - } else if (StrUtil.equals(type,"0")){ - - if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求插轴,当前设备工作模式未自动"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求插轴,当前设备未全自动"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求插轴,当前设备未待机"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求插轴,当前设备未远程控制"); - return resultJson; - } - if(plugPullDeviceSiteDeviceDriver.getMove() != 1){ - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "请求插轴,当前设备没有轴"); - return resultJson; - } - - if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 - && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==1 - && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ - - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code","to_size"); - map.put("value",size); - list.add(map); - Map map2 = new HashMap(); - map2.put("code","to_type"); - map2.put("value",type); - list.add(map2); - Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); - list.add(map3); - plugPullDeviceSiteDeviceDriver.writing(list); - - } else { - JSONObject resultJson = new JSONObject(); - resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "当前设备状态不满足下发条件"); - return resultJson; - } - } - } +// PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; +// if (device.getDeviceDriver() instanceof PlugPullDeviceSiteDeviceDriver) { +// plugPullDeviceSiteDeviceDriver = (PlugPullDeviceSiteDeviceDriver) device.getDeviceDriver(); +// // 0 穿轴 1拔轴 +// if(StrUtil.equals(type,"1")){ +// +// if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求拔轴,当前设备工作模式未自动"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求拔轴,当前设备未全自动"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求拔轴,当前设备未待机"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求拔轴,当前设备未远程控制"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getMove() != 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求拔轴,当前设备有轴"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 +// && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==0 +// && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ +// +// List list = new ArrayList(); +// Map map = new HashMap(); +// map.put("code","to_size"); +// map.put("value",size); +// list.add(map); +// Map map2 = new HashMap(); +// map2.put("code","to_type"); +// map2.put("value",type); +// list.add(map2); +// Map map3 = new HashMap(); +// map3.put("code","to_command"); +// map3.put("value","1"); +// list.add(map3); +// plugPullDeviceSiteDeviceDriver.writing(list); +// +// } else { +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "当前设备状态不满足下发条件"); +// return resultJson; +// } +// +// } else if (StrUtil.equals(type,"0")){ +// +// if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求插轴,当前设备工作模式未自动"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求插轴,当前设备未全自动"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求插轴,当前设备未待机"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求插轴,当前设备未远程控制"); +// return resultJson; +// } +// if(plugPullDeviceSiteDeviceDriver.getMove() != 1){ +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "请求插轴,当前设备没有轴"); +// return resultJson; +// } +// +// if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 +// && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==1 +// && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ +// +// List list = new ArrayList(); +// Map map = new HashMap(); +// map.put("code","to_size"); +// map.put("value",size); +// list.add(map); +// Map map2 = new HashMap(); +// map2.put("code","to_type"); +// map2.put("value",type); +// list.add(map2); +// Map map3 = new HashMap(); +// map3.put("code","to_command"); +// map3.put("value","1"); +// list.add(map3); +// plugPullDeviceSiteDeviceDriver.writing(list); +// +// } else { +// JSONObject resultJson = new JSONObject(); +// resultJson.put("status", HttpStatus.BAD_REQUEST.value()); +// resultJson.put("message", "当前设备状态不满足下发条件"); +// return resultJson; +// } +// } +// } JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.OK.value()); @@ -604,33 +595,33 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { route_plan_code = "normal"; } - if(StrUtil.equals(task_type,"5")){ - Device device = deviceAppService.findDeviceByCode(next_device_code); - SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; - if(device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if (ObjectUtil.equal("true", siemensConveyorDeviceDriver.getExtraValue().get("inspect_in_stock"))) { - if(siemensConveyorDeviceDriver.getMove() == 1) - { - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", "终点"+siemensConveyorDeviceDriver.getDevice_code()+"有货无法生成任务"); - errArr.add(json); - continue; - } - } - } - - if( taskService.querySameDeviceReadyTask(start_device_code,next_device_code,"0") > 1){ - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", "已存在相同的起点:"+start_device_code + "终点:"+ next_device_code + "未执行的输送任务"); - errArr.add(json); - continue; - } - } +// if(StrUtil.equals(task_type,"5")){ +// Device device = deviceAppService.findDeviceByCode(next_device_code); +// SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; +// if(device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { +// siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); +// if (ObjectUtil.equal("true", siemensConveyorDeviceDriver.getExtraValue().get("inspect_in_stock"))) { +// if(siemensConveyorDeviceDriver.getMove() == 1) +// { +// JSONObject json = new JSONObject(); +// json.put("task_code", task_code); +// json.put("ext_task_id", ext_task_id); +// json.put("message", "终点"+siemensConveyorDeviceDriver.getDevice_code()+"有货无法生成任务"); +// errArr.add(json); +// continue; +// } +// } +// } +// +// if( taskService.querySameDeviceReadyTask(start_device_code,next_device_code,"0") > 1){ +// JSONObject json = new JSONObject(); +// json.put("task_code", task_code); +// json.put("ext_task_id", ext_task_id); +// json.put("message", "已存在相同的起点:"+start_device_code + "终点:"+ next_device_code + "未执行的输送任务"); +// errArr.add(json); +// continue; +// } +// } TaskDto taskDto = taskService.findByCodeFromCache(task_code); if (taskDto != null) { diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 9bfc719a..f0bc3c21 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -105,6 +105,13 @@ public interface InstructionService { */ void create(Instruction dto) throws Exception; + /** + * 创建双工任务 + * + * @param dto / + */ + void createTwoInst(Instruction dto,Instruction dto2) throws Exception; + void create2(Instruction dto) throws Exception; /** * 再次创建 diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 91e40d7d..e8c1a767 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; @@ -18,10 +19,12 @@ import org.nl.acs.auto.initial.ApplicationAutoInitial; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.impl.DeviceServiceImpl; import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; -import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.lamp_three_color.LampThreecolorDeviceDriver; +import org.nl.acs.device_driver.basedriver.standard_conveyor_control.StandardCoveyorControlDeviceDriver; +import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_plcscanner.StandardCoveyorControlWithPlcScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; +import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; import org.nl.acs.instruction.service.InstructionService; @@ -42,6 +45,7 @@ import org.nl.modules.system.service.ParamService; import org.nl.modules.system.util.CodeUtil; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.exception.WDKException; import org.nl.modules.wql.util.SpringContextHolder; import org.nl.modules.wql.util.WqlUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -238,7 +242,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByCode(String code) { WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_code ='" + code + "'","create_time desc").uniqueResult(0); + JSONObject json = wo.query("instruction_code ='" + code + "'", "create_time desc").uniqueResult(0); if (ObjectUtil.isEmpty(json)) { return null; } @@ -249,27 +253,27 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByTaskcode(String code) { WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_code ='" + code + "'","create_time desc").uniqueResult(0); + JSONObject json = wo.query("task_code ='" + code + "'", "create_time desc").uniqueResult(0); final Instruction obj = json.toJavaObject(Instruction.class); return obj; } @Override public Instruction findByTaskcodeAndStatus(String code) { - Iterator var3 = instructions.iterator(); - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getTask_code(), code) - && StrUtil.equals(instruction.getInstruction_status(), "0")) { - return instruction; - } + Iterator var3 = instructions.iterator(); + while (var3.hasNext()) { + Instruction instruction = (Instruction) var3.next(); + if (StrUtil.equals(instruction.getTask_code(), code) + && StrUtil.equals(instruction.getInstruction_status(), "0")) { + return instruction; } - return null; + } + return null; } @Override - public Instruction findByTaskcodeAndStatus(String code,String status) { + public Instruction findByTaskcodeAndStatus(String code, String status) { Iterator var3 = instructions.iterator(); while (var3.hasNext()) { Instruction instruction = (Instruction) var3.next(); @@ -288,7 +292,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu wherecaluse = " and " + wherecaluse; } WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse,"create_time desc").uniqueResult(0); + JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse, "create_time desc").uniqueResult(0); if (ObjectUtil.isNotEmpty(json)) { return json.toJavaObject(Instruction.class); } @@ -300,7 +304,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu dto = foramte(dto); String task_code = dto.getTask_code(); TaskDto task = taskService.findByCodeFromCache(task_code); + String excutetype = null; + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); if (StrUtil.isEmpty(dto.getRoute_plan_code())) { @@ -321,26 +327,11 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (StrUtil.isEmpty(dto.getLink_num())) { dto.setIs_send(task.getLink_num()); } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { + dto.setInstruction_type(task.getTask_type()); - } else { - dto.setInstruction_type("3"); - } - - // 查询是否存在相同指令号 - // if (!StrUtil.isEmpty(dto.getVehicle_code() )) { - // Instruction inst_dto = findByContainer(dto.getVehicle_code()); - // if (inst_dto != null) { - // log.error("存在相同载具号任务,载具号"+dto.getVehicle_code()); - // throw new BadRequestException("存在相同载具号任务!"); - // } - // } - // 起点设备与终点设备相同则为初始指令 + //起点设备与终点设备相同则为初始指令 if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { dto.setCompound_inst("1"); dto.setCompound_inst_data(task.getCompound_task_data()); } @@ -352,63 +343,76 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu dto.setCreate_time(now); dto.setStart_parent_code(task.getStart_parent_code()); dto.setNext_parent_code(task.getNext_parent_code()); + // 1 双工agv系统 2叉车agv系统 + if (StrUtil.equals(task.getAgv_system_type(), "1")) { + dto.setAgv_system_type("1"); + } else if (StrUtil.equals(task.getAgv_system_type(), "2")) { + dto.setAgv_system_type("2"); + } - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); + if (StrUtil.equals(task.getTask_type(), "1")) { + dto.setAgv_inst_type("1"); + } else if (StrUtil.equals(task.getTask_type(), "2")) { + dto.setAgv_inst_type("2"); + } else if (StrUtil.equals(task.getTask_type(), "3")) { + dto.setAgv_inst_type("3"); + } else if (StrUtil.equals(task.getTask_type(), "4")) { + dto.setAgv_inst_type("4"); + } else if (StrUtil.equals(task.getTask_type(), "5")) { + dto.setAgv_inst_type("5"); + } else if (StrUtil.equals(task.getTask_type(), "6")) { + dto.setAgv_inst_type("1"); + } else if (StrUtil.equals(task.getTask_type(), "7")) { + dto.setAgv_inst_type("2"); + } else if (StrUtil.equals(task.getTask_type(), "8")) { + dto.setAgv_inst_type("3"); } DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + LampThreecolorDeviceDriver lampThreecolorDeviceDriver; StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } + StandardCoveyorControlWithPlcScannerDeviceDriver standardCoveyorControlWithPlcScannerDeviceDriver; + StandardCoveyorControlDeviceDriver standardCoveyorControlDeviceDriver; + StandardStorageDeviceDriver standardStorageDeviceDriver; + //将指令赋予对象 下发指令号给电气 +// if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { +// standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); +// standardInspectSiteDeviceDriver.setBranchProtocol(2); +// standardInspectSiteDeviceDriver.setInst(dto); +// standardInspectSiteDeviceDriver.setMessage("下发指令:dto.getInstruction_code(),执行中"); +// standardInspectSiteDeviceDriver.writing(3, 1); +// } try { - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = - routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) - && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; - } - } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); - } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") - && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - log.warn("下发AGV指令数据,"+ "指令号:" + dto.getInstruction_code() + ",AGV系统类型:"+ task.getAgv_system_type()); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); - } else { - // Boolean result = createLkInst(task.getStorage_task_type(),dto); - Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(), dto); - if (StrUtil.equals(resp.result, "true")) { - dto.setSend_status("1"); - } else { - dto.setSend_status("2"); - } + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { + //区分是否下发、下发任务类型、以及调度系统 + //dto.setInstruction_type("2"); + //任务、指令类型 + /** + * 1 双工agv双任务 + * 2 双工agv但认为 + * 3 单入-单任务 + * 4 双入-双任务 + * 5 点对点任务 + * 6 称重平台称重PS20 agvtype:1 + * 7 不去称重平台称重PS20 agvtype:2 + * 8 RT20 agvtype:3 + */ + if (StrUtil.equals("1", dto.getAgv_system_type())) { + ndcAgvService.sendAgvTwoInstToNDC(dto, null); + } else if (StrUtil.equals("2", dto.getAgv_system_type())) { + ndcAgvService.sendAgvOneInstToNDC(dto); } + dto.setSend_status("1"); + } } catch (Exception e) { dto.setSend_status("2"); e.printStackTrace(); - log.warn("创建指令异常:"+e.getMessage()); } WQLObject wo = WQLObject.getWQLObject("acs_instruction"); @@ -418,6 +422,172 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu instructions.add(dto); } + public Instruction findByContainer(String container_code) { + Iterator var3 = instructions.iterator(); + + while (var3.hasNext()) { + Instruction instruction = (Instruction) var3.next(); + if (StrUtil.equals(instruction.getVehicle_code(), container_code)) { + return instruction; + } + } + + return null; + } + + @Override + public void createTwoInst(Instruction dto, Instruction dto2) throws Exception { + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + if (ObjectUtils.isNotEmpty(dto)) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + String excutetype = null; + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + JSONObject instcheckjson = instwo.query(" instruction_status <2 and next_point_code= '" + dto.getNext_point_code() + "'" + " and start_point_code = '" + dto.getStart_point_code() + "'" + " and task_id = '" + dto.getTask_id() + "'").uniqueResult(0); + if (instcheckjson != null) { + throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + } + if (!StrUtil.isEmpty(dto.getVehicle_code())) { + Instruction inst_dto = this.findByContainer(dto.getVehicle_code()); + if (ObjectUtils.isNotEmpty(inst_dto) && !StrUtil.equals(inst_dto.getTask_id(), dto.getTask_id())) { + throw new WDKException("已存在该载具号的指令!"); + } + } + //起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + } + + if (ObjectUtils.isNotEmpty(dto2)) { + dto2 = foramte(dto2); + String task_code2 = dto2.getTask_code(); + TaskDto task2 = taskService.findByCodeFromCache(task_code2); + String excutetype2 = null; + WQLObject instwo2 = WQLObject.getWQLObject("acs_instruction"); + String currentUsername2 = SecurityUtils.getCurrentUsername(); + String now2 = DateUtil.now(); + if (StrUtil.isEmpty(dto2.getRoute_plan_code())) { + dto2.setRoute_plan_code(task2.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto2.getPriority())) { + dto2.setPriority(task2.getPriority()); + } + if (StrUtil.isEmpty(dto2.getInstruction_code())) { + dto2.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto2.getInstruction_id())) { + dto2.setInstruction_id(IdUtil.simpleUUID()); + } + JSONObject instcheckjson2 = instwo.query(" instruction_status <2 and next_point_code= '" + dto.getNext_point_code() + "'" + " and start_point_code = '" + dto.getStart_point_code() + "'" + " and task_id = '" + dto.getTask_id() + "'").uniqueResult(0); + if (instcheckjson2 != null) { + throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + } + if (!StrUtil.isEmpty(dto2.getVehicle_code())) { + Instruction inst_dto2 = this.findByContainer(dto2.getVehicle_code()); + if (ObjectUtils.isNotEmpty(inst_dto2) && !StrUtil.equals(inst_dto2.getTask_id(), dto2.getTask_id())) { + throw new WDKException("已存在该载具号的指令!"); + } + } + //起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task2.getStart_device_code(), dto2.getStart_device_code())) { + if (!StrUtil.equals(dto2.getCompound_inst(), "0") && StrUtil.equals(task2.getCompound_task(), "1")) { + dto2.setCompound_inst("1"); + dto2.setCompound_inst_data(task2.getCompound_task_data()); + } + } + + dto2.setCreate_by(currentUsername2); + dto2.setUpdate_by(currentUsername2); + dto2.setUpdate_time(now2); + dto2.setCreate_time(now2); + dto2.setStart_parent_code(task2.getStart_parent_code()); + dto2.setNext_parent_code(task2.getNext_parent_code()); + } + + + try { + // != 0 为agv任务 + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { + + /** + * 1 双工agv双任务 + * 2 双工agv但认为 + * 3 单入-单任务 + * 4 双入-双任务 + * 5 点对点任务 + * 6 称重平台称重PS20 agvtype:1 + * 7 不去称重平台称重PS20 agvtype:2 + * 8 RT20 agvtype:3 + */ + if (StrUtil.equals("1", dto.getInstruction_type())) { + ndcAgvService.sendAgvTwoInstToNDC(dto, dto2); + dto.setSend_status("1"); + dto2.setSend_status("1"); + } else if (StrUtil.equals("2", dto.getInstruction_type())) { + dto.setSend_status("1"); + ndcAgvService.sendAgvTwoInstToNDC(dto, null); + } else if (StrUtil.equals("3", dto.getInstruction_type())) { + + } else if (StrUtil.equals("4", dto.getInstruction_type())) { + + } else if (StrUtil.equals("5", dto.getInstruction_type())) { + + } else if (StrUtil.equals("6", dto.getInstruction_type())) { + dto.setSend_status("1"); + ndcAgvService.sendAgvOneInstToNDC(dto); + } else if (StrUtil.equals("7", dto.getInstruction_type())) { + ndcAgvService.sendAgvOneInstToNDC(dto); + dto.setSend_status("1"); + } else if (StrUtil.equals("8", dto.getInstruction_type())) { + dto.setSend_status("1"); + ndcAgvService.sendAgvOneInstToNDC(dto); + } + + } + } catch (Exception e) { + if (ObjectUtil.isNotEmpty(dto)) { + dto.setSend_status("2"); + } + if (ObjectUtil.isNotEmpty(dto2)) { + dto2.setSend_status("2"); + } + e.printStackTrace(); + } + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + JSONObject json2 = (JSONObject) JSONObject.toJSON(dto2); + wo.insert(json); + wo.insert(json2); + instructions.add(dto); + instructions.add(dto2); + } + @Override public void create2(Instruction dto) throws Exception { dto = foramte(dto); @@ -477,14 +647,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } - try { String start_device_code = dto.getStart_device_code(); String next_device_code = dto.getNext_device_code(); @@ -760,9 +922,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu TaskDto obj = taskjson.toJavaObject(TaskDto.class); // =0 则不用再次请求 if (StrUtil.equals(obj.getRequest_again(), "0")) { - if(StrUtil.equals(obj.getTask_type(),"8")){ + if (StrUtil.equals(obj.getTask_type(), "8")) { //中转为空 - if(StrUtil.isEmpty(obj.getPut_device_code())){ + if (StrUtil.isEmpty(obj.getPut_device_code())) { if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { taskService.finish(obj.getTask_id()); } else { @@ -771,7 +933,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } else { if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { finishAndCreateHXInst(entity); - } else if (StrUtil.equals(obj.getPut_device_code(), instnextdevice)) { + } else if (StrUtil.equals(obj.getPut_device_code(), instnextdevice)) { taskService.finish(obj.getTask_id()); } } @@ -807,9 +969,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu TaskDto obj = taskjson.toJavaObject(TaskDto.class); // =0 则不用再次请求 if (StrUtil.equals(obj.getRequest_again(), "0")) { - if(StrUtil.equals(obj.getTask_type(),"8")){ + if (StrUtil.equals(obj.getTask_type(), "8")) { //中转为空 - if(StrUtil.isEmpty(obj.getPut_device_code())){ + if (StrUtil.isEmpty(obj.getPut_device_code())) { if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { taskService.finish(obj.getTask_id()); } else { @@ -818,7 +980,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } else { if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { finishAndCreateHXInst(dto); - } else if (StrUtil.equals(obj.getPut_device_code(), instnextdevice)) { + } else if (StrUtil.equals(obj.getPut_device_code(), instnextdevice)) { taskService.finish(obj.getTask_id()); } } @@ -1233,77 +1395,77 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByLinkNumSend(String code) { - Iterator 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; - } + Iterator 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; } @Override public List findByLinkNum(String code) { - List list = new ArrayList<>(); - Iterator 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); - } + List list = new ArrayList<>(); + Iterator 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); } - return list; + } + return list; } @Override public Instruction findByLinkNumNoSend(String code) { - Iterator 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; - } + Iterator 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; + return null; } @Override public Instruction findByCodeFromCache(String code) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getInstruction_code())) { - return inst; - } + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getInstruction_code())) { + return inst; } - return null; + } + return null; } @Override public Instruction findByBarcodeFromCache(String barcode) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(barcode, inst.getVehicle_code())) { - return inst; - } + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(barcode, inst.getVehicle_code())) { + return inst; } - return null; + } + return null; } @Override public Instruction findByIdFromCache(String id) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(id, inst.getInstruction_id())) { - return inst; - } + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(id, inst.getInstruction_id())) { + return inst; } - return null; + } + return null; } @Override @@ -1379,23 +1541,23 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByDeviceCodeFromCache(String devicecode) { - List instructionList = instructions; - ListUtil.sort( - instructionList, - new Comparator() { - @Override - public int compare(Instruction o1, Instruction o2) { - return o1.getCreate_time().compareTo(o2.getCreate_time()); - } - }); - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(devicecode, inst.getStart_device_code()) - && inst.getInstruction_status().equals("0")) { - return inst; - } + List instructionList = instructions; + ListUtil.sort( + instructionList, + new Comparator() { + @Override + public int compare(Instruction o1, Instruction o2) { + return o1.getCreate_time().compareTo(o2.getCreate_time()); + } + }); + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(devicecode, inst.getStart_device_code()) + && inst.getInstruction_status().equals("0")) { + return inst; } + } return null; } @@ -1407,52 +1569,52 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Integer querySameDestinationInst(String devicecode) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String next_code = inst.getNext_point_code(); - if (next_code.indexOf(".") != -1) { - next_code = next_code.substring(0, next_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + // 处理空盘位站点 + String next_code = inst.getNext_point_code(); + if (next_code.indexOf(".") != -1) { + next_code = next_code.substring(0, next_code.indexOf(".")); } + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; + } + } - return num; + return num; } @Override public Integer querySameInstType(String inst_type) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { - num = num + 1; - } + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { + num = num + 1; } - return num; } + return num; + } @Override public Integer querySameOriginInst(String devicecode) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String start_code = inst.getStart_point_code(); - if (start_code.indexOf(".") != -1) { - start_code = start_code.substring(0, start_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; - } + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + // 处理空盘位站点 + String start_code = inst.getStart_point_code(); + if (start_code.indexOf(".") != -1) { + start_code = start_code.substring(0, start_code.indexOf(".")); } - return num; + if (StrUtil.equals(devicecode, start_code)) { + num = num + 1; + } + } + return num; } @Override @@ -1575,7 +1737,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); - if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { +/* if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); List> list = new ArrayList<>(); @@ -1592,6 +1754,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu map3.put("value", "1"); list.add(map3); ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); - } + }*/ } } diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java b/wcs/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java new file mode 100644 index 00000000..4f5df86a --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java @@ -0,0 +1,94 @@ + +package org.nl.acs.order.rest; + + +import com.alibaba.fastjson.JSONObject; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.modules.logging.annotation.Log; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; + +/** +* @author geng by +* @date 2022-06-06 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "工单信息管理") +@RequestMapping("/api/produceshiftorder") +@Slf4j +public class ProduceshiftorderController { + + private final ProduceshiftorderService produceshiftorderService; + + @GetMapping + @Log("查询工单信息") + @ApiOperation("查询工单信息") + //@PreAuthorize("@el.check('produceshiftorder:list')") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page){ + return new ResponseEntity<>(produceshiftorderService.queryAll(whereJson,page),HttpStatus.OK); + } + + @PostMapping + @Log("新增工单信息") + @ApiOperation("新增工单信息") + //@PreAuthorize("@el.check('produceshiftorder:add')") + public ResponseEntity create(@Validated @RequestBody ProduceshiftorderDto dto){ + produceshiftorderService.create(dto); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改工单信息") + @ApiOperation("修改工单信息") + //@PreAuthorize("@el.check('produceshiftorder:edit')") + public ResponseEntity update(@Validated @RequestBody ProduceshiftorderDto dto){ + produceshiftorderService.update(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除工单信息") + @ApiOperation("删除工单信息") + //@PreAuthorize("@el.check('produceshiftorder:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody String[] ids) { + produceshiftorderService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("导出工单信息") + @ApiOperation("导出工单信息") + @GetMapping(value = "/download") + //@PreAuthorize("@el.check('produceshiftorder:list')") + public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + produceshiftorderService.download(produceshiftorderService.queryAll(whereJson), response); + } + + @PostMapping("/finishd") + @Log("工单强制完成") + @ApiOperation("工单强制完成") + //@PreAuthorize("@el.check('produceshiftorder:add')") + public ResponseEntity finishd(@RequestBody JSONObject param){ + produceshiftorderService.finishd(param); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PostMapping("/synchron") + @Log("工单同步") + @ApiOperation("工单同步") + //@PreAuthorize("@el.check('produceshiftorder:add')") + public ResponseEntity synchron(){ + produceshiftorderService.synchron(); + return new ResponseEntity<>(HttpStatus.CREATED); + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java new file mode 100644 index 00000000..571976df --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java @@ -0,0 +1,110 @@ + +package org.nl.acs.order.service; + +import com.alibaba.fastjson.JSONObject; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @description 服务接口 +* @author geng by +* @date 2022-06-06 +**/ +public interface ProduceshiftorderService { + + /** + * 查询数据分页 + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + /** + * 查询数据 + * @param whereJson 条件 + * @return Map + */ + List queryAll(String whereJson); + + + /** + * 查询所有数据不分页 + * @param whereJson 条件参数 + * @return List + */ + List queryAll(Map whereJson); + + /** + * 根据ID查询 + * @param order_id ID + * @return Produceshiftorder + */ + ProduceshiftorderDto findById(String order_id); + + /** + * 根据编码查询 + * @param code code + * @return Produceshiftorder + */ + ProduceshiftorderDto findByCode(String code); + + + /** + * 创建 + * @param dto / + */ + void create(ProduceshiftorderDto dto); + + /** + * 编辑 + * @param dto / + */ + void update(ProduceshiftorderDto dto); + + /** + * 编辑 + * @param dto / + */ + void updateByOrderCode(ProduceshiftorderDto dto); + + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(String[] ids); + + /** + * 导出数据 + * @param dtos 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List dtos, HttpServletResponse response) throws IOException; + + /** + * 工单强制完成 + * @param param + */ + void finishd(JSONObject param); + + /** + * 数据同步 + */ + void reload(); + + List findAllOrderFromCache(); + + ProduceshiftorderDto findOrderByDeviceCode(String device_code); + + /** + * 工单同步 + */ + void synchron(); + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderDto.java b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderDto.java new file mode 100644 index 00000000..946bab92 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderDto.java @@ -0,0 +1,72 @@ +package org.nl.acs.order.service.dto; + +import lombok.Data; + import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @description / +* @author geng by +* @date 2022-06-06 +**/ +@Data +public class ProduceshiftorderDto implements Serializable { + + /** 工单标识 */ + private String order_id; + + /** 工单编码 */ + private String order_code; + + /** 工单状态 */ + private String order_status; + + /** 下料数量 */ + private BigDecimal qty; + + /** 每框接料数量 */ + private BigDecimal one_qty; + + /** 物料编码 */ + private String material_code; + + /** 物料名称 */ + private String material_name; + + /** 物料标识 */ + private String material_uuid; + + /** 规格型号 */ + private String material_spec; + + /** 创建者 */ + private String create_by; + + /** 创建时间 */ + private String create_time; + + /** 修改者 */ + private String update_by; + + /** 修改时间 */ + private String update_time; + + /** 是否删除 */ + private String is_deleted; + + /** 工单外部标识 */ + private String ext_order_id; + + /** 设备编号 */ + private String device_code; + + /** 是否下发AGV */ + private String is_needmove; + + //托盘模板 + private String lane_tray_template; + + //托盘总量 + private String tray_num; + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java new file mode 100644 index 00000000..6d5c6641 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java @@ -0,0 +1,543 @@ + +package org.nl.acs.order.service.impl; + + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import lombok.RequiredArgsConstructor; +import org.nl.acs.auto.initial.ApplicationAutoInitial; +import org.nl.acs.device.service.DeviceExtraService; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_cleaning_machine_storage_station.HailiangCleaningMachineStorageStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_engraving_machine.HailiangEngravingMachineDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_packer_station.HailiangPackerStationDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test.HailiangSmartplcTestDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_special_device.HailiangSpecialDeviceDriver; +import org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_stacking_station.HailiangStackingStationDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.opc.Device; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.common.utils.FileUtil; +import org.nl.modules.common.utils.SecurityUtils; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.ResultBean; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.WqlUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import org.springframework.data.domain.Pageable; + +import java.math.BigDecimal; +import java.util.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; + +/** + * @author geng by + * @description 服务实现 + * @date 2022-06-06 + **/ +@Service +@RequiredArgsConstructor +@Slf4j +public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, ApplicationAutoInitial { + + private final org.nl.acs.opc.DeviceAppService deviceAppService; + private final DeviceExtraService deviceExtraService; + + List order = new ArrayList(); + + @Autowired + AcsToWmsService acsToWmsService; + + @Override + public void autoInitial() throws Exception { + this.reload(); + } + + public synchronized void reload() { + this.order = this.queryAll(" order_status !='2' and order_status !='3' and is_deleted =0"); + } + + @Override + public List queryAll(String whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONArray arr = wo.query(whereJson).getResultJSONArray(0); + List list = arr.toJavaList(ProduceshiftorderDto.class); + return list; + } + + @Override + public Map queryAll(Map whereJson, Pageable page) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "is_deleted = '0' and order_status != '2' and order_status != '3'", "update_time desc"); + final JSONObject json = rb.pageResult(); + return json; + } + + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(ProduceshiftorderDto.class); + return list; + } + + @Override + public ProduceshiftorderDto findById(String order_id) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONObject json = wo.query("order_id ='" + order_id + "'").uniqueResult(0); + final ProduceshiftorderDto obj = (ProduceshiftorderDto) JSONObject.toJavaObject(json, ProduceshiftorderDto.class); + return obj; + } + + @Override + public ProduceshiftorderDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONObject json = wo.query("order_code ='" + code + "'").uniqueResult(0); + final ProduceshiftorderDto obj = (ProduceshiftorderDto) JSONObject.toJavaObject(json, ProduceshiftorderDto.class); + return obj; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(ProduceshiftorderDto dto) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + Device device = deviceAppService.findDeviceByCode(dto.getDevice_code()); + if (ObjectUtil.isEmpty(device)) { + throw new BadRequestException("未找到对应设备:" + dto.getDevice_code()); + } + JSONArray resultJSONArray = wo.query("is_deleted = '0' and order_status in ('0', '1') and device_code = '" + dto.getDevice_code() + "'").getResultJSONArray(0); + if (ObjectUtil.isNotEmpty(resultJSONArray)) { + throw new BadRequestException("该设备已存在未完成工单,不能下发"); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setOrder_id(IdUtil.simpleUUID()); + if (StrUtil.isEmpty(dto.getOrder_code())) { + String order_no = CodeUtil.getNewCode("ORDER_NO"); + dto.setOrder_code(order_no); + } + dto.setOrder_status("0"); + if (StrUtil.isEmpty(dto.getCreate_by())) { + dto.setCreate_by(currentUsername); + } + if (StrUtil.isEmpty(dto.getUpdate_by())) { + dto.setUpdate_by(currentUsername); + } + dto.setCreate_time(now); + dto.setUpdate_time(now); + String is_needmove = dto.getIs_needmove(); + + //海亮专机 + HailiangSpecialDeviceDriver hailiangSpecialDeviceDriver; + //刻字机 + HailiangEngravingMachineDeviceDriver hailiangEngravingMachineDeviceDriver; + //包装机 + HailiangPackerStationDeviceDriver hailiangPackerStationDeviceDriver; + //smart200 + HailiangSmartplcTestDeviceDriver hailiangSmartplcTestDeviceDriver; + //机械手巷道 + HailiangStackingStationDriver hailiangStackingStationDriver; + + if (device.getDeviceDriver() instanceof HailiangSpecialDeviceDriver) { + hailiangSpecialDeviceDriver = (HailiangSpecialDeviceDriver) device.getDeviceDriver(); + //专机下发工单信号:倒料数量(-99999) 当前产量清零(1) 订单生产总量 每箱接料数量 工单号 + + String extra_value = hailiangSpecialDeviceDriver.getExtraValue().get("one_qty").toString(); + + if (StrUtil.equals(is_needmove, "1")) { + if (ObjectUtil.isEmpty(extra_value)) { + throw new BadRequestException("满料框数量为空"); + } + } else { + extra_value = "99999"; + } + if (!hailiangSpecialDeviceDriver.getItemProtocol().getIsonline()){ + throw new BadRequestException("设备未开机,开工失败!"); + } + dto.setOne_qty(BigDecimal.valueOf((Long.parseLong(extra_value)))); + hailiangSpecialDeviceDriver.writing("to_clear", "1"); + hailiangSpecialDeviceDriver.writing("to_order", dto.getOrder_code()); + hailiangSpecialDeviceDriver.writing("to_one_box_num", extra_value); + hailiangSpecialDeviceDriver.writing("to_order_prod_num", dto.getQty().toString()); + hailiangSpecialDeviceDriver.writing("to_out_num", "0"); + hailiangSpecialDeviceDriver.writing("to_pause", "0"); + } + + if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + String extra_value = hailiangEngravingMachineDeviceDriver.getExtraValue().get("one_qty").toString(); + if (StrUtil.equals(is_needmove, "1")) { + if (ObjectUtil.isEmpty(extra_value)) { + throw new BadRequestException("满料框数量为空"); + } + } else { + extra_value = "99999"; + } + dto.setOne_qty(BigDecimal.valueOf((Long.parseLong(extra_value)))); + if (!hailiangEngravingMachineDeviceDriver.getItemProtocol().getIsonline()){ + throw new BadRequestException("设备未开机,工单下发失败!"); + } + hailiangEngravingMachineDeviceDriver.writing("to_clear", "1"); + hailiangEngravingMachineDeviceDriver.writing("to_order", dto.getOrder_code()); + hailiangEngravingMachineDeviceDriver.writing("to_one_box_num", extra_value); + hailiangEngravingMachineDeviceDriver.writing("to_order_prod_num", dto.getQty().toString()); + } + + if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + if (!hailiangPackerStationDeviceDriver.getItemProtocol().getIsonline()){ + throw new BadRequestException("设备未开机,工单下发失败"); + } + hailiangPackerStationDeviceDriver.writing("to_clear", "1"); + hailiangPackerStationDeviceDriver.writing("to_order", dto.getOrder_code()); + hailiangPackerStationDeviceDriver.writing("to_order_prod_num", dto.getQty().toString()); + } + + if (device.getDeviceDriver() instanceof HailiangSmartplcTestDeviceDriver) { + hailiangSmartplcTestDeviceDriver = (HailiangSmartplcTestDeviceDriver) device.getDeviceDriver(); + hailiangSmartplcTestDeviceDriver.writing("to_clear", "1"); + hailiangSmartplcTestDeviceDriver.writing("to_task", dto.getOrder_code()); + hailiangSmartplcTestDeviceDriver.writing("to_qty", dto.getQty().toString()); + hailiangSmartplcTestDeviceDriver.writing("to_material", dto.getMaterial_code()); + hailiangSmartplcTestDeviceDriver.writing("to_pause", "0"); + } + + if (device.getDeviceDriver() instanceof HailiangStackingStationDriver){ + String lane_tray_template = dto.getLane_tray_template(); + String to_tray_info = ""; + if (lane_tray_template.equals("1")){ + to_tray_info = lane_tray_template + "12"; + } + if (lane_tray_template.equals("2")){ + to_tray_info = lane_tray_template + "24"; + } + if (StrUtil.isEmpty(dto.getTray_num())){ + dto.setTray_num("1"); + } + hailiangStackingStationDriver = (HailiangStackingStationDriver) device.getDeviceDriver(); + if (!hailiangStackingStationDriver.getItemProtocol().getIsonline()){ + throw new BadRequestException("设备未开机,工单下发失败"); + } + hailiangStackingStationDriver.writing("to_clear","1"); + hailiangStackingStationDriver.writing("to_order",dto.getOrder_code()); + hailiangStackingStationDriver.writing("to_order_prod_num",dto.getQty().toString()); + hailiangStackingStationDriver.writing("to_tray_num",dto.getTray_num()); + hailiangStackingStationDriver.writing("to_tray_info",to_tray_info); + } + + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + wo.insert(json); + order.add(dto); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(ProduceshiftorderDto dto) { + ProduceshiftorderDto entity = this.findById(dto.getOrder_id()); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + wo.update(json); + Iterator iterator = order.iterator(); + while (iterator.hasNext()) { + ProduceshiftorderDto instruction = iterator.next(); + if (instruction.getOrder_code().equals(dto.getOrder_code())) { + iterator.remove(); + } + } + if (StrUtil.equals(dto.getOrder_status(), "0") || StrUtil.equals(dto.getOrder_status(), "1")) { + order.add(dto); + } + if (StrUtil.equals(dto.getOrder_status(), "3")) { + WQLObject wo1 = WQLObject.getWQLObject("acs_deviceisonline"); + String device_code = dto.getDevice_code(); + JSONObject jsonObject = wo1.query("device_code = '" + device_code + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(jsonObject)){ + jsonObject = new JSONObject(); + } + JSONObject map = new JSONObject(); + map.put("online_id",IdUtil.simpleUUID()); + map.put("device_code",device_code); + map.put("order_code", dto.getOrder_code()); + map.put("online_status","0"); + map.put("create_by",currentUsername); + map.put("create_time",now); + Device device = deviceAppService.findDeviceByCode(device_code); + HailiangEngravingMachineDeviceDriver hailiangEngravingMachineDeviceDriver; + HailiangPackerStationDeviceDriver hailiangPackerStationDeviceDriver; + HailiangSpecialDeviceDriver hailiangSpecialDeviceDriver; + HailiangStackingStationDriver hailiangStackingStationDriver; + if (device.getDeviceDriver() instanceof HailiangSpecialDeviceDriver) { + hailiangSpecialDeviceDriver = (HailiangSpecialDeviceDriver) device.getDeviceDriver(); + if (hailiangSpecialDeviceDriver.getStatus_type() == 1){ + if (ObjectUtil.isEmpty(jsonObject)){ + wo1.insert(map); + } else { + jsonObject.put("online_status","0"); + jsonObject.put("order_code",dto.getOrder_code()); + jsonObject.put("update_by",currentUsername); + jsonObject.put("update_time",now); + wo1.update(jsonObject); + } + }else { + hailiangSpecialDeviceDriver.writing("to_order_compel_finished","1"); + hailiangSpecialDeviceDriver.writing("to_confirm_finished", "1"); + hailiangSpecialDeviceDriver.writing("to_order", "0"); + hailiangSpecialDeviceDriver.writing("to_clear", "1"); + } + } else if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + if (hailiangPackerStationDeviceDriver.getStatus_type() == 1){ + if (ObjectUtil.isEmpty(jsonObject)){ + wo1.insert(map); + } else { + jsonObject.put("online_status","0"); + jsonObject.put("order_code",dto.getOrder_code()); + jsonObject.put("update_by",currentUsername); + jsonObject.put("update_time",now); + wo1.update(jsonObject); + } + }else { + hailiangPackerStationDeviceDriver.writing("to_order_compel_finished","1"); + hailiangPackerStationDeviceDriver.writing("to_confirm_finished", "1"); + hailiangPackerStationDeviceDriver.writing("to_order", "0"); + hailiangPackerStationDeviceDriver.writing("to_clear", "1"); + } + } else if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + if (hailiangEngravingMachineDeviceDriver.getStatus_type() == 1){ + if (ObjectUtil.isEmpty(jsonObject)){ + wo1.insert(map); + } else { + jsonObject.put("online_status","0"); + jsonObject.put("order_code",dto.getOrder_code()); + jsonObject.put("update_by",currentUsername); + jsonObject.put("update_time",now); + wo1.update(jsonObject); + } + }else { + hailiangEngravingMachineDeviceDriver.writing("to_order_compel_finished","1"); + hailiangEngravingMachineDeviceDriver.writing("to_confirm_finished", "1"); + hailiangEngravingMachineDeviceDriver.writing("to_order", "0"); + hailiangEngravingMachineDeviceDriver.writing("to_clear", "1"); + } + } else if (device.getDeviceDriver() instanceof HailiangStackingStationDriver){ + hailiangStackingStationDriver = (HailiangStackingStationDriver) device.getDeviceDriver(); + hailiangStackingStationDriver.writing("to_compel_finish","1"); + } + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateByOrderCode(ProduceshiftorderDto dto) { + ProduceshiftorderDto entity = this.findByCode(dto.getOrder_code()); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setOrder_status(dto.getOrder_status()); + entity.setUpdate_by(currentUsername); + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json, "order_code = '" + dto.getOrder_code() + "'"); + Iterator iterator = order.iterator(); + while (iterator.hasNext()) { + ProduceshiftorderDto oneorder = iterator.next(); + if (oneorder.getOrder_code().equals(dto.getOrder_code())) { + iterator.remove(); + } + } + if (StrUtil.equals(dto.getOrder_status(), "0") || StrUtil.equals(dto.getOrder_status(), "1")) { + order.add(dto); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + for (String order_id : ids) { + wo.delete("order_id = '" + order_id + "'"); + Iterator iterator = order.iterator(); + while (iterator.hasNext()) { + ProduceshiftorderDto instruction = iterator.next(); + if (instruction.getOrder_id().equals(order_id)) { + iterator.remove(); + } + } + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (ProduceshiftorderDto produceshiftorder : all) { + Map map = new LinkedHashMap<>(); + map.put("工单编码", produceshiftorder.getOrder_code()); + map.put("工单状态", produceshiftorder.getOrder_status()); + map.put("下料数量", produceshiftorder.getQty()); + map.put("物料编码", produceshiftorder.getMaterial_code()); + map.put("物料名称", produceshiftorder.getMaterial_name()); + map.put("物料标识", produceshiftorder.getMaterial_uuid()); + map.put("规格型号", produceshiftorder.getMaterial_spec()); + map.put("创建者", produceshiftorder.getCreate_by()); + map.put("创建时间", produceshiftorder.getCreate_time()); + map.put("修改者", produceshiftorder.getUpdate_by()); + map.put("修改时间", produceshiftorder.getUpdate_time()); + map.put("是否删除", produceshiftorder.getIs_deleted()); + map.put("工单外部标识", produceshiftorder.getExt_order_id()); + map.put("设备编号", produceshiftorder.getDevice_code()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finishd(JSONObject param) { + WQLObject wo = WQLObject.getWQLObject("acs_deviceisonline"); + param = param.getJSONObject("data"); + String now = DateUtil.now(); + String currentUsername = SecurityUtils.getCurrentUsername(); + String order_id = param.getString("order_id"); + String ext_order_id = param.getString("ext_order_id"); + String device_code = param.getString("device_code"); + String order_code = param.getString("order_code"); + if (StrUtil.isNotEmpty(ext_order_id)) { + // TODO + param.put("status", "3"); + param.put("type", "2"); + acsToWmsService.feedbackOrderStatus(param); + } + Device device = deviceAppService.findDeviceByCode(device_code); + HailiangSpecialDeviceDriver hailiangSpecialDeviceDriver; + HailiangPackerStationDeviceDriver hailiangPackerStationDeviceDriver; + HailiangEngravingMachineDeviceDriver hailiangEngravingMachineDeviceDriver; + HailiangStackingStationDriver hailiangStackingStationDriver; + JSONObject jsonObject = wo.query("device_code = '" + device_code + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(jsonObject)){ + jsonObject = new JSONObject(); + } + JSONObject map = new JSONObject(); + map.put("online_id",IdUtil.simpleUUID()); + map.put("device_code",device_code); + map.put("order_code",order_code); + map.put("online_status","0"); + map.put("create_by",currentUsername); + map.put("create_time",now); + if (device.getDeviceDriver() instanceof HailiangSpecialDeviceDriver) { + hailiangSpecialDeviceDriver = (HailiangSpecialDeviceDriver) device.getDeviceDriver(); + if (hailiangSpecialDeviceDriver.getStatus_type() == 1) { + if (ObjectUtil.isEmpty(jsonObject)){ + wo.insert(map); + } else { + jsonObject.put("online_status","0"); + jsonObject.put("order_code",order_code); + jsonObject.put("update_by",currentUsername); + jsonObject.put("update_time",now); + wo.update(jsonObject); + } + } else { + hailiangSpecialDeviceDriver.writing("to_order_compel_finished", "1"); + hailiangSpecialDeviceDriver.writing("to_confirm_finished", "1"); + hailiangSpecialDeviceDriver.writing("to_order", "0"); + hailiangSpecialDeviceDriver.writing("to_clear", "1"); + } + } + if (device.getDeviceDriver() instanceof HailiangPackerStationDeviceDriver) { + hailiangPackerStationDeviceDriver = (HailiangPackerStationDeviceDriver) device.getDeviceDriver(); + if (hailiangPackerStationDeviceDriver.getStatus_type() == 1) { + if (ObjectUtil.isEmpty(jsonObject)){ + wo.insert(map); + } else { + jsonObject.put("online_status","0"); + jsonObject.put("order_code",order_code); + jsonObject.put("update_by",currentUsername); + jsonObject.put("update_time",now); + wo.update(jsonObject); + } + } else { + hailiangPackerStationDeviceDriver.writing("to_order_compel_finished", "1"); + hailiangPackerStationDeviceDriver.writing("to_confirm_finished", "1"); + hailiangPackerStationDeviceDriver.writing("to_order", "0"); + hailiangPackerStationDeviceDriver.writing("to_clear", "1"); + } + } + if (device.getDeviceDriver() instanceof HailiangEngravingMachineDeviceDriver) { + hailiangEngravingMachineDeviceDriver = (HailiangEngravingMachineDeviceDriver) device.getDeviceDriver(); + if (hailiangEngravingMachineDeviceDriver.getStatus_type() == 1){ + if (ObjectUtil.isEmpty(jsonObject)){ + wo.insert(map); + } else { + jsonObject.put("online_status","0"); + jsonObject.put("order_code",order_code); + jsonObject.put("update_by",currentUsername); + jsonObject.put("update_time",now); + wo.update(jsonObject); + } + } else { + hailiangEngravingMachineDeviceDriver.writing("to_order_compel_finished", "1"); + hailiangEngravingMachineDeviceDriver.writing("to_confirm_finished", "1"); + hailiangEngravingMachineDeviceDriver.writing("to_order", "0"); + hailiangEngravingMachineDeviceDriver.writing("to_clear", "1"); + } + } + if (device.getDeviceDriver() instanceof HailiangStackingStationDriver) { + hailiangStackingStationDriver = (HailiangStackingStationDriver) device.getDeviceDriver(); + hailiangStackingStationDriver.writing("to_compel_finish","1"); + } + JSONObject map1 = new JSONObject(); + map1.put("order_id", order_id); + map1.put("order_status", "3"); + map1.put("update_by", SecurityUtils.getCurrentUsername()); + map1.put("update_time", now); + WQLObject wo1 = WQLObject.getWQLObject("acs_produceshiftorder"); + wo1.update(map1); + Iterator iterator = order.iterator(); + while (iterator.hasNext()) { + ProduceshiftorderDto instruction = iterator.next(); + if (instruction.getOrder_code().equals(order_code)) { + iterator.remove(); + } + } + } + + @Override + public List findAllOrderFromCache() { + return order; + } + + @Override + public ProduceshiftorderDto findOrderByDeviceCode(String device_code) { + for (int i = 0; i < this.order.size(); i++) { + ProduceshiftorderDto dto = order.get(i); + if (StrUtil.equals(device_code, dto.getDevice_code())) { + return dto; + } + } + return null; + } + + @Override + public void synchron() { + this.reload(); + } + +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls new file mode 100644 index 00000000..c92c3c4c Binary files /dev/null and b/wcs/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls differ diff --git a/wcs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 5d0de6ee..a1c1e5b1 100644 --- a/wcs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/wcs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -39,6 +39,7 @@ import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.utils.FileUtil; import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.system.util.CodeUtil; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; @@ -1080,76 +1081,54 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public Instruction createInst(String ids) throws Exception { + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); TaskDto acsTask = this.findById(ids); - if (acsTask == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + if (acsTask == null) throw new BadRequestException("被删除或无权限,操作失败!"); InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 "); - if (inst != null) { - throw new BadRequestException("有指令未完成!"); - } - + if (inst != null) throw new BadRequestException("有指令未完成!"); + String link_no = CodeUtil.getNewCode("LINK_NO"); String taskid = acsTask.getTask_id(); String taskcode = acsTask.getTask_code(); String vehiclecode = acsTask.getVehicle_code(); String priority = acsTask.getPriority(); + String material = acsTask.getMaterial(); String start_point_code = acsTask.getStart_point_code(); String start_device_code = acsTask.getStart_device_code(); String route_plan_code = acsTask.getRoute_plan_code(); String vehicleType = acsTask.getVehicle_type(); - // 是否复合任务 =0非复合任务 + //是否复合任务 =0非复合任务 String compound_task = acsTask.getCompound_task(); String next_point_code = acsTask.getNext_point_code(); String next_device_code = acsTask.getNext_device_code(); - String start_point_code2 = acsTask.getStart_point_code2(); - String next_point_code2 = acsTask.getNext_point_code2(); String agv_system_type = acsTask.getAgv_system_type(); + String put_device_code = acsTask.getPut_device_code(); + String put_point_code = acsTask.getPut_point_code(); + String remark = acsTask.getRemark(); String task_type = acsTask.getTask_type(); - /** 开始平均分解校验 */ - String this_device_code = - this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); - if (StrUtil.isEmpty(this_device_code)) { - List shortPathsList = - routeLineService.getShortPathLines( - start_device_code, acsTask.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; - } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_device_code; + String quantity = acsTask.getQuantity(); + String is_send = acsTask.getIs_send(); + if(StrUtil.equals(is_send,"0")){ + throw new BadRequestException("is_send"); } - - if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); instdto.setInstruction_type(task_type); instdto.setInstruction_id(IdUtil.simpleUUID()); instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); + instdto.setRemark(remark); + instdto.setLink_num(link_no); + instdto.setMaterial(material); + instdto.setQuantity(quantity); + instdto.setPut_device_code(put_device_code); + instdto.setPut_point_code(put_point_code); + instdto.setAgv_system_type(agv_system_type); instdto.setTask_id(taskid); instdto.setTask_code(taskcode); instdto.setVehicle_code(vehiclecode); String now = DateUtil.now(); + String currentUsername = SecurityUtils.getCurrentUsername(); instdto.setCreate_time(now); - instdto.setCreate_by("auto"); + instdto.setCreate_by(currentUsername); instdto.setStart_device_code(start_device_code); instdto.setNext_device_code(next_device_code); instdto.setStart_point_code(start_point_code); @@ -1158,40 +1137,12 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { instdto.setInstruction_status("0"); instdto.setExecute_device_code(start_point_code); instdto.setVehicle_type(vehicleType); - instdto.setStart_point_code2(start_point_code2); - instdto.setStart_device_code2(start_point_code2); - instdto.setNext_device_code2(next_point_code2); - instdto.setNext_point_code2(next_point_code2); - instdto.setAgv_system_type(agv_system_type); - // 判断agv系统 - // 1、1楼叉车系统 - // 2、2楼1区域AGV系统 - // 3、2楼2区域AGV系统 - if (!StrUtil.equals(agv_system_type, "1")) { - // task_type - // 1、生箔; Itype=1:取空,取满,放空,放满; - // 2、分切 Itype=3取满、取空、放满、放空; - // 3、普通任务 Itype=2:取货、放货; - // 4、叉车任务 - // 5、输送任务 - // 6、行架 - // 7、立库 - if (StrUtil.equals(task_type, "1")) { - instdto.setAgv_inst_type("1"); - } else if (StrUtil.equals(task_type, "3")) { - instdto.setAgv_inst_type("2"); - } else if (StrUtil.equals(task_type, "2")) { - instdto.setAgv_inst_type("3"); - } else if (StrUtil.equals(task_type, "8")) { - instdto.setAgv_inst_type("2"); - } - } else { - instdto.setAgv_inst_type("4"); - } - instructionservice.create2(instdto); - - // acsTask.setTask_status("1"); - // this.update(acsTask); + instructionservice.create(instdto); + //创建指令后修改任务状态 + acsTask.setTask_status("1"); + acsTask.setTask_type("2"); + acsTask.setLink_num(link_no); + taskserver.update(acsTask); return instdto; } diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVOneInst.java b/wcs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVOneInst.java new file mode 100644 index 00000000..33615921 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVOneInst.java @@ -0,0 +1,104 @@ +package org.nl.modules.quartz.task; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 自动创建指令 + */ +@Slf4j +@Component +public class AutoCreateAGVOneInst { + + /** + * 根据任务状态创建指令、生成下一条指令 + * 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 + */ + public void run() throws Exception { + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); + List list = taskserver.queryAll("task_status = '0' and agv_system_type = '2' "); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + for (int i = 0; i < list.size(); i++) { + TaskDto acsTask = list.get(i); + String taskid = acsTask.getTask_id(); + String taskcode = acsTask.getTask_code(); + String vehiclecode = acsTask.getVehicle_code(); + String priority = acsTask.getPriority(); + String is_send = acsTask.getIs_send(); + String create_time = acsTask.getCreate_time(); + String start_device_code = acsTask.getStart_device_code(); + String next_device_code = acsTask.getNext_device_code(); + + String start_point_code = acsTask.getStart_point_code(); + String put_point_code = acsTask.getPut_point_code(); + String put_device_code = acsTask.getPut_device_code(); + String route_plan_code = acsTask.getRoute_plan_code(); + String vehicleType = acsTask.getVehicle_type(); + + //是否复合任务 =0非复合任务 + String compound_task = acsTask.getCompound_task(); + String next_point_code = acsTask.getNext_point_code(); + + if(StrUtil.equals(is_send,"0")){ + continue; + } + + String link_no = CodeUtil.getNewCode("LINK_NO"); + Instruction instdto = new Instruction(); + instdto.setInstruction_type(acsTask.getTask_type()); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setPut_device_code(put_device_code); + instdto.setPut_point_code(put_point_code); + instdto.setNext_device_code(next_device_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + instdto.setVehicle_type(vehicleType); + instdto.setLink_num(link_no); + try { + instructionService.create(instdto); + } catch (Exception e) { + acsTask.setRemark(e.getMessage()); + taskserver.updateByCodeFromCache(acsTask); + continue; + } + //创建指令后修改任务状态 + acsTask.setTask_status("1"); + acsTask.setLink_num(link_no); + taskserver.update(acsTask); + + } + } +} diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVTwoInst.java b/wcs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVTwoInst.java new file mode 100644 index 00000000..d31d7906 --- /dev/null +++ b/wcs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateAGVTwoInst.java @@ -0,0 +1,330 @@ +package org.nl.modules.quartz.task; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.nl.acs.AcsConfig; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.service.impl.ParamServiceImpl; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +/** + * 自动创建指令 + */ +@Slf4j +@Component +public class AutoCreateAGVTwoInst { + + /** + * 根据任务状态创建指令、生成下一条指令 + * 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 + */ + public void run() throws Exception { + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); + List list = taskserver.queryAll("task_status = '0' and agv_system_type = '1' "); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + int maxSendTaskTime = Integer.valueOf(String.valueOf(paramService.findByCode(AcsConfig.MAXSENDTASKTIME).getValue())); + for (int i = 0; i < list.size(); i++) { + TaskDto acsTask = list.get(i); + String taskid = acsTask.getTask_id(); + String taskcode = acsTask.getTask_code(); + String vehiclecode = acsTask.getVehicle_code(); + String priority = acsTask.getPriority(); + String is_send = acsTask.getIs_send(); + String create_time = acsTask.getCreate_time(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + String start_device_code = acsTask.getStart_device_code(); + String next_device_code = acsTask.getNext_device_code(); + + String start_point_code = acsTask.getStart_point_code(); + String put_point_code = acsTask.getPut_point_code(); + String put_device_code = acsTask.getPut_device_code(); + String route_plan_code = acsTask.getRoute_plan_code(); + String vehicleType = acsTask.getVehicle_type(); + + //是否复合任务 =0非复合任务 + String compound_task = acsTask.getCompound_task(); + String next_point_code = acsTask.getNext_point_code(); + + if(StrUtil.equals(is_send,"0")){ + continue; + } + + //判断当前任务创建时间是否超过最大等待时间 + if(date.getTime() - simpleDateFormat.parse(create_time).getTime() > (long) maxSendTaskTime*1000){ + //判断是否能进行合并 + //不能合并则立刻下发AGV + Device start_device = appService.findDeviceByCode(start_device_code); + String start_region = start_device.getRegion(); + Device next_device = appService.findDeviceByCode(next_device_code); + String next_region = next_device.getRegion(); + boolean flag = false; + if(list.size()>1){ + for(int j=0;j1) { + for (int j = 0; j < list.size(); j++) { + TaskDto taskDto = list.get(j); + if (!StrUtil.equals(taskDto.getTask_code(), taskcode)) { + String one_start_region = appService.findDeviceByCode(taskDto.getStart_device_code()).getRegion(); + String one_next_region = appService.findDeviceByCode(taskDto.getNext_device_code()).getRegion(); + if (StrUtil.equals(start_region, one_start_region) && StrUtil.equals(next_region, one_next_region)) { + //成功找到匹配的任务 + //生成指令 + String link_no = CodeUtil.getNewCode("LINK_NO"); + Instruction instdto = new Instruction(); + instdto.setInstruction_type(acsTask.getTask_type()); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setPut_device_code(put_device_code); + instdto.setPut_point_code(put_point_code); + instdto.setNext_device_code(next_device_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + instdto.setVehicle_type(vehicleType); + instdto.setLink_num(link_no); + + Instruction instdto2 = new Instruction(); + String start_point_code2 = taskDto.getStart_point_code(); + String start_device_code2 = taskDto.getStart_device_code(); + String put_point_code2 = taskDto.getPut_point_code(); + String put_device_code2 = taskDto.getPut_device_code(); + String route_plan_code2 = taskDto.getRoute_plan_code(); + String vehicleType2 = taskDto.getVehicle_type(); + String priority2 = taskDto.getPriority(); + String compound_task2 = taskDto.getCompound_task(); + String next_point_code2 = taskDto.getNext_point_code(); + String next_device_code2 = taskDto.getNext_device_code(); + instdto2.setInstruction_type(taskDto.getTask_type()); + instdto2.setInstruction_id(IdUtil.simpleUUID()); + instdto2.setRoute_plan_code(route_plan_code2); + instdto2.setRemark(taskDto.getRemark()); + instdto2.setMaterial(taskDto.getMaterial()); + instdto2.setQuantity(taskDto.getQuantity()); + instdto2.setTask_id(taskDto.getTask_id()); + instdto2.setTask_code(taskDto.getTask_code()); + instdto2.setVehicle_code(taskDto.getVehicle_code()); + instdto2.setCreate_time(now); + instdto2.setCreate_by("auto"); + instdto2.setStart_device_code(start_device_code2); + instdto2.setStart_point_code(start_point_code2); + instdto2.setPut_device_code(put_device_code2); + instdto2.setPut_point_code(put_point_code2); + instdto2.setNext_device_code(next_device_code2); + instdto2.setNext_point_code(next_point_code2); + instdto2.setPriority(priority2); + instdto2.setInstruction_status("0"); + instdto2.setExecute_device_code(start_point_code2); + instdto2.setVehicle_type(vehicleType2); + instdto2.setLink_num(link_no); + + try { + instructionService.createTwoInst(instdto, instdto2); + list.remove(i); + list.remove(j); + flag = true; + } catch (Exception e) { + acsTask.setRemark(e.getMessage()); + taskserver.updateByCodeFromCache(acsTask); + taskDto.setRemark(e.getMessage()); + taskserver.updateByCodeFromCache(taskDto); + continue; + } + //创建指令后修改任务状态 + acsTask.setTask_status("1"); + acsTask.setLink_num(link_no); + taskserver.update(acsTask); + + taskDto.setTask_status("1"); + taskDto.setLink_num(link_no); + taskserver.update(taskDto); + break; + } else { + continue; + } + } + } + } + } + } + } +} diff --git a/wcs/nladmin-ui/src/views/acs/device/config.vue b/wcs/nladmin-ui/src/views/acs/device/config.vue index e58e5a5e..70077a81 100644 --- a/wcs/nladmin-ui/src/views/acs/device/config.vue +++ b/wcs/nladmin-ui/src/views/acs/device/config.vue @@ -75,61 +75,93 @@ import { get, selectDriverCodeList } from '@/api/acs/device/driverConfig' import { getDicts } from '@/api/system/dict' import standard_inspect_site from './driver/standard_inspect_site' import standard_ordinary_site from './driver/standard_ordinary_site' +import weighing_site from './driver/weighing_site' +import machines_site from './driver/machines_site' +import lamp_three_color from './driver/lamp_three_color' +import standard_autodoor from './driver/standard_autodoor' +import standard_emptypallet_site from './driver/standard_emptypallet_site' +import standard_manipulator_inspect_site from './driver/standard_manipulator_inspect_site' +import standard_special_inspect_site from './driver/standard_special_inspect_site' +import special_ordinary_site from './driver/special_ordinary_site' import standard_storage from '@/views/acs/device/driver/standard_storage' import standard_scanner from '@/views/acs/device/driver/standard_scanner' import standard_conveyor_control_with_scanner from '@/views/acs/device/driver/standard_conveyor_control_with_scanner' +import standard_conveyor_control_with_plcscanner from '@/views/acs/device/driver/standard_conveyor_control_with_plcscanner' import standard_conveyor_control from '@/views/acs/device/driver/standard_conveyor_control' import standard_conveyor_monitor from '@/views/acs/device/driver/standard_conveyor_monitor' -import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_smart_plc_test' -import paint_conveyor from '@/views/acs/device/driver/paint_conveyor' -import cargo_lift_conveyor from '@/views/acs/device/driver/cargo_lift_conveyor' -import empty_vehicle_stacking_position from '@/views/acs/device/driver/empty_vehicle_stacking_position' +import non_line_manipulator_inspect_site from '@/views/acs/device/driver/non_line_manipulator_inspect_site' +import non_line_inspect_site from '@/views/acs/device/driver/non_line_inspect_site' +import manipulator_inspect_site_NDC from '@/views/acs/device/driver/manipulator_inspect_site_NDC' +import standard_manipulator_stacking_site from '@/views/acs/device/driver/standard_manipulator_stacking_site' +import standard_photoelectric_inspect_site from '@/views/acs/device/driver/standard_photoelectric_inspect_site' + +import hailiang_special_pick_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_pick_station' +import hailiang_special_empty_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_empty_station' +import hailiang_special_full_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_full_station' +import hailiang_special_pour_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_pour_station' +import hailiang_special_device from '@/views/acs/device/driver/hailiang_one/hailiang_special_device' +import hailiang_engraving_machine from '@/views/acs/device/driver/hailiang_one/hailiang_engraving_machine' +import hailiang_engraving_cache from '@/views/acs/device/driver/hailiang_one/hailiang_engraving_cache' +import hailiang_packer_station from '@/views/acs/device/driver/hailiang_one/hailiang_packer_station' +import hailiang_auto_cache_line from '@/views/acs/device/driver/hailiang_one/hailiang_auto_cache_line' +import hailiang_cleaning_feeding_line from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line' +import hailiang_cleaning_machine from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine' +import hailiang_cleaning_machine_storage_station from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine_storage_station' import agv_ndc_one from '@/views/acs/device/driver/agv/agv_ndc_one' import agv_ndc_two from '@/views/acs/device/driver/agv/agv_ndc_two' -import box_palletizing_manipulator from '@/views/acs/device/driver/box_palletizing_manipulator' -import oven_manipulator from '@/views/acs/device/driver/oven_manipulator' -import siemens_conveyor from '@/views/acs/device/driver/siemens_conveyor' -import slit_two_manipulator from '@/views/acs/device/driver/slit_two_manipulator' -import hongxiang_device from '@/views/acs/device/driver/hongxiang_device' -import hongxiang_conveyor from '@/views/acs/device/driver/hongxiang_conveyor' -import plug_pull_device_site from '@/views/acs/device/driver/plug_pull_device_site' -import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling' -import siemens_conveyor_ckk from '@/views/acs/device/driver/siemens_conveyor_ckk' -import siemens_onefloor_agv_conveyor from '@/views/acs/device/driver/siemens_onefloor_agv_conveyor' -import photoelectric_inspection_site from '@/views/acs/device/driver/photoelectric_inspection_site' -import standard_autodoor from '@/views/acs/device/driver/standard_autodoor' -import lamp_three_color from '@/views/acs/device/driver/lamp_three_color' - +import hailiang_xj_plc_test from '@/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test' +import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_one/hailiang_smart_plc_test' +import hailiang_threestation_smart from '@/views/acs/device/driver/hailiang_one/hailiang_threestation_smart' +import hailiang_foldingDisc_smart from '@/views/acs/device/driver/hailiang_one/hailiang_foldingDisc_smart' +import hailiang_elevator_wiring from '@/views/acs/device/driver/hailiang_one/hailiang_elevator_wiring' +import hailiang_paint_line from '@/views/acs/device/driver/hailiang_one/hailiang_paint_line' +import hailiang_stacking_station from '@/views/acs/device/driver/hailiang_one/hailiang_stacking_station' export default { name: 'DeviceConfig', components: { standard_ordinary_site, standard_inspect_site, + standard_autodoor, + standard_emptypallet_site, + standard_manipulator_inspect_site, + standard_special_inspect_site, + lamp_three_color, standard_storage, + special_ordinary_site, standard_scanner, standard_conveyor_control_with_scanner, + standard_conveyor_control_with_plcscanner, standard_conveyor_control, standard_conveyor_monitor, - hailiang_smart_plc_test, - paint_conveyor, - cargo_lift_conveyor, - empty_vehicle_stacking_position, + weighing_site, + machines_site, + non_line_manipulator_inspect_site, + non_line_inspect_site, + manipulator_inspect_site_NDC, + standard_manipulator_stacking_site, + standard_photoelectric_inspect_site, agv_ndc_two, agv_ndc_one, - hongxiang_device, - hongxiang_conveyor, - box_palletizing_manipulator, - oven_manipulator, - siemens_conveyor, - slit_two_manipulator, - plug_pull_device_site, - siemens_conveyor_labeling, - siemens_conveyor_ckk, - siemens_onefloor_agv_conveyor, - photoelectric_inspection_site, - standard_autodoor, - lamp_three_color + hailiang_packer_station, + hailiang_engraving_cache, + hailiang_special_pick_station, + hailiang_special_empty_station, + hailiang_special_full_station, + hailiang_special_pour_station, + hailiang_special_device, + hailiang_engraving_machine, + hailiang_auto_cache_line, + hailiang_cleaning_feeding_line, + hailiang_cleaning_machine, + hailiang_cleaning_machine_storage_station, + hailiang_xj_plc_test, + hailiang_smart_plc_test, + hailiang_threestation_smart, + hailiang_foldingDisc_smart, + hailiang_elevator_wiring, + hailiang_paint_line, + hailiang_stacking_station }, dicts: ['device_type'], mixins: [crud], diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_auto_cache_line.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_auto_cache_line.vue new file mode 100644 index 00000000..c8922f9e --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_auto_cache_line.vue @@ -0,0 +1,504 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line.vue new file mode 100644 index 00000000..67f88303 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line.vue @@ -0,0 +1,504 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine.vue new file mode 100644 index 00000000..67f88303 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine.vue @@ -0,0 +1,504 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine_storage_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine_storage_station.vue new file mode 100644 index 00000000..b0e0908e --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine_storage_station.vue @@ -0,0 +1,428 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_elevator_wiring.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_elevator_wiring.vue new file mode 100644 index 00000000..9f1191a2 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_elevator_wiring.vue @@ -0,0 +1,487 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_engraving_cache.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_engraving_cache.vue new file mode 100644 index 00000000..3796acda --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_engraving_cache.vue @@ -0,0 +1,420 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_engraving_machine.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_engraving_machine.vue new file mode 100644 index 00000000..ed7887a6 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_engraving_machine.vue @@ -0,0 +1,433 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_foldingDisc_smart.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_foldingDisc_smart.vue new file mode 100644 index 00000000..884c08fe --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_foldingDisc_smart.vue @@ -0,0 +1,487 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_packer_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_packer_station.vue new file mode 100644 index 00000000..8f081626 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_packer_station.vue @@ -0,0 +1,423 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_paint_line.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_paint_line.vue new file mode 100644 index 00000000..015d6264 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_paint_line.vue @@ -0,0 +1,487 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_smart_plc_test.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_smart_plc_test.vue new file mode 100644 index 00000000..67f88303 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_smart_plc_test.vue @@ -0,0 +1,504 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_device.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_device.vue new file mode 100644 index 00000000..27ad70c0 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_device.vue @@ -0,0 +1,465 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_empty_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_empty_station.vue new file mode 100644 index 00000000..02a3e183 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_empty_station.vue @@ -0,0 +1,443 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_full_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_full_station.vue new file mode 100644 index 00000000..66122e1e --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_full_station.vue @@ -0,0 +1,460 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_pick_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_pick_station.vue new file mode 100644 index 00000000..7ecfc6d2 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_pick_station.vue @@ -0,0 +1,449 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_pour_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_pour_station.vue new file mode 100644 index 00000000..e917194b --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_special_pour_station.vue @@ -0,0 +1,455 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_stacking_station.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_stacking_station.vue new file mode 100644 index 00000000..8f081626 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_stacking_station.vue @@ -0,0 +1,423 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_threestation_smart.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_threestation_smart.vue new file mode 100644 index 00000000..41d2800d --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_threestation_smart.vue @@ -0,0 +1,487 @@ + + + + + diff --git a/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test.vue b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test.vue new file mode 100644 index 00000000..67f88303 --- /dev/null +++ b/wcs/nladmin-ui/src/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test.vue @@ -0,0 +1,504 @@ + + + + +