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