|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
using DNSD_DB;
|
|
|
|
|
using NDSD_Screwdriver.Entity;
|
|
|
|
|
using Chloe;
|
|
|
|
|
using DNSD_DB;
|
|
|
|
|
using DNSD_DB.Entity;
|
|
|
|
|
using NDSD_Screwdriver.Tool;
|
|
|
|
|
|
|
|
|
|
using NDSD_TouchSocket;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
@ -35,7 +35,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<MonitorEntity> monitorEntities;
|
|
|
|
|
|
|
|
|
|
private List<RfidSetting> rfidSettings;
|
|
|
|
|
private List<RFIDConfigEntity> RFIDConfigEntitys;
|
|
|
|
|
|
|
|
|
|
private Random rand = new Random();
|
|
|
|
|
|
|
|
|
@ -55,29 +55,50 @@ namespace NDSD_Screwdriver
|
|
|
|
|
public int ReadyRowIndex = 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// RFID列表
|
|
|
|
|
/// RFID状态列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string[] RFIDs;
|
|
|
|
|
public List<RFIDStatesEntity> RFIDStatesEntities;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 报警灯配置实例
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<LightsEntity> lightsEntities;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日志实例
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<RFIDLogsEntity> RFIDLogsEntitys;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日志数据库操作实例
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IDbContext LogContext;
|
|
|
|
|
|
|
|
|
|
Thread thread;
|
|
|
|
|
|
|
|
|
|
bool flag = false;
|
|
|
|
|
|
|
|
|
|
bool IsFirst = true;
|
|
|
|
|
|
|
|
|
|
SerialPortFactory serialPort;
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
|
|
|
|
|
|
|
|
|
private int textindex = 0;
|
|
|
|
|
|
|
|
|
|
public int textRFID;
|
|
|
|
|
|
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
|
SqlLiteTool.CreateTable(AppTool.GetDb());
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
LogContext = SqlLiteTool.GetDb(AppTool.GetDb());
|
|
|
|
|
RFIDLogsEntitys = LogContext.Query<RFIDLogsEntity>().ToList();
|
|
|
|
|
DOperate = new DOperate();
|
|
|
|
|
if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务端打开失败!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务端打开失败");
|
|
|
|
|
}
|
|
|
|
|
FlashThread();
|
|
|
|
|
serialPort = new SerialPortFactory();
|
|
|
|
@ -91,10 +112,13 @@ namespace NDSD_Screwdriver
|
|
|
|
|
if (!server.ServerStop())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务端关闭失败!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务端关闭失败");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (!server.ServerDispose())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("服务端释放失败!");
|
|
|
|
|
FormUtils.LogInsert(LogContext, "服务端释放失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -122,22 +146,20 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void TestButton1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (RFIDs.Length == 0)
|
|
|
|
|
if (RFIDStatesEntities.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("没有值,请先设置。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetNowWorkRow(RFIDs[textindex]);
|
|
|
|
|
SetNowWorkRow(RFIDStatesEntities[NowRowIndex].RFIDValue);
|
|
|
|
|
SetNowRowsLightState(1);
|
|
|
|
|
if (flag && thread.ThreadState == ThreadState.Suspended)
|
|
|
|
|
{
|
|
|
|
|
thread.Resume();
|
|
|
|
|
}
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
if (++textindex >= RFIDs.Length)
|
|
|
|
|
if (++NowRowIndex >= RFIDStatesEntities.Count)
|
|
|
|
|
{
|
|
|
|
|
textindex = 0;
|
|
|
|
|
NowRowIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -151,8 +173,16 @@ namespace NDSD_Screwdriver
|
|
|
|
|
NowRowIndex = 0;
|
|
|
|
|
//读取rfid数据
|
|
|
|
|
var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
|
|
|
|
|
var list = ctx.Query<RfidSetting>().Where(x => x.IsEnable == true).ToList();
|
|
|
|
|
RFIDs = list.Select(x => x.RfidNo).ToArray();
|
|
|
|
|
var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList();
|
|
|
|
|
var strs = list.Select(x => x.RfidNo).ToArray();
|
|
|
|
|
RFIDStatesEntities = new List<RFIDStatesEntity>();
|
|
|
|
|
foreach (var a in strs)
|
|
|
|
|
{
|
|
|
|
|
RFIDStatesEntities.Add(new RFIDStatesEntity()
|
|
|
|
|
{
|
|
|
|
|
RFIDValue = a,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//读取报警灯数据
|
|
|
|
|
lightsEntities = new List<LightsEntity>();
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
@ -166,7 +196,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
}
|
|
|
|
|
//初始化列表框架
|
|
|
|
|
monitorEntities = new List<MonitorEntity>();
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities.Add(new MonitorEntity()
|
|
|
|
|
{
|
|
|
|
@ -179,9 +209,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
thread.Suspend();
|
|
|
|
|
}
|
|
|
|
|
//更新值
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[i].RowEntitys[1].Value = RFIDs[i];
|
|
|
|
|
monitorEntities[i].RowEntitys[1].Value = RFIDStatesEntities[i].RFIDValue;
|
|
|
|
|
}
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
}
|
|
|
|
@ -279,7 +309,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void RefreshRoll()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
ScrewdriverMonitor.AddRowTop(new string[]{
|
|
|
|
|
"",
|
|
|
|
@ -315,7 +345,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
}
|
|
|
|
|
monitorEntities[NowRowIndex].RowEntitys[2].Color = brush;
|
|
|
|
|
SetNextRowsFlash();
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : "";
|
|
|
|
|
}
|
|
|
|
@ -326,8 +356,7 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetNextRowsFlash()
|
|
|
|
|
{
|
|
|
|
|
ReadyRowIndex = NowRowIndex + 1;
|
|
|
|
|
if (ReadyRowIndex >= RFIDs.Length)
|
|
|
|
|
if (ReadyRowIndex >= RFIDStatesEntities.Count)
|
|
|
|
|
{
|
|
|
|
|
ReadyRowIndex = 0;
|
|
|
|
|
thread.Suspend();
|
|
|
|
@ -347,24 +376,46 @@ namespace NDSD_Screwdriver
|
|
|
|
|
/// <param name="rfid">读取到的RFID</param>
|
|
|
|
|
private void SetNowWorkRow(string rfid)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (monitorEntities[i].RowEntitys[1].Value == rfid)
|
|
|
|
|
ReadyRowIndex = NowRowIndex + 1;
|
|
|
|
|
//RFIDStatesEntities[ReadyRowIndex].RFIDState = 2;
|
|
|
|
|
//if (IsFirst)
|
|
|
|
|
//{
|
|
|
|
|
// IsFirst = false;
|
|
|
|
|
for (int i = 0; i < RFIDStatesEntities.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
NowRowIndex = i;
|
|
|
|
|
return;
|
|
|
|
|
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;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据IO口控制灯的开关
|
|
|
|
|
/// IO控制
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void LightControl()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ComDataAnalysis(string str)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表回调函数
|
|
|
|
|
/// </summary>
|
|
|
|
@ -402,8 +453,9 @@ namespace NDSD_Screwdriver
|
|
|
|
|
{
|
|
|
|
|
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 这里是你的长期运行逻辑
|
|
|
|
|
Thread.Sleep(1000); // 模拟一些长时间的工作
|
|
|
|
|
Thread.Sleep(rand.Next(4, 16) * 1000); // 模拟一些长时间的工作
|
|
|
|
|
}
|
|
|
|
|
}, cancellationTokenSource.Token);
|
|
|
|
|
}
|
|
|
|
|