| | |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{ |
| | | add(100);add(101);add(102);add(103);add(104);add(105);add(106);add(107); |
| | | add(1001);add(1002);add(1003);add(1004);add(1005);add(1006);add(1007); |
| | | add(1008);add(1009);add(1010);add(1011);add(1012);add(1013);add(1014);add(1015); |
| | | add(1016);add(1017);add(1018);add(1019);add(1020);add(1021);add(1022);add(1023); |
| | | }}; |
| | | |
| | | /** |
| | | * 条码数量 |
| | | */ |
| | | private int barcodeSize = 4; |
| | | private int barcodeSize = 3; |
| | | |
| | | /** |
| | | * 入出库模式 |
| | |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | // staProtocol.setAutoing(true); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | // staProtocol.setLoading(true); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | // staProtocol.setInEnable(true); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setOutEnable(true);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | staProtocol.setHigh(status[6]); // 高库位 |
| | | staProtocol.setLow(status[7]); // 低库位 |
| | | staProtocol.setStaOk(status[8]); // 就绪 |
| | | |
| | | |
| | | |
| | |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | if (result.IsSuccess) { |
| | |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | basDevps.add(staProtocol.toSqlModel()); |
| | | } |
| | | |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | | if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) { |
| | | throw new Exception("更新数据库数据失败"); |
| | | try{ |
| | | BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); |
| | | if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) { |
| | | throw new Exception("更新数据库数据失败"); |
| | | } |
| | | } catch (Exception e){ |
| | | log.error("e:"+e.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】更新数据库数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | log.error("更新数据库数据失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | } |
| | | |
| | | DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); |
| | | deviceErrorService.deleteDeviceError("devp", slave.getId()); |
| | | try{ |
| | | DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); |
| | | deviceErrorService.deleteDeviceError("devp", slave.getId()); |
| | | } catch (Exception e){ |
| | | log.error("e:"+e.getMessage()); |
| | | } |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】读取输送线plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | // log.error("读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | |
| | | |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | |
| | | //更新命令日志 |
| | | CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class); |
| | | CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class); |
| | | CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId()); |
| | | CommandInfoLog commandInfoLog = new CommandInfoLog(); |
| | | if (commandInfo != null) { |
| | | commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); |
| | | commandInfoLog.setId(null); |
| | | }else { |
| | | Date now = new Date(); |
| | | commandInfoLog.setCommand(JSON.toJSONString(staProtocol)); |
| | | commandInfoLog.setCommandStatus(3); |
| | | commandInfoLog.setStartTime(now); |
| | | commandInfoLog.setExecuteTime(now); |
| | | commandInfoLog.setCompleteTime(now); |
| | | commandInfoLog.setDevice(SlaveType.Devp.toString()); |
| | | commandInfoLog.setWrkNo(9999); |
| | | commandInfoLog.setTaskNo("9999"); |
| | | commandInfoLog.setCommandDesc("手动命令"); |
| | | } |
| | | // //更新命令日志 |
| | | // CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class); |
| | | // CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class); |
| | | // CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId()); |
| | | // CommandInfoLog commandInfoLog = new CommandInfoLog(); |
| | | // if (commandInfo != null) { |
| | | // commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class); |
| | | // commandInfoLog.setId(null); |
| | | // }else { |
| | | // Date now = new Date(); |
| | | // commandInfoLog.setCommand(JSON.toJSONString(staProtocol)); |
| | | // commandInfoLog.setCommandStatus(3); |
| | | // commandInfoLog.setStartTime(now); |
| | | // commandInfoLog.setExecuteTime(now); |
| | | // commandInfoLog.setCompleteTime(now); |
| | | // commandInfoLog.setDevice(SlaveType.Devp.toString()); |
| | | // commandInfoLog.setWrkNo(9999); |
| | | // commandInfoLog.setTaskNo("9999"); |
| | | // commandInfoLog.setCommandDesc("手动命令"); |
| | | // } |
| | | |
| | | OperateResult writeResult; |
| | | //任务下发次数 |
| | |
| | | //任务下发成功标识 |
| | | boolean writeFlag = false; |
| | | while(writeCount < 5){ |
| | | OperateResult writeResult1 = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult writeResult2 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo()); // 目标站 |
| | | OperateResult writeResult1 = siemensS7Net.Write("DB101." + index*8, staProtocol.getWorkNo()); // 工作号 |
| | | OperateResult writeResult2 = siemensS7Net.Write("DB101." + (index*8+4), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | if(writeResult1.IsSuccess && writeResult2.IsSuccess){ |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB101.0" + index*8, (short)4); |
| | | |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发成功"); |
| | | commandInfoLogService.insert(commandInfoLog); |
| | | // commandInfoLog.setDeviceLog("指令下发成功"); |
| | | // commandInfoLogService.insert(commandInfoLog); |
| | | |
| | | if(readResult.IsSuccess){ |
| | | Integer workNo = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); |
| | |
| | | log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | |
| | | //更新指令日志 |
| | | commandInfoLog.setDeviceLog("指令下发失败"); |
| | | commandInfoLogService.insert(commandInfoLog); |
| | | // commandInfoLog.setDeviceLog("指令下发失败"); |
| | | // commandInfoLogService.insert(commandInfoLog); |
| | | } |
| | | Thread.sleep(200); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置入库标记 |
| | | */ |
| | | @Override |
| | | public void setGrossWt(Integer siteId, Double grossWt) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null != staProtocol) { |
| | | staProtocol.setGrossWt(grossWt); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | siemensS7Net.ConnectClose(); |