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
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
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
 
namespace TProduct.Link.Kedi
{
    public partial class LinkHelper
    {
        /// <summary>
        /// 构建设备
        /// </summary>
        /// <param name="workBench"></param>
        /// <param name="instrumentParas"></param>
        /// <param name="allMonitors"></param>
        /// <param name="error_info"></param>
        /// <returns></returns>
        public bool InitialData杭州力夫(
            TProduct.Model.ProductMainExPump pump,
            TProduct.Model.ProductMainExMotor motor,
            TProduct.Model.WorkBenchBase workBench,
            TProduct.Model.TestProjectItemView tesItem,
            List<Model.WorkBenchInstrumentKedi> instrumentParas,
            List<TProduct.Model.WorkBenchMonitorPoint> allMonitors,
            out string error_info)
        {
            _singleCommList = new List<SingleComBaseHelper>();
 
            var com_names = (from x in instrumentParas select x.ComPortName).Distinct();
            foreach (var com_name in com_names)
            {
                if (string.IsNullOrEmpty(com_name))
                    continue;
 
                var single_com_helper = new SingleComBaseHelper();
 
                single_com_helper.InitialComPort(workBench, com_name);
 
                single_com_helper.OnReceivePollValue += (values, additionInfo, info, bytes) =>
                {
                    this.InvokeReceiveMonitorValue(values, additionInfo, info, bytes);
                };
                single_com_helper.OnShowMsg += (content) =>
                {
                    if (OnShowMsg != null)
                    {
                        OnShowMsg(content);
                    }
                };
 
                var f_instrumentParas = from x in instrumentParas where x.ComPortName == com_name select x;
 
                foreach (var instrument in f_instrumentParas)
                {
                    if (instrument.UseStatus != Model.eUseStatus.Enable)
                        continue;
 
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.电参数仪)
                    {
                        var msg_item = new MsgItem_力夫_电参数();
                        msg_item.Name = "电参数仪";
                        msg_item.InitialData(instrument, allMonitors);
                        single_com_helper.AddMsgItem(msg_item);
                    }
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.无纸数据记录仪)
                    {
                        var msg_item = new MsgItem_力夫_Dr();
                        msg_item.Name = "无纸数据记录仪";
                        msg_item.InitialData(instrument, allMonitors);
                        single_com_helper.AddMsgItem(msg_item);
                    }
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.直流电源)
                    {
                        bool isHaveV = false;
                        if (motor != null)
                        {
                            if (motor.RatedU != null)
                            {
                                isHaveV = true;
                                var msg_item = new MsgItem_力夫_直流电源();
                                msg_item.Name = "直流电源";
                                msg_item.InitialData(Convert.ToSingle(motor.RatedU.Value.ToString()));
 
                                single_com_helper.AddMsgItem(msg_item);
                            }
                        }
                        else
                        {
                            var pumpParas = TProduct.Model.RatedParas4Pump.ToModel(pump.RatedParas);
                            if (pumpParas.Voltage > 0)
                            {
                                isHaveV = true;
                                var msg_item = new MsgItem_力夫_直流电源();
                                msg_item.Name = "直流电源";
                                msg_item.InitialData(Convert.ToSingle(pumpParas.Voltage.ToString()));
 
                                single_com_helper.AddMsgItem(msg_item);
                            }
                        }
                        if (!isHaveV)
                        {
                            error_info = "未设置电机电压";
                            return false;
                        }
                    }
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.PLC)
                    {
                        var msg_item = new MsgItem_力夫_PLC();
                        msg_item.Name = "PLC";
                        single_com_helper.SetParity(Parity.Even);
                        single_com_helper.SetDataBits(7);
                        single_com_helper.AddMsgItem(msg_item);
                    }
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.温度控制仪)
                    {
                        var msg_item = new MsgItem_力夫_温度控制器();
                        msg_item.InitialData(instrument, allMonitors);
                        msg_item.Name = "温度控制仪";
                        single_com_helper.AddMsgItem(msg_item);
                    }
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.阀门)
                    {
                        var pipeParas = new Model.PipeParas4Pump(workBench.PipeParas);
                        if (string.IsNullOrEmpty(workBench.PipeParas))
                        {
                            error_info = "测试台未设置进出口口径";
                            return false;
                        }
                        if (pipeParas.InletDia == null)
                        {
                            error_info = "测试台未设置进出口口径";
                            return false;
                        }
                        int inletDia = (int)pipeParas.InletDia.Value;
                        if (inletDia != 8 && inletDia != 15 && inletDia != 20)
                        {
                            error_info = "测试台未设置进口口径,只支持8,15,20";
                            return false;
                        }
                        if (pipeParas.OutletDia == null)
                        {
                            error_info = "测试台未设置 出口口径";
                            return false;
                        }
                        int outletDia = (int)pipeParas.OutletDia.Value;
                        if (outletDia != 8 && outletDia != 15 && outletDia != 20)
                        {
                            error_info = "测试台未设置出口口径,只支持8,15,20";
                            return false;
                        }
                        var msg_item = new MsgItem_力夫_阀门();
                        msg_item.Name = "阀门";
                        msg_item.InitialData(inletDia, outletDia);
                        single_com_helper.AddMsgItem(msg_item);
                    }
                
                    
                    if (instrument.InstrumentType ==
                        (int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.扭矩仪)
                    {
 
                    }
                }
 
 
                if (single_com_helper.TotalMsgItemCount > 0)
                    _singleCommList.Add(single_com_helper);
            }
 
 
 
            error_info = null;
 
            return true;
        }
 
    }
}