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