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 Analogs = new List(); 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); } } } }