wu
2024-03-12 4677bbb4284ddb08537d6726bbe87400f021c86a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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.device.PlcParameterObject;
import com.example.springboot.mapper.AlbaniaMapper;
import com.google.common.primitives.Bytes;
 
 
@Service
public class SpianServiceNew {
    @Autowired
    private AlbaniaMapper albaniaMapper;
     //读取DB105区文件
    private PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
public Short selectAll(GlassInfo glassInfo) {
    //定义初始字段
    int cageid;
    String glassid=glassInfo.getGlassid();
    Double width=glassInfo.getWidth();
    Double height=glassInfo.getHeight();
    int glasstype=glassInfo.getGlasstype();
    
    
 
    //判断是否有同类型的
     cageid=albaniaMapper.SelectCage(glassInfo.getGlasstype(), glassInfo.getWidth(), 50);
    //如果有同类型时直接增加
    if(cageid!=Integer.MIN_VALUE){
        //发送plc任务
        
        //任务完成后增加数量
        albaniaMapper.UpdateCageNumberAdd(cageid);
    }else{
         //判断玻璃是否进入大片笼
        if(glassInfo.getThickness()>=15){
            cageid=albaniaMapper.SelectNewCell(3,5);
        }else{
            cageid=albaniaMapper.SelectNewCell(3,5);
            //发送plc任务
        }
        //当返回的格子号为空时,返回400笼子已满
        if(cageid==Integer.MIN_VALUE){
            return(400);
        }else{
            //判断完成任务后增加数量
            albaniaMapper.AddCage(cageid, glassid, width, height, width, height, 0, glasstype, 1);
        }
    }
    //增加任务记录
    albaniaMapper.Inserttask(0, 0, 0, cageid, glassInfo.getGlassid(), 0, 0);
    return(200);
 
}
 
 
    public Short selectout(int line) {
        //判断笼子最先出哪片
         
       
        return(200);// 结束
    }
 
    // 派发任务玻璃id
    public void outmesid(String glassid, String address) {
      //读取DB105区文件
      PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
        // System.out.println("outmesid:" + glassid);
        List<Byte> glassidlist = new ArrayList();
        char ds[] = glassid.toCharArray();
        for (char iditem : ds) {
            glassidlist.add((byte) iditem);
        }
        byte[] bytes = Bytes.toArray(glassidlist);
        System.out.println("outmesidbytes:" + bytes.length);
        S7control.getinstance().WriteByte(plcmes.getPlcParameter(address).getAddress(plcmes.getPlcParameter(address).getAddressIndex()),bytes);
        //S7control.getinstance().WriteByte(address, bytes);// 派发出片id
 
    }
 
    // 获取地址内的玻璃id转字符串
    public StringBuilder queGlassid(String address, int count) {
        StringBuilder writedstrIdOut = new StringBuilder();
        byte[] writedglassidbytesOut = S7control.getinstance().ReadByte(address, count);
        if (writedglassidbytesOut != null) {
            // 获取玻璃id
            for (byte iditem : writedglassidbytesOut) {
                writedstrIdOut.append((char) iditem);
            }
        }
        return writedstrIdOut;
    }
 
    // char数组转化成bit数组
    public static byte[] toBytes(char[] chars) {
        String s = new String(chars);
        return s.getBytes(StandardCharsets.UTF_8);
    }
 
    // bit数组转化成char数组
    public static char[] toChars(byte[] bytes) {
        String s = new String(bytes, StandardCharsets.UTF_8);
        return s.toCharArray();
    }
 
    // 判断集合里是否为1
    public boolean listbool(String address) {
        List<Short> list = S7control.getinstance().ReadWord(address, 1);// 返回为ture时为1
        boolean listbool = list.contains((short) 1);
        return listbool;
    }
 
    // 根据玻璃id完成在进行中的任务
    public void overtask(String glassid) {
 
        // 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());// 把进片的玻璃更新到出片队列中
    }
 
}