springboot-vue3/src/main/java/com/example/springboot/service/SpianServiceNew.java
@@ -1,267 +1,268 @@
package com.example.springboot.service;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.springboot.component.PLCAutoMes;
import com.example.springboot.component.S7control;
import com.example.springboot.entity.GlassInfo;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.north_glass_buffer1;
import com.example.springboot.entity.StorageTask;
import com.example.springboot.entity.device.PlcParameterObject;
import com.example.springboot.mapper.SpianMapper;
import com.example.springboot.mapper.AlbaniaMapper;
import com.google.common.primitives.Bytes;
@Service
public class SpianServiceNew {
    @Autowired
    private SpianMapper spianMapper;
    // @GetMapping("/all")
    public Short selectAll(String glassid) {
 //读取DB105区文件
 PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
 //读106
 PlcParameterObject plcread=PLCAutoMes.PlcReadObject;
        int cage1 = 0;
        int cells;
        int ids;
        int prcid;
        int tiers;
        int prctier;
        double width;
        double minwidth = 0;
    private AlbaniaMapper albaniaMapper;
    @Autowired
    private StorageCageService storageCageService;
    // 读取DB105区文件
    private PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        north_glass_buffer1 glasslist = spianMapper.selectGlass(glassid); // 获取玻璃参数
        // 如果没有此id时
        if (glasslist == null) {
            return (300);
    public Short selectAll(GlassInfo glassInfo) {
        if (glassInfo == null) {
            // 有进片请求但是测量台没有玻璃
            return 400;
        }
        double widths = glasslist.getglasslengthmm();
        String orderids = glasslist.getordernumber();
        String FrameBarcode = glasslist.getFrameBarcode();
        // 获取铝框相关度最高的笼子排序
        List<StorageCage> storageCage = spianMapper.selectAllFbarcode(FrameBarcode, widths, 400);
        // 判断铝框指定空格是否需要间隔空间
        if (storageCage.size() == 0) {
            storageCage = spianMapper.selectAll(orderids, FrameBarcode);
        }
        if (storageCage == null) {
            return (400);
        }
        for (StorageCage storageCage2 : storageCage) {
            // 保存订单优先顺序笼子号
            cage1 = storageCage2.getCage();
            // 判断该笼子号相邻最大的空格数
            int cages = spianMapper.selectCage(cage1);
        System.out.println(glassInfo + "初始");
        // 定义初始字段
        StorageCage cage;
        String glassid = glassInfo.getGlassid();
        Double width = glassInfo.getWidth();
        Double height = glassInfo.getHeight();
        String flowcard = glassInfo.getFlowcard();
        Integer glasstype = glassInfo.getGlasstype();
        Double thickness = glassInfo.getThickness();
        GlassInfo glassfilms = albaniaMapper.SelectGlassinfo(glasstype);
        // 判断是否有同类型的
        cage = albaniaMapper.SelectCage(glasstype, width, 300);
        // 如果有同类型时直接增加
        if (cage != null) {
            // 发送plc任务
            Mestast(glassid, 1001, cage.getId(), 1, "MESID1", 1);
            System.out.println("任务发送玻璃id:" + glassid + "起始位置:" + 1001 + "格子号:" + cage.getId() + "启动:" + 1);
            // 如果相邻笼子没有空格,或者有正在执行的出片任务时返回400
            if (cages == 0) {
        } else {
            // 判断玻璃是否进入大片笼
            if (glassInfo.getThickness() > 14) {
                cage = albaniaMapper.SelectNewCell(3, 5);
            } else {
                cage = albaniaMapper.SelectNewCell(0, 4);
                // System.out.println(cage + "理片笼判断");
            }
            // 当小片笼子不够,则符合条件的可以进入大片笼
            if (cage == null && glassInfo.getWidth() >= 1500 && glassInfo.getThickness() > 4) {
                cage = albaniaMapper.SelectNewCell(3, 5);
            }
            // 当返回的格子号为空时,返回400笼子已满
            if (cage != null) {
                albaniaMapper.AddCage(cage.getId(), glassid, width, height, 1, glasstype, 0, thickness,
                        glassfilms.getFilms(), glassfilms.getFlowcard(), glassfilms.getMateid(), glassfilms.getTier());
                Mestast(glassid, 1001, cage.getId(), 1, "MESID1", 1);
                System.out.println("任务发送玻璃id:" + glassid + "起始位置:" + 1001 + "格子号:" + cage.getId() + "启动:" + 1);
                albaniaMapper.UpdateStorage(width, height, cage.getId());
            } else {
                return (400);
            }
            StorageCage cages1;
            // 判断是否是第二片需要加间隔物
            prctier = spianMapper.selectsum(cage1, storageCage2.getCell());// 传给prc的格子内玻璃数
            if (prctier > 0) {
                cages1 = spianMapper.selectCage1(cage1, storageCage2.getCell(), widths + 400);
            } else {
                cages1 = spianMapper.selectCage1(cage1, storageCage2.getCell(), widths);
            }
            // 判断选中笼子是否有合适宽度空格
            // 有合适空格时进片
            if (cages1 != null && cages >= 1 && storageCage2.getDisabled() == 0) {
                ids = cages1.getId();// 数据库ID
                tiers = cages1.getTier();// 内外片
                cells = cages1.getCell();// 格子号
                prcid = cages1.getPrcId();// 传给prc的目标地id
                width = cages1.getWidth();// 格子剩余宽度
                widths = glasslist.getglasslengthmm();
                // 执行进片
                // 获取该格子内是否有玻璃
                int cellint = spianMapper.selectcell(cage1, cells);
                if (cellint == 1) {
                    // 将外片玻璃的数据更新到内片
                    spianMapper.UpdateDBCage(ids, cage1, cells, 1);
                    // 将新入的玻璃存入外片
                    spianMapper.UpdataAddCage2(orderids, glassid, glasslist, cage1, cells, ids - 1, 2);
                    spianMapper.UpdataAddCage1(widths, cage1, cells);// 减少格子宽度
                } else {
                    // 数据库修改笼子表新增一条玻璃
                    spianMapper.UpdataAddCage2(orderids, glassid, glasslist, cage1, cells, ids, 2);
                    spianMapper.UpdataAddCage1(widths, cage1, cells);// 减少格子宽度
                }
                // 进片车起始位置
                S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddStart").getAddress(plcmes.getPlcParameter("AddStart").getAddressIndex()), (short) 1000);
                // 进片车目标位置
                S7control.getinstance().WriteWord(plcmes.getPlcParameter("Addgoal").getAddress(plcmes.getPlcParameter("Addgoal").getAddressIndex()), (short) prcid);
                // 进片玻璃宽
                S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddLength").getAddress(plcmes.getPlcParameter("AddLength").getAddressIndex()), (short) widths);
                // 进片笼内已有玻璃数
                S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddCount").getAddress(plcmes.getPlcParameter("AddCount").getAddressIndex()), (short) prctier);
                // 进片车启动 1为启动
                S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddActivate").getAddress(plcmes.getPlcParameter("AddActivate").getAddressIndex()), (short) 1);
                String activate =plcmes.getPlcParameter("AddActivate").getValue();// 判断启动是否写入
                int activate2 = 0;
                if (activate.equals("1")) {
                    activate2 = 1;
                }else{
                    while (activate.equals("1")) {
                        // 出片任务发送字改为1
                        S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddActivate").getAddress(plcmes.getPlcParameter("AddActivate").getAddressIndex()), (short) 1);
                        activate =plcmes.getPlcParameter("AddActivate").getValue();// 判断启动是否写入
                    }
                }
                outmesid(glassid, "FeedID");//派发id
                spianMapper.Inserttask(0, 0, 1000, ids, glassid.toString(), prctier,activate2);// 新增任务
                return (200);
            }
        }
        return (400);
        // 增加任务记录
        albaniaMapper.Inserttask(0, 0, 1001, cage.getId(), glassid, glasstype, flowcard, glassfilms.getMateid(),
                glassfilms.getTier());
        albaniaMapper.UpdateQueueState(glassid);
        return (200);
    }
    public Short selectout2(String glassid) {
         //读取DB105区文件
            PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
        //读106
        PlcParameterObject plcread=PLCAutoMes.PlcReadObject;
    // 补充出片
    public Short mateOut() {
        double carwidth = -300;
        char[] a = glassid.toCharArray();
        List<Short> datas = new ArrayList<>();
        // 获取优先出片的位置
        StorageCage cageout = spianMapper.selectOut2(glassid);
        if (cageout == null) {
            return (300);
        }
        int cage = cageout.getCage(); // 储存出片位置,笼子格子几号玻璃
        int cell = cageout.getCell();// 出片格号
        int tier = cageout.getTier();// 出片内外片
        int prcid = cageout.getPrcId();// prcid
        int prcid2;
        int ids;
        int cages;
        int cells;
        double glasswidth = cageout.getGlassWidth();
        int state = spianMapper.selectGlassState(cage, cell);// 获取格子数量
        // 判断玻璃内外片
        if (tier == 2) {
            // 判断玻璃可直接出片时
            spianMapper.OverOutSlice(glassid.toString(), 1, 0);// 更新出片队列任务状态为进行中
            spianMapper.UpdataOutCage1(glasswidth, cage, cell);// 增加原格子宽度
            spianMapper.UpdataGlassCageState(glassid.toString(), 3);// 更改笼子表的玻璃状态
            spianMapper.Inserttask(1, 0, cageout.getId(), 1000, glassid, state, 3);// 新增任务
        List<StorageTask> glassmate = albaniaMapper.SelectOutTask();
        String type = glassmate.get(0).getTaskType();
        if (glassmate.size() == 0) {
            return (400);
        } else {
            // 获取格子的玻璃数量
            // 判断内片是否需要调拨
            if (state == 1) {
                spianMapper.OverOutSlice(glassid.toString(), 1, 0);// 更新出片队列任务状态为进行中
                spianMapper.UpdataOutCage1(glasswidth, cage, cell);// 增加原格子宽度
                spianMapper.UpdataGlassCageState(glassid, 3);// 更改笼子表的玻璃状态
                spianMapper.Inserttask(1, 0, cageout.getId(), 1000, glassid, 1,3);// 新增任务
            for (int i = 0; i < glassmate.size(); i++) {
                GlassInfo glass = albaniaMapper.SelectGlassInfo(glassmate.get(i).getGlasstype());
                carwidth = carwidth + glass.getWidth() + 300;
                if (carwidth >= 4300 && type != glassmate.get(i).getTaskType()) {
                    S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 出片任务启动
                    MestoPlc();
                    return (200);
                } else {
                    // 增加一条任务记录
                    albaniaMapper.Inserttask(1, 0, Integer.parseInt(glassmate.get(i).getShelfRack()), 2001,
                            glassmate.get(i).getGlassId(), glassmate.get(i).getGlasstype(),
                            glassmate.get(i).getFlowcard(), glassmate.get(i).getMateid(), glassmate.get(i).geTier());
                    // 完成出片队列的任务
                    albaniaMapper.UpdateOutTask(glassmate.get(i).getId());
                    // 发送plc任务
                    Mestast(glassmate.get(i).getGlassId(),
                            Integer.parseInt(glassmate.get(i).getShelfRack()), 2001, 0, "MESID" + (i + 1), i + 1);
                    System.out.println("发送出片队列配片任务:" + glassmate.get(i).getShelfRack());
                }
            }
            // 本次配片完成发送启动命令
            // S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(),
            // (short) 1);// 出片任务启动
            while (true) {
                String currentValue = plcmes.getPlcParameter("MESToPLC").getValue();
                // 检查 MESToPLC 的值是否为 0
                if (currentValue.equals("1")) {
                    System.out.println("发送启动字现在为1,停止循环写入");
                    break; // 退出循环
                }
                // 如果不为 1,继续写入
                S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 任务发送字
                System.out.println("继续写入 MESToPLC,当前值:" + currentValue);
                try {
                    Thread.sleep(100); // 例如每秒检查一次
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            MestoPlc();
        }
        return (200);
    }
    // 出片
    public Short selectout(int line) {
        GlassInfo glassmate = new GlassInfo();
        GlassInfo method = new GlassInfo();
        StorageCage glass = new StorageCage();
        int glassend = 0;
        double carwidth = -300;
        double width = 0;
        method = albaniaMapper.SelectMethod(line);
        if (method == null) {
            return (400);
        }
        // 如果不是直通模式只出有完整配片的流程卡
        if (method.getMethod() == 0) {
            // glassmate= albaniaMapper.SelectOutGlass(1);
            // 判断有数量的配片id
            List<GlassInfo> peipianid = albaniaMapper.SelectOutGlass3(method.getFlowcard());
            if (peipianid.size() == 0) {
                System.out.println("peipianid:" + peipianid);
                return (400);
            } else {
                // 玻璃需要调拨时,判断属于哪个半区的笼子
                if (cage < 6) {
                    StorageCage cagecell = spianMapper.selectGlassCage(cage, glasswidth, 0, 6, cell);
                    if (cagecell == null) {
                        return (300);
                for (int j = 0; j < peipianid.size(); j++) {
                    // 判断配片宽度是否够上大车
                    // GlassInfo glasswidth =
                    // albaniaMapper.SelectOutGlass6(peipianid.get(j).getFlowcard(),peipianid.get(j).getMateid());
                    // if (glasswidth.getWidth() <= 4300) {
                    // 是否有足够的库存数量
                    List<String> peipiancage = albaniaMapper.SelectOutGlass4(peipianid.get(j).getFlowcard(),
                            peipianid.get(j).getMateid());
                    // 是否有足够的可出片数量
                    List<String> peipiancage2 = albaniaMapper.SelectOutGlass8(peipianid.get(j).getFlowcard(),
                            peipianid.get(j).getMateid());
                    // System.out.println("peipiancage:"+peipiancage+peipianid.get(j).getMateid());
                    // System.out.println("peipiancage2:"+peipiancage2);
                    if (!peipiancage.contains("不足")) {
                        List<GlassInfo> chupian = albaniaMapper.SelectOutGlass7(peipianid.get(j).getFlowcard(),
                                peipianid.get(j).getMateid());
                        for (int k = 0; k < chupian.size(); k++) {
                            glass = albaniaMapper.SelectCageGlass(chupian.get(k).getGlasstype());
                            carwidth = carwidth + glass.getGlassWidth() + 300;
                            if (carwidth <= 4300) {
                                // 发送配片数据
                                Mestast(chupian.get(k).getGlassid(), glass.getId(), 2001, 0, "MESID" + (k + 1),
                                        k + 1);
                                albaniaMapper.AddFinishNumber(chupian.get(k).getFlowcard(),
                                        chupian.get(k).getMateid(), chupian.get(k).getTier());
                                storageCageService.UpdateStroageCageByCell(glass.getId(), -1);// 玻璃数量-1
                                albaniaMapper.Inserttask(1, 0, glass.getId(), 2001, chupian.get(k).getGlassid(),
                                        chupian.get(k).getGlasstype(), chupian.get(k).getFlowcard(),
                                        chupian.get(k).getMateid(), chupian.get(k).getTier());
                            } else {
                                albaniaMapper.AddFinishNumber(chupian.get(k).getFlowcard(),
                                        chupian.get(k).getMateid(), chupian.get(k).getTier());
                                storageCageService.UpdateStroageCageByCell(glass.getId(), -1);// 玻璃数量-1
                                // 增加出片队列的任务
                                albaniaMapper.InsertOutTask(1, 0, glass.getId(), 2001, chupian.get(k).getGlassid(),
                                        chupian.get(k).getGlasstype(), chupian.get(k).getFlowcard(),
                                        chupian.get(k).getMateid(), chupian.get(k).getTier());
                            }
                        }
                        // 本次配片完成发送启动命令
                        // S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(),(short)
                        // 1);// 出片任务启动
                        MestoPlc();
                        return (200);// 结束
                    }
                    // 获取调拨位置进行调拨
                    prcid2 = cagecell.getPrcId();// 调拨目标位PRCID
                    ids = cagecell.getId();// 调拨目标位ID
                    cages = cagecell.getCage();// 调拨目标位笼子
                    cells = cagecell.getCell();// 调拨目标位格子
                    // 更换玻璃的笼子
                    String glassids = spianMapper.SelectGlassid(cage, cell); // 获取被调拨的玻璃id
                    spianMapper.UpdataGlassCageState(glassids, 3);// 更改笼子表的玻璃状态
                    spianMapper.UpdateDBCage(ids, cage, cell, 2);// 将原格子数据更新到新格子里
                    spianMapper.UpdataAddCage1(glasswidth, cages, cells);// 减少新格子宽度
                    spianMapper.UpdataOutCage1(glasswidth, cage, cell);// 增加原格子宽度
                    spianMapper.Inserttask(2, 0, cageout.getId(), ids, glassids, 2, 3);// 新增调度任务
                } else {// 笼子号大于5时
                    StorageCage cagecell = spianMapper.selectGlassCage(cage, glasswidth, 5, 11, cell);
                    if (cagecell == null) {
                        return (300);
                    // }
                    // else {
                    // continue;
                    // }
                }
                System.out.println("未有完整配片");
                return (400);
            }
        } else {
            for (int i = 1; i <= 7; i++) {
                // 直通模式时按顺序直出
                // glassmate = albaniaMapper.SelectOutGlass(1);
                glassmate = albaniaMapper.SelectOutGlass2();
                System.err.println("出片:" + glassmate);
                if (glassmate == null && i > 1) {
                    // 本次配片完成发送启动命令
                    // 出片任务启动
                    MestoPlc();
                    System.out.println("出完任务:1,任务状态:0,起始:" + glass.getId() + ",目标" + "2001");
                    return (200);// 结束
                }
                if (glassmate == null) {
                    // 未领取任务
                    System.out.println("未领取任务:" + i);
                    return (400);
                } else {
                    glass = albaniaMapper.SelectCageGlass(glassmate.getGlasstype());
                    System.out.println("出片glass:" + glass);
                    if (glass != null) {
                        // 发送任务之前判断车上的剩余宽度是否大于此玻璃
                        width = width + glassmate.getWidth() + 300;
                        // 大于车上空余宽度时提前发送出片启动
                        if (width > 4300) {
                            // 本次配片完成发送启动命令
                            MestoPlc();
                            return (200);// 结束
                        }
                        // 发送配片数据
                        Mestast(glass.getGlassId(), glass.getId(), 2001, 0, "MESID" + i, i);
                        albaniaMapper.AddFinishNumber(glassmate.getFlowcard(), glassmate.getMateid(),
                                glassmate.getTier());
                        storageCageService.UpdateStroageCageByCell(glass.getId(), -1);// 玻璃数量-1
                        albaniaMapper.Inserttask(1, 0, glass.getId(), 2001, glassmate.getGlassid(),
                                glassmate.getGlasstype(), glass.getFlowcard(), glassmate.getMateid(),
                                glassmate.getTier());
                    } else {
                        return (400);// 结束
                    }
                    // 获取调拨位置进行调拨
                    prcid2 = cagecell.getPrcId();// 调拨目标位prcID
                    ids = cagecell.getId();// 调拨目标位ID
                    cages = cagecell.getCage();// 调拨目标位笼子
                    cells = cagecell.getCell();// 调拨目标位格子
                    String glassids = spianMapper.SelectGlassid(cage, cell); // 获取被调拨的玻璃id
                    spianMapper.UpdataGlassCageState(glassids, 3);// 更改笼子表的玻璃状态
                    spianMapper.Inserttask(2, 0, cageout.getId() + 1, ids, glassids, 2, 3);// 新增调度任务
                    spianMapper.UpdateDBCage(ids, cage, cell, 2);// 将原格子数据更新到新格子里
                    spianMapper.UpdataAddCage1(glasswidth, cages, cells);// 减少新格子宽度
                    spianMapper.UpdataOutCage1(glasswidth, cage, cell);// 增加原格子宽度
                }
                //发送plc任务
                 S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddStart").getAddress(plcmes.getPlcParameter("AddStart").getAddressIndex()), (short) prcid);
                 S7control.getinstance().WriteWord(plcmes.getPlcParameter("Addgoal").getAddress(plcmes.getPlcParameter("Addgoal").getAddressIndex()), (short) prcid2);
                 S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddCount").getAddress(plcmes.getPlcParameter("AddCount").getAddressIndex()), (short) state);
                 S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddActivate").getAddress(plcmes.getPlcParameter("AddActivate").getAddressIndex()), (short) 1);
                 String activate =plcmes.getPlcParameter("AddActivate").getValue();// 判断启动是否写入
                 int activate2 = 0;
                 if (activate.equals("1")) {
                     activate2 = 1;
                 }else{
                     while (activate.equals("1")) {
                         // 出片任务发送字改为1
                         S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddActivate").getAddress(plcmes.getPlcParameter("AddActivate").getAddressIndex()), (short) 1);
                         activate =plcmes.getPlcParameter("AddActivate").getValue();// 判断启动是否写入
                     }
                 }
                outmesid(glassid, "ReleaseID");//派发id
                //发送完倒片结束
                return (200); // 结束
            }
        }
         // 出片车起始位置
         S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddStart").getAddress(plcmes.getPlcParameter("OutStart").getAddressIndex()), (short) prcid);
         // 出片车目标位置
         S7control.getinstance().WriteWord(plcmes.getPlcParameter("Addgoal").getAddress(plcmes.getPlcParameter("Outgoal").getAddressIndex()), (short) 1000);
         // 出片笼内已有玻璃数
         S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddCount").getAddress(plcmes.getPlcParameter("OutCount").getAddressIndex()), (short) state);
         // 出片车启动 1为启动
         S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddActivate").getAddress(plcmes.getPlcParameter("OutActivate").getAddressIndex()), (short) 1);
         String activate =plcmes.getPlcParameter("AddActivate").getValue();// 判断启动是否写入
         int activate2 = 0;
         if (activate.equals("1")) {
             activate2 = 1;
         }else{
             while (activate.equals("1")) {
                 // 出片任务发送字改为1
                 S7control.getinstance().WriteWord(plcmes.getPlcParameter("AddActivate").getAddress(plcmes.getPlcParameter("AddActivate").getAddressIndex()), (short) 1);
                 activate =plcmes.getPlcParameter("AddActivate").getValue();// 判断启动是否写入
             }
         }
         outmesid(glassid, "ReleaseID");//派发id
        //直接出片结束
        return(200);// 结束
        return (200);// 结束
    }
    // 派发任务玻璃id
    public void outmesid(String glassid, String address) {
      //读取DB105区文件
      PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
        // 读取DB105区文件
        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        // System.out.println("outmesid:" + glassid);
        List<Byte> glassidlist = new ArrayList();
        char ds[] = glassid.toCharArray();
@@ -269,9 +270,10 @@
            glassidlist.add((byte) iditem);
        }
        byte[] bytes = Bytes.toArray(glassidlist);
        // writeString
        System.out.println("outmesidbytes:" + bytes.length);
        S7control.getinstance().WriteByte(plcmes.getPlcParameter(address).getAddress(plcmes.getPlcParameter(address).getAddressIndex()),bytes);
        //S7control.getinstance().WriteByte(address, bytes);// 派发出片id
        System.out.println(plcmes.getPlcParameter(address).getAddress());
        System.out.println();
    }
@@ -307,15 +309,44 @@
        return listbool;
    }
    // 根据玻璃id完成在进行中的任务
    public void overtask(String glassid) {
    // 下发理片任务
    public void Mestast(String glassid, int MESToPLCStart1, int MESToPLCTarget1, int MESToPLC, String address, int i) {
        S7control.getinstance().writeString(plcmes.getPlcParameter(address).getAddress(), glassid);// 玻璃id
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCStart" + i).getAddress(),
                (short) MESToPLCStart1);// 起始位置
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLCTarget" + i).getAddress(),
                (short) MESToPLCTarget1);// 目标位置
        if (MESToPLC != 0) {
            // S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(),
            // (short) MESToPLC);// mes理片任务类型
            MestoPlc();
        }
    }
        spianMapper.UpdatetaskOut(glassid.toString());// 完成上一次 出片或者进片任务
        spianMapper.OverOutSlice(glassid.toString(), 2, 1);// 完成出片队列任务
        spianMapper.UpdataGlassCage(glassid.toString(), 0);// 清除出片格子玻璃信息
        spianMapper.UpdateCageOver(glassid.toString(), 0);// 更改笼子表出片状态
        spianMapper.UpdateCageadd(glassid.toString(), 1);// 更改笼子表进片状态
        spianMapper.UpdateAddQueue(glassid.toString());// 把进片的玻璃更新到出片队列中
    // 扫码增加队列任务
    public boolean scan(String address) {
        List<Short> list = S7control.getinstance().ReadWord(address, 1);// 返回为ture时为1
        boolean listbool = list.contains((short) 1);
        return listbool;
    }
    public void MestoPlc() {
        while (true) {
            String currentValue = plcmes.getPlcParameter("MESToPLC").getValue();
            // 检查 MESToPLC 的值是否为 0
            if (currentValue.equals("1")) {
                System.out.println("发送启动字现在为1,停止循环写入");
                break; // 退出循环
            }
            // 如果不为 1,继续写入
            S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToPLC").getAddress(), (short) 1);// 任务发送字
            System.out.println("继续写入 MESToPLC,当前值:" + currentValue);
            try {
                Thread.sleep(100); // 例如每秒检查一次
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}