change - 逻辑完备IO测试完毕

master
SoulStar 1 month ago
parent 44ba5c47fa
commit 1e678902f5

@ -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;
}
}

@ -77,7 +77,11 @@ namespace NDSD_Screwdriver
SqlLiteTool.CreateTable(AppTool.GetDb());
InitializeComponent();
LogContext = SqlLiteTool.GetDb(AppTool.GetDb());
RFIDLogsEntitys = LogContext.Query<RFIDLogsEntity>().ToList();
RFIDLogsEntitys = LogContext.Query<RFIDLogsEntity>().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<LightsEntity>();
lightsEntities.Clear();
@ -192,6 +198,7 @@ namespace NDSD_Screwdriver
flashThread.Start();
alarmThread.Start();
RefreshRoll();
RefreshIO();
}
/// <summary>
@ -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
/// <param name="rfid">读取到的RFID</param>
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
});
}
/// <summary>
/// 获取Log
/// </summary>
private void GetLog()
{
RFIDLogsEntitys = LogContext.Query<RFIDLogsEntity>().OrderByDesc(a => a.CreateTime).Take(200).ToList();
LogDataGridView.DataSource = null;
LogDataGridView.DataSource = RFIDLogsEntitys;
}
/// <summary>
/// 等待工作指示灯闪烁进程
/// </summary>
@ -498,12 +589,17 @@ namespace NDSD_Screwdriver
{
while (true)
{
Thread.Sleep(500);
}
});
}
/// <summary>
/// 获取准备行
/// </summary>
/// <returns>准备行index</returns>
private int GetReadyRowIndex()
{
for (int i = 0; i < RFIDStatesEntities.Count; i++)
@ -516,6 +612,10 @@ namespace NDSD_Screwdriver
return -1;
}
/// <summary>
/// 获取正在工作的行
/// </summary>
/// <returns>工作行index</returns>
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
}

@ -123,4 +123,7 @@
<metadata name="LogValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RFIDValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

@ -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()
{

Loading…
Cancel
Save