Test
杨威 3 weeks ago
parent aeddacaedd
commit d649cbbd8a

@ -6,12 +6,5 @@ using System.Threading.Tasks;
namespace DNSD_DB.Entity
{
public class LightsEntity
{
public int Green { get; set; }
public int Yellow { get; set; }
public int Red { get; set; }
}
}

@ -18,6 +18,24 @@ namespace DNSD_DB.Entity
/// 行编号
/// </summary>
public int RowIndex { get; set; }
/// <summary>
/// RFID值
/// </summary>
public string RFIDValue { get; set; }
/// <summary>
/// 状态指示 0未操作 1正在操作 2准备操作 3已完成 4超时报警
/// </summary>
public int RFIDState { get; set; } = 0;
public int Green { get; set; }
public int Yellow { get; set; }
public int Red { get; set; }
}
public class RowEntity

@ -6,16 +6,5 @@ using System.Threading.Tasks;
namespace DNSD_DB.Entity
{
public class RFIDStatesEntity
{
/// <summary>
/// RFID值
/// </summary>
public string RFIDValue { get; set; }
/// <summary>
/// 状态指示 0未操作 1正在操作 2准备操作 3已完成 4超时报警
/// </summary>
public int RFIDState { get; set; } = 0;
}
}

@ -11,7 +11,7 @@ namespace NDSD_Screwdriver
public int port { get; set; }
/// <summary>
/// -1 DClose > 0 DTimeOpen =0 Dopen
/// -1 DClose > 1 DTimeOpen = 0 Dopen
/// </summary>
public int delay { get; set; }

