천호석
2022-06-20 ffc1d79815b6ca50cf07a132705b83156f2db97a
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
 
namespace SHARP_CLAS_UI.Screen
{
    public partial class Form_Maintenance_IO : Form
    {
        Form_Frame _Parent;
 
        List<uc_Input_Vlaue> Inputs = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_1 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_2 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_3 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_4 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_5 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_6 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_7 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_8 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_9 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_10 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_11 = new List<uc_Input_Vlaue>();
        List<uc_Input_Vlaue> Input_12 = new List<uc_Input_Vlaue>();
 
        List<uc_Output_Vlaue> Outputs = new List<uc_Output_Vlaue>();
        List<uc_Output_Vlaue> Output_1 = new List<uc_Output_Vlaue>();
        List<uc_Output_Vlaue> Output_2 = new List<uc_Output_Vlaue>();
        List<uc_Output_Vlaue> Output_3 = new List<uc_Output_Vlaue>();
        List<uc_Output_Vlaue> Output_4 = new List<uc_Output_Vlaue>();
        List<uc_Output_Vlaue> Output_5 = new List<uc_Output_Vlaue>();
        List<uc_Output_Vlaue> Output_6 = new List<uc_Output_Vlaue>();
        Thread Data_Update_Th;
 
        /// <summary>
        /// colum 425 row 50 
        /// </summary>
        /// <param name="_parent"></param>
        public Form_Maintenance_IO(Form_Frame _Parent)
        {
            InitializeComponent();
            this._Parent = _Parent;
            Init_InputData();
            Init_OutputData();
            Data_Update_Th = new Thread(Data_Update_Th_Set);
            Data_Update_Th.Start();
        }
 
        public void Init_InputData()
        {
            byte[] input;
            string[] descriptions = Input_Memory_Address.Get_Name_of_Memory_Address();
 
            _Parent.sm.Get_SharedMemorybytes(out input, 1000, descriptions.Length);
 
            if (descriptions.Length % 16 != 0)
                return;
 
            int iosplit = 32;
            int iolength = descriptions.Length / iosplit;
 
            for (int i = 0; i < iolength; i++)
            {
                for (int j = 0; j < iosplit; j++)
                {
                    string ioname = ((iosplit * i) + j).ToString("X3");
                    Inputs.Add(new uc_Input_Vlaue(ioname, descriptions[(iosplit * i) + j], Convert.ToBoolean(input[(iosplit * i) + j])));
                }
            }
 
            for (int i = 0; i < iolength; i++)
            {
                for (int j = 0; j < iosplit; j++)
                {
                    switch(i)
                    {
                        case 0:
                            {
                                Input_1.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 1:
                            {
                                Input_2.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 2:
                            {
                                Input_3.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 3:
                            {
                                Input_4.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 4:
                            {
                                Input_5.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 5:
                            {
                                Input_6.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 6:
                            {
                                Input_7.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 7:
                            {
                                Input_8.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 8:
                            {
                                Input_9.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 9:
                            {
                                Input_10.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 10:
                            {
                                Input_11.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                        case 11:
                            {
                                Input_12.Add(Inputs[(iosplit * i) + j]);
                                break;
                            }
                    }
                }
            }
 
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_1[i]);
                tlp_Input.Controls.Add(Input_1[i + Input_1.Count / 2]);
            }
        }
 
        public void Init_OutputData()
        {
            byte[] output;
            string[] descriptions = Output_Memory_Address.Get_Name_of_Memory_Address();
 
            _Parent.sm.Get_SharedMemorybytes(out output, 1500, descriptions.Length);
 
 
            if (descriptions.Length % 16 != 0)
                return;
 
            int iosplit = 32;
            int iolength = descriptions.Length / iosplit;
 
            int i = 0;
            foreach(ushort axis in Enum.GetValues(typeof(OutputAxis)))
            {
                for (int j = 0; j < iosplit; j++)
                {
                    string ioname = ((iosplit * i) + j).ToString("X3");
                    uc_Output_Vlaue data = new uc_Output_Vlaue(ioname, descriptions[(iosplit * i) + j], (OutputAxis)axis, j, Convert.ToBoolean(output[(iosplit * i) + j]));
                    data.Add_Click_Event(Output_Click);
                    Outputs.Add(data);
                }
                i++;
            }
 
            for (i = 0; i < iolength; i++)
            {
                for (int j = 0; j < iosplit; j++)
                {
                    switch (i)
                    {
                        case 0:
                            {
                                Output_1.Add(Outputs[(iosplit * i) + j]);
                                break;
                            }
                        case 1:
                            {
                                Output_2.Add(Outputs[(iosplit * i) + j]);
                                break;
                            }
                        case 2:
                            {
                                Output_3.Add(Outputs[(iosplit * i) + j]);
                                break;
                            }
                        case 3:
                            {
                                Output_4.Add(Outputs[(iosplit * i) + j]);
                                break;
                            }
                        case 4:
                            {
                                Output_5.Add(Outputs[(iosplit * i) + j]);
                                break;
                            }
                        case 5:
                            {
                                Output_6.Add(Outputs[(iosplit * i) + j]);
                                break;
                            }
                    }
                }
            }
 
            tlp_Output.Controls.Clear();
 
            for (i = 0; i < Output_1.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_1[i]);
                tlp_Output.Controls.Add(Output_1[i + Output_1.Count / 2]);
            }
        }
        
        private void Output_Click(object sender, EventArgs e)
        {
            Label data = (Label)sender;
            uc_Output_Vlaue output_value = (uc_Output_Vlaue)data.Parent;
 
            int row = Convert.ToInt32(output_value.name, 16);
            OutputData output;
            Enum.TryParse(Enum.GetName(typeof(OutputData), (object)row), out output);
 
            _Parent._equip.Board_Control.IO_manager.Set_Output(output, !output_value.status);
        }
 
        private void Data_Update_Th_Set()
        {
            while (!_Parent.IsDisposed)
            {
                Thread.Sleep(10);
                Data_Update();
            }
        }
 
        private void Data_Update()
        {
            try
            {
                DateTime dt = DateTime.Now;
                Update_Input_Data();
                Update_Output_Data();
                TimeSpan ts = DateTime.Now - dt;
            }
            catch (Exception ex)
            {
                _Parent.WriteExceptionLog(this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex);
            }
        }
 
        public void Update_Input_Data()
        {
            byte[] input;
            _Parent.sm.Get_SharedMemorybytes(out input, 1000, Input_Memory_Address.Get_Address_Infos().Length);
            
            int iolength = input.Length / 32;
 
            for (int i = 0; i < iolength; i++)
            {
                for (int j = 0; j < 32; j++)
                {
                    bool status = Convert.ToBoolean(input[(32 * i) + j]);
                    Inputs[(32 * i) + j].Change_Status(status);
                }
            }
        }
 
        public void Update_Output_Data()
        {
            byte[] input;
            _Parent.sm.Get_SharedMemorybytes(out input, 1500, Output_Memory_Address.Get_Address_Infos().Length);
 
            int iolength = input.Length / 32;
 
            for (int i = 0; i < iolength; i++)
            {
                for (int j = 0; j < 32; j++)
                {
                    bool status = Convert.ToBoolean(input[(32 * i) + j]);
                    Outputs[(32 * i) + j].Change_Status(status);
                }
            }
        }
 
        private void btn_In_1_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_1[i]);
                tlp_Input.Controls.Add(Input_1[i + Input_1.Count / 2]);
            }
        }
 
        private void btn_In_2_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_2.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_2[i]);
                tlp_Input.Controls.Add(Input_2[i + Input_2.Count / 2]);
            }
        }
 
        private void btn_In_3_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_3.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_3[i]);
                tlp_Input.Controls.Add(Input_3[i + Input_3.Count / 2]);
            }
        }
 
        private void btn_In_4_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_4.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_4[i]);
                tlp_Input.Controls.Add(Input_4[i + Input_4.Count / 2]);
            }
        }
 
        private void btn_In_5_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_5[i]);
                tlp_Input.Controls.Add(Input_5[i + Input_5.Count / 2]);
            }
        }
 
        private void btn_In_6_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_6.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_6[i]);
                tlp_Input.Controls.Add(Input_6[i + Input_6.Count / 2]);
            }
 
        }
 
        private void btn_In_7_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_7[i]);
                tlp_Input.Controls.Add(Input_7[i + Input_7.Count / 2]);
            }
        }
 
        private void btn_In_8_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_8.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_8[i]);
                tlp_Input.Controls.Add(Input_8[i + Input_8.Count / 2]);
            }
        }
 
        private void btn_In_9_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_9.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_9[i]);
                tlp_Input.Controls.Add(Input_9[i + Input_9.Count / 2]);
            }
        }
 
        private void btn_In_10_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_10[i]);
                tlp_Input.Controls.Add(Input_10[i + Input_10.Count / 2]);
            }
        }
 
        private void btn_In_11_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_11[i]);
                tlp_Input.Controls.Add(Input_11[i + Input_11.Count / 2]);
            }
        }
 
        private void btn_In_12_Click(object sender, EventArgs e)
        {
            tlp_Input.Controls.Clear();
 
            for (int i = 0; i < Input_1.Count / 2; i++)
            {
                tlp_Input.Controls.Add(Input_12[i]);
                tlp_Input.Controls.Add(Input_12[i + Input_12.Count / 2]);
            }
        }
 
        private void btn_Out_1_Click(object sender, EventArgs e)
        {
            tlp_Output.Controls.Clear();
 
            for (int i = 0; i < Output_1.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_1[i]);
                tlp_Output.Controls.Add(Output_1[i + Output_1.Count / 2]);
            }
        }
 
        private void btn_Out_2_Click(object sender, EventArgs e)
        {
            tlp_Output.Controls.Clear();
 
            for (int i = 0; i < Output_2.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_2[i]);
                tlp_Output.Controls.Add(Output_2[i + Output_2.Count / 2]);
            }
        }
 
        private void btn_Out_3_Click(object sender, EventArgs e)
        {
            tlp_Output.Controls.Clear();
 
            for (int i = 0; i < Output_3.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_3[i]);
                tlp_Output.Controls.Add(Output_3[i + Output_3.Count / 2]);
            }
        }
 
        private void btn_Out_4_Click(object sender, EventArgs e)
        {
            tlp_Output.Controls.Clear();
 
            for (int i = 0; i < Output_4.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_4[i]);
                tlp_Output.Controls.Add(Output_4[i + Output_4.Count / 2]);
            }
        }
 
        private void btn_Out_5_Click(object sender, EventArgs e)
        {
            tlp_Output.Controls.Clear();
 
            for (int i = 0; i < Output_5.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_5[i]);
                tlp_Output.Controls.Add(Output_5[i + Output_5.Count / 2]);
            }
        }
 
        private void btn_Out_6_Click(object sender, EventArgs e)
        {
            tlp_Output.Controls.Clear();
 
            for (int i = 0; i < Output_6.Count / 2; i++)
            {
                tlp_Output.Controls.Add(Output_6[i]);
                tlp_Output.Controls.Add(Output_6[i + Output_6.Count / 2]);
            }
        }
    }
}