천호석
2022-06-17 4de9ea98e13449174aa2cd09c8351fc0e978f44a
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace SHARP_CLAS_UI
{
    public partial class Form_Auto_Power_Viewer : Form
    {
        delegate void UI_Update_Delegate();
 
        Equipment _equip;
 
        Thread UI_Update_Th;
 
        bool update_check;
 
        public bool shown;
 
        bool Clear_bit;
 
        Queue<string> Info_Que = new Queue<string>();
 
        public Form_Auto_Power_Viewer(Equipment _equip)
        {
            InitializeComponent();
            this._equip = _equip;
            
            UI_Update_Th = new Thread(UI_Update_Th_Set);
            UI_Update_Th.Start();
        }
 
        private void UI_Update_Th_Set()
        {
            while (!_equip.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
                {
                    object value;
 
                    lb_Power_Measuring.BackColor = _equip.process.ablation.Is_Power_Measure ? Color.Lime : Color.Green;
 
                    if (_equip.sm.Get_Value(Process_Memory_Address.Power_Meter_Energy, out value))
                    {
                        tb_Power.Text = value.ToString();
                    }
 
                    if (_equip.sm.Get_Value(Process_Memory_Address.Power_Meter_Average, out value))
                    {
                        tb_Average.Text = value.ToString();
                    }
                    if (_equip.sm.Get_Value(Process_Memory_Address.Power_Meter_Count, out value))
                    {
                        tb_Count.Text = value.ToString();
                    }
                    if (_equip.sm.Get_Value(Process_Memory_Address.Power_Meter_Max, out value))
                    {
                        tb_Max.Text = value.ToString();
                    }
                    if (_equip.sm.Get_Value(Process_Memory_Address.Power_Meter_Min, out value))
                    {
                        tb_Min.Text = value.ToString();
                    }
 
                    tb_Hour.Text = (_equip.Power_Parameter.Measurement_Cycle_Hour - (DateTime.Now - _equip.Power_Parameter.Measure_Date).TotalHours).ToString();
                    
                    if (Info_Que.Count > 0)
                    {
                        string str = Info_Que.Dequeue();
 
                        tb_Info.AppendText(str + "\r\n");
                    }
 
                    if(Clear_bit)
                    {
                        tb_Info.Text = string.Empty;
                        Clear_bit = false;
                    }
                }
                catch (Exception ex)
                {
 
                }
                finally
                {
                    update_check = false;
                }
            }
        }
 
        public void Add_Info(string str)
        {
            Info_Que.Enqueue(str);
        }
 
        public void Clear_Info()
        {
            Clear_bit = true;
        }
 
        private void btn_Hide_Click(object sender, EventArgs e)
        {
            shown = false;
            this.Hide();
        }
    }
}