diff --git a/UserClass/AsyncSerialPortClient.cs b/UserClass/AsyncSerialPortClient.cs index bfd69bc..c55bc77 100644 --- a/UserClass/AsyncSerialPortClient.cs +++ b/UserClass/AsyncSerialPortClient.cs @@ -65,8 +65,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass for (int i = 0; i < sArray.Length; i++) { - if (!string.IsNullOrEmpty(sArray[i])) + if (sArray[i].Length>5) { + return EasyTask.CompletedTask; ; string SYSAPI = sArray[i].Substring(0, 5); string Station = ClipBetween(sArray[i], '[', ']'); string DAT = sArray[i].Substring(sArray[i].IndexOf("]") + 1); @@ -129,7 +130,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - // return EasyTask.CompletedTask; ; Dictionary _new = new Dictionary();//缓存函数 _new = JsonConvert.DeserializeObject>(DAT);//反序列化 DataRow drEmployee = MainWindowViewModel.Machines.Select("Station='" + diff --git a/View/MonitorView.xaml b/View/MonitorView.xaml index 0065645..ce8c00b 100644 --- a/View/MonitorView.xaml +++ b/View/MonitorView.xaml @@ -126,19 +126,40 @@ - + - + + + + + - - + + + + + + + + + + diff --git a/ViewModel/CurveDiagramViewModel.cs b/ViewModel/CurveDiagramViewModel.cs index eb85858..0814c0b 100644 --- a/ViewModel/CurveDiagramViewModel.cs +++ b/ViewModel/CurveDiagramViewModel.cs @@ -90,7 +90,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel CrosshairSnapEnabled = true, Position = LiveChartsCore.Measure.AxisPosition.End }, //液位轴 - new Axis // + /* new Axis // { MinLimit =0, MaxLimit =14, @@ -106,7 +106,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel DrawTicksPath = true, CrosshairSnapEnabled = true, Position = LiveChartsCore.Measure.AxisPosition.End - }, //PH轴 + },*/ //PH轴 }; private static Random _r = new Random(); @@ -136,10 +136,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel if (mode) { if (string.IsNullOrEmpty(w)) return; - SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 - SQLiteHelpers.Open(); //打开数据库 - CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where WorkOrder = '" + w + "'order by Time", null).Tables[0]; - SQLiteHelpers.Close(); + CDB = MainWindowViewModel.SQLiteChartAdress.ExecuteDataSet("select * from Chart where WorkOrder = '" + w + "'order by Time", null).Tables[0]; } else @@ -147,18 +144,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel if (string.IsNullOrEmpty(m)) return; if (string.IsNullOrEmpty(s)) return; if (string.IsNullOrEmpty(e)) return; - SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 - SQLiteHelpers.Open(); //打开数据库 - CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where Machine = '" + m + "'" + + // SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 + // SQLiteHelpers.Open(); //打开数据库 + CDB = MainWindowViewModel.SQLiteChartAdress.ExecuteDataSet("select * from Chart where Machine = '" + m + "'" + " and Time > '" + s + "' and Time < '" + e + "' order by Time", null).Tables[0]; - SQLiteHelpers.Close(); + // SQLiteHelpers.Close(); } CDB_Count = CDB.Rows.Count; var MTT_items = new List(); var MTL_items = new List(); - var MTH_items = new List(); + // var MTH_items = new List(); var MST_items = new List(); var MUT_items = new List(); var STTA_items = new List(); @@ -167,12 +164,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel var STLB_items = new List(); var STTC_items = new List(); var STLC_items = new List(); - for (var i = 0; i < CDB_Count; i++) + for (var i = 0; i < CDB_Count; i=i+10) { DateTime TIME = Convert.ToDateTime(CDB.Rows[i].Field("Time")); MTT_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("MTT"))); MTL_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("MTL"))); - MTH_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("MTH"))); + // MTH_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("MTH"))); MST_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("MST"))); MUT_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("MUT"))); STTA_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field("STTA"))); @@ -186,7 +183,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel MTT_values = new ObservableCollection(MTT_items); MTL_values = new ObservableCollection(MTL_items); - MTH_values = new ObservableCollection(MTH_items); + // MTH_values = new ObservableCollection(MTH_items); MST_values = new ObservableCollection(MST_items); MUT_values = new ObservableCollection(MUT_items); STTA_values = new ObservableCollection(STTA_items); @@ -198,7 +195,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel Series = new ISeries[] { - new LineSeries + /* new LineSeries { Name = Properties.Resources.MasterCylinder +"PH", Values = MTH_values, @@ -208,7 +205,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel Fill = null, LineSmoothness = 0, ScalesYAt = 2, - }, //PH + }, *///PH new LineSeries { Name = Resources.Target + Resources.Temperature, diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 76f8136..4cda391 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -1062,8 +1062,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel , Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD1"))); AsyncSerialPortClient._responseEvent.Set(); - Thread myThread1 = new Thread(Port1_link); - myThread1.Start(); + Port1_link(); } if (Machines.Select("Type='false' AND Serial='PORT2'").Length > 0) { @@ -1075,8 +1074,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel , Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD2"))); AsyncSerialPortClient._responseEvent2.Set(); - Thread myThread2 = new Thread(Port2_link); - myThread2.Start(); + Port2_link(); } if (Machines.Select("Type='false' AND Serial='PORT3'").Length > 0) { @@ -1087,9 +1085,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel , Configini.IniReadvalue("SYS", "COMP3") , Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD3"))); AsyncSerialPortClient._responseEvent3.Set(); - - Thread myThread3 = new Thread(Port3_link); - myThread3.Start(); + + Port3_link(); } if (Machines.Select("Type='false' AND Serial='PORT4'").Length > 0) { @@ -1100,194 +1097,205 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel , Configini.IniReadvalue("SYS", "COMP4") , Convert.ToInt32(Configini.IniReadvalue("SYS", "BAUD4"))); AsyncSerialPortClient._responseEvent4.Set(); - - Thread myThread4 = new Thread(Port4_link); - myThread4.Start(); + + Port4_link(); } } - private void Port1_link() + private async void Port1_link() { - while (true) + await Task.Run(() => { - try + while (MachiensPortClient[0].Online ) { - if (stringQueueSerial_1.Count > 0) //信息发送队列 + try { - if (AsyncSerialPortClient._responseEvent.IsSet) + if (stringQueueSerial_1.Count > 0) //信息发送队列 { - QueueSerial t = stringQueueSerial_1.Dequeue(); - AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT + "\n"); - //MachiensPortClient[t.ID].Send(t.DAT); + if (AsyncSerialPortClient._responseEvent.IsSet) + { + QueueSerial t = stringQueueSerial_1.Dequeue(); + AsyncSerialPortClient.SendCommandAndWait(MachiensPortClient[0], t.DAT + "\n"); + //MachiensPortClient[t.ID].Send(t.DAT); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(50)); + } } else { - Thread.Sleep(TimeSpan.FromMilliseconds(50)); - } - } - else - { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'")) - { - if (MachinesRow["State"].ToString() == "800") + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'")) { - stringQueueSerial_1.Enqueue(new QueueSerial + if (MachinesRow["State"].ToString() == "800") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(5)); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(5)); + } } } } + catch (Exception) + { + } + finally + { + } } - catch (Exception) - { - } - finally - { - } - } + }); }//发送 - private void Port2_link() + private async void Port2_link() { - while (true) + await Task.Run(() => { - try + while (MachiensPortClient[1].Online) { - if (stringQueueSerial_2.Count > 0) //信息发送队列 + try { - if (AsyncSerialPortClient._responseEvent2.IsSet) + if (stringQueueSerial_2.Count > 0) //信息发送队列 { - QueueSerial t = stringQueueSerial_2.Dequeue(); - AsyncSerialPortClient.SendCommandAndWait2(MachiensPortClient[1], t.DAT + "\n"); - //MachiensPortClient[t.ID].Send(t.DAT); + if (AsyncSerialPortClient._responseEvent2.IsSet) + { + QueueSerial t = stringQueueSerial_2.Dequeue(); + AsyncSerialPortClient.SendCommandAndWait2(MachiensPortClient[1], t.DAT + "\n"); + //MachiensPortClient[t.ID].Send(t.DAT); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(50)); + } } else { - Thread.Sleep(TimeSpan.FromMilliseconds(50)); - } - } - else - { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'")) - { - if (MachinesRow["State"].ToString() == "800") + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'")) { - stringQueueSerial_2.Enqueue(new QueueSerial + if (MachinesRow["State"].ToString() == "800") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(5)); + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(5)); + } } } } + catch (Exception) + { + } + finally + { + } } - catch (Exception) - { - } - finally - { - } - } + }); }//发送 - private void Port3_link() + private async void Port3_link() { - while (true) + await Task.Run(() => { - try + while (MachiensPortClient[2].Online) { - if (stringQueueSerial_3.Count > 0) //信息发送队列 - { - if (AsyncSerialPortClient._responseEvent3.IsSet) - { - QueueSerial t = stringQueueSerial_3.Dequeue(); - AsyncSerialPortClient.SendCommandAndWait3(MachiensPortClient[2], t.DAT + "\n"); - //MachiensPortClient[t.ID].Send(t.DAT); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(50)); - } - } - else + try { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'")) + if (stringQueueSerial_3.Count > 0) //信息发送队列 { - if (MachinesRow["State"].ToString() == "800") + if (AsyncSerialPortClient._responseEvent3.IsSet) { - stringQueueSerial_3.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); + QueueSerial t = stringQueueSerial_3.Dequeue(); + AsyncSerialPortClient.SendCommandAndWait3(MachiensPortClient[2], t.DAT + "\n"); + //MachiensPortClient[t.ID].Send(t.DAT); } else { Thread.Sleep(TimeSpan.FromMilliseconds(50)); } } + else + { + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'")) + { + if (MachinesRow["State"].ToString() == "800") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(50)); + } + } + } + } + catch (Exception) + { + } + finally + { } } - catch (Exception) - { - } - finally - { - } - } + }); }//发送 - private void Port4_link() + private async void Port4_link() { - while (true) + await Task.Run(() => { - try + while (MachiensPortClient[3].Online) { - if (stringQueueSerial_4.Count > 0) //信息发送队列 - { - if (AsyncSerialPortClient._responseEvent4.IsSet) - { - QueueSerial t = stringQueueSerial_4.Dequeue(); - AsyncSerialPortClient.SendCommandAndWait4(MachiensPortClient[3], t.DAT + "\n"); - //MachiensPortClient[t.ID].Send(t.DAT); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(50)); - } - } - else + try { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'")) + if (stringQueueSerial_4.Count > 0) //信息发送队列 { - if (MachinesRow["State"].ToString() == "800") + if (AsyncSerialPortClient._responseEvent4.IsSet) { - stringQueueSerial_4.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); + QueueSerial t = stringQueueSerial_4.Dequeue(); + AsyncSerialPortClient.SendCommandAndWait4(MachiensPortClient[3], t.DAT + "\n"); + //MachiensPortClient[t.ID].Send(t.DAT); } else { Thread.Sleep(TimeSpan.FromMilliseconds(50)); } } + else + { + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'")) + { + if (MachinesRow["State"].ToString() == "800") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(50)); + } + } + } + } + catch (Exception) + { + } + finally + { } } - catch (Exception) - { - } - finally - { - } - } + }); }//发送 public static string SYS_WorkNumder; //工单号