| | |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.common.utils.News; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.protocol.StaError1; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import com.zy.entity.BasDevp; |
| | | import com.zy.service.BasDevpService; |
| | | import com.zy.utils.News; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | |
| | | private SiemensS7Net siemensS7Net; |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | // public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ |
| | | // |
| | | // }}; |
| | | public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{ |
| | | add(101);add(102);add(103);add(104); |
| | | add(105);add(106);add(107);add(108); |
| | | private StaError1 staError1; |
| | | public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{ |
| | | add(100);add(101);add(102);add(103); |
| | | add(104);add(105);add(106);add(107); |
| | | add(200);add(201);add(202);add(203);add(210); |
| | | add(300);add(301);add(302);add(303);add(304);add(305); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{ |
| | | add(201);add(202);add(203); |
| | | add(204);add(205);add(206); |
| | | public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{ |
| | | add(1); add(2); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{ |
| | | add(301);add(302);add(303); |
| | | add(304);add(305);add(306); |
| | | public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{ |
| | | add(101); add(103); |
| | | }}; |
| | | |
| | | |
| | | private Integer count=0; |
| | | |
| | | /** |
| | | * 条码数量 |
| | | */ |
| | | private int barcodeSize = 6; |
| | | private int barcodeSize = 2; |
| | | |
| | | /** |
| | | * 入出库模式 |
| | |
| | | * 3.出库启动中 (不能生成入库工作档) |
| | | * 4.出库模式 |
| | | */ |
| | | public IoModeType ioModeOf2F = IoModeType.NONE; |
| | | public IoModeType ioModeOf101 = IoModeType.NONE; |
| | | public IoModeType ioModeOf103 = IoModeType.NONE; |
| | | public IoModeType ioModeOf305 = IoModeType.NONE; |
| | | // public IoModeType ioMode = IoModeType.NONE; |
| | | public IoModeType ioModeOf4F = IoModeType.NONE; |
| | | // public IoModeType ioModeOf4F = IoModeType.NONE; |
| | | // public IoModeType ioMode = IoModeType.NONE; |
| | | |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | |
| | | } |
| | | |
| | | private ArrayList<Integer> getStaNo() { |
| | | switch (slave.getId()) { |
| | | case 1: |
| | | return staNos1; |
| | | case 2: |
| | | return staNos2; |
| | | case 3: |
| | | return staNos3; |
| | | default: |
| | | throw new CoolException("服务器异常"); |
| | | } |
| | | return staNos; |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 写数据 ID+目标站 |
| | | case 2: |
| | | write((StaProtocol)task.getData()); |
| | | log.error("输送线下发命令:"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo()); |
| | | break; |
| | | // 写开门 |
| | | case 3: |
| | | write2((Integer) task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | // 心跳 |
| | | // heartbeat(); |
| | | Thread.sleep(300); |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | private void write2(int flag) throws InterruptedException { |
| | | if (flag == 0) { |
| | | OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1); |
| | | if (readOpenResult.IsSuccess) { |
| | | boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1); |
| | | booleans[1] = true; // 关门信号 |
| | | booleans[0] = false; |
| | | siemensS7Net.Write("DB100.826",booleans); |
| | | } |
| | | } else if(flag == 1) { |
| | | OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1); |
| | | if (readOpenResult.IsSuccess) { |
| | | boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1); |
| | | booleans[0] = true; // 开门信号 |
| | | booleans[1] = false; |
| | | siemensS7Net.Write("DB100.826",booleans); |
| | | } |
| | | } |
| | | Thread.sleep(500); |
| | | OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1); |
| | | if (readOpenResult.IsSuccess) { |
| | | boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1); |
| | | StaProtocol staProtocol = station.get(305); |
| | | if (null == staProtocol) { |
| | | staProtocol = new StaProtocol(); |
| | | staProtocol.setSiteId(305); |
| | | station.put(305, staProtocol); |
| | | } |
| | | staProtocol.setOpenAskDoor(booleans[0]); |
| | | staProtocol.setCloseAskDoor(booleans[1]); |
| | | staProtocol.setIfOpenDoor(booleans[2]); |
| | | staProtocol.setIfCloseDoor(booleans[3]); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化站点状态 |
| | | */ |
| | | private void initSite() { |
| | | count ++; |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | if(count > 77) { |
| | | // 站点编号 |
| | | for (Integer siteId : staNos) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo((short) 0); // ID |
| | | staProtocol.setWorkNo(0); // ID |
| | | staProtocol.setAutoing(false); // 自动 |
| | | staProtocol.setLoading(false); // 有物 |
| | | staProtocol.setInEnable(false); // 可入 |
| | |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | count = 0; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | private void read() throws InterruptedException { |
| | | // // 更新入出库模式 |
| | | // updateIoMode(); |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int staNoSize = staNos.size(); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4)); |
| | | // OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB100.2", (short) (staNoSize*2)); |
| | | // ArrayList<Integer> staNos = getStaNo(); |
| | | // int staNoSize = staNos.size(); |
| | | // 读一楼连续8个站点 |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (8*8)); |
| | | if (result.IsSuccess) { |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | for (int i = 0; i < 8; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4)); // 工作号 |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 工作号 |
| | | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4 + 2)); // 目标站 |
| | | } |
| | | } |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 目标站 |
| | | |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.2", (short) (staNoSize * 4)); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 0; i < staNoSize; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*4, 1); |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | } |
| | | // 读二楼连续4个站点 |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.800", (short) (4*8)); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 8; i < 12; i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | | staProtocol = new StaProtocol(); |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result2.Content, (i-8)*8)); // 工作号 |
| | | |
| | | if (staProtocol.getStamp()>=2 && !staProtocol.isLoading()){ |
| | | staProtocol.setStamp(0); |
| | | }else if (staProtocol.getStamp()<2 && staProtocol.isLoading()){ |
| | | //lfd入库印记 当stamp>=2时才入库 |
| | | staProtocol.setStamp(staProtocol.getStamp()+1); |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result2.Content, (i-8)*8 + 4)); // 目标站 |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result2.Content, (i-8)*8 + 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | staProtocol.setHigh(status[6]); // 高库位 |
| | | staProtocol.setLow(status[7]); // 低库位 |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | } |
| | | // 读二楼210 |
| | | OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB101.880", (short) (8)); |
| | | if (result3.IsSuccess) { |
| | | Integer siteId = staNos.get(12); // 站点编号210 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | | staProtocol = new StaProtocol(); |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result3.Content, 0)); // 工作号 |
| | | |
| | | // Thread.sleep(200); |
| | | // OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 186); |
| | | // if (result0.IsSuccess) { |
| | | // for (int i = 0; i < 93; i++) { |
| | | // Integer siteId = staNos.get(i); // 站点编号 |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result3.Content, 4)); // 目标站 |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | staProtocol.setHigh(status[6]); // 高库位 |
| | | staProtocol.setLow(status[7]); // 低库位 |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | // 读二楼3区 |
| | | OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB101.1600", (short) (6*8)); |
| | | if (result2.IsSuccess) { |
| | | for (int i = 13; i < staNos.size(); i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null == staProtocol) { |
| | | staProtocol = new StaProtocol(); |
| | | staProtocol.setSiteId(siteId); |
| | | station.put(siteId, staProtocol); |
| | | } |
| | | staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(result4.Content, (i-13)*8)); // 工作号 |
| | | |
| | | staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result4.Content, (i-13)*8 + 4)); // 目标站 |
| | | |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(result4.Content, (i-13)*8 + 6, 2); |
| | | staProtocol.setAutoing(status[0]); // 自动 |
| | | staProtocol.setLoading(status[1]); // 有物 |
| | | staProtocol.setInEnable(status[2]); // 可入 |
| | | staProtocol.setOutEnable(status[3]);// 可出 |
| | | staProtocol.setEmptyMk(status[4]); // 空板信号 |
| | | staProtocol.setFullPlt(status[5]); // 满托盘 |
| | | staProtocol.setHigh(status[6]); // 高库位 |
| | | staProtocol.setLow(status[7]); // 低库位 |
| | | |
| | | if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { |
| | | staProtocol.setPakMk(true); |
| | | } |
| | | } |
| | | } |
| | | // BasRgvMapService basRgvMapService = SpringUtils.getBean(BasRgvMapService.class); |
| | | //RGV小车1 |
| | | // Thread.sleep(100); |
| | | // OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB50.200",(short)10); |
| | | // if (result3.IsSuccess) { |
| | | // BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result3.Content, 0)); |
| | | // if (!Cools.isEmpty(basRgvMap)){ |
| | | // Integer siteId = 1; |
| | | // StaProtocol staProtocol = station.get(siteId); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(siteId); |
| | | // station.put(siteId, staProtocol); |
| | | // } |
| | | // staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2)); // 目标站 |
| | | // staProtocol.setAutoing(true); |
| | | // staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 8))); |
| | | // } |
| | | // } |
| | | //条码扫描器 |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.0",(short)(barcodeSize*8)); |
| | | if (result2.IsSuccess && 1!=1) { |
| | | if (slave.getId()==1){ |
| | | for (int i = 0; i < barcodeSize/3; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)){ |
| | | // && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | }else if (slave.getId()==2){ |
| | | for (int i = barcodeSize/3; i < barcodeSize; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,(i-barcodeSize/3)*8,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)){ |
| | | // && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | }else if (slave.getId()==3){ |
| | | for (int i = barcodeSize/3+1; i < barcodeSize; i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,(i-(barcodeSize/3)*2)*8,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)){ |
| | | // && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | |
| | | // 条码扫描器 |
| | | OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.1672", (short) ((BarcodeList.size()+1) * 8)); // 不连续 |
| | | if (barcodeResult.IsSuccess) { |
| | | for (int i = 0; i < BarcodeList.size(); i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*16,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, BarcodeList.get(i)); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (result.IsSuccess && result1.IsSuccess) { |
| | | // 外形检测 |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.1652", (short) ((staNosErrList.size()+1)*4)); // 不连续,多读中间一个 |
| | | if (resultErr.IsSuccess){ |
| | | for (int i = 0;i<staNosErrList.size();i++){ |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*9+2, 1); |
| | | StaProtocol staProtocol = station.get(staNosErrList.get(i)); |
| | | staProtocol.setFrontErr(status[0]); |
| | | staProtocol.setBackErr(status[1]); |
| | | staProtocol.setHighErr(status[2]); |
| | | staProtocol.setLeftErr(status[3]); |
| | | staProtocol.setRightErr(status[4]); |
| | | staProtocol.setWeightErr(status[5]); |
| | | staProtocol.setBarcodeErr(status[6]); |
| | | } |
| | | } |
| | | // 读一楼连续8个站点,故障信息反馈 |
| | | OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.3312", (short) (8*2)); |
| | | if (resultErr2.IsSuccess) { |
| | | for (int i = 0; i < 8; i++) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*2 + 1, 1); |
| | | StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号 |
| | | staProtocol.setBreakerErr(status[0]); |
| | | staProtocol.setInfraredErr(status[1]); |
| | | staProtocol.setOutTimeErr(status[2]); |
| | | staProtocol.setSeizeSeatErr(status[3]); |
| | | staProtocol.setWrkYgoodsN(status[4]); |
| | | staProtocol.setInverterErr(status[5]); |
| | | staProtocol.setContactErr(status[6]); |
| | | staProtocol.setUpcontactErr(status[7]); |
| | | |
| | | } |
| | | } |
| | | // 读二楼连续4个站点,故障信息反馈 |
| | | OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB101.3512", (short) (4*2)); |
| | | if (resultErr3.IsSuccess) { |
| | | for (int i = 8; i < 12; i++) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr3.Content, (i-8) * 2 + 1, 1); |
| | | StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号 |
| | | staProtocol.setBreakerErr(status[0]); |
| | | staProtocol.setInfraredErr(status[1]); |
| | | staProtocol.setOutTimeErr(status[2]); |
| | | staProtocol.setSeizeSeatErr(status[3]); |
| | | staProtocol.setWrkYgoodsN(status[4]); |
| | | staProtocol.setInverterErr(status[5]); |
| | | staProtocol.setContactErr(status[6]); |
| | | staProtocol.setUpcontactErr(status[7]); |
| | | } |
| | | } |
| | | // 读三区故障信息反馈 |
| | | OperateResultExOne<byte[]> resultErr4 = siemensS7Net.Read("DB101.2096", (short) (6*2)); |
| | | if (resultErr4.IsSuccess) { |
| | | for (int i = 13; i < staNos.size(); i++) { |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr4.Content, (i-13) * 2 + 1, 1); |
| | | StaProtocol staProtocol = station.get(staNos.get(i)); // 站点编号 |
| | | staProtocol.setBreakerErr(status[0]); |
| | | staProtocol.setInfraredErr(status[1]); |
| | | staProtocol.setOutTimeErr(status[2]); |
| | | staProtocol.setSeizeSeatErr(status[3]); |
| | | staProtocol.setWrkYgoodsN(status[4]); |
| | | staProtocol.setInverterErr(status[5]); |
| | | staProtocol.setContactErr(status[6]); |
| | | staProtocol.setUpcontactErr(status[7]); |
| | | } |
| | | } |
| | | |
| | | // 一楼出入库模式切换 |
| | | // OperateResultExOne<byte[]> ioModeResult = siemensS7Net.Read("DB101.3724", (short) 1); |
| | | // if (ioModeResult.IsSuccess) { |
| | | // boolean[] ioModelBooleans = siemensS7Net.getByteTransform().TransBool(ioModeResult.Content, 0, 1); |
| | | //// log.info("读取出入库模式:" + Arrays.toString(ioModelBooleans)); |
| | | // WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class); |
| | | // if (ioModelBooleans[0]) { // 100切入库 |
| | | // if (ioModeOf101 == IoModeType.PAKOUT_MODE) { |
| | | // int outCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 101) |
| | | // .eq("sta_no", 100).in("wrk_sts", 12, 13, 14)); |
| | | // if (outCount == 0) { |
| | | // boolean[] booleans = new boolean[8]; |
| | | // booleans[0]=true; |
| | | // ioModeOf101 = IoModeType.PAKIN_MODE; |
| | | // siemensS7Net.Write("DB100.824",booleans); |
| | | // log.info("101切换入库模式成功"); |
| | | // } |
| | | // } |
| | | // } |
| | | // if (ioModelBooleans[1]) { // 100切出库 |
| | | // if (ioModeOf101 == IoModeType.PAKIN_MODE) { |
| | | // int inCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 1) |
| | | // .eq("sta_no", 101).in("wrk_sts", 2, 3, 4)); |
| | | // if (inCount == 0) { |
| | | // boolean[] booleans = new boolean[8]; |
| | | // booleans[0]=true; |
| | | // ioModeOf101 = IoModeType.PAKOUT_MODE; |
| | | // siemensS7Net.Write("DB100.824",booleans); |
| | | // log.info("101切换出库模式成功"); |
| | | // } |
| | | // } |
| | | // } |
| | | // if (ioModelBooleans[2]) { // 102切入库 |
| | | // if (ioModeOf103 == IoModeType.PAKOUT_MODE) { |
| | | // int outCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 101) |
| | | // .eq("sta_no", 102).in("wrk_sts", 12, 13, 14)); |
| | | // if (outCount == 0) { |
| | | // boolean[] booleans = new boolean[8]; |
| | | // booleans[1]=true; |
| | | // ioModeOf103 = IoModeType.PAKIN_MODE; |
| | | // siemensS7Net.Write("DB100.824",booleans); |
| | | // log.info("103切换入库模式成功"); |
| | | // } |
| | | // } |
| | | // } |
| | | // if (ioModelBooleans[3]) { // 102切出库 |
| | | // if (ioModeOf103 == IoModeType.PAKIN_MODE) { |
| | | // int inCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 1) |
| | | // .eq("sta_no", 103).in("wrk_sts", 2, 3, 4)); |
| | | // if (inCount == 0) { |
| | | // boolean[] booleans = new boolean[8]; |
| | | // booleans[1]=true; |
| | | // ioModeOf103 = IoModeType.PAKOUT_MODE; |
| | | // siemensS7Net.Write("DB100.824",booleans); |
| | | // log.info("103切换出库模式成功"); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // 读开门信号 |
| | | // OperateResultExOne<byte[]> readOpenResult = siemensS7Net.Read("DB100.826", (short) 1); |
| | | // if (readOpenResult.IsSuccess) { |
| | | // boolean[] booleans = siemensS7Net.getByteTransform().TransBool(readOpenResult.Content, 0, 1); |
| | | // StaProtocol staProtocol = station.get(305); |
| | | // if (null == staProtocol) { |
| | | // staProtocol = new StaProtocol(); |
| | | // staProtocol.setSiteId(305); |
| | | // station.put(305, staProtocol); |
| | | // } |
| | | // staProtocol.setOpenAskDoor(booleans[0]); |
| | | // staProtocol.setCloseAskDoor(booleans[1]); |
| | | // staProtocol.setIfOpenDoor(booleans[2]); |
| | | // staProtocol.setIfCloseDoor(booleans[3]); |
| | | //// log.info("开门信号:" + Arrays.toString(booleans)); |
| | | // } |
| | | |
| | | |
| | | //// OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB13.400", (short) 3); |
| | | //// if (resultErr3.IsSuccess) { |
| | | //// if (staError1 == null){ |
| | | //// staError1 = new StaError1(); |
| | | // } |
| | | // boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr3.Content, 0, 3); |
| | | // staError1.setEMERGENCY_Stop_Core(status[0]); |
| | | // staError1.setEMERGENCY_STOP1(status[1]); |
| | | // staError1.setEMERGENCY_STOP2(status[2]); |
| | | // staError1.setEMERGENCY_STOP3(status[3]); |
| | | // staError1.setEMERGENCY_STOP4(status[4]); |
| | | // |
| | | // staError1.setDoor_EMERGENCY_STOP1(status[5]); |
| | | // staError1.setDoor_EMERGENCY_STOP2(status[6]); |
| | | // staError1.setDoor_EMERGENCY_STOP3(status[7]); |
| | | // staError1.setDoor_EMERGENCY_STOP4(status[8]); |
| | | // staError1.setDoor_EMERGENCY_STOP5(status[9]); |
| | | // staError1.setDoor_EMERGENCY_STOP6(status[10]); |
| | | // |
| | | // staError1.setDoor_Open_Err1(status[11]); |
| | | // staError1.setDoor_Open_Err1(status[12]); |
| | | // staError1.setDoor_Open_Err1(status[13]); |
| | | // staError1.setDoor_Open_Err1(status[14]); |
| | | // staError1.setDoor_Open_Err1(status[15]); |
| | | // staError1.setDoor_Open_Err1(status[16]); |
| | | // |
| | | // } |
| | | |
| | | |
| | | if (result.IsSuccess) { |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int index = staNos.indexOf(staProtocol.getSiteId()); |
| | | short[] array = new short[2]; |
| | | array[0] = staProtocol.getWorkNo(); |
| | | array[1] = staProtocol.getStaNo(); |
| | | // OperateResult write = siemensS7Net.Write("DB100." + index*4, array); |
| | | |
| | | OperateResult write = null; |
| | | int address = -1; |
| | | switch (staProtocol.getSiteId()) { |
| | | case 100: address = 0; break; |
| | | case 101: address = 4; break; |
| | | case 102: address = 8; break; |
| | | case 103: address = 12; break; |
| | | case 104: address = 16; break; |
| | | case 105: address = 20; break; |
| | | case 106: address = 24; break; |
| | | case 107: address = 28; break; |
| | | case 200: address = 400; break; |
| | | case 201: address = 404; break; |
| | | case 202: address = 408; break; |
| | | case 203: address = 412; break; |
| | | case 210: address = 440; break; |
| | | case 300: address = 800; break; |
| | | case 301: address = 804; break; |
| | | case 302: address = 808; break; |
| | | case 303: address = 812; break; |
| | | case 304: address = 816; break; |
| | | case 305: address = 820; break; |
| | | default: |
| | | } |
| | | if(address == -1) { |
| | | throw new CoolException("写入站点异常:" + staProtocol.getSiteId()); |
| | | } |
| | | OperateResult write; |
| | | OperateResult write1; |
| | | //任务下发次数 |
| | | int writeCount = 0; |
| | | do { |
| | | // write = siemensS7Net.Write("DB100.0" + index*2, staProtocol.getWorkNo()); // 工作号 |
| | | // Thread.sleep(500); |
| | | // write1 = siemensS7Net.Write("DB100.0" + index*2+2, staProtocol.getStaNo()); // 目标站 |
| | | write = siemensS7Net.Write("DB100." + index*4, array); |
| | | if(write.IsSuccess){ |
| | | Thread.sleep(200); |
| | | OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100.0" + index*2, (short) 2); |
| | | OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB100.0" + index*2+2, (short) 2); |
| | | if(readResult.IsSuccess && readResult1.IsSuccess){ |
| | | short workNo = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); |
| | | short staNo = siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0); |
| | | if(staProtocol.getWorkNo().equals(workNo) && staProtocol.getStaNo().equals(staNo)){ |
| | | //任务命令写入成功 |
| | | log.info("写入堆垛机命令后返回成功,并且回读成功。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | break; |
| | | } else {//返回结果是成功了,但是真实值不相同 |
| | | writeCount++; |
| | | log.error("写入堆垛机命令后返回成功,但是读取任务值不一致。堆垛机plc编号={},{},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | } else { |
| | | writeCount++; |
| | | log.error("写入堆垛机命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | write1 = siemensS7Net.Write("DB100." + (address+2), staProtocol.getStaNo()); // 目标站 |
| | | write = siemensS7Net.Write("DB100." + address, staProtocol.getWorkNo().shortValue()); // 工作号 |
| | | Thread.sleep(200); |
| | | if(write.IsSuccess && write1.IsSuccess){ |
| | | break; |
| | | } |
| | | else { |
| | | writeCount++; |
| | | log.error("写入堆垛机命令后读取失败。堆垛机plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | log.error("写入输送线命令失败。输送线plc编号={},站点数据={},写入次数={}", slave.getId(), JSON.toJSON(staProtocol), writeCount); |
| | | } |
| | | }while (writeCount<5); |
| | | |
| | |
| | | |
| | | // 更新入出库模式 |
| | | private void updateIoMode() throws InterruptedException { |
| | | if (this.ioModeOf2F != IoModeType.NONE) { |
| | | if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | News.error("SiemensDevp"+" - 6"+" - 写入输送线2F入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | } |
| | | } |
| | | // if (this.ioModeOf2F != IoModeType.NONE) { |
| | | // if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) { |
| | | // OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线2F入出库模式失败。输送线plc编号={1}", slave.getId())); |
| | | // News.error("SiemensDevp"+" - 6"+" - 写入输送线2F入出库模式失败。输送线plc编号={}", slave.getId()); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | siemensS7Net.ConnectClose(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(staNos1.indexOf(129)); |
| | | System.out.println(staNos1.size()); |
| | | for (int i = 0; i<staNos1.size(); i++) { |
| | | // System.out.println(i*2); |
| | | // System.out.println(i*2 + 200); |
| | | // System.out.println(i); |
| | | } |
| | | int index = staNos1.indexOf(128); |
| | | System.out.println(index*2); |
| | | System.out.println(index*2 + 200); |
| | | } |
| | | |
| | | // public static void main(String[] args) throws Exception { |
| | | // DevpSlave slave = new DevpSlave(); |
| | | // slave.setIp("192.168.2.125"); |
| | | // SiemensDevpThread devpThread = new SiemensDevpThread(slave); |
| | | // devpThread.connect(); |
| | | // devpThread.read(); |
| | | public static void main(String[] args) throws Exception { |
| | | DevpSlave slave = new DevpSlave(); |
| | | slave.setIp("10.10.10.18"); |
| | | SiemensDevpThread devpThread = new SiemensDevpThread(slave); |
| | | devpThread.connect(); |
| | | devpThread.write2(0); |
| | | devpThread.read(); |
| | | // // 写 |
| | | // StaProtocol staProtocol = devpThread.getStation().get(1); |
| | | // staProtocol.setWorkNo((short) 232); |
| | |
| | | // // 读 |
| | | // devpThread.read(); |
| | | // System.out.println(JSON.toJSONString(devpThread.station)); |
| | | // |
| | | // } |
| | | |
| | | } |
| | | |
| | | } |