| | |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ |
| | | add(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);add(109); |
| | | // add(201);add(202);add(203);add(204); |
| | | // add(301);add(302);add(303);add(304);add(305);add(306); |
| | | add(101);add(102);add(103);add(104); |
| | | add(201);add(202);add(203);add(204);add(205);add(206); |
| | | add(207);add(208);add(209);add(210);add(211);add(212); |
| | | add(213);add(105); |
| | | }}; |
| | | |
| | | /** |
| | | * 条码数量 |
| | | */ |
| | | private int barcodeSize = 1; |
| | | private int barcodeSize = 2; |
| | | public IoModeType ioMode = IoModeType.NONE; |
| | | |
| | | public int[] startSignal = new int[48]; |
| | | public int[][] startSignal = new int[48][2]; |
| | | |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | | this.slave = slave; |
| | |
| | | // 写数据 ID+目标站 |
| | | case 2: |
| | | write((StaProtocol)task.getData()); |
| | | break; |
| | | // 写数据 103站点写入PACK码 |
| | | case 4: |
| | | write103((String)task.getData()); |
| | | break; |
| | | // 火警信号 |
| | | case 5: |
| | | StaProtocol staProtocol2 = (StaProtocol)task.getData(); |
| | | siemensS7Net.Write("DB102.0" + staProtocol2.getSiteId(), staProtocol2.getStaNo()==1); |
| | | break; |
| | | //复位测试信号 |
| | | case 3: |
| | |
| | | } |
| | | |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.190",(short)(barcodeSize*12)); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.190",(short)(26)); |
| | | OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB100.216",(short)(6)); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 0; i < barcodeSize; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*12,12, "UTF-8"); |
| | | String barcode =siemensS7Net.getByteTransform().TransString(result2.Content,0,26, "UTF-8"); |
| | | // String barcode=new String(result2.Content,i*12,12); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | if (result5.IsSuccess) { |
| | | String barcode =siemensS7Net.getByteTransform().TransString(result5.Content,0,6, "UTF-8"); |
| | | // String barcode=new String(result2.Content,i*12,12); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 2); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB102.0", (short) 96); |
| | | OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB102.0", (short) 96); |
| | | if(result3.IsSuccess) { |
| | | for(int i=0; i<48; i++){ |
| | | startSignal[i] = siemensS7Net.getByteTransform().TransInt16(result3.Content, i*2); |
| | | startSignal[i][0] = siemensS7Net.getByteTransform().TransInt16(result3.Content, i*2); |
| | | startSignal[i][1] = siemensS7Net.getByteTransform().TransInt16(result4.Content, i*2); |
| | | } |
| | | } |
| | | // OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB200.0"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 写入 pack码 =====> 单站点写入 |
| | | */ |
| | | private void write103(String packNo){ |
| | | try{ |
| | | OperateResult write = siemensS7Net.Write("DB100.", packNo); |
| | | if (!write.IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(packNo))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(packNo)); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】 输送线命令下发 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(packNo))); |
| | | log.info("输送线命令下发 [id:{}] >>>>> 命令下发: {}", slave.getId(), JSON.toJSON(packNo)); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("103站点写入数据失败,输送线线程write103"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 写入 ID+目标站 =====> 单站点写入 |
| | | */ |
| | | private void write(StaProtocol staProtocol) throws InterruptedException { |