ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.Threading;
using iWareCommon.Utils;
 
using System.Linq;
using Newtonsoft.Json;
using System.Collections.Generic;
using iWareCommon;
using System.Text;
using iWareModel;
 
 
 
namespace iWareSda
{
    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“LineService”。
    public class HuscoLineService : IHuscoLineService
    {
        private static string _namespace = "iWareSda.HuscoLineService";
        private static string nofoundStackerMsg = SysHelper.Language(WareSdaStruct.LanguageFlg, "没有找到输送线", "No found the Line");
        public HuscoLineView GetLineInfo(int deviceId)
        {
            var device = HuscoLine_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
            if (device == null)
            {
                return null;
            }
            return device.View;
        }
 
        /// <summary>
        /// 判断是否有心跳
        /// </summary>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public SdaResEntity IsHaveHeatBeat(int deviceId)
        {
            SdaResEntity sdaResult = new SdaResEntity();
            string msg;
            try
            {
                var device = HuscoLine_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
                if (device == null)
                {
                    sdaResult.resMsg = nofoundStackerMsg;
                    return sdaResult;
                }
 
                var result = device.IsHaveHeatBeat();
 
                sdaResult.result = true;
                sdaResult.resData = result;
                return sdaResult;
 
            }
            catch (Exception ex)
            {
                msg = "验证是否有心跳出现异常:" + ex.Message;
                Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
                sdaResult.result = false;
                sdaResult.resMsg = msg;
                return sdaResult;
            }
        }
 
        /// <summary>
        /// 检测设备是否可以发任务
        /// </summary>
        /// <returns></returns>
        public SdaResEntity IsAllowSendTask(int deviceId)
        {
            SdaResEntity res = new SdaResEntity();
            res.result = true;
            return res;
            //try
            //{
            //    DeviceEnum device = (DeviceEnum)Enum.Parse(typeof(DeviceEnum), deviceId.ToString());
            //    AreaEnum area = BussinessHelper.GetAreaByDevice(device);
            //    var line = HuscoLine_CacheEntity.Lines[0];
            //    switch (area)
            //    {
            //        case AreaEnum.区域1:
            //            if (!line.R_AutoMode_1)
            //            {
            //                res.resData = false;
            //                res.resMsg = "区域1设备不是自动模式";
            //                return res;
            //            }
            //            break;
            //        case AreaEnum.区域2:
            //            if (!line.R_AutoMode_2)
            //            {
            //                res.resData = false;
            //                res.resMsg = "区域2设备不是自动模式";
            //                return res;
            //            }
            //            break;
            //    }
 
            //    if (!line.IsConnected)
            //    {
            //        res.resData = false;
            //        res.resMsg = "未与PLC连接";
            //        return res;
            //    }
 
            //    switch (device)
            //    {
            //        case DeviceEnum.翻转机R01:
            //            if (line.R_R01_TaskNo != 0)
            //            {
            //                res.resData = false;
            //                res.resMsg = "R01上有任务在执行";
            //                return res;
            //            }
            //            break;
            //        case DeviceEnum.翻转机R04:
            //            if (line.R_R04_TaskNo != 0)
            //            {
            //                res.resData = false;
            //                res.resMsg = "R04上有任务在执行";
            //                return res;
            //            }
            //            break;
            //        default:
            //            break;
            //    }
 
            //    res.resData = true;
            //    return res;
            //}
            //catch (Exception ex)
            //{
            //    Log4NetHelper.WriteErrorLog(LogType.SdaService, "检测R01是否可以发任务 出现异常", ex);
            //    res.result = false;
            //    res.resMsg = "检测R01是否可以发任务 出现异常:" + ex.Message;
            //    return res;
            //}
        }
 
        /// <summary>
        /// 写入TaskFinish
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="rgvLocation"></param>
        /// <returns></returns>
        public SdaResEntity WriteTaskFinish(int deviceId, int rgvLocation)
        {
            SdaResEntity sdaResult = new SdaResEntity();
            return sdaResult;
            //string msg;
            //try
            //{
            //    var line = HuscoLine_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
            //    if (line == null)
            //    {
            //        sdaResult.resMsg = nofoundStackerMsg;
            //        return sdaResult;
            //    }
            //    EDevice _rgv = (EDevice)Enum.Parse(typeof(EDevice), rgvLocation.ToString());
            //    MessageModel fr = null;
            //    switch (_rgv)
            //    {
            //        case EDevice.RGV1:
            //            fr = line.S7.WriteValuePoint(HuscoLine_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T1_Finish, 1, line.View.W_T1_Finish);
            //            break;
            //        case EDevice.RGV2:
            //            fr = line.S7.WriteValuePoint(HuscoLine_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T2_Finish, 1, line.View.W_T2_Finish);
            //            break;
            //        case EDevice.RGV3:
            //            fr = line.S7.WriteValuePoint(HuscoLine_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T3_Finish, 1, line.View.W_T3_Finish);
            //            break;
            //    }
            //    if (fr.result)
            //    {
            //        sdaResult.result = true;
            //        return sdaResult;
            //    }
            //    else
            //    {
            //        sdaResult.resMsg = fr.resMsg;
            //        return sdaResult;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    msg = "写入Task_Finish_ACK出现异常:" + ex.Message;
            //    Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
            //    sdaResult.result = false;
            //    sdaResult.resMsg = msg;
            //    return sdaResult;
            //}
        }
    }
}