diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 57448eb..6f7be0b 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -162,7 +162,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { a.UseCheckClear() .SetCheckClearType(CheckClearType.All) - .SetTick(TimeSpan.FromSeconds(10)) + .SetTick(TimeSpan.FromSeconds(30)) .SetOnClose((c, t) => { c.TryShutdown(); diff --git a/View/MonitorView.xaml b/View/MonitorView.xaml index 7919a68..b9d861b 100644 --- a/View/MonitorView.xaml +++ b/View/MonitorView.xaml @@ -7,9 +7,13 @@ xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel" + xmlns:ConvertMoels="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ConvertMoels" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}" mc:Ignorable="d" d:DesignHeight="1000" d:DesignWidth="1900"> + + + @@ -54,7 +58,21 @@ - + + + + + + + + + + + + diff --git a/View/MonitorView.xaml.cs b/View/MonitorView.xaml.cs index 0ae7ba1..04c679e 100644 --- a/View/MonitorView.xaml.cs +++ b/View/MonitorView.xaml.cs @@ -52,9 +52,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量 if (rownum != -1)//判断鼠标定位是否有效 { - machine = (Griddata.Columns[0].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列, - workOrder = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列, - dyelot = (Griddata.Columns[2].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列, + machine = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列, + workOrder = (Griddata.Columns[2].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列, + dyelot = (Griddata.Columns[3].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列, machin_LOG.Text = Properties.Resources.Machine+":"+machine+" "+Properties.Resources.WorkOrder+":"+workOrder; } @@ -224,7 +224,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View { if (machines_info == 0) { - MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC832" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID=index,DAT= "SC832" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) }); + + // MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC832" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); }//信息 else if (machines_info == 1) { @@ -232,7 +234,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View }//输送状态 else if (machines_info == 2) { - MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC833" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID = index, DAT = "SC833" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) }); + + // MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC833" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); }//单据 } else @@ -242,7 +246,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View if ((State_ == 101) || (State_ == 201) || (State_ == 202) || (State_ == 309))//获得细节信息 { - MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC831" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID = index, DAT = "SC831" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) }); + + // MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC831" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); } else { diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 728d383..1b22ed0 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -101,6 +101,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel }; disTimer.Tick += new EventHandler(DisTimer_500MS);//每一秒执行的方法 disTimer.Start();//计时开始 + + DispatcherTimer dis50ms = new DispatcherTimer + { + Interval = TimeSpan.FromMilliseconds(50) //毫秒 + }; + dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法 + dis50ms.Start();//计时开始 }//时间周期初始化 void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S { @@ -116,13 +123,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel //Updata_Machines(Machines, Convert.ToInt16(dt["ID"]), "State", "800"); } } - for (int i = 0; i < Machinesdata_Count; i++) + for (int i = 0; i < Machinesdata_Count; i++) { string mac_s = Selet_Machines(Machines, "State", i).ToString(); if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "309"))//获取信息 { - MachiensTcpClient[i].SendAsync("SC830" + Selet_Machines(Machines, "SYSKEY", i).ToString()); + stringQueue.Enqueue(new QueueString { ID = i, DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", i).ToString() });//信息插入队列 + // MachiensTcpClient[i].SendAsync("SC830" + Selet_Machines(Machines, "SYSKEY", i).ToString()); } } } @@ -134,15 +142,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel if (Selet_Machines(Machines, "State", i).ToString() == "801") { MachiensTcpClient[i].SendAsync("SC800:SCCM[" + MachiensTcpClient[i].IP + ";" + MachiensTcpClient[i].Port + "]"); - } - + } } } void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS { DATA_view(); - + + } + void DisTimer_50MS(object sender, EventArgs e)//Tick_Event周期执行事件50MS + { + if (stringQueue.Count > 0) //信息发送队列 + { + QueueString t= stringQueue.Dequeue(); + MachiensTcpClient[t.ID].SendAsync(t.DAT); + } } private SQLiteHelper SQLiteHelpers = null; //定义数据库 @@ -369,7 +384,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel public string Process { get; set; } public string Step { get; set; } public string Message { get; set; } - + public string State { get; set; } + } public ObservableCollection ToObservableCollection(DataTable dt) where T : class, new() { @@ -418,5 +434,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } return lst; } + //通讯队列 + public class QueueString + { + public int ID { get; set; } + public string DAT { get; set; } + } + public static class Queue + { + public static int ID { get; set; } + public static string DAT { get; set; } + } + // 创建一个字符串类型的队列 + public static Queue stringQueue = new Queue(); } }