From 1e678902f53fce4144968d09c08975ad68347473 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Fri, 16 Aug 2024 17:47:00 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E9=80=BB=E8=BE=91=E5=AE=8C?= =?UTF-8?q?=E5=A4=87IO=E6=B5=8B=E8=AF=95=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NDSD-Screwdriver/MainForm.Designer.cs | 26 ++++- NDSD-Screwdriver/MainForm.cs | 125 +++++++++++++++++++-- NDSD-Screwdriver/MainForm.resx | 3 + NDSD-Screwdriver/Tool/SerialPortFactory.cs | 2 +- 4 files changed, 142 insertions(+), 14 deletions(-) diff --git a/NDSD-Screwdriver/MainForm.Designer.cs b/NDSD-Screwdriver/MainForm.Designer.cs index 764c947..9bcb888 100644 --- a/NDSD-Screwdriver/MainForm.Designer.cs +++ b/NDSD-Screwdriver/MainForm.Designer.cs @@ -32,6 +32,7 @@ this.LogDataGridView = new System.Windows.Forms.DataGridView(); this.logTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.LogValue = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.RFIDValue = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.ScrewdriverMonitor = new DNSD_Controls.HslTable(); this.TestButton = new System.Windows.Forms.Button(); @@ -59,17 +60,20 @@ this.LogDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.LogDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.logTime, - this.LogValue}); + this.LogValue, + this.RFIDValue}); this.LogDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.LogDataGridView.Location = new System.Drawing.Point(3, 21); this.LogDataGridView.Name = "LogDataGridView"; + this.LogDataGridView.RowHeadersVisible = false; this.LogDataGridView.RowHeadersWidth = 51; this.LogDataGridView.RowTemplate.Height = 27; - this.LogDataGridView.Size = new System.Drawing.Size(388, 826); + this.LogDataGridView.Size = new System.Drawing.Size(587, 826); this.LogDataGridView.TabIndex = 1; // // logTime // + this.logTime.DataPropertyName = "CreateTime"; this.logTime.HeaderText = "日志时间"; this.logTime.MinimumWidth = 6; this.logTime.Name = "logTime"; @@ -78,10 +82,19 @@ // LogValue // this.LogValue.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.LogValue.DataPropertyName = "LogText"; this.LogValue.HeaderText = "日志内容"; this.LogValue.MinimumWidth = 6; this.LogValue.Name = "LogValue"; // + // RFIDValue + // + this.RFIDValue.DataPropertyName = "RFIDId"; + this.RFIDValue.HeaderText = "RFID值"; + this.RFIDValue.MinimumWidth = 6; + this.RFIDValue.Name = "RFIDValue"; + this.RFIDValue.Width = 150; + // // groupBox1 // this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; @@ -89,7 +102,7 @@ this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Location = new System.Drawing.Point(754, 0); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(394, 850); + this.groupBox1.Size = new System.Drawing.Size(593, 850); this.groupBox1.TabIndex = 2; this.groupBox1.TabStop = false; this.groupBox1.Text = "日志"; @@ -119,7 +132,7 @@ this.ScrewdriverMonitor.Text = "hslTable1"; this.ScrewdriverMonitor.TopHeaderColor = System.Drawing.Color.Black; this.ScrewdriverMonitor.TopHeaderHeight = 0.05F; - this.ScrewdriverMonitor.TopHeaderText = "螺丝刀监控"; + this.ScrewdriverMonitor.TopHeaderText = "拧紧枪监控"; this.ScrewdriverMonitor.TopHeaderTextSize = 18F; this.ScrewdriverMonitor.OnDrawCellTextEvent += new DNSD_Controls.HslTable.DrawCellTextDelegate(this.ScrewdriverMonitor_OnDrawCellTextEvent); // @@ -187,7 +200,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1148, 850); + this.ClientSize = new System.Drawing.Size(1347, 850); this.Controls.Add(this.ServerStopButton); this.Controls.Add(this.StartServerButton); this.Controls.Add(this.ServerRestartButton); @@ -198,7 +211,7 @@ this.Controls.Add(this.groupBox1); this.Controls.Add(this.DOTest); this.Name = "MainForm"; - this.Text = "MainForm"; + this.Text = "拧紧枪监控主界面"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); ((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).EndInit(); this.groupBox1.ResumeLayout(false); @@ -220,5 +233,6 @@ private System.Windows.Forms.Button ServerStopButton; private System.Windows.Forms.DataGridViewTextBoxColumn logTime; private System.Windows.Forms.DataGridViewTextBoxColumn LogValue; + private System.Windows.Forms.DataGridViewTextBoxColumn RFIDValue; } } \ No newline at end of file diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs index b4cbda2..4c24463 100644 --- a/NDSD-Screwdriver/MainForm.cs +++ b/NDSD-Screwdriver/MainForm.cs @@ -77,7 +77,11 @@ namespace NDSD_Screwdriver SqlLiteTool.CreateTable(AppTool.GetDb()); InitializeComponent(); LogContext = SqlLiteTool.GetDb(AppTool.GetDb()); - RFIDLogsEntitys = LogContext.Query().ToList(); + RFIDLogsEntitys = LogContext.Query().OrderByDesc(a => a.CreateTime).Take(200).ToList(); + LogDataGridView.AutoGenerateColumns = false; + LogDataGridView.DataSource = null; + LogDataGridView.DataSource = RFIDLogsEntitys; + DOperate = new DOperate(); if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort)) { @@ -161,6 +165,8 @@ namespace NDSD_Screwdriver }); } RFIDStatesEntities[0].RFIDState = 2; + FormUtils.LogInsert(LogContext, "RFID " + 0 + " 准备工作", RFIDStatesEntities[0].RFIDValue); + GetLog(); //读取报警灯数据 lightsEntities = new List(); lightsEntities.Clear(); @@ -192,6 +198,7 @@ namespace NDSD_Screwdriver flashThread.Start(); alarmThread.Start(); RefreshRoll(); + RefreshIO(); } /// @@ -215,10 +222,13 @@ namespace NDSD_Screwdriver if (server.ServerRestart(MemorySetting.ServerIP, MemorySetting.ServerPort)) { MessageBox.Show("服务器重启成功!"); + FormUtils.LogInsert(LogContext, "服务器重启成功"); } else { MessageBox.Show("服务器重启失败!请手动启动服务器。"); + FormUtils.LogInsert(LogContext, "服务器重启失败"); + } } @@ -233,10 +243,13 @@ namespace NDSD_Screwdriver if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort)) { MessageBox.Show("服务端打开失败!"); + FormUtils.LogInsert(LogContext, "服务端打开失败"); + } else { MessageBox.Show("服务器启动成功"); + FormUtils.LogInsert(LogContext, "服务器启动成功"); } } @@ -252,10 +265,14 @@ namespace NDSD_Screwdriver if (!server.ServerStop()) { MessageBox.Show("服务端关闭失败!"); + FormUtils.LogInsert(LogContext, "服务端关闭失败"); + } if (!server.ServerDispose()) { MessageBox.Show("服务端释放失败!"); + FormUtils.LogInsert(LogContext, "服务端释放失败"); + } } } @@ -283,7 +300,7 @@ namespace NDSD_Screwdriver textRFID = 0; return; } - + } #endregion @@ -297,18 +314,36 @@ namespace NDSD_Screwdriver /// 读取到的RFID private void SetNowWorkRow(string rfid) { + //设置RFID状态 int flag = 0; for (int i = 0; i < RFIDStatesEntities.Count; i++) { if (RFIDStatesEntities[i].RFIDValue == rfid && RFIDStatesEntities[i].RFIDState == 2) { RFIDStatesEntities[i].RFIDState = 1; + FormUtils.LogInsert(LogContext, "RFID " + i + " 开始工作", RFIDStatesEntities[i].RFIDValue); + GetLog(); if (i - 1 >= 0) { - RFIDStatesEntities[i - 1].RFIDState = 3; + string rfidValue = RFIDStatesEntities[i - 1].RFIDValue; + var leastTime = RFIDLogsEntitys.Where(x => x.RFIDId == rfidValue)/*.OrderByDescending(x => x.CreateTime)*/.FirstOrDefault().CreateTime; + double timeSpan = (DateTime.Now - leastTime).TotalSeconds; + if (timeSpan >= MemorySetting.AlarmTimeValue) + { + RFIDStatesEntities[i - 1].RFIDState = 4; + FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", RFIDStatesEntities[i].RFIDValue); + } + if (timeSpan < MemorySetting.AlarmTimeValue) + { + RFIDStatesEntities[i - 1].RFIDState = 3; + FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", RFIDStatesEntities[i].RFIDValue); + } + GetLog(); } if (i + 1 < RFIDStatesEntities.Count) { + FormUtils.LogInsert(LogContext, "RFID " + (i + 1) + " 准备工作", RFIDStatesEntities[i].RFIDValue); + GetLog(); RFIDStatesEntities[i + 1].RFIDState = 2; FlashIndex = i + 1; } @@ -326,10 +361,23 @@ namespace NDSD_Screwdriver { if (RFIDStatesEntities[i].RFIDState == 1) { - RFIDStatesEntities[i].RFIDState = 3; + string rfidValue = RFIDStatesEntities[i - 1].RFIDValue; + var leastTime = RFIDLogsEntitys.Where(x => x.RFIDId == rfidValue)/*.OrderByDescending(x => x.CreateTime)*/.FirstOrDefault().CreateTime; + double timeSpan = (DateTime.Now - leastTime).TotalSeconds; + if (timeSpan >= MemorySetting.AlarmTimeValue) + { + RFIDStatesEntities[i].RFIDState = 4; + FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", RFIDStatesEntities[i].RFIDValue); + } + if (timeSpan < MemorySetting.AlarmTimeValue) + { + RFIDStatesEntities[i].RFIDState = 3; + FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", RFIDStatesEntities[i].RFIDValue); + } } } } + //刷新前端灯的状态 for (int i = 0; i < RFIDStatesEntities.Count; i++) { if (RFIDStatesEntities[i].RFIDState == 1) @@ -349,6 +397,39 @@ namespace NDSD_Screwdriver SetRowsLightState(i, Brushes.Transparent); } } + if(flashThread.ThreadState == ThreadState.Running) + { + flashThread.Suspend(); + Thread.Sleep(100); + } + //刷新IO的状态 + for (int i = 0; i < RFIDStatesEntities.Count; i++) + { + + if (RFIDStatesEntities[i].RFIDState == 1) + { + DOperate.DOpen(lightsEntities[i].Yellow); + Thread.Sleep(100); + } + else if (RFIDStatesEntities[i].RFIDState == 3) + { + DOperate.DOpen(lightsEntities[i].Green); + Thread.Sleep(100); + DOperate.DClose(lightsEntities[i].Yellow); + Thread.Sleep(100); + } + else if (RFIDStatesEntities[i].RFIDState == 4) + { + DOperate.DOpen(lightsEntities[i].Red); + Thread.Sleep(100); + DOperate.DClose(lightsEntities[i].Yellow); + Thread.Sleep(100); + } + } + if (flashThread.ThreadState == ThreadState.Stopped) + { + flashThread.Resume(); + } RefreshRoll(); } @@ -477,7 +558,7 @@ namespace NDSD_Screwdriver { while (true) { - DOperate.DTimeOpen(1, 1); + DOperate.DTimeOpen(lightsEntities[FlashIndex].Yellow, 1); monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow; RefreshRoll(); Thread.Sleep(1000); @@ -488,6 +569,16 @@ namespace NDSD_Screwdriver }); } + /// + /// 获取Log + /// + private void GetLog() + { + RFIDLogsEntitys = LogContext.Query().OrderByDesc(a => a.CreateTime).Take(200).ToList(); + LogDataGridView.DataSource = null; + LogDataGridView.DataSource = RFIDLogsEntitys; + } + /// /// 等待工作指示灯闪烁进程 /// @@ -498,12 +589,17 @@ namespace NDSD_Screwdriver { while (true) { - + Thread.Sleep(500); } }); } + + /// + /// 获取准备行 + /// + /// 准备行index private int GetReadyRowIndex() { for (int i = 0; i < RFIDStatesEntities.Count; i++) @@ -516,6 +612,10 @@ namespace NDSD_Screwdriver return -1; } + /// + /// 获取正在工作的行 + /// + /// 工作行index private int GetNowRowIndex() { for (int i = 0; i < RFIDStatesEntities.Count; i++) @@ -528,7 +628,18 @@ namespace NDSD_Screwdriver return -1; } - + private void RefreshIO() + { + for (int i = 0; i < RFIDStatesEntities.Count; i++) + { + DOperate.DClose(lightsEntities[i].Yellow); + Thread.Sleep(100); + DOperate.DClose(lightsEntities[i].Red); + Thread.Sleep(100); + DOperate.DClose(lightsEntities[i].Green); + Thread.Sleep(100); + } + } #endregion } diff --git a/NDSD-Screwdriver/MainForm.resx b/NDSD-Screwdriver/MainForm.resx index 891754e..5abf5a2 100644 --- a/NDSD-Screwdriver/MainForm.resx +++ b/NDSD-Screwdriver/MainForm.resx @@ -123,4 +123,7 @@ True + + True + \ No newline at end of file diff --git a/NDSD-Screwdriver/Tool/SerialPortFactory.cs b/NDSD-Screwdriver/Tool/SerialPortFactory.cs index a15083c..29503c7 100644 --- a/NDSD-Screwdriver/Tool/SerialPortFactory.cs +++ b/NDSD-Screwdriver/Tool/SerialPortFactory.cs @@ -29,7 +29,7 @@ namespace NDSD_Screwdriver.Tool StopBits = System.IO.Ports.StopBits.One //停止位 }).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter())); - clientSerialPortClient.Connect(); + //clientSerialPortClient.Connect(); waitClient = clientSerialPortClient.CreateWaitingClient(new WaitingOptions() {