222
schangxiang@126.com
2025-08-25 533c702ee6602a45a7090324e66f4c8e892af6c2
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
using iWareCc.Properties;
using iWareCommon.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.Conveyor.Datagram
{
    public class GateDatagramAnalyze
    {
        /// <summary>
        /// 将收到的字节码数值转换成相应的属性
        /// </summary>
        /// <param name="msg">字节码数组形式的报文</param>
        /// <returns></returns>
        public GateDatagramProp Analyze(byte[] msg)
        {
            GateDatagramProp prop = new GateDatagramProp();
 
            //解析时去掉最后的/r/n(如果有的话)
            byte[] tmp = msg[msg.Length - 1].Equals((byte)'#') ? new byte[msg.Length - 1] : new byte[msg.Length];
            Array.Copy(msg, 0, tmp, 0, tmp.Length);
            string msgStr = ASCIIEncoding.UTF8.GetString(tmp);
            string[] msgArray = msgStr.Split('@');
            if (msgArray.Length>=3)
                {
              
                   prop.Name = msgArray.Length >= 3 ? msgArray[0] : null;
                   prop.InPlace = msgArray.Length >= 3 ? msgArray[1] : null;
                   prop.IsEmpty = msgArray.Length >= 3 ? msgArray[2] : null;
                }
            return prop;
        }
        /// <summary>
        /// 将收到的字节码数值转换成相应的属性
        /// </summary>
        /// <param name="msg">字节码数组形式的报文</param>
        /// <returns></returns>
        public GateDatagramProp AlarmAnalyze(byte[] msg)
        {
            GateDatagramProp prop = new GateDatagramProp();
 
            //解析时去掉最后的/r/n(如果有的话)
            byte[] tmp = msg[msg.Length - 1].Equals((byte)'#') ? new byte[msg.Length - 1] : new byte[msg.Length];
            Array.Copy(msg, 0, tmp, 0, tmp.Length);
            string msgStr = ASCIIEncoding.UTF8.GetString(tmp);
            string[] msgArray = msgStr.Split('@');
            if (msgArray.Length >= 2)
            {
                prop.Name = msgArray.Length >= 2 ? msgArray[0] : null;
                prop.Alarmcode = msgArray.Length >= 2 ? msgArray[1] : null;
            }
            return prop;
        }
        /// <summary>
        /// 将收到的字节码数值转换成相应的属性
        /// </summary>
        /// <param name="msg">字节码数组形式的报文</param>
        /// <returns></returns>
        public GateDatagramProp SCAnalyze(byte[] msg)
        {
            GateDatagramProp prop = new GateDatagramProp();
 
            //解析时去掉最后的/r/n(如果有的话)
            byte[] tmp = msg[msg.Length - 1].Equals((byte)'#') ? new byte[msg.Length - 1] : new byte[msg.Length];
            Array.Copy(msg, 0, tmp, 0, tmp.Length);
            string msgStr = ASCIIEncoding.UTF8.GetString(tmp);
            string[] msgArray = msgStr.Split('@');
            if (msgArray.Length >= 2)
            {
                prop.Name = msgArray.Length >= 2 ? msgArray[0] : null;
                prop.MaterialCode = msgArray.Length >= 2 ? msgArray[1] : null;
            }
            return prop;
        }
    }
}