@ -38,9 +38,6 @@
this.TestButton = new System.Windows.Forms.Button();
this.InitButton = new System.Windows.Forms.Button();
this.SettingButton = new System.Windows.Forms.Button();
this.ServerRestartButton = new System.Windows.Forms.Button();
this.StartServerButton = new System.Windows.Forms.Button();
this.ServerStopButton = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).BeginInit();
@ -52,7 +49,7 @@
// DOTest
//
this.DOTest.Location = new System.Drawing.Point(15, 15);
this.DOTest.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.DOTest.Margin = new System.Windows.Forms.Padding(2);
this.DOTest.Name = "DOTest";
this.DOTest.Size = new System.Drawing.Size(63, 35);
this.DOTest.TabIndex = 0;
@ -69,12 +66,12 @@
this.RFIDValue});
this.LogDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.LogDataGridView.Location = new System.Drawing.Point(2, 16);
this.LogDataGridView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.LogDataGridView.Margin = new System.Windows.Forms.Padding(2);
this.LogDataGridView.Name = "LogDataGridView";
this.LogDataGridView.RowHeadersVisible = false;
this.LogDataGridView.RowHeadersWidth = 51;
this.LogDataGridView.RowTemplate.Height = 27;
this.LogDataGridView.Size = new System.Drawing.Size(441, 1251);
this.LogDataGridView.Size = new System.Drawing.Size(441, 1043);
this.LogDataGridView.TabIndex = 1;
//
// logTime
@ -107,10 +104,10 @@
this.groupBox1.Controls.Add(this.LogDataGridView);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(713, 0);
this.groupBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.groupBox1.Size = new System.Drawing.Size(445, 1269);
this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
this.groupBox1.Size = new System.Drawing.Size(445, 1061);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "日志";
@ -134,10 +131,10 @@
this.ScrewdriverMonitor.ForeColor = System.Drawing.Color.Black;
this.ScrewdriverMonitor.HeaderColor = System.Drawing.Color.Black;
this.ScrewdriverMonitor.Location = new System.Drawing.Point(0, 0);
this.ScrewdriverMonitor.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.ScrewdriverMonitor.Margin = new System.Windows.Forms.Padding(2);
this.ScrewdriverMonitor.Name = "ScrewdriverMonitor";
this.ScrewdriverMonitor.RowsTotalCount = 13;
this.ScrewdriverMonitor.Size = new System.Drawing.Size(622, 1269);
this.ScrewdriverMonitor.Size = new System.Drawing.Size(622, 1061);
this.ScrewdriverMonitor.TabIndex = 3;
this.ScrewdriverMonitor.Text = "hslTable1";
this.ScrewdriverMonitor.TopHeaderColor = System.Drawing.Color.Black;
@ -149,7 +146,7 @@
// TestButton
//
this.TestButton.Location = new System.Drawing.Point(15, 113);
this.TestButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.TestButton.Margin = new System.Windows.Forms.Padding(2);
this.TestButton.Name = "TestButton";
this.TestButton.Size = new System.Drawing.Size(63, 36);
this.TestButton.TabIndex = 4;
@ -160,7 +157,7 @@
// InitButton
//
this.InitButton.Location = new System.Drawing.Point(15, 70);
this.InitButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.InitButton.Margin = new System.Windows.Forms.Padding(2);
this.InitButton.Name = "InitButton";
this.InitButton.Size = new System.Drawing.Size(63, 30);
this.InitButton.TabIndex = 7;
@ -170,8 +167,8 @@
//
// SettingButton
//
this.SettingButton.Location = new System.Drawing.Point(15, 400);
this.SettingButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.SettingButton.Location = new System.Drawing.Point(15, 179);
this.SettingButton.Margin = new System.Windows.Forms.Padding(2);
this.SettingButton.Name = "SettingButton";
this.SettingButton.Size = new System.Drawing.Size(63, 62);
this.SettingButton.TabIndex = 8;
@ -179,52 +176,16 @@
this.SettingButton.UseVisualStyleBackColor = true;
this.SettingButton.Click += new System.EventHandler(this.SettingButton_Click);
//
// ServerRestartButton
//
this.ServerRestartButton.Location = new System.Drawing.Point(15, 327);
this.ServerRestartButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.ServerRestartButton.Name = "ServerRestartButton";
this.ServerRestartButton.Size = new System.Drawing.Size(63, 54);
this.ServerRestartButton.TabIndex = 9;
this.ServerRestartButton.Text = "重启服务器";
this.ServerRestartButton.UseVisualStyleBackColor = true;
this.ServerRestartButton.Click += new System.EventHandler(this.ServerRestartButton_Click);
//
// StartServerButton
//
this.StartServerButton.Location = new System.Drawing.Point(15, 169);
this.StartServerButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.StartServerButton.Name = "StartServerButton";
this.StartServerButton.Size = new System.Drawing.Size(63, 55);
this.StartServerButton.TabIndex = 10;
this.StartServerButton.Text = "手动启动服务器";
this.StartServerButton.UseVisualStyleBackColor = true;
this.StartServerButton.Click += new System.EventHandler(this.StartServerButton_Click);
//
// ServerStopButton
//
this.ServerStopButton.Location = new System.Drawing.Point(15, 250);
this.ServerStopButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.ServerStopButton.Name = "ServerStopButton";
this.ServerStopButton.Size = new System.Drawing.Size(63, 58);
this.ServerStopButton.TabIndex = 11;
this.ServerStopButton.Text = "手动关闭服务器";
this.ServerStopButton.UseVisualStyleBackColor = true;
this.ServerStopButton.Click += new System.EventHandler(this.ServerStopButton_Click);
//
// panel1
//
this.panel1.Controls.Add(this.DOTest);
this.panel1.Controls.Add(this.SettingButton);
this.panel1.Controls.Add(this.ServerRestartButton);
this.panel1.Controls.Add(this.ServerStopButton);
this.panel1.Controls.Add(this.InitButton);
this.panel1.Controls.Add(this.StartServerButton);
this.panel1.Controls.Add(this.TestButton);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(622, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(91, 1269);
this.panel1.Size = new System.Drawing.Size(91, 1061);
this.panel1.TabIndex = 12;
//
// panel2
@ -233,18 +194,18 @@
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(622, 1269);
this.panel2.Size = new System.Drawing.Size(622, 1061);
this.panel2.TabIndex = 13;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1158, 1269);
this.ClientSize = new System.Drawing.Size(1158, 1061);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Controls.Add(this.groupBox1);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "MainForm";
this.Text = "拧紧枪监控主界面";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
@ -265,9 +226,6 @@
private System.Windows.Forms.Button TestButton;
private System.Windows.Forms.Button InitButton;
private System.Windows.Forms.Button SettingButton;
private System.Windows.Forms.Button ServerRestartButton;
private System.Windows.Forms.Button StartServerButton;
private System.Windows.Forms.Button ServerStopButton;
private System.Windows.Forms.DataGridViewTextBoxColumn logTime;
private System.Windows.Forms.DataGridViewTextBoxColumn LogValue;
private System.Windows.Forms.DataGridViewTextBoxColumn RFIDValue;

