천호석
2022-12-12 d98672af4137db3f52930760ad200b8ddc969954
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
using DIT.SharedMemory;
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_Analog : Form
    {
        Form_Frame _Parent;
        List<uc_Analog_Vlaue> Analogs = new List<uc_Analog_Vlaue>();
 
        private delegate void UI_Update_Delegate();
        Thread Data_Update_Th;
        Thread UI_Update_Th;
 
        bool update_check;
 
        public Form_Maintenance_Analog(Form_Frame _Parent)
        {
            InitializeComponent();
            this._Parent = _Parent;
 
            Init_AnalogData();
            Data_Update_Th = new Thread(Data_Update_Th_Set);
            Data_Update_Th.Start();
            UI_Update_Th = new Thread(UI_Update_Th_Set);
            UI_Update_Th.Start();
        }
 
        public void Set_Language()
        {
            
 
        }
 
        public void Init_AnalogData()
        {
            string[] descriptions = Analog_Data_Memory_Address.Get_Name_of_Memory_Address();
 
            int iosplit = 8;
            int iolength = descriptions.Length / iosplit;
 
            for (int i = 0; i < iolength; i++)
            {
                for (int j = 0; j < iosplit; j++)
                {
                    string ioname = $"CH {j + 1}";
                    Analogs.Add(new uc_Analog_Vlaue(ioname, descriptions[(iosplit * i) + j]));
                }
            }
 
            for (int i = 0; i < iolength; i++)
            {
                for (int j = 0; j < iosplit; j++)
                {
                    if (i == 0)
                    {
                        tlp_Analog_1.Controls.Add(Analogs[(iosplit * i) + j]);
                    }
                    else if(i == 1)
                    {
                        tlp_Analog_2.Controls.Add(Analogs[(iosplit * i) + j]);
                    }
                    else if (i == 2)
                    {
                        tlp_Analog_3.Controls.Add(Analogs[(iosplit * i) + j]);
                    }
                    else if (i == 3)
                    {
                        tlp_Analog_4.Controls.Add(Analogs[(iosplit * i) + j]);
                    }
                }
            }
        }
 
        private void UI_Update_Th_Set()
        {
            while (!this.IsDisposed)
            {
                Thread.Sleep(100);
 
                if (!update_check)
                {
                    update_check = true;
                    UI_Update();
                }
            }
        }
 
        private void UI_Update()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new UI_Update_Delegate(UI_Update));
                return;
            }
            else
            {
                try
                {
                    foreach (uc_Analog_Vlaue anaolg in Analogs)
                    {
                        anaolg.Change_Text();
                    }
                }
                catch (Exception ex)
                {
 
                }
                finally
                {
                    update_check = false;
                }
            }
        }
 
        private void Data_Update_Th_Set()
        {
            while (!this.IsDisposed)
            {
                Thread.Sleep(10);
                Data_Update();
            }
        }
 
        private void Data_Update()
        {
            try
            {
                DateTime dt = DateTime.Now;
                int i = 0;
                foreach(SharedmemoryAddressInfo info in Analog_Data_Memory_Address.Get_Address_Infos())
                {
                    object value = 0;
                    if(_Parent.sm.Get_Value(info, out value))
                    {
                        Analogs[i].Change_Value((float)value);
                    }
 
                    i++;
                }
                TimeSpan ts = DateTime.Now - dt;
            }
            catch (Exception ex)
            {
                _Parent.WriteExceptionLog(this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex);
            }
        }
    }
}