自动化立体仓库 - WCS系统
#
luxiaotao1123
2020-08-04 6abc20e29568c129f4ca71eccec9310534a8c779
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
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.zy.common.HslCommunication.Core.IMessage;
 
public class MelsecA1EBinaryMessage implements INetMessage {
 
    /**
     * 消息头的指令长度
     */
    public int ProtocolHeadBytesLength(){
        return 2;
    }
 
 
    /**
     * 从当前的头子节文件中提取出接下来需要接收的数据长度
     * @return 返回接下来的数据内容长度
     */
    public int GetContentLengthByHeadBytes(){
        if(HeadBytes == null) return 0;
 
        int contentLength = 0;
 
        if (HeadBytes[1] == 0x5B)
        {
            contentLength = 2; //结束代码 + 0x00
            return contentLength;
        }
        else
        {
            int length = (SendBytes[10] % 2 == 0) ? SendBytes[10] : SendBytes[10] + 1;
            switch (HeadBytes[0])
            {
                case (byte) 0x80: //位单位成批读出后,回复副标题
                    contentLength = length / 2;
                    break;
                case (byte) 0x81: //字单位成批读出后,回复副标题
                    contentLength = SendBytes[10] * 2;
                    break;
                case (byte) 0x82: //位单位成批写入后,回复副标题
                    break;
                case (byte) 0x83: //字单位成批写入后,回复副标题
                    break;
                default:
                    break;
            }
            // 在A兼容1E协议中,写入值后,若不发生异常,只返回副标题 + 结束代码(0x00)
            // 这已经在协议头部读取过了,后面要读取的长度为0(contentLength=0)
        }
        return contentLength;
    }
 
 
    /**
     * 检查头子节的合法性
     * @param token 特殊的令牌,有些特殊消息的验证
     * @return 是否合法的验证
     */
    public boolean CheckHeadBytesLegal(byte[] token)
    {
        if (HeadBytes != null)
        {
            if ((HeadBytes[0] - SendBytes[0]) == (byte) 0x80) { return true; }
        }
        return false;
    }
 
 
    /**
     * 获取头子节里的消息标识
     * @return
     */
    public int GetHeadBytesIdentity(){
 
        return 0;
    }
 
 
    /**
     * 获取消息头字节
     *
     * @return
     */
    @Override
    public byte[] getHeadBytes() {
        return HeadBytes;
    }
 
    /**
     * 获取消息内容字节
     *
     * @return
     */
    @Override
    public byte[] getContentBytes() {
        return ContentBytes;
    }
 
    /**
     * 获取发送的消息
     *
     * @return
     */
    @Override
    public byte[] getSendBytes() {
        return SendBytes;
    }
 
    /**
     * 设置消息头子节
     * @param headBytes 字节数据
     */
    public void setHeadBytes(byte[] headBytes){
        HeadBytes = headBytes;
    }
 
 
 
 
    /**
     * 设置消息内容字节
     * @param contentBytes 内容字节
     */
    public void setContentBytes(byte[] contentBytes){
        ContentBytes = contentBytes;
    }
 
 
 
    /**
     * 设置发送的字节信息
     * @param sendBytes 发送的字节信息
     */
    public void setSendBytes(byte[] sendBytes){
        SendBytes = sendBytes;
    }
 
 
    private byte[] HeadBytes = null;
 
    private byte[] ContentBytes = null;
 
    private byte[] SendBytes = null;
}