@ -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)
{
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()
for (int i = 0; i < monitorEntities.Count; i++)
{
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)
{
var monitorEntitiesCount = monitorEntities.Count;
if (id < monitorEntitiesCount)
{
step = 1;
tool.AddMq(new DOperateEntity()
/// 状态指示 0未操作 2准备操作 1正在操作 3已完成 4超时报警
int RFIDState = monitorEntities[id].RFIDState;
if (step1 == 0)
{
port = lightsEntities[FlashIndex].Yellow,
delay = 1
});
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;
}
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;
}
////等待闪烁线程
//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);
// }
//});
}
}
}
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
}

@ -33,6 +33,7 @@ namespace NDSD_Screwdriver
private ICache cache = Cache.Default;
public ScrewdriverTest()
{
DOperate = new DOperate();
InitializeComponent();
cache.Set("Test", DateTime.Now);
@ -97,15 +98,11 @@ namespace NDSD_Screwdriver
MessageBox.Show("属性值无效!");
return;
}
Thread thread = new Thread(() =>
{
for (int i = 0; i <= 16; i++)
{
DOperate.DOpen(i);
Thread.Sleep(span);
Thread.Sleep(200);
}
});
thread.Start();
}
private void ScrewdriverTest_FormClosed(object sender, FormClosedEventArgs e)

@ -15,9 +15,9 @@ namespace NDSD_Screwdriver
List<string> ls = new List<string>
{
"E0040150B8C12108",
"E0040150B8C170F6",
"E0040150B8C1393A",
"E0040150B8C0512F",
"E0040150B8C170F6",
"E0040150B8C12100"
};

@ -35,40 +35,43 @@ namespace NDSD_Screwdriver.Tool
/// <summary>
/// RFID刷新任务
/// </summary>
private void SendRunningTask()
{
sendCancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
while (!sendCancellationTokenSource.Token.IsCancellationRequested)
{
while (_methodQueue.Count > 0)
{
var q = _methodQueue.Dequeue();
// -1 DClose > 0 DTimeOpen =0 Dopen
if (q.delay == -1)
{
DOperateInfo.DClose(q.port);
}
if (q.delay == 0)
{
DOperateInfo.DOpen(q.port);
}
if (q.delay > 0)
{
DOperateInfo.DTimeOpen(q.port, q.delay);
}
Thread.Sleep(210); // 模拟一些长时间的工作
}
Thread.Sleep(100); // 模拟一些长时间的工作
}
}, sendCancellationTokenSource.Token);
}
// private void SendRunningTask()
// {
// sendCancellationTokenSource = new CancellationTokenSource();
// Task.Run(() =>
// {
// while (!sendCancellationTokenSource.Token.IsCancellationRequested)
// {
// while (_methodQueue.Count > 0)
// {
// var q = _methodQueue.Dequeue();
// // -1 DClose > 0 DTimeOpen =0 Dopen
// //-1 DClose > 0 DTimeOpen =0 Dopen
// if (q.delay == -1)
// {
// DOperateInfo.DClose(q.port);
// }
//
// if (q.delay == 0)
// {
// DOperateInfo.DClose(q.port);
// Thread.Sleep(100); // 模拟一些长时间的工作
// DOperateInfo.DOpen(q.port);
// }
//
// if (q.delay ==1)
// {
//
// DOperateInfo.DTimeOpen(q.port, q.delay);
// }
//
// Thread.Sleep(100); // 模拟一些长时间的工作
// }
//
// Thread.Sleep(10); // 模拟一些长时间的工作
// }
// }, sendCancellationTokenSource.Token);
// }
@ -86,7 +89,7 @@ namespace NDSD_Screwdriver.Tool
public void Start()
{
SendRunningTask();
// SendRunningTask();
}
public void Restart()

