| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | private StaError1 staError1; |
| | | 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); |
| | | |
| | | |
| | | |
| | | public static final ArrayList<Integer> staNos1= new ArrayList<Integer>() {{ |
| | | 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);add(1024);add(1071); |
| | | }}; |
| | | public static final ArrayList<Integer> staNos2= new ArrayList<Integer>() {{ |
| | | add(1025);add(1026);add(1027);add(1028);add(1029);add(1030);add(1031);add(1032);add(1033); |
| | | add(1034);add(1035);add(1036);add(1037);add(1039);add(1040);add(1041);add(1042);add(1043); |
| | | add(1044);add(1045);add(1046);add(1047);add(1048); |
| | | }}; |
| | | |
| | | public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{ |
| | | add(1); add(2); |
| | | }}; |
| | | public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{ |
| | | add(104); add(106); |
| | | }}; |
| | | |
| | | /** |
| | | * 条码数量 |
| | | */ |
| | | private int barcodeSize = 2; |
| | | public static final ArrayList<Integer> BarcodeList1 = new ArrayList<Integer>() {{ |
| | | add(1002); add(1004);add(1006); add(1008); |
| | | }}; |
| | | public static final ArrayList<Integer> BarcodeList2 = new ArrayList<Integer>() {{ |
| | | add(1041); add(1043);add(1045); add(1047); |
| | | }}; |
| | | |
| | | /** |
| | | * 入出库模式 |
| | |
| | | } |
| | | |
| | | private ArrayList<Integer> getStaNo() { |
| | | return staNos; |
| | | if (slave.getId() == 1){ |
| | | return staNos2; |
| | | }else { |
| | | return staNos1; |
| | | } |
| | | |
| | | } |
| | | private ArrayList<Integer> getBarcodeList() { |
| | | if (slave.getId() == 1){ |
| | | return BarcodeList2; |
| | | }else { |
| | | return BarcodeList1; |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | * 读取状态 ====> 整块plc |
| | | */ |
| | | private void read() { |
| | | |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | // 站点信息 |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (8*8)); |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNos.size()*8)); |
| | | if (result.IsSuccess) { |
| | | for (int i = 0; i < staNos.size(); i++) { |
| | | Integer siteId = staNos.get(i); // 站点编号 |
| | |
| | | News.error("SiemensCrn"+" - 4"+" - 读取输送线plc状态信息失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); |
| | | return; |
| | | } |
| | | |
| | | ArrayList<Integer> barcodeList = getBarcodeList(); |
| | | // 条码扫描器 |
| | | OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.400", (short) (BarcodeList.size() * 10)); |
| | | OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.860", (short) (barcodeList.size() * 8)); |
| | | if (barcodeResult.IsSuccess) { |
| | | for (int i = 0; i < BarcodeList.size(); i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*10 + 2,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, BarcodeList.get(i)); |
| | | for (int i = 0; i < barcodeList.size(); i++) { |
| | | String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*8 ,8, "UTF-8"); |
| | | BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeList.get(i)); |
| | | if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) { |
| | | barcodeThread.setBarcode(barcode); |
| | | } |
| | |
| | | } |
| | | |
| | | // 外形检测 |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.430", (short) (staNosErrList.size() *4)); // 不连续,多读中间一个 |
| | | OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.800", (short) (barcodeList.size() *6)); // 不连续,多读中间一个 |
| | | if (resultErr.IsSuccess){ |
| | | for (int i = 0;i<staNosErrList.size();i++){ |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4, 1); |
| | | StaProtocol staProtocol = station.get(staNosErrList.get(i)); |
| | | for (int i = 0;i<barcodeList.size();i++){ |
| | | StaProtocol staProtocol = station.get(barcodeList.get(i)); |
| | | short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 4); |
| | | staProtocol.setGoodsHeight(goodsHeight); |
| | | boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4+2, 1); |
| | | staProtocol.setFrontErr(status[0]); |
| | | staProtocol.setBackErr(status[1]); |
| | | staProtocol.setHighErr(status[2]); |
| | |
| | | staProtocol.setGroupSupportErr(status[5]); |
| | | staProtocol.setBarcodeErr(status[6]); |
| | | staProtocol.setWeightErr(status[7]); |
| | | short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 4 + 2); |
| | | staProtocol.setGoodsHeight(goodsHeight); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | |
| | | ArrayList<Integer> staNos = getStaNo(); |
| | | int address = staNos.indexOf(staProtocol.getSiteId()) * 4; |
| | | |
| | | OperateResult write; |