tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TProduct.Model;
 
namespace TProduct.Link.Kedi
{
    /// <summary>
    /// 丹泉款
    /// </summary>
    public class SiPumpHelper :   IDisposable
    {
        List<SiSingleComLinkHelper> _singleLinkList = null;
 
  
        /// <summary>
        /// 构造函数(输入测试类型)
        /// </summary>
        public SiPumpHelper()
        { 
      
        }
 
        /// <summary>
        /// 构建设备
        /// </summary>
        /// <param name="bundles"></param>
        /// <param name="error_info"></param>
        /// <returns></returns>
        public bool InitialData(
             List<Model.WorkBenchInstrumentKedi> instrumentParas,
             List<TProduct.Model.WorkBenchMonitorPoint> allMonitors,
             out string error_info)
        {
            _singleLinkList = new List<SiSingleComLinkHelper>();
            var com_names = (from x in instrumentParas where x.UseStatus == eUseStatus.Enable select x.ComPortName).Distinct();
            foreach (var com_name in com_names)
            {
                if (string.IsNullOrEmpty(com_name))
                    continue;
 
                var f_allItemList = from x in instrumentParas 
                                    where x.ComPortName == com_name && x.UseStatus == eUseStatus.Enable
                                    select x;
                if(f_allItemList == null || f_allItemList.Count() == 0)
                {
                    continue;
                }
                SiSingleComLinkHelper singleComlink = new SiSingleComLinkHelper();
                singleComlink.OnReceiveMsg += (s, e) => { InvokeReceiveMsg(e.Values, e.ErrorInfo, e.BtyeMessage); };
                if (!singleComlink.InitialData(com_name, f_allItemList.ToList(), allMonitors, out error_info))
                {
                    return false;
                }
                _singleLinkList.Add(singleComlink);
            }
            if (_singleLinkList.Count == 0)
            {
                error_info = "数据未初始化失败";
                return false;
            }
 
            error_info = null;
            return true;
        }
 
        /// <summary>
        /// 发送控制消息
        /// </summary>
        /// <param name="error_info"></param>
        /// <returns></returns>
        public override  bool SendCtrlMsg(string tag, string paras, out string error_info)
        {
            if (_singleLinkList == null)
            {
                error_info = null;
                return true ;
            }
            foreach (var link in _singleLinkList)
            {
                link.SendCtrlMsg(tag, paras, out error_info);
            }
            error_info = null;
            return true;
        }
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="error_info"></param>
        /// <returns></returns>
        public override bool Start(out string error_info)
        {
            if (_singleLinkList == null)
            {
                error_info = "COM数据未初始化";
                return false;
            }
            foreach (var link in _singleLinkList)
            {
                if (!link.Start(out error_info))
                {
                    return false;
                }
                Thread.Sleep(150);//错开一下
            }
            error_info = null;
            return true;
        }
 
 
 
 
 
 
        /// <summary>
        /// 关闭 
        /// </summary>
        public override bool Stop(out string error_info)
        {
            error_info = null;
            if (_singleLinkList == null)
            {
                return true ;
            }
            foreach (var link in _singleLinkList)
            {
                link.Stop(out error_info);
            }
            return true;
        }
 
 
 
 
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            string strInfo;
            Stop(out strInfo);
        }
    }
 
 
}