@ -2,16 +2,21 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using NewLife.Log;
using TouchSocket.Core;
using TouchSocket.Sockets;
using Timer = System.Timers.Timer;
namespace NDSD_Screwdriver.Tool
{
public class QingTcpClient2
{
public int IsOk { get; set; }
public string updateTime { get; set; }
private int eable = -1;
TcpClient tcpClient = new TcpClient();
private Timer timer1 = null;
@ -33,32 +38,40 @@ namespace NDSD_Screwdriver.Tool
var sb = Sub(mes);
switch (sb)
{
case "0002":
switch (eable)
{
case 1:
client.Send("00200043 \0");
break;
case 0:
client.Send("00200042 \0");
break;
}
eable = -1;
break;
case "0043":
client.Send("00300064001 0000000000\0");
break;
}
XTrace.WriteLine($"客户端接收到信息:{mes}");
// switch (sb)
// {
// case "0002":
// switch (eable)
// {
// case 1:
// client.Send("00200043 \0");
// break;
// case 0:
// client.Send("00200042 \0");
// break;
// }
// eable = -1;
// break;
// case "0043":
// client.Send("00300064001 0000000000\0");
// break;
//
// case "0065":
// IsOk = mes.Substring(96, 19).ToInt();
// updateTime = mes.Substring(95, 1);
// break;
// }
// XTrace.WriteLine($"客户端接收到信息:{mes}");
return EasyTask.CompletedTask;
};
tcpClient.Connect();
Begin();
Thread.Sleep(200);
Satus();
timer1 = new Timer();
@ -77,12 +90,12 @@ namespace NDSD_Screwdriver.Tool
var length = str.TrimStart().Length;
if (length >= 9)
{
mes= str.Substring(5, 4);
mes = str.Substring(4, 4);
}
if (mes == "0005" && length >= 24)
{
mes = str.Substring(21, 4);
mes = str.Substring(20, 4);
}
return mes;
@ -90,29 +103,33 @@ namespace NDSD_Screwdriver.Tool
private void timer1_Tick(object sender, EventArgs e)
{
tcpClient.Send("00209999 \0");
}
public void Begin()
{
tcpClient.Send("00200001 \0");
}
public void Enable()
{
eable = 1;
tcpClient.Send("00200043 \0");
}
public void Close()
{
eable = 0;
tcpClient.Send("00200042 \0");
}
public void Satus()
{
tcpClient.Send("00300064001 0000000000\0");
}

@ -30,7 +30,7 @@ namespace NDSD_Screwdriver.Tool
StopBits = System.IO.Ports.StopBits.One //停止位
}).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter()));
//clientSerialPortClient.Connect();
clientSerialPortClient.Connect();
waitClient = clientSerialPortClient.CreateWaitingClient(new WaitingOptions()
{
@ -48,7 +48,8 @@ namespace NDSD_Screwdriver.Tool
try
{
ResponsedData responsedData = waitClient.SendThenResponse(new byte[] { 0x00, 0x03, 0x00, 0x50, 0x00, 0x04, 0x45, 0xC9 });
ResponsedData responsedData = waitClient.SendThenResponse(new byte[]
{ 0x00, 0x03, 0x00, 0x50, 0x00, 0x04, 0x45, 0xC9 },500);
IRequestInfo requestInfo = responsedData.RequestInfo;
var myFixedHeaderRequestInfo = requestInfo as MyFixedHeaderRequestInfo;
return myFixedHeaderRequestInfo?.GetBody();

@ -67,6 +67,8 @@ namespace NDSD_TouchSocket
Server.SendMessage(sendAnalysis.DCloseDataAnlysis((byte)port));
}
/// <summary>
/// int控制接口关
/// </summary>

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NewLife;
using NewLife.Log;
using TouchSocket.Core;
namespace NDSD_TouchSocket
@ -50,6 +52,8 @@ namespace NDSD_TouchSocket
public byte[] DOpenDataAnalysis(byte port)
{
string CrcData = DOperateHead + port.ToString("X2") + DOpenData; //结合
XTrace.WriteLine("deng:"+CrcData);
return CrcCombine(CrcData);
}
@ -61,7 +65,11 @@ namespace NDSD_TouchSocket
public byte[] DCloseDataAnlysis(byte port)
{
string CrcData = DOperateHead + port.ToString("X2") + DCloseData; //结合
return CrcCombine(CrcData);
var by= CrcCombine(CrcData);
return by;
}
/// <summary>

Loading…
Cancel
Save