schangxiang@126.com
2025-02-20 c9e3a7f0c154892f2327e300e28af53f81e40ad0
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
 
 
using iWareModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCommon.Utils
{
    /// <summary>
    /// 业务帮助类
    /// </summary>
    public class BusinessHelper
    {
        /// <summary>
        /// RGV等特殊点位的转换
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static int ConvertStationCodeForRGV(string name)
        {
            if (name.ToUpper() == "RGV1040")
            {
                return 1040;
            }
            else if (name == "提升机1030")
            {
                return 1030;
            }
            else if (name == "拆盘机1020")
            {
                return 1020;
            }
            return 0;
        }
 
        /// <summary>
        /// 获取堆垛机列表
        /// </summary>
        /// <param name="placeNo"></param>
        /// <returns></returns>
        public static List<EDevice> GetSrmDeviceList()
        {
            return new List<EDevice>() { 
                EDevice.一号堆垛机,
                EDevice.二号堆垛机,
                EDevice.三号堆垛机,
                EDevice.四号堆垛机
            };
        }
 
        /// <summary>
        /// 根据库位寻找设备
        /// </summary>
        /// <param name="placeNo"></param>
        /// <returns></returns>
        public static EDevice GetDeviceByPlaceNo(EDeviceType deviceType, string placeNo)
        {
            switch (deviceType)
            {
                case EDeviceType.堆垛机:
                    return GetSrmDeviceByPlaceNo(placeNo);
                case EDeviceType.RGV:
                    return EDevice.RGV;
                default:
                    throw new Exception("未知设备");
            }
        }
 
        /// <summary>
        /// 根据设备获取设备类型
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static EDeviceType GetEDeviceTypeByEDevice(EDevice device)
        {
            switch (device)
            {
                case EDevice.AGV:
                    return EDeviceType.AGV;
                case EDevice.一号堆垛机:
                case EDevice.二号堆垛机:
                case EDevice.三号堆垛机:
                case EDevice.四号堆垛机:
                    return EDeviceType.堆垛机;
                default:
                    return EDeviceType.RGV;
            }
        }
 
        /// <summary>
        /// 根据库位寻找堆垛机的枚举
        /// </summary>
        /// <param name="placeNo"></param>
        /// <returns></returns>
        public static EDevice GetSrmDeviceByPlaceNo(string placeNo)
        {
            var arr = placeNo.Split('-');
            int i = Convert.ToInt16(arr[0]);
            if (i == 1)
                return EDevice.一号堆垛机;
            if (i == 2)
                return EDevice.二号堆垛机;
            if (i == 3)
                return EDevice.三号堆垛机;
            if (i == 4)
                return EDevice.四号堆垛机;
            throw new Exception("库位不正确,根据库位" + placeNo + "找不到堆垛机");
        }
 
 
  
        /// <summary>
        /// 创建输送线任务号,随机生成(1, 3000)的PLC任务号
        /// </summary>
        /// <returns></returns>
        public static string CreatePlcTaskIdForConveyorTask()
        {
            int iSeed = 3000;
            return new Random(Guid.NewGuid().GetHashCode()).Next(1, iSeed).ToString();
        }
        /// <summary>
        /// 创建堆垛机任务号,随机生成 (1, 99999)的PLC任务号
        /// </summary>
        /// <returns></returns>
        public static string CreatePlcTaskIdForSrmTask()
        {
            int iSeed = 9999;
            //从101-9999,为什么要从101开始,因为1-100作为手动任务下发。【EditBy shaocx,2022-05-10】
            return new Random(Guid.NewGuid().GetHashCode()).Next(101, iSeed).ToString();
        }
 
        public static string CreatePlcTaskId()
        {
            int iSeed = 9999;
            //从101-9999,为什么要从101开始,因为1-100作为手动任务下发。【EditBy shaocx,2022-05-10】
            return new Random(Guid.NewGuid().GetHashCode()).Next(101, iSeed).ToString();
        }
    }
}