|
|
|
@ -19,6 +19,8 @@ using System.Windows.Forms;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using NewLife.Caching;
|
|
|
|
|
using NewLife.Collections;
|
|
|
|
|
using System.IO.Ports;
|
|
|
|
|
using NewLife.Log;
|
|
|
|
|
|
|
|
|
|
namespace NDSD_Screwdriver
|
|
|
|
|
{
|
|
|
|
@ -43,15 +45,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
|
|
|
|
|
private Random rand = new Random();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// RFID状态列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<RFIDStatesEntity> RFIDStatesEntities;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 报警灯配置实例
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<LightsEntity> lightsEntities;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日志实例
|
|
|
|
@ -78,10 +74,11 @@ namespace NDSD_Screwdriver
|
|
|
|
|
private ICache cache = Cache.Default;
|
|
|
|
|
int FlashIndex = 0;
|
|
|
|
|
|
|
|
|
|
bool _flashflag = true;
|
|
|
|
|
// bool _flashflag = true;
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, int> dictionary = new Dictionary<string, int>();
|
|
|
|
|
|
|
|
|
|
private DengTool tool;
|
|
|
|
|
// private DengTool tool;
|
|
|
|
|
|
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
@ -90,8 +87,8 @@ namespace NDSD_Screwdriver
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
tool = new DengTool();
|
|
|
|
|
tool.Start();
|
|
|
|
|
// tool = new DengTool();
|
|
|
|
|
// tool.Start();
|
|
|
|
|
|
|
|
|
|
FlashThreadTime();
|
|
|
|
|
var memorySetting = MemorySetting.Current;
|
|
|
|
@ -102,6 +99,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
LogDataGridView.AutoGenerateColumns = false;
|
|
|
|
|
LogDataGridView.DataSource = null;
|
|
|
|
|
LogDataGridView.DataSource = RFIDLogsEntitys;
|
|
|
|
|
|
|
|
|
|
DOperateInfo = new DOperate();
|
|
|
|
|
if (!server.ServerOpen(memorySetting.ServerIP, memorySetting.ServerPort))
|
|
|
|
|
{
|
|
|
|
@ -111,8 +109,16 @@ namespace NDSD_Screwdriver
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serialPort = new SerialPortFactory(memorySetting.Com);
|
|
|
|
|
StartLongRunningTask();
|
|
|
|
|
for (int w = 0; w < 2; w++)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
DOperateInfo.DClose(i);
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
@ -120,6 +126,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
MessageBox.Show(e.Message);
|
|
|
|
|
FormUtils.LogInsert(LogContext, e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -144,7 +151,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tool.Stop();
|
|
|
|
|
// tool.Stop();
|
|
|
|
|
|
|
|
|
|
if (cancellationTokenSource != null)
|
|
|
|
|
{
|
|
|
|
@ -179,6 +186,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
private void InitButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InitTable();
|
|
|
|
|
StartLongRunningTask();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -186,7 +194,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitTable()
|
|
|
|
|
{
|
|
|
|
|
_flashflag = true;
|
|
|
|
|
// _flashflag = true;
|
|
|
|
|
FlashIndex = 0;
|
|
|
|
|
textRFID = 0;
|
|
|
|
|
timer.Start();
|
|
|
|
@ -196,51 +204,29 @@ namespace NDSD_Screwdriver
|
|
|
|
|
var ctx = SqlLiteTool.GetDb(memorySetting.DB);
|
|
|
|
|
var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList();
|
|
|
|
|
var strs = list.Select(x => x.RfidNo).ToArray();
|
|
|
|
|
RFIDStatesEntities = new List<RFIDStatesEntity>();
|
|
|
|
|
RFIDStatesEntities.Clear();
|
|
|
|
|
foreach (var a in strs)
|
|
|
|
|
{
|
|
|
|
|
RFIDStatesEntities.Add(new RFIDStatesEntity()
|
|
|
|
|
{
|
|
|
|
|
RFIDValue = a,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
RFIDStatesEntities[0].RFIDState = 2;
|
|
|
|
|
FormUtils.LogInsert(LogContext, "RFID " + 0 + " 准备工作", RFIDStatesEntities[0].RFIDValue);
|
|
|
|
|
GetLog();
|
|
|
|
|
//读取报警灯数据
|
|
|
|
|
lightsEntities = new List<LightsEntity>();
|
|
|
|
|
lightsEntities.Clear();
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
lightsEntities.Add(new LightsEntity()
|
|
|
|
|
{
|
|
|
|
|
Green = Convert.ToInt32(list[i].Green),
|
|
|
|
|
Yellow = Convert.ToInt32(list[i].Yellow),
|
|
|
|
|
Red = Convert.ToInt32(list[i].Red),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//初始化列表框架
|
|
|
|
|
monitorEntities = new List<MonitorEntity>();
|
|
|
|
|
monitorEntities.Clear();
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
monitorEntities = new List<MonitorEntity>(list.Count);
|
|
|
|
|
int i1 = 0;
|
|
|
|
|
foreach (var en in list)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities.Add(new MonitorEntity()
|
|
|
|
|
{
|
|
|
|
|
RowIndex = i,
|
|
|
|
|
Green = Convert.ToInt32(en.Green),
|
|
|
|
|
Yellow = Convert.ToInt32(en.Yellow),
|
|
|
|
|
Red=Convert.ToInt32(en.Red),
|
|
|
|
|
RFIDState = 0,
|
|
|
|
|
RFIDValue = en.RfidNo,
|
|
|
|
|
RowIndex = i1,
|
|
|
|
|
RowEntitys = InitRows()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//更新值
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[i].RowEntitys[1].Value = RFIDStatesEntities[i].RFIDValue;
|
|
|
|
|
}
|
|
|
|
|
timer.Start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
monitorEntities[i1].RowEntitys[1].Value = en.RfidNo;
|
|
|
|
|
i1++;
|
|
|
|
|
}
|
|
|
|
|
monitorEntities[0].RFIDState = 2;
|
|
|
|
|
FormUtils.LogInsert(LogContext, "RFID " + 0 + " 准备工作", monitorEntities[0].RFIDValue);
|
|
|
|
|
GetLog();
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
RefreshIO();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -254,74 +240,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
frmSetting.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务端重启按钮
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ServerRestartButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var memorySetting = MemorySetting.Current;
|
|
|
|
|
|
|
|
|
|
if (server.ServerRestart(memorySetting.ServerIP, memorySetting.ServerPort))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务器重启成功!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务器重启成功");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务器重启失败!请手动启动服务器。");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务器重启失败");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务端手动启动
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void StartServerButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var memorySetting = MemorySetting.Current;
|
|
|
|
|
if (!server.ServerOpen(memorySetting.ServerIP, memorySetting.ServerPort))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务端打开失败!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务端打开失败");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务器启动成功");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务器启动成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务端手动停止
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ServerStopButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (server != null)
|
|
|
|
|
{
|
|
|
|
|
if (!server.ServerStop())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务端关闭失败!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务端关闭失败");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (!server.ServerDispose())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务端释放失败!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务端释放失败");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 测试按钮
|
|
|
|
@ -330,23 +251,25 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
|
|
|
|
//if (monitorEntities.Count == 0)
|
|
|
|
|
//{
|
|
|
|
|
// MessageBox.Show("请先初始化RFID列表!");
|
|
|
|
|
//}
|
|
|
|
|
//else if (textRFID == monitorEntities.Count)
|
|
|
|
|
//{
|
|
|
|
|
// SetNowWorkRow("0000000");
|
|
|
|
|
// textRFID = 0;
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
//SetNowWorkRow(monitorEntities[textRFID].RFIDValue);
|
|
|
|
|
//if (++textRFID > monitorEntities.Count)
|
|
|
|
|
//{
|
|
|
|
|
// textRFID = 0;
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
LogContext.Delete<RFIDLogsEntity>(x=>x.ID>0);
|
|
|
|
|
GetLog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
@ -360,47 +283,45 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// <param name="rfid">读取到的RFID</param>
|
|
|
|
|
private void SetNowWorkRow(string rfid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var memorySetting = MemorySetting.Current;
|
|
|
|
|
//设置RFID状态
|
|
|
|
|
int flag = 0;
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
for (int i = 0; i < monitorEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (RFIDStatesEntities[i].RFIDValue == rfid && RFIDStatesEntities[i].RFIDState == 2)
|
|
|
|
|
if (monitorEntities[i].RFIDValue == rfid && monitorEntities[i].RFIDState == 2)
|
|
|
|
|
{
|
|
|
|
|
RFIDStatesEntities[i].RFIDState = 1;
|
|
|
|
|
FormUtils.LogInsert(LogContext, "RFID " + i + " 开始工作", RFIDStatesEntities[i].RFIDValue);
|
|
|
|
|
monitorEntities[i].RFIDState = 1;
|
|
|
|
|
FormUtils.LogInsert(LogContext, "RFID " + i + " 开始工作", monitorEntities[i].RFIDValue);
|
|
|
|
|
GetLog();
|
|
|
|
|
if (i - 1 >= 0)
|
|
|
|
|
{
|
|
|
|
|
string rfidValue = RFIDStatesEntities[i - 1].RFIDValue;
|
|
|
|
|
var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).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;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
timer.Stop();
|
|
|
|
|
_flashflag = false;
|
|
|
|
|
}
|
|
|
|
|
// if (i - 1 >= 0)
|
|
|
|
|
// {
|
|
|
|
|
// string rfidValue = monitorEntities[i - 1].RFIDValue;
|
|
|
|
|
// var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).CreateTime;
|
|
|
|
|
// double timeSpan = (DateTime.Now - leastTime).TotalSeconds;
|
|
|
|
|
// if (timeSpan >= memorySetting.AlarmTimeValue)
|
|
|
|
|
// {
|
|
|
|
|
// monitorEntities[i - 1].RFIDState = 4;
|
|
|
|
|
// FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", monitorEntities[i].RFIDValue);
|
|
|
|
|
// }
|
|
|
|
|
// if (timeSpan < memorySetting.AlarmTimeValue)
|
|
|
|
|
// {
|
|
|
|
|
// monitorEntities[i - 1].RFIDState = 3;
|
|
|
|
|
// FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", monitorEntities[i].RFIDValue);
|
|
|
|
|
// }
|
|
|
|
|
// GetLog();
|
|
|
|
|
// }
|
|
|
|
|
// if (i + 1 < monitorEntities.Count)
|
|
|
|
|
// {
|
|
|
|
|
// FormUtils.LogInsert(LogContext, "RFID " + (i + 1) + " 准备工作", monitorEntities[i].RFIDValue);
|
|
|
|
|
// GetLog();
|
|
|
|
|
// monitorEntities[i + 1].RFIDState = 2;
|
|
|
|
|
// FlashIndex = i + 1;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// timer.Stop();
|
|
|
|
|
// // _flashflag = false;
|
|
|
|
|
// }
|
|
|
|
|
flag = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -408,97 +329,101 @@ namespace NDSD_Screwdriver
|
|
|
|
|
if (flag == 0) //列表里没有已读的RFID
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (RFIDStatesEntities[i].RFIDState == 1)
|
|
|
|
|
{
|
|
|
|
|
string rfidValue = RFIDStatesEntities[i - 1].RFIDValue;
|
|
|
|
|
var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).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 < monitorEntities.Count; i++)
|
|
|
|
|
// {
|
|
|
|
|
// if (monitorEntities[i].RFIDState == 1)
|
|
|
|
|
// {
|
|
|
|
|
// string rfidValue = monitorEntities[i - 1].RFIDValue;
|
|
|
|
|
// if (rfidValue != null)
|
|
|
|
|
// {
|
|
|
|
|
// var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).CreateTime;
|
|
|
|
|
// double timeSpan = (DateTime.Now - leastTime).TotalSeconds;
|
|
|
|
|
// if (timeSpan >= memorySetting.AlarmTimeValue)
|
|
|
|
|
// {
|
|
|
|
|
// monitorEntities[i].RFIDState = 4;
|
|
|
|
|
// FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", monitorEntities[i].RFIDValue);
|
|
|
|
|
// }
|
|
|
|
|
// if (timeSpan < memorySetting.AlarmTimeValue)
|
|
|
|
|
// {
|
|
|
|
|
// monitorEntities[i].RFIDState = 3;
|
|
|
|
|
// FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", monitorEntities[i].RFIDValue);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
//刷新前端灯的状态
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (RFIDStatesEntities[i].RFIDState == 1)
|
|
|
|
|
{
|
|
|
|
|
SetRowsLightState(i, 1);
|
|
|
|
|
}
|
|
|
|
|
else if (RFIDStatesEntities[i].RFIDState == 3)
|
|
|
|
|
for (int i = 0; i < monitorEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
SetRowsLightState(i, 0);
|
|
|
|
|
}
|
|
|
|
|
else if (RFIDStatesEntities[i].RFIDState == 4)
|
|
|
|
|
{
|
|
|
|
|
SetRowsLightState(i, 2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetRowsLightState(i, Brushes.Transparent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(_flashflag)
|
|
|
|
|
timer.Stop();
|
|
|
|
|
|
|
|
|
|
//刷新IO的状态
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (RFIDStatesEntities[i].RFIDState == 1)
|
|
|
|
|
{
|
|
|
|
|
// DOperateInfo.DOpen(lightsEntities[i].Yellow);
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Yellow,
|
|
|
|
|
delay = 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (RFIDStatesEntities[i].RFIDState == 3)
|
|
|
|
|
{
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Green,
|
|
|
|
|
delay = 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Yellow,
|
|
|
|
|
delay = -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (RFIDStatesEntities[i].RFIDState == 4)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Red,
|
|
|
|
|
delay = 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Yellow,
|
|
|
|
|
delay = -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// if (monitorEntities[i].RFIDState == 1)
|
|
|
|
|
// {
|
|
|
|
|
// SetRowsLightState(i, 1);
|
|
|
|
|
// }
|
|
|
|
|
// else if (monitorEntities[i].RFIDState == 3)
|
|
|
|
|
// {
|
|
|
|
|
// SetRowsLightState(i, 0);
|
|
|
|
|
// }
|
|
|
|
|
// else if (monitorEntities[i].RFIDState == 4)
|
|
|
|
|
// {
|
|
|
|
|
// SetRowsLightState(i, 2);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// SetRowsLightState(i, Brushes.Transparent);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
if (_flashflag)
|
|
|
|
|
timer.Start();
|
|
|
|
|
// if(_flashflag)
|
|
|
|
|
// timer.Stop();
|
|
|
|
|
//
|
|
|
|
|
// //刷新IO的状态
|
|
|
|
|
// // for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
// // {
|
|
|
|
|
// //
|
|
|
|
|
// // if (RFIDStatesEntities[i].RFIDState == 1)
|
|
|
|
|
// // {
|
|
|
|
|
// // // DOperateInfo.DOpen(lightsEntities[i].Yellow);
|
|
|
|
|
// // tool.AddMq(new DOperateEntity()
|
|
|
|
|
// // {
|
|
|
|
|
// // port = lightsEntities[i].Yellow,
|
|
|
|
|
// // delay = 0
|
|
|
|
|
// // });
|
|
|
|
|
// //
|
|
|
|
|
// // }
|
|
|
|
|
// // else if (RFIDStatesEntities[i].RFIDState == 3)
|
|
|
|
|
// // {
|
|
|
|
|
// // tool.AddMq(new DOperateEntity()
|
|
|
|
|
// // {
|
|
|
|
|
// // port = lightsEntities[i].Green,
|
|
|
|
|
// // delay = 0
|
|
|
|
|
// // });
|
|
|
|
|
// //
|
|
|
|
|
// // tool.AddMq(new DOperateEntity()
|
|
|
|
|
// // {
|
|
|
|
|
// // port = lightsEntities[i].Yellow,
|
|
|
|
|
// // delay = -1
|
|
|
|
|
// // });
|
|
|
|
|
// //
|
|
|
|
|
// // }
|
|
|
|
|
// // else if (RFIDStatesEntities[i].RFIDState == 4)
|
|
|
|
|
// // {
|
|
|
|
|
// //
|
|
|
|
|
// // tool.AddMq(new DOperateEntity()
|
|
|
|
|
// // {
|
|
|
|
|
// // port = lightsEntities[i].Red,
|
|
|
|
|
// // delay = 0
|
|
|
|
|
// // });
|
|
|
|
|
// //
|
|
|
|
|
// // tool.AddMq(new DOperateEntity()
|
|
|
|
|
// // {
|
|
|
|
|
// // port = lightsEntities[i].Yellow,
|
|
|
|
|
// // delay = -1
|
|
|
|
|
// // });
|
|
|
|
|
// //
|
|
|
|
|
// // }
|
|
|
|
|
// // }
|
|
|
|
|
// if (_flashflag)
|
|
|
|
|
// timer.Start();
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -525,7 +450,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
private void RefreshRoll()
|
|
|
|
|
{
|
|
|
|
|
List<string[]> values = new List<string[]>();
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
for (int i = 0; i < monitorEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
values.Add(new string[]
|
|
|
|
|
{
|
|
|
|
@ -554,9 +479,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[index].RowEntitys[2].Color = brush;
|
|
|
|
|
//工作中箭头指示
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
for (int i = 0; i < monitorEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[i].RowEntitys[0].Value = RFIDStatesEntities[i].RFIDState == 1 ? "=>" : "";
|
|
|
|
|
monitorEntities[i].RowEntitys[0].Value = monitorEntities[i].RFIDState == 1 ? "=>" : "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -588,6 +513,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QingTcpClient2 quClient2 = new QingTcpClient2();
|
|
|
|
|
|
|
|
|
|
private DateTime dateTime = DateTime.Now;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// RFID刷新任务
|
|
|
|
|
/// </summary>
|
|
|
|
@ -596,11 +524,71 @@ namespace NDSD_Screwdriver
|
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
//SetNowWorkRow("0000000");
|
|
|
|
|
// 这里是你的长期运行逻辑
|
|
|
|
|
Thread.Sleep(1000); // 模拟一些长时间的工作
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var read = serialPort?.Read();
|
|
|
|
|
|
|
|
|
|
// var read = "";
|
|
|
|
|
|
|
|
|
|
if (read.Length == 16)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
SetNowWorkRow(read);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var monitorEntitiesCount = monitorEntities.Count;
|
|
|
|
|
var last = monitorEntities[FlashIndex].RFIDState;
|
|
|
|
|
if (FlashIndex < monitorEntitiesCount)
|
|
|
|
|
{
|
|
|
|
|
if (last != 100 && last==1)
|
|
|
|
|
{
|
|
|
|
|
quClient2.Enable();
|
|
|
|
|
dateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if (FlashIndex < monitorEntitiesCount)
|
|
|
|
|
{
|
|
|
|
|
XTrace.WriteLine("a");
|
|
|
|
|
//状态修改
|
|
|
|
|
monitorEntities[FlashIndex].RFIDState = 1;
|
|
|
|
|
DOperateInfo.DOpen(monitorEntities[FlashIndex].Yellow);
|
|
|
|
|
|
|
|
|
|
timer.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
XTrace.WriteLine("aa");
|
|
|
|
|
var total = DateTime.Now - dateTime;
|
|
|
|
|
if (total.TotalSeconds > 2)
|
|
|
|
|
{
|
|
|
|
|
quClient2.Close();
|
|
|
|
|
dateTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(500); // 模拟一些长时间的工作
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, cancellationTokenSource.Token);
|
|
|
|
|
}
|
|
|
|
@ -608,28 +596,8 @@ namespace NDSD_Screwdriver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 等待工作指示灯闪烁进程
|
|
|
|
|
///// </summary>
|
|
|
|
|
//private void FlashThread()
|
|
|
|
|
//{
|
|
|
|
|
// //等待闪烁线程
|
|
|
|
|
// flashThread = new Thread(() =>
|
|
|
|
|
// {
|
|
|
|
|
// while (true)
|
|
|
|
|
// {
|
|
|
|
|
// DOperate.DTimeOpen(lightsEntities[FlashIndex].Yellow, 1);
|
|
|
|
|
// monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow;
|
|
|
|
|
// RefreshRoll();
|
|
|
|
|
// Thread.Sleep(1000);
|
|
|
|
|
// monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Transparent;
|
|
|
|
|
// RefreshRoll();
|
|
|
|
|
// Thread.Sleep(1000);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(1000); // 设置1秒间隔
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(500); // 设置1秒间隔
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 等待工作指示灯闪烁进程
|
|
|
|
|
/// </summary>
|
|
|
|
@ -637,50 +605,119 @@ namespace NDSD_Screwdriver
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int step = 0;
|
|
|
|
|
|
|
|
|
|
timer.Elapsed += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (step == 0)
|
|
|
|
|
Set(FlashIndex);
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int step1 = 0;
|
|
|
|
|
public void Set(int id)
|
|
|
|
|
{
|
|
|
|
|
step = 1;
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
|
|
|
|
|
var monitorEntitiesCount = monitorEntities.Count;
|
|
|
|
|
if (id < monitorEntitiesCount)
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[FlashIndex].Yellow,
|
|
|
|
|
delay = 1
|
|
|
|
|
});
|
|
|
|
|
/// 状态指示 0未操作 2准备操作 1正在操作 3已完成 4超时报警
|
|
|
|
|
int RFIDState = monitorEntities[id].RFIDState;
|
|
|
|
|
if (step1 == 0)
|
|
|
|
|
{
|
|
|
|
|
step1 = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow;
|
|
|
|
|
RFIDState = monitorEntities[id].RFIDState;
|
|
|
|
|
if (RFIDState == 2)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DOperateInfo.DClose(monitorEntities[id].Red);
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
DOperateInfo.DClose(monitorEntities[id].Green);
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
|
|
|
|
|
DOperateInfo.DTimeOpen(monitorEntities[id].Yellow, 1);
|
|
|
|
|
monitorEntities[id].RowEntitys[2].Color = Brushes.Yellow;
|
|
|
|
|
}
|
|
|
|
|
else if (step == 1)
|
|
|
|
|
|
|
|
|
|
RFIDState = monitorEntities[id].RFIDState;
|
|
|
|
|
if (RFIDState == 1)
|
|
|
|
|
{
|
|
|
|
|
step=0;
|
|
|
|
|
monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Transparent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((id+1) < monitorEntitiesCount)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[id + 1].RFIDState = 2;
|
|
|
|
|
/// 状态指示 0未操作 2准备操作 1正在操作 3已完成 4超时报警
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (dictionary.ContainsKey(monitorEntities[id].RFIDValue))
|
|
|
|
|
{
|
|
|
|
|
var i = dictionary[monitorEntities[id].RFIDValue];
|
|
|
|
|
dictionary[monitorEntities[id].RFIDValue] = i + 1;
|
|
|
|
|
if (i >3)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[id].RFIDState = 3;
|
|
|
|
|
dictionary[monitorEntities[id].RFIDValue] = 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dictionary[monitorEntities[id].RFIDValue] = 1;
|
|
|
|
|
}
|
|
|
|
|
monitorEntities[id].RowEntitys[2].Color = Brushes.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////等待闪烁线程
|
|
|
|
|
//flashThread = new Thread(() =>
|
|
|
|
|
//{
|
|
|
|
|
// while (true)
|
|
|
|
|
// {
|
|
|
|
|
// DOperate.DTimeOpen(lightsEntities[FlashIndex].Yellow, 1);
|
|
|
|
|
// monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow;
|
|
|
|
|
// RefreshRoll();
|
|
|
|
|
// Thread.Sleep(1000);
|
|
|
|
|
// monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Transparent;
|
|
|
|
|
// RefreshRoll();
|
|
|
|
|
// Thread.Sleep(1000);
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
RFIDState = monitorEntities[id].RFIDState;
|
|
|
|
|
if (RFIDState == 3)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DOperateInfo.DClose(monitorEntities[id].Red);
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
DOperateInfo.DClose(monitorEntities[id].Yellow);
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
|
|
|
|
|
FormUtils.LogInsert(LogContext, "RFID {0} 发送绿灯", monitorEntities[id].RFIDValue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XTrace.WriteLine("========================================================================");
|
|
|
|
|
DOperateInfo.DOpen(monitorEntities[id].Green);
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
DOperateInfo.DOpen(monitorEntities[id].Green);
|
|
|
|
|
quClient2.Close();
|
|
|
|
|
monitorEntities[id].RowEntitys[2].Color = Brushes.Green;
|
|
|
|
|
monitorEntities[id].RFIDState=100;
|
|
|
|
|
timer.Stop();
|
|
|
|
|
|
|
|
|
|
FlashIndex += 1;
|
|
|
|
|
timer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (step1 == 1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
step1=0;
|
|
|
|
|
|
|
|
|
|
if (RFIDState == 2)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[id].RowEntitys[2].Color = Brushes.Transparent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int step2 = 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取Log
|
|
|
|
|
/// </summary>
|
|
|
|
@ -700,9 +737,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// <returns>准备行index</returns>
|
|
|
|
|
private int GetReadyRowIndex()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
for (int i = 0; i < monitorEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (RFIDStatesEntities[i].RFIDState == 2)
|
|
|
|
|
if (monitorEntities[i].RFIDState == 2)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
@ -716,9 +753,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// <returns>工作行index</returns>
|
|
|
|
|
private int GetNowRowIndex()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
for (int i = 0; i < monitorEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (RFIDStatesEntities[i].RFIDState == 1)
|
|
|
|
|
if (monitorEntities[i].RFIDState == 1)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
@ -726,32 +763,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshIO()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Yellow,
|
|
|
|
|
delay = -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Red,
|
|
|
|
|
delay = -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tool.AddMq(new DOperateEntity()
|
|
|
|
|
{
|
|
|
|
|
port = lightsEntities[i].Green,
|
|
|
|
|
delay = -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|