| | |
| | | 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 startSignal1 = 0; |
| | | public int startSignal2 = 0; |
| | | public int startSignal3 = 0; |
| | | public int startSignal4 = 0; |
| | | public int[][] startSignal = new int[48][2]; |
| | | |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | | this.slave = slave; |
| | |
| | | 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: |
| | | siemensS7Net.Write("DB100." + (150 + (int)task.getData()), 0); |
| | | StaProtocol staProtocol = (StaProtocol)task.getData(); |
| | | siemensS7Net.Write("DB102.0" + staProtocol.getSiteId(), staProtocol.getStaNo()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | // } |
| | | // } |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB150.0", (short) (staNoSize*2)); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB101.0", (short) (staNoSize*2)); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 0; i < staNoSize-1; i++) { |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | |
| | | } |
| | | |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.190",(short)(barcodeSize*8)); |
| | | 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*8,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | 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, 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("DB100.150", (short) 8); |
| | | OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB102.0", (short) 96); |
| | | OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB102.0", (short) 96); |
| | | if(result3.IsSuccess) { |
| | | startSignal1 = siemensS7Net.getByteTransform().TransInt16(result.Content, 0); |
| | | startSignal2 = siemensS7Net.getByteTransform().TransInt16(result.Content, 2); |
| | | startSignal3 = siemensS7Net.getByteTransform().TransInt16(result.Content, 4); |
| | | startSignal4 = siemensS7Net.getByteTransform().TransInt16(result.Content, 6); |
| | | for(int i=0; i<48; i++){ |
| | | 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"); |
| | | // if (result2.IsSuccess) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 写入 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 { |
| | |
| | | return; |
| | | } |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | short[] array = new short[10]; |
| | | short[] array = new short[2]; |
| | | array[0] = staProtocol.getWorkNo(); |
| | | array[1] = staProtocol.getStaNo(); |
| | | OperateResult write = siemensS7Net.Write("DB100." + index*4, array); |