wu
2024-03-07 712b7bd7bfc09dee41a63c769a272b9ebae68c90
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
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.glassinfo;
import com.example.springboot.entity.device.PlcParameterObject;
import com.example.springboot.mapper.AlbaniaMapper;
import com.example.springboot.mapper.SpianMapper;
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;
 
    //判断是否有同类型的
     cageid=albaniaMapper.SelectCage(glassInfo.getGlasstype(), glassInfo.getWidth(), 50);
    //如果有同类型时直接增加
    if(cageid!=Integer.MIN_VALUE){
        albaniaMapper.UpdateCageNumberAdd(cageid);
    }else{
         //判断玻璃是否进入大片笼
        if(glassInfo.getThickness()>=15){
            cageid=albaniaMapper.SelectNewCell(3,5);
        }else{
            cageid=albaniaMapper.SelectNewCell(3,5);
        }
        //当返回的格子号为空时,返回400笼子已满
        if(cageid==Integer.MIN_VALUE){
            return(400);
        }
    }
    return(200);
 
}
 
    public Short selectout2(String glassid) {
       
        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());// 把进片的玻璃更新到出片队列中
    }
 
}