| | |
| | | private void read() throws InterruptedException { |
| | | List<Integer> staNos = slave.getStaNos(); |
| | | int staNoSize = staNos.size(); |
| | | byte[] stationStatus = s7PLC.readByte(StationStatusField.TASK_NUMBER.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + StationStatusField.TASK_NUMBER.getOffset(), StationStatusField.TASK_NUMBER.getOffset() + staNoSize * PlcConstant.STATION_STATUS_LENGTH); |
| | | byte[] stationStatus = s7PLC.readByte(StationStatusField.TASK_NUMBER.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + StationStatusField.TASK_NUMBER.getOffset(), StationStatusField.TASK_NUMBER.getOffset() + staNoSize * StationStatusField.ALL.getByteLength()); |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | // 站点编号 |
| | | Integer siteId = staNos.get(i); |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo((int) ByteUtils.getLong(stationStatus, StationStatusField.TASK_NUMBER.getOffset() + i * PlcConstant.STATION_STATUS_LENGTH)); |
| | | staProtocol.setStaNo((int) ByteUtils.getShort(stationStatus, StationStatusField.FINAL_TARGET.getOffset() + i * PlcConstant.STATION_STATUS_LENGTH)); |
| | | boolean[] status = ByteUtils.getBooleans(stationStatus, StationStatusField.STATUS_WORD.getOffset() + i * PlcConstant.STATION_STATUS_LENGTH, StationStatusField.STATUS_WORD.getByteLength()); |
| | | staProtocol.setWorkNo((int) ByteUtils.getLong(stationStatus, StationStatusField.TASK_NUMBER.getOffset() + i * StationStatusField.ALL.getByteLength())); |
| | | staProtocol.setStaNo((int) ByteUtils.getShort(stationStatus, StationStatusField.FINAL_TARGET.getOffset() + i * StationStatusField.ALL.getByteLength())); |
| | | boolean[] status = ByteUtils.getBooleans(stationStatus, StationStatusField.STATUS_WORD.getOffset() + i * StationStatusField.ALL.getByteLength(), StationStatusField.STATUS_WORD.getByteLength()); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | |
| | | byte[] deviceField = s7PLC.readByte(DeviceField.BARCODE.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + DeviceField.BARCODE.getOffset(), DeviceField.BARCODE.getOffset() + DeviceField.BARCODE.getByteLength() * slave.getBarcodeSize()); |
| | | for (int i = 0; i < slave.getBarcodeSize(); i++) { |
| | | List<Integer> barcodeNumber = slave.getBarcodeNumber(); |
| | | byte[] deviceField = s7PLC.readByte(DeviceField.BARCODE.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + DeviceField.BARCODE.getOffset(), DeviceField.BARCODE.getOffset() + DeviceField.BARCODE.getByteLength() * barcodeNumber.size()); |
| | | for (int i = 0; i < barcodeNumber.size(); i++) { |
| | | String barcode = ByteUtils.getString(deviceField, i * DeviceField.BARCODE.getByteLength(), DeviceField.BARCODE.getByteLength()); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeNumber.get(i)); |
| | | if (Cools.isEmpty(barcode)) { |
| | | barcodeThread.clearBarcode(); |
| | | } else { |
| | |
| | | List<Integer> staNos = slave.getStaNos(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | |
| | | s7PLC.writeInt32(TaskField.TASK_NUMBER.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + (TaskField.DEST_STATION.getOffset() + index * PlcConstant.TASK_LENGTH), staProtocol.getWorkNo()); // 工作号 |
| | | s7PLC.writeInt32(TaskField.TASK_NUMBER.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + (TaskField.DEST_STATION.getOffset() + index * TaskField.ALL.getByteLength()), staProtocol.getWorkNo()); // 工作号 |
| | | Thread.sleep(100); |
| | | s7PLC.writeInt16(TaskField.DEST_STATION.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + (index * PlcConstant.TASK_LENGTH + TaskField.DEST_STATION.getOffset() + TaskField.DEST_STATION.getAddressPattern()), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | s7PLC.writeInt16(TaskField.DEST_STATION.getAddressPattern() + PlcConstant.ADDRESS_CONCATENATION + (index * TaskField.ALL.getByteLength() + TaskField.DEST_STATION.getOffset() + TaskField.DEST_STATION.getAddressPattern()), staProtocol.getStaNo().shortValue()); // 目标站 |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | News.error("SiemensDevp" + " - 4" + " - 写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |