|
|
@ -14,6 +14,7 @@ using System.Text;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NDSD_Screwdriver
|
|
|
|
namespace NDSD_Screwdriver
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -34,6 +35,8 @@ namespace NDSD_Screwdriver
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private List<MonitorEntity> monitorEntities;
|
|
|
|
private List<MonitorEntity> monitorEntities;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<RfidSetting> rfidSettings;
|
|
|
|
|
|
|
|
|
|
|
|
private Random rand = new Random();
|
|
|
|
private Random rand = new Random();
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
///// <summary>
|
|
|
@ -46,23 +49,28 @@ namespace NDSD_Screwdriver
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public int NowRowIndex = 0;
|
|
|
|
public int NowRowIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 准备工作的行号
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public int ReadyRowIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// RFID列表
|
|
|
|
/// RFID列表
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public string[] RFIDs = new string[]
|
|
|
|
public string[] RFIDs;
|
|
|
|
{
|
|
|
|
|
|
|
|
"1111222233334444",
|
|
|
|
public List<LightsEntity> lightsEntities;
|
|
|
|
"2222222233334444",
|
|
|
|
|
|
|
|
"3333222233334444",
|
|
|
|
|
|
|
|
"4444222233334444",
|
|
|
|
|
|
|
|
"5555222233334444"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread thread;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool flag = false;
|
|
|
|
|
|
|
|
|
|
|
|
SerialPortFactory serialPort;
|
|
|
|
SerialPortFactory serialPort;
|
|
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int textindex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
public MainForm()
|
|
|
|
public MainForm()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
InitializeComponent();
|
|
|
@ -71,25 +79,27 @@ namespace NDSD_Screwdriver
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务端打开失败!");
|
|
|
|
MessageBox.Show("服务端打开失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FlashThread();
|
|
|
|
serialPort=new SerialPortFactory();
|
|
|
|
serialPort = new SerialPortFactory();
|
|
|
|
|
|
|
|
|
|
|
|
StartLongRunningTask();
|
|
|
|
StartLongRunningTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StartLongRunningTask()
|
|
|
|
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
if (server != null)
|
|
|
|
Task.Run(() =>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
|
|
|
if (!server.ServerStop())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 这里是你的长期运行逻辑
|
|
|
|
MessageBox.Show("服务端关闭失败!");
|
|
|
|
Thread.Sleep(1000); // 模拟一些长时间的工作
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, cancellationTokenSource.Token);
|
|
|
|
if (!server.ServerDispose())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MessageBox.Show("服务端释放失败!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 按钮
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 打开DO测试
|
|
|
|
/// 打开DO测试
|
|
|
@ -99,117 +109,153 @@ namespace NDSD_Screwdriver
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 测试按钮
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void TestButton1_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (server != null)
|
|
|
|
if (RFIDs.Length == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!server.ServerStop())
|
|
|
|
MessageBox.Show("没有值,请先设置。");
|
|
|
|
{
|
|
|
|
}
|
|
|
|
MessageBox.Show("服务端关闭失败!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!server.ServerDispose())
|
|
|
|
SetNowWorkRow(RFIDs[textindex]);
|
|
|
|
{
|
|
|
|
SetNowRowsLightState(1);
|
|
|
|
MessageBox.Show("服务端释放失败!");
|
|
|
|
if (flag && thread.ThreadState == ThreadState.Suspended)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
thread.Resume();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
|
|
|
if (++textindex >= RFIDs.Length)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
textindex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 列表回调函数
|
|
|
|
/// 初始化按钮
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="g"></param>
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
/// <param name="rowIndex"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
/// <param name="colIndex"></param>
|
|
|
|
private void InitButton_Click(object sender, EventArgs e)
|
|
|
|
/// <param name="rectangle"></param>
|
|
|
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
|
|
/// <param name="sf"></param>
|
|
|
|
|
|
|
|
private void ScrewdriverMonitor_OnDrawCellTextEvent(Graphics g, int rowIndex, int colIndex, RectangleF rectangle, string value, StringFormat sf)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (MonitorEntity entity in monitorEntities)
|
|
|
|
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();
|
|
|
|
|
|
|
|
//读取报警灯数据
|
|
|
|
|
|
|
|
lightsEntities = new List<LightsEntity>();
|
|
|
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (rowIndex == entity.RowIndex)
|
|
|
|
lightsEntities.Add(new LightsEntity()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (RowEntity rowEneiey in entity.RowEntitys)
|
|
|
|
Green = Convert.ToInt32(list[i].Green),
|
|
|
|
{
|
|
|
|
Yellow = Convert.ToInt32(list[i].Yellow),
|
|
|
|
if (colIndex == rowEneiey.ColumnIndex)
|
|
|
|
Red = Convert.ToInt32(list[i].Red),
|
|
|
|
{
|
|
|
|
});
|
|
|
|
g.FillRectangle(rowEneiey.Color, rectangle);
|
|
|
|
}
|
|
|
|
g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf);
|
|
|
|
//初始化列表框架
|
|
|
|
}
|
|
|
|
monitorEntities = new List<MonitorEntity>();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
monitorEntities.Add(new MonitorEntity()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RowIndex = i,
|
|
|
|
|
|
|
|
RowEntitys = InitRows(i)
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
thread.Suspend();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//更新值
|
|
|
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
monitorEntities[i].RowEntitys[1].Value = RFIDs[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshRoll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 SettingButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (RFIDs.Length == 0)
|
|
|
|
FrmSetting frmSetting = new FrmSetting();
|
|
|
|
|
|
|
|
frmSetting.Show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 服务端重启按钮
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void ServerRestartButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (server.ServerRestart(MemorySetting.ServerIP, MemorySetting.ServerPort))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("没有值,请先设置。");
|
|
|
|
MessageBox.Show("服务器重启成功!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
SetNowRowsLightState(FormUtils.TestRamColor());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
|
|
|
if (++NowRowIndex >= RFIDs.Length)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NowRowIndex = 0;
|
|
|
|
MessageBox.Show("服务器重启失败!请手动启动服务器。");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void InitButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NowRowIndex = 0;
|
|
|
|
|
|
|
|
InitMonitirIntity();
|
|
|
|
|
|
|
|
//var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
|
|
|
|
|
|
|
|
//var list = ctx.Query<RfidSetting>().Where(x => x.IsEnable == true).ToList();
|
|
|
|
|
|
|
|
//RFIDs = list.Select(x => x.RfidNo).ToArray();
|
|
|
|
|
|
|
|
SetRFIDValue(RFIDs);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 刷新列表
|
|
|
|
/// 服务端手动启动
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private void RefreshRoll()
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void StartServerButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ScrewdriverMonitor.AddRowTop(new string[]{
|
|
|
|
MessageBox.Show("服务端打开失败!");
|
|
|
|
"",
|
|
|
|
}
|
|
|
|
"",
|
|
|
|
else
|
|
|
|
""
|
|
|
|
{
|
|
|
|
});
|
|
|
|
MessageBox.Show("服务器启动成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化整个列表
|
|
|
|
/// 服务端手动停止
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private void InitMonitirIntity()
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void ServerStopButton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
monitorEntities = new List<MonitorEntity>();
|
|
|
|
if (server != null)
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
monitorEntities.Add(new MonitorEntity()
|
|
|
|
if (!server.ServerStop())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RowIndex = i,
|
|
|
|
MessageBox.Show("服务端关闭失败!");
|
|
|
|
RowEntitys = InitRows(i)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!server.ServerDispose())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MessageBox.Show("服务端释放失败!");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RefreshRoll();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 功能性方法
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化一行
|
|
|
|
/// 初始化一行
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -229,84 +275,162 @@ namespace NDSD_Screwdriver
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化RFID数据
|
|
|
|
/// 刷新列表
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rFIDvalue">RFID列表</param>
|
|
|
|
private void RefreshRoll()
|
|
|
|
private void SetRFIDValue(string[] rFIDvalue)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < rFIDvalue.Length; i++)
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
monitorEntities[i].RowEntitys[1].Value = rFIDvalue[i];
|
|
|
|
ScrewdriverMonitor.AddRowTop(new string[]{
|
|
|
|
|
|
|
|
"",
|
|
|
|
|
|
|
|
"",
|
|
|
|
|
|
|
|
""
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 设置当前行指示灯的状态以及工作的行
|
|
|
|
/// 设置当前行指示灯的状态以及工作的行的标识 输入枚举类
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="lightState"></param>
|
|
|
|
/// <param name="lightState"></param>
|
|
|
|
private void SetNowRowsLightState(LightState lightState)
|
|
|
|
private void SetNowRowsLightState(LightState lightState)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
monitorEntities[NowRowIndex].RowEntitys[2].Color = FormUtils.EnumColorToBrush(lightState);
|
|
|
|
SetNowRowsLightState(FormUtils.EnumColorToBrush(lightState));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
private void SetNowRowsLightState(int lightState)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
monitorEntities[NowRowIndex].RowEntitys[0].Value = i == NowRowIndex ? "=>" : "";
|
|
|
|
SetNowRowsLightState((LightState)lightState);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 设置当前行指示灯的状态以及工作的行的标识 输入Brush
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="brush"></param>
|
|
|
|
private void SetNowRowsLightState(Brush brush)
|
|
|
|
private void SetNowRowsLightState(Brush brush)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (monitorEntities.Count == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
monitorEntities[NowRowIndex].RowEntitys[2].Color = brush;
|
|
|
|
monitorEntities[NowRowIndex].RowEntitys[2].Color = brush;
|
|
|
|
|
|
|
|
SetNextRowsFlash();
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : "";
|
|
|
|
monitorEntities[i].RowEntitys[0].Value = i == NowRowIndex ? "=>" : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SettingButton_Click(object sender, EventArgs e)
|
|
|
|
/// <summary>
|
|
|
|
{
|
|
|
|
/// 设置待工作灯闪烁
|
|
|
|
FrmSetting frmSetting = new FrmSetting();
|
|
|
|
/// </summary>
|
|
|
|
frmSetting.Show();
|
|
|
|
private void SetNextRowsFlash()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ServerRestartButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (server.ServerRestart(MemorySetting.ServerIP, MemorySetting.ServerPort))
|
|
|
|
ReadyRowIndex = NowRowIndex + 1;
|
|
|
|
|
|
|
|
if (ReadyRowIndex >= RFIDs.Length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务器重启成功!");
|
|
|
|
ReadyRowIndex = 0;
|
|
|
|
|
|
|
|
thread.Suspend();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务器重启失败!请手动启动服务器。");
|
|
|
|
thread.Start();
|
|
|
|
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StartServerButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 根据读取到的RFID条码设置当前工作的行
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="rfid">读取到的RFID</param>
|
|
|
|
|
|
|
|
private void SetNowWorkRow(string rfid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!server.ServerOpen(MemorySetting.ServerIP, MemorySetting.ServerPort))
|
|
|
|
for (int i = 0; i < RFIDs.Length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务端打开失败!");
|
|
|
|
if (monitorEntities[i].RowEntitys[1].Value == rfid)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NowRowIndex = i;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 根据IO口控制灯的开关
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void LightControl()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 列表回调函数
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
|
|
|
/// <param name="rowIndex"></param>
|
|
|
|
|
|
|
|
/// <param name="colIndex"></param>
|
|
|
|
|
|
|
|
/// <param name="rectangle"></param>
|
|
|
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
|
|
/// <param name="sf"></param>
|
|
|
|
|
|
|
|
private void ScrewdriverMonitor_OnDrawCellTextEvent(Graphics g, int rowIndex, int colIndex, RectangleF rectangle, string value, StringFormat sf)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (MonitorEntity entity in monitorEntities)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务器启动成功");
|
|
|
|
if (rowIndex == entity.RowIndex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (RowEntity rowEneiey in entity.RowEntitys)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (colIndex == rowEneiey.ColumnIndex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
g.FillRectangle(rowEneiey.Color, rectangle);
|
|
|
|
|
|
|
|
g.DrawString(rowEneiey.Value, this.ScrewdriverMonitor.Font, Brushes.Black, rectangle, sf);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ServerStopButton_Click(object sender, EventArgs e)
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// RFID刷新任务
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void StartLongRunningTask()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (server != null)
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!server.ServerStop())
|
|
|
|
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务端关闭失败!");
|
|
|
|
// 这里是你的长期运行逻辑
|
|
|
|
|
|
|
|
Thread.Sleep(1000); // 模拟一些长时间的工作
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!server.ServerDispose())
|
|
|
|
}, cancellationTokenSource.Token);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 等待工作指示灯闪烁进程
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private void FlashThread()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//等待闪烁线程
|
|
|
|
|
|
|
|
thread = new Thread(() =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("服务端释放失败!");
|
|
|
|
DOperate.DTimeOpen(1, 1);
|
|
|
|
|
|
|
|
monitorEntities[ReadyRowIndex].RowEntitys[2].Color = Brushes.Yellow;
|
|
|
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
monitorEntities[ReadyRowIndex].RowEntitys[2].Color = Brushes.Transparent;
|
|
|
|
|
|
|
|
RefreshRoll();
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|