Compare commits

..

2 Commits

@ -30,6 +30,8 @@
{ {
this.DOTest = new System.Windows.Forms.Button(); this.DOTest = new System.Windows.Forms.Button();
this.LogDataGridView = new System.Windows.Forms.DataGridView(); this.LogDataGridView = new System.Windows.Forms.DataGridView();
this.logTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.LogValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.ScrewdriverMonitor = new DNSD_Controls.HslTable(); this.ScrewdriverMonitor = new DNSD_Controls.HslTable();
this.TestButton = new System.Windows.Forms.Button(); this.TestButton = new System.Windows.Forms.Button();
@ -38,8 +40,6 @@
this.ServerRestartButton = new System.Windows.Forms.Button(); this.ServerRestartButton = new System.Windows.Forms.Button();
this.StartServerButton = new System.Windows.Forms.Button(); this.StartServerButton = new System.Windows.Forms.Button();
this.ServerStopButton = new System.Windows.Forms.Button(); this.ServerStopButton = new System.Windows.Forms.Button();
this.logTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.LogValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -68,6 +68,20 @@
this.LogDataGridView.Size = new System.Drawing.Size(388, 826); this.LogDataGridView.Size = new System.Drawing.Size(388, 826);
this.LogDataGridView.TabIndex = 1; this.LogDataGridView.TabIndex = 1;
// //
// logTime
//
this.logTime.HeaderText = "日志时间";
this.logTime.MinimumWidth = 6;
this.logTime.Name = "logTime";
this.logTime.Width = 125;
//
// LogValue
//
this.LogValue.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.LogValue.HeaderText = "日志内容";
this.LogValue.MinimumWidth = 6;
this.LogValue.Name = "LogValue";
//
// groupBox1 // groupBox1
// //
this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
@ -169,19 +183,6 @@
this.ServerStopButton.UseVisualStyleBackColor = true; this.ServerStopButton.UseVisualStyleBackColor = true;
this.ServerStopButton.Click += new System.EventHandler(this.ServerStopButton_Click); this.ServerStopButton.Click += new System.EventHandler(this.ServerStopButton_Click);
// //
// logTime
//
this.logTime.HeaderText = "日志时间";
this.logTime.MinimumWidth = 6;
this.logTime.Name = "logTime";
//
// LogValue
//
this.LogValue.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.LogValue.HeaderText = "日志内容";
this.LogValue.MinimumWidth = 6;
this.LogValue.Name = "LogValue";
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);

@ -3,6 +3,7 @@ using DNSD_DB;
using DNSD_DB.Entity; using DNSD_DB.Entity;
using NDSD_Screwdriver.Tool; using NDSD_Screwdriver.Tool;
using NDSD_TouchSocket; using NDSD_TouchSocket;
using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -39,21 +40,6 @@ namespace NDSD_Screwdriver
private Random rand = new Random(); private Random rand = new Random();
///// <summary>
///// 判断是否是第一次初始化
///// </summary>
//private int flag = 0;
/// <summary>
/// 判断现在操作哪一行
/// </summary>
public int NowRowIndex = 0;
/// <summary>
/// 准备工作的行号
/// </summary>
public int ReadyRowIndex = 0;
/// <summary> /// <summary>
/// RFID状态列表 /// RFID状态列表
/// </summary> /// </summary>
@ -74,19 +60,17 @@ namespace NDSD_Screwdriver
/// </summary> /// </summary>
public IDbContext LogContext; public IDbContext LogContext;
Thread thread; Thread flashThread;
bool flag = false;
bool IsFirst = true;
SerialPortFactory serialPort; SerialPortFactory serialPort;
private CancellationTokenSource cancellationTokenSource; private CancellationTokenSource cancellationTokenSource;
private int textindex = 0; public int textRFID = 0;
Thread alarmThread;
public int textRFID; int FlashIndex = 0;
public MainForm() public MainForm()
{ {
@ -100,7 +84,6 @@ namespace NDSD_Screwdriver
MessageBox.Show("服务端打开失败!"); MessageBox.Show("服务端打开失败!");
FormUtils.LogInsert(LogContext, "服务端打开失败"); FormUtils.LogInsert(LogContext, "服务端打开失败");
} }
FlashThread();
serialPort = new SerialPortFactory(); serialPort = new SerialPortFactory();
StartLongRunningTask(); StartLongRunningTask();
} }
@ -121,6 +104,14 @@ namespace NDSD_Screwdriver
FormUtils.LogInsert(LogContext, "服务端释放失败"); FormUtils.LogInsert(LogContext, "服务端释放失败");
} }
} }
if (flashThread != null)
{
flashThread.Abort();
}
if (alarmThread != null)
{
alarmThread.Abort();
}
} }
#region 按钮 #region 按钮
@ -132,50 +123,36 @@ namespace NDSD_Screwdriver
/// <param name="e"></param> /// <param name="e"></param>
private void DOTest_Click(object sender, EventArgs e) private void DOTest_Click(object sender, EventArgs e)
{ {
//string str = serialPort.Read(); //string str = serialPort.Read();
ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate); ScrewdriverTest screwdriverTest = new ScrewdriverTest(server, DOperate);
screwdriverTest.Show(); screwdriverTest.Show();
} }
/// <summary> /// <summary>
/// 测试按钮 /// 初始化按钮
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void TestButton1_Click(object sender, EventArgs e) private void InitButton_Click(object sender, EventArgs e)
{ {
if (RFIDStatesEntities.Count == 0) FlashIndex = 0;
textRFID = 0;
if (flashThread != null)
{ {
MessageBox.Show("没有值,请先设置。"); flashThread.Abort();
} }
SetNowWorkRow(RFIDStatesEntities[NowRowIndex].RFIDValue); FlashThread();
SetNowRowsLightState(1); if (alarmThread != null)
if (flag && thread.ThreadState == ThreadState.Suspended)
{
thread.Resume();
}
RefreshRoll();
if (++NowRowIndex >= RFIDStatesEntities.Count)
{ {
NowRowIndex = 0; alarmThread.Abort();
}
} }
AlarmThread();
/// <summary>
/// 初始化按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InitButton_Click(object sender, EventArgs e)
{
NowRowIndex = 0;
//读取rfid数据 //读取rfid数据
var ctx = SqlLiteTool.GetDb(AppTool.GetDb()); var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList(); var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList();
var strs = list.Select(x => x.RfidNo).ToArray(); var strs = list.Select(x => x.RfidNo).ToArray();
RFIDStatesEntities = new List<RFIDStatesEntity>(); RFIDStatesEntities = new List<RFIDStatesEntity>();
RFIDStatesEntities.Clear();
foreach (var a in strs) foreach (var a in strs)
{ {
RFIDStatesEntities.Add(new RFIDStatesEntity() RFIDStatesEntities.Add(new RFIDStatesEntity()
@ -183,8 +160,10 @@ namespace NDSD_Screwdriver
RFIDValue = a, RFIDValue = a,
}); });
} }
RFIDStatesEntities[0].RFIDState = 2;
//读取报警灯数据 //读取报警灯数据
lightsEntities = new List<LightsEntity>(); lightsEntities = new List<LightsEntity>();
lightsEntities.Clear();
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
lightsEntities.Add(new LightsEntity() lightsEntities.Add(new LightsEntity()
@ -196,6 +175,7 @@ namespace NDSD_Screwdriver
} }
//初始化列表框架 //初始化列表框架
monitorEntities = new List<MonitorEntity>(); monitorEntities = new List<MonitorEntity>();
monitorEntities.Clear();
for (int i = 0; i < RFIDStatesEntities.Count; i++) for (int i = 0; i < RFIDStatesEntities.Count; i++)
{ {
monitorEntities.Add(new MonitorEntity() monitorEntities.Add(new MonitorEntity()
@ -204,15 +184,13 @@ namespace NDSD_Screwdriver
RowEntitys = InitRows(i) RowEntitys = InitRows(i)
}); });
} }
if (flag)
{
thread.Suspend();
}
//更新值 //更新值
for (int i = 0; i < RFIDStatesEntities.Count; i++) for (int i = 0; i < RFIDStatesEntities.Count; i++)
{ {
monitorEntities[i].RowEntitys[1].Value = RFIDStatesEntities[i].RFIDValue; monitorEntities[i].RowEntitys[1].Value = RFIDStatesEntities[i].RFIDValue;
} }
flashThread.Start();
alarmThread.Start();
RefreshRoll(); RefreshRoll();
} }
@ -282,10 +260,98 @@ namespace NDSD_Screwdriver
} }
} }
/// <summary>
/// 测试按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TestButton1_Click(object sender, EventArgs e)
{
if (RFIDStatesEntities.Count == 0)
{
MessageBox.Show("请先初始化RFID列表");
}
else if (textRFID == RFIDStatesEntities.Count)
{
SetNowWorkRow("0000000");
textRFID = 0;
return;
}
SetNowWorkRow(RFIDStatesEntities[textRFID].RFIDValue);
if (++textRFID > RFIDStatesEntities.Count)
{
textRFID = 0;
return;
}
}
#endregion #endregion
#region 功能性方法 #region 功能性方法
/// <summary>
/// 根据读取到的RFID条码设置当前工作的行 并且更新state
/// </summary>
/// <param name="rfid">读取到的RFID</param>
private void SetNowWorkRow(string 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;
if (i - 1 >= 0)
{
RFIDStatesEntities[i - 1].RFIDState = 3;
}
if (i + 1 < RFIDStatesEntities.Count)
{
RFIDStatesEntities[i + 1].RFIDState = 2;
FlashIndex = i + 1;
}
else
{
flashThread.Abort();
}
flag = 1;
break;
}
}
if (flag == 0) //列表里没有已读的RFID
{
for (int i = 0; i < RFIDStatesEntities.Count; i++)
{
if (RFIDStatesEntities[i].RFIDState == 1)
{
RFIDStatesEntities[i].RFIDState = 3;
}
}
}
for (int i = 0; i < RFIDStatesEntities.Count; i++)
{
if (RFIDStatesEntities[i].RFIDState == 1)
{
SetRowsLightState(i, 1);
}
else if (RFIDStatesEntities[i].RFIDState == 3)
{
SetRowsLightState(i, 0);
}
else if (RFIDStatesEntities[i].RFIDState == 4)
{
SetRowsLightState(i, 2);
}
else
{
SetRowsLightState(i, Brushes.Transparent);
}
}
RefreshRoll();
}
/// <summary> /// <summary>
/// 初始化一行 /// 初始化一行
/// </summary> /// </summary>
@ -309,98 +375,40 @@ namespace NDSD_Screwdriver
/// </summary> /// </summary>
private void RefreshRoll() private void RefreshRoll()
{ {
List<string[]> values = new List<string[]>();
for (int i = 0; i < RFIDStatesEntities.Count; i++) for (int i = 0; i < RFIDStatesEntities.Count; i++)
{ {
ScrewdriverMonitor.AddRowTop(new string[]{ values.Add(new string[]
"", {
"", "", "", ""
""
}); });
} }
} ScrewdriverMonitor.SetTableValue(values);
/// <summary>
/// 设置当前行指示灯的状态以及工作的行的标识 输入枚举类
/// </summary>
/// <param name="lightState"></param>
private void SetNowRowsLightState(LightState lightState)
{
SetNowRowsLightState(FormUtils.EnumColorToBrush(lightState));
} }
private void SetNowRowsLightState(int lightState) private void SetRowsLightState(int index, LightState lightState)
{ {
SetNowRowsLightState((LightState)lightState); SetRowsLightState(index, FormUtils.EnumColorToBrush(lightState));
} }
/// <summary> private void SetRowsLightState(int index, int lightState)
/// 设置当前行指示灯的状态以及工作的行的标识 输入Brush
/// </summary>
/// <param name="brush"></param>
private void SetNowRowsLightState(Brush brush)
{
if (monitorEntities.Count == 0)
{ {
return; SetRowsLightState(index, (LightState)lightState);
}
monitorEntities[NowRowIndex].RowEntitys[2].Color = brush;
SetNextRowsFlash();
for (int i = 0; i < RFIDStatesEntities.Count; i++)
{
monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : "";
}
} }
/// <summary> /// <summary>
/// 设置待工作灯闪烁 /// 设置指定行指示灯的状态以及工作的行的标识
/// </summary> /// </summary>
private void SetNextRowsFlash() /// <param name="brush"></param>
{ private void SetRowsLightState(int index, Brush brush)
if (ReadyRowIndex >= RFIDStatesEntities.Count)
{
ReadyRowIndex = 0;
thread.Suspend();
return;
}
if (!flag)
{
thread.Start();
flag = true;
}
}
/// <summary>
/// 根据读取到的RFID条码设置当前工作的行
/// </summary>
/// <param name="rfid">读取到的RFID</param>
private void SetNowWorkRow(string rfid)
{ {
ReadyRowIndex = NowRowIndex + 1; monitorEntities[index].RowEntitys[2].Color = brush;
//RFIDStatesEntities[ReadyRowIndex].RFIDState = 2; //工作中箭头指示
//if (IsFirst)
//{
// IsFirst = false;
for (int i = 0; i < RFIDStatesEntities.Count; i++) for (int i = 0; i < RFIDStatesEntities.Count; i++)
{ {
if (monitorEntities[i].RowEntitys[1].Value == rfid) monitorEntities[i].RowEntitys[0].Value = RFIDStatesEntities[i].RFIDState == 1 ? "=>" : "";
{
NowRowIndex = i;
return;
}
} }
//}
//else
//{
// for (int i = 0; i < RFIDStatesEntities.Count; i++)
// {
// if (RFIDStatesEntities[i].RFIDState == 2)
// {
// NowRowIndex = i;
// return;
// }
// }
//}
} }
/// <summary> /// <summary>
@ -453,7 +461,6 @@ namespace NDSD_Screwdriver
{ {
while (!cancellationTokenSource.Token.IsCancellationRequested) while (!cancellationTokenSource.Token.IsCancellationRequested)
{ {
// 这里是你的长期运行逻辑 // 这里是你的长期运行逻辑
Thread.Sleep(rand.Next(4, 16) * 1000); // 模拟一些长时间的工作 Thread.Sleep(rand.Next(4, 16) * 1000); // 模拟一些长时间的工作
} }
@ -466,23 +473,63 @@ namespace NDSD_Screwdriver
private void FlashThread() private void FlashThread()
{ {
//等待闪烁线程 //等待闪烁线程
thread = new Thread(() => flashThread = new Thread(() =>
{ {
while (true) while (true)
{ {
DOperate.DTimeOpen(1, 1); DOperate.DTimeOpen(1, 1);
monitorEntities[ReadyRowIndex].RowEntitys[2].Color = Brushes.Yellow; monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow;
RefreshRoll(); RefreshRoll();
Thread.Sleep(1000); Thread.Sleep(1000);
monitorEntities[ReadyRowIndex].RowEntitys[2].Color = Brushes.Transparent; monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Transparent;
RefreshRoll(); RefreshRoll();
Thread.Sleep(1000); Thread.Sleep(1000);
} }
}); });
} }
#endregion /// <summary>
/// 等待工作指示灯闪烁进程
/// </summary>
private void AlarmThread()
{
//等待闪烁线程
alarmThread = new Thread(() =>
{
while (true)
{
Thread.Sleep(500);
}
});
}
private int GetReadyRowIndex()
{
for (int i = 0; i < RFIDStatesEntities.Count; i++)
{
if (RFIDStatesEntities[i].RFIDState == 2)
{
return i;
}
}
return -1;
}
private int GetNowRowIndex()
{
for (int i = 0; i < RFIDStatesEntities.Count; i++)
{
if (RFIDStatesEntities[i].RFIDState == 1)
{
return i;
}
}
return -1;
}
#endregion
} }
} }

@ -123,10 +123,4 @@
<metadata name="LogValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="LogValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="logTime.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="LogValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>
Loading…
Cancel
Save