alielie
2025-11-25 006c98e5650b530e5220f279c1e803fefe69d40d
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using CommunityToolkit.Mvvm.ComponentModel;
using ConnectionUtil;
using HslCommunication.Profinet.Siemens;
using Plugin.CurrentSensorControl.Entity;
using System.Drawing;
using System.Windows.Controls;
using System.Windows.Markup;
 
namespace Plugin.CurrentSensorControl
{
    /// <summary>
    /// BurnInOven.xaml 的交互逻辑
    /// </summary>
    [ObservableObject]
    public partial class BurnInOven : UserControl
    {
        private BaseConfig config;
 
        private static readonly string[] datas = new string[] { "_LEDLight", "_Req", "_SetTemp", "_SaveTemp", "_TempDown", "_TempUp", "_AvgTemp" };
 
        [ObservableProperty]
        private string header;
 
        [ObservableProperty]
        private string req;
        [ObservableProperty]
        private string reqStatus;
 
        [ObservableProperty]
        private string setTemp;
        [ObservableProperty]
        private string saveTemp;
        [ObservableProperty]
        private string tempDown;
        [ObservableProperty]
        private string tempUp;
        [ObservableProperty]
        private string avgTemp;
 
        private bool lightStatus;
 
        public bool LightStatus
        {
            get => lightStatus;
            set
            {
                try
                {
                    string name = $"Oven{ovenIndex + 1}_LEDLight";
                    if (S7Context.WriteData(api, name, value))
                    {
                        lightStatus = value;
                        OnPropertyChanged(nameof(lightStatus));
                    }
                }
                catch (Exception ex)
                {
 
                }
            }
        }
 
        private int ovenIndex;
 
        private SiemensS7Net api;
 
        private int cellCount;
 
        private BurnInCell[] cells;
 
        public BurnInOven(int ovenIndex)
        {
            this.ovenIndex = ovenIndex;
            config = BaseConfig.Instance;
            this.cellCount = config.PositionCount;
            this.cells = new BurnInCell[cellCount];
            DataContext = this;
            api = S7Context.Get($"1");
            InitializeComponent();
            InitGrid();
        }
 
        private void InitGrid()
        {
            mainGrid.Columns = config.PositionColumn;
            for (int i = 0; i < cellCount; i++)
            {
                var cell = new BurnInCell(ovenIndex, i);
                cells[i] = cell;
                mainGrid.Children.Add(cell);
            }
        }
 
        public void Refresh()
        {
            try
            {
                //Task[] allTask = new Task[cells.Length];
                //for (int i = 0; i < cells.Length; i++)
                //{
                //    var cell = cells[i];
                //    var task = Task.Factory.StartNew(() =>
                //    {
                //        cell.Refresh();
                //    });
                //    allTask[i] = task;
                //}
                //Task.WaitAll(allTask);
 
                foreach (var cell in cells)
                {
                    cell.Refresh();
                }
 
                string name;
                object v;
                foreach (var data in datas)
                {
                    name = $"Oven{ovenIndex + 1}{data}";
                    if (S7Context.GetData(api, name, out v))
                    {
                        var val = v?.ToString();
                        if (data == "_LEDLight")
                        {
                            lightStatus = bool.Parse(val);
                            OnPropertyChanged("LightStatus");
                        }
                        else if (data == "_Req")
                        {
                            Req = val;
                            if (val == "0")
                            {
                                ReqStatus = "停止等待";
                            }
                            else if (val == "1")
                            {
                                ReqStatus = "加热启动";
                            }
                            else if (val == "2")
                            {
                                ReqStatus = "冷却启动";
                            }
                        }
                        else if (data == "_SetTemp")
                        {
                            SetTemp = val;
                        }
                        else if (data == "_SaveTemp")
                        {
                            SaveTemp = val;
                        }
                        else if (data == "_TempDown")
                        {
                            TempDown = val;
                        }
                        else if (data == "_TempUp")
                        {
                            TempUp = val;
                        }
                        else if (data == "_AvgTemp")
                        {
                            AvgTemp = val;
                        }
                    }
 
 
                    //;
                    //if (api.DoFctReadSingle(name, out string val, out _))
                    //{
                    //    if (data == "_Req")
                    //    {
                    //        Req = val;
                    //        if (val == "0")
                    //        {
                    //            ReqStatus = "停止等待";
                    //        }
                    //        else if (val == "1")
                    //        {
                    //            ReqStatus = "加热启动";
                    //        }
                    //        else if (val == "2")
                    //        {
                    //            ReqStatus = "冷却启动";
                    //        }
                    //    }
                    //    else if (data == "_SetTemp")
                    //    {
                    //        SetTemp = val;
                    //    }
                    //    else if (data == "_SaveTemp")
                    //    {
                    //        SaveTemp = val;
                    //    }
                    //    else if (data == "_TempDown")
                    //    {
                    //        TempDown = val;
                    //    }
                    //    else if (data == "_TempUp")
                    //    {
                    //        TempUp = val;
                    //    }
                    //    else if (data == "_AvgTemp")
                    //    {
                    //        AvgTemp = val;
                    //    }
                    //}
                }
 
                //if (api.Connec   (out string errMsg))
                //{
 
                //}
                //else
                //{
                //    OPCContext.Connect($"Oven{ovenIndex}");
                //    Thread.Sleep(1000);
                //}
            }
            catch (Exception ex)
            {
 
            }
        }
 
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var btn = sender as Button;
            string name = $"Oven{ovenIndex + 1}_Cmd";
            S7Context.WriteData(api, name, short.Parse(btn.Tag.ToString()));
            //api.DoFctWriteSingle(name, btn.Tag.ToString(), out string errMsg);
        }
    }
}