Test
杨威 3 weeks ago
parent aeddacaedd
commit d649cbbd8a

@ -6,12 +6,5 @@ using System.Threading.Tasks;
namespace DNSD_DB.Entity 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> /// </summary>
public int RowIndex { get; set; } 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 public class RowEntity

@ -6,16 +6,5 @@ using System.Threading.Tasks;
namespace DNSD_DB.Entity 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; } public int port { get; set; }
/// <summary> /// <summary>
/// -1 DClose > 0 DTimeOpen =0 Dopen /// -1 DClose > 1 DTimeOpen = 0 Dopen
/// </summary> /// </summary>
public int delay { get; set; } public int delay { get; set; }

@ -38,9 +38,6 @@
this.TestButton = new System.Windows.Forms.Button(); this.TestButton = new System.Windows.Forms.Button();
this.InitButton = new System.Windows.Forms.Button(); this.InitButton = new System.Windows.Forms.Button();
this.SettingButton = 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.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.LogDataGridView)).BeginInit();
@ -52,7 +49,7 @@
// DOTest // DOTest
// //
this.DOTest.Location = new System.Drawing.Point(15, 15); 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.Name = "DOTest";
this.DOTest.Size = new System.Drawing.Size(63, 35); this.DOTest.Size = new System.Drawing.Size(63, 35);
this.DOTest.TabIndex = 0; this.DOTest.TabIndex = 0;
@ -69,12 +66,12 @@
this.RFIDValue}); this.RFIDValue});
this.LogDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.LogDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.LogDataGridView.Location = new System.Drawing.Point(2, 16); 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.Name = "LogDataGridView";
this.LogDataGridView.RowHeadersVisible = false; this.LogDataGridView.RowHeadersVisible = false;
this.LogDataGridView.RowHeadersWidth = 51; this.LogDataGridView.RowHeadersWidth = 51;
this.LogDataGridView.RowTemplate.Height = 27; 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; this.LogDataGridView.TabIndex = 1;
// //
// logTime // logTime
@ -107,10 +104,10 @@
this.groupBox1.Controls.Add(this.LogDataGridView); this.groupBox1.Controls.Add(this.LogDataGridView);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(713, 0); 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.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
this.groupBox1.Size = new System.Drawing.Size(445, 1269); this.groupBox1.Size = new System.Drawing.Size(445, 1061);
this.groupBox1.TabIndex = 2; this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "日志"; this.groupBox1.Text = "日志";
@ -134,10 +131,10 @@
this.ScrewdriverMonitor.ForeColor = System.Drawing.Color.Black; this.ScrewdriverMonitor.ForeColor = System.Drawing.Color.Black;
this.ScrewdriverMonitor.HeaderColor = System.Drawing.Color.Black; this.ScrewdriverMonitor.HeaderColor = System.Drawing.Color.Black;
this.ScrewdriverMonitor.Location = new System.Drawing.Point(0, 0); 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.Name = "ScrewdriverMonitor";
this.ScrewdriverMonitor.RowsTotalCount = 13; 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.TabIndex = 3;
this.ScrewdriverMonitor.Text = "hslTable1"; this.ScrewdriverMonitor.Text = "hslTable1";
this.ScrewdriverMonitor.TopHeaderColor = System.Drawing.Color.Black; this.ScrewdriverMonitor.TopHeaderColor = System.Drawing.Color.Black;
@ -149,7 +146,7 @@
// TestButton // TestButton
// //
this.TestButton.Location = new System.Drawing.Point(15, 113); 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.Name = "TestButton";
this.TestButton.Size = new System.Drawing.Size(63, 36); this.TestButton.Size = new System.Drawing.Size(63, 36);
this.TestButton.TabIndex = 4; this.TestButton.TabIndex = 4;
@ -160,7 +157,7 @@
// InitButton // InitButton
// //
this.InitButton.Location = new System.Drawing.Point(15, 70); 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.Name = "InitButton";
this.InitButton.Size = new System.Drawing.Size(63, 30); this.InitButton.Size = new System.Drawing.Size(63, 30);
this.InitButton.TabIndex = 7; this.InitButton.TabIndex = 7;
@ -170,8 +167,8 @@
// //
// SettingButton // SettingButton
// //
this.SettingButton.Location = new System.Drawing.Point(15, 400); this.SettingButton.Location = new System.Drawing.Point(15, 179);
this.SettingButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.SettingButton.Margin = new System.Windows.Forms.Padding(2);
this.SettingButton.Name = "SettingButton"; this.SettingButton.Name = "SettingButton";
this.SettingButton.Size = new System.Drawing.Size(63, 62); this.SettingButton.Size = new System.Drawing.Size(63, 62);
this.SettingButton.TabIndex = 8; this.SettingButton.TabIndex = 8;
@ -179,52 +176,16 @@
this.SettingButton.UseVisualStyleBackColor = true; this.SettingButton.UseVisualStyleBackColor = true;
this.SettingButton.Click += new System.EventHandler(this.SettingButton_Click); 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 // panel1
// //
this.panel1.Controls.Add(this.DOTest); this.panel1.Controls.Add(this.DOTest);
this.panel1.Controls.Add(this.SettingButton); 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.InitButton);
this.panel1.Controls.Add(this.StartServerButton);
this.panel1.Controls.Add(this.TestButton); this.panel1.Controls.Add(this.TestButton);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right; this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(622, 0); this.panel1.Location = new System.Drawing.Point(622, 0);
this.panel1.Name = "panel1"; 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; this.panel1.TabIndex = 12;
// //
// panel2 // panel2
@ -233,18 +194,18 @@
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(0, 0); this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2"; 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; this.panel2.TabIndex = 13;
// //
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.panel2);
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.groupBox1); 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.Name = "MainForm";
this.Text = "拧紧枪监控主界面"; this.Text = "拧紧枪监控主界面";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); 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 TestButton;
private System.Windows.Forms.Button InitButton; private System.Windows.Forms.Button InitButton;
private System.Windows.Forms.Button SettingButton; 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 logTime;
private System.Windows.Forms.DataGridViewTextBoxColumn LogValue; private System.Windows.Forms.DataGridViewTextBoxColumn LogValue;
private System.Windows.Forms.DataGridViewTextBoxColumn RFIDValue; private System.Windows.Forms.DataGridViewTextBoxColumn RFIDValue;

@ -19,6 +19,8 @@ using System.Windows.Forms;
using System.Xml.Serialization; using System.Xml.Serialization;
using NewLife.Caching; using NewLife.Caching;
using NewLife.Collections; using NewLife.Collections;
using System.IO.Ports;
using NewLife.Log;
namespace NDSD_Screwdriver namespace NDSD_Screwdriver
{ {
@ -43,15 +45,9 @@ namespace NDSD_Screwdriver
private Random rand = new Random(); private Random rand = new Random();
/// <summary>
/// RFID状态列表
/// </summary>
public List<RFIDStatesEntity> RFIDStatesEntities;
/// <summary>
/// 报警灯配置实例
/// </summary>
public List<LightsEntity> lightsEntities;
/// <summary> /// <summary>
/// 日志实例 /// 日志实例
@ -78,10 +74,11 @@ namespace NDSD_Screwdriver
private ICache cache = Cache.Default; private ICache cache = Cache.Default;
int FlashIndex = 0; 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() public MainForm()
{ {
@ -89,9 +86,9 @@ namespace NDSD_Screwdriver
InitializeComponent(); InitializeComponent();
tool = new DengTool(); // tool = new DengTool();
tool.Start(); // tool.Start();
FlashThreadTime(); FlashThreadTime();
var memorySetting = MemorySetting.Current; var memorySetting = MemorySetting.Current;
@ -102,6 +99,7 @@ namespace NDSD_Screwdriver
LogDataGridView.AutoGenerateColumns = false; LogDataGridView.AutoGenerateColumns = false;
LogDataGridView.DataSource = null; LogDataGridView.DataSource = null;
LogDataGridView.DataSource = RFIDLogsEntitys; LogDataGridView.DataSource = RFIDLogsEntitys;
DOperateInfo = new DOperate(); DOperateInfo = new DOperate();
if (!server.ServerOpen(memorySetting.ServerIP, memorySetting.ServerPort)) if (!server.ServerOpen(memorySetting.ServerIP, memorySetting.ServerPort))
{ {
@ -111,8 +109,16 @@ namespace NDSD_Screwdriver
try try
{ {
serialPort = new SerialPortFactory(memorySetting.Com); 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) catch (Exception e)
@ -120,6 +126,7 @@ namespace NDSD_Screwdriver
MessageBox.Show(e.Message); MessageBox.Show(e.Message);
FormUtils.LogInsert(LogContext, e.Message); FormUtils.LogInsert(LogContext, e.Message);
} }
} }
@ -144,7 +151,7 @@ namespace NDSD_Screwdriver
} }
tool.Stop(); // tool.Stop();
if (cancellationTokenSource != null) if (cancellationTokenSource != null)
{ {
@ -179,6 +186,7 @@ namespace NDSD_Screwdriver
private void InitButton_Click(object sender, EventArgs e) private void InitButton_Click(object sender, EventArgs e)
{ {
InitTable(); InitTable();
StartLongRunningTask();
} }
/// <summary> /// <summary>
@ -186,7 +194,7 @@ namespace NDSD_Screwdriver
/// </summary> /// </summary>
private void InitTable() private void InitTable()
{ {
_flashflag = true; // _flashflag = true;
FlashIndex = 0; FlashIndex = 0;
textRFID = 0; textRFID = 0;
timer.Start(); timer.Start();
@ -196,51 +204,29 @@ namespace NDSD_Screwdriver
var ctx = SqlLiteTool.GetDb(memorySetting.DB); var ctx = SqlLiteTool.GetDb(memorySetting.DB);
var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList(); var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList();
var strs = list.Select(x => x.RfidNo).ToArray(); var strs = list.Select(x => x.RfidNo).ToArray();
RFIDStatesEntities = new List<RFIDStatesEntity>(); monitorEntities = new List<MonitorEntity>(list.Count);
RFIDStatesEntities.Clear(); int i1 = 0;
foreach (var a in strs) foreach (var en in list)
{
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.Add(new MonitorEntity() 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() 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(); RefreshRoll();
RefreshIO();
} }
/// <summary> /// <summary>
@ -254,74 +240,9 @@ namespace NDSD_Screwdriver
frmSetting.Show(); 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> /// <summary>
/// 测试按钮 /// 测试按钮
@ -330,23 +251,25 @@ namespace NDSD_Screwdriver
/// <param name="e"></param> /// <param name="e"></param>
private void TestButton1_Click(object sender, EventArgs e) private void TestButton1_Click(object sender, EventArgs e)
{ {
if (RFIDStatesEntities.Count == 0) //if (monitorEntities.Count == 0)
{ //{
MessageBox.Show("请先初始化RFID列表"); // MessageBox.Show("请先初始化RFID列表");
} //}
else if (textRFID == RFIDStatesEntities.Count) //else if (textRFID == monitorEntities.Count)
{ //{
SetNowWorkRow("0000000"); // SetNowWorkRow("0000000");
textRFID = 0; // textRFID = 0;
return; // return;
} //}
SetNowWorkRow(RFIDStatesEntities[textRFID].RFIDValue); //SetNowWorkRow(monitorEntities[textRFID].RFIDValue);
if (++textRFID > RFIDStatesEntities.Count) //if (++textRFID > monitorEntities.Count)
{ //{
textRFID = 0; // textRFID = 0;
return; // return;
} //}
LogContext.Delete<RFIDLogsEntity>(x=>x.ID>0);
GetLog();
} }
#endregion #endregion
@ -360,47 +283,45 @@ namespace NDSD_Screwdriver
/// <param name="rfid">读取到的RFID</param> /// <param name="rfid">读取到的RFID</param>
private void SetNowWorkRow(string rfid) private void SetNowWorkRow(string rfid)
{ {
var memorySetting = MemorySetting.Current; var memorySetting = MemorySetting.Current;
//设置RFID状态 //设置RFID状态
int flag = 0; 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; monitorEntities[i].RFIDState = 1;
FormUtils.LogInsert(LogContext, "RFID " + i + " 开始工作", RFIDStatesEntities[i].RFIDValue); FormUtils.LogInsert(LogContext, "RFID " + i + " 开始工作", monitorEntities[i].RFIDValue);
GetLog(); GetLog();
if (i - 1 >= 0) // if (i - 1 >= 0)
{ // {
string rfidValue = RFIDStatesEntities[i - 1].RFIDValue; // string rfidValue = monitorEntities[i - 1].RFIDValue;
var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).CreateTime; // var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).CreateTime;
double timeSpan = (DateTime.Now - leastTime).TotalSeconds; // double timeSpan = (DateTime.Now - leastTime).TotalSeconds;
if (timeSpan >= memorySetting.AlarmTimeValue) // if (timeSpan >= memorySetting.AlarmTimeValue)
{ // {
RFIDStatesEntities[i - 1].RFIDState = 4; // monitorEntities[i - 1].RFIDState = 4;
FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", RFIDStatesEntities[i].RFIDValue); // FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", monitorEntities[i].RFIDValue);
} // }
if (timeSpan < memorySetting.AlarmTimeValue) // if (timeSpan < memorySetting.AlarmTimeValue)
{ // {
RFIDStatesEntities[i - 1].RFIDState = 3; // monitorEntities[i - 1].RFIDState = 3;
FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", RFIDStatesEntities[i].RFIDValue); // FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", monitorEntities[i].RFIDValue);
} // }
GetLog(); // GetLog();
} // }
if (i + 1 < RFIDStatesEntities.Count) // if (i + 1 < monitorEntities.Count)
{ // {
FormUtils.LogInsert(LogContext, "RFID " + (i + 1) + " 准备工作", RFIDStatesEntities[i].RFIDValue); // FormUtils.LogInsert(LogContext, "RFID " + (i + 1) + " 准备工作", monitorEntities[i].RFIDValue);
GetLog(); // GetLog();
RFIDStatesEntities[i + 1].RFIDState = 2; // monitorEntities[i + 1].RFIDState = 2;
FlashIndex = i + 1; // FlashIndex = i + 1;
} // }
else // else
{ // {
timer.Stop(); // timer.Stop();
_flashflag = false; // // _flashflag = false;
} // }
flag = 1; flag = 1;
break; break;
} }
@ -408,97 +329,101 @@ namespace NDSD_Screwdriver
if (flag == 0) //列表里没有已读的RFID if (flag == 0) //列表里没有已读的RFID
{ {
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)
{ // {
string rfidValue = RFIDStatesEntities[i - 1].RFIDValue; // string rfidValue = monitorEntities[i - 1].RFIDValue;
var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).CreateTime; // if (rfidValue != null)
double timeSpan = (DateTime.Now - leastTime).TotalSeconds; // {
if (timeSpan >= memorySetting.AlarmTimeValue) // var leastTime = RFIDLogsEntitys.First(x => x.RFIDId == rfidValue).CreateTime;
{ // double timeSpan = (DateTime.Now - leastTime).TotalSeconds;
RFIDStatesEntities[i].RFIDState = 4; // if (timeSpan >= memorySetting.AlarmTimeValue)
FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", RFIDStatesEntities[i].RFIDValue); // {
} // monitorEntities[i].RFIDState = 4;
if (timeSpan < memorySetting.AlarmTimeValue) // FormUtils.LogInsert(LogContext, "RFID " + i + " 超时结束", monitorEntities[i].RFIDValue);
{ // }
RFIDStatesEntities[i].RFIDState = 3; // if (timeSpan < memorySetting.AlarmTimeValue)
FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", RFIDStatesEntities[i].RFIDValue); // {
} // monitorEntities[i].RFIDState = 3;
} // FormUtils.LogInsert(LogContext, "RFID " + (i - 1) + " 成功结束", monitorEntities[i].RFIDValue);
} // }
// }
//
// }
// }
} }
//刷新前端灯的状态 //刷新前端灯的状态
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)
{ // {
SetRowsLightState(i, 1); // SetRowsLightState(i, 1);
} // }
else if (RFIDStatesEntities[i].RFIDState == 3) // else if (monitorEntities[i].RFIDState == 3)
{ // {
SetRowsLightState(i, 0); // SetRowsLightState(i, 0);
} // }
else if (RFIDStatesEntities[i].RFIDState == 4) // else if (monitorEntities[i].RFIDState == 4)
{ // {
SetRowsLightState(i, 2); // SetRowsLightState(i, 2);
} // }
else // else
{ // {
SetRowsLightState(i, Brushes.Transparent); // SetRowsLightState(i, Brushes.Transparent);
} // }
} }
if(_flashflag) // if(_flashflag)
timer.Stop(); // timer.Stop();
//
//刷新IO的状态 // //刷新IO的状态
for (int i = 0; i < RFIDStatesEntities.Count; i++) // // for (int i = 0; i < RFIDStatesEntities.Count; i++)
{ // // {
// //
if (RFIDStatesEntities[i].RFIDState == 1) // // if (RFIDStatesEntities[i].RFIDState == 1)
{ // // {
// DOperateInfo.DOpen(lightsEntities[i].Yellow); // // // DOperateInfo.DOpen(lightsEntities[i].Yellow);
tool.AddMq(new DOperateEntity() // // tool.AddMq(new DOperateEntity()
{ // // {
port = lightsEntities[i].Yellow, // // port = lightsEntities[i].Yellow,
delay = 0 // // delay = 0
}); // // });
// //
} // // }
else if (RFIDStatesEntities[i].RFIDState == 3) // // else if (RFIDStatesEntities[i].RFIDState == 3)
{ // // {
tool.AddMq(new DOperateEntity() // // tool.AddMq(new DOperateEntity()
{ // // {
port = lightsEntities[i].Green, // // port = lightsEntities[i].Green,
delay = 0 // // delay = 0
}); // // });
// //
tool.AddMq(new DOperateEntity() // // tool.AddMq(new DOperateEntity()
{ // // {
port = lightsEntities[i].Yellow, // // port = lightsEntities[i].Yellow,
delay = -1 // // delay = -1
}); // // });
// //
} // // }
else if (RFIDStatesEntities[i].RFIDState == 4) // // else if (RFIDStatesEntities[i].RFIDState == 4)
{ // // {
// //
tool.AddMq(new DOperateEntity() // // tool.AddMq(new DOperateEntity()
{ // // {
port = lightsEntities[i].Red, // // port = lightsEntities[i].Red,
delay = 0 // // delay = 0
}); // // });
// //
tool.AddMq(new DOperateEntity() // // tool.AddMq(new DOperateEntity()
{ // // {
port = lightsEntities[i].Yellow, // // port = lightsEntities[i].Yellow,
delay = -1 // // delay = -1
}); // // });
// //
} // // }
} // // }
if (_flashflag) // if (_flashflag)
timer.Start(); // timer.Start();
RefreshRoll(); RefreshRoll();
} }
@ -525,7 +450,7 @@ namespace NDSD_Screwdriver
private void RefreshRoll() private void RefreshRoll()
{ {
List<string[]> values = new List<string[]>(); 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[] values.Add(new string[]
{ {
@ -554,9 +479,9 @@ namespace NDSD_Screwdriver
{ {
monitorEntities[index].RowEntitys[2].Color = brush; 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> /// <summary>
/// RFID刷新任务 /// RFID刷新任务
/// </summary> /// </summary>
@ -596,11 +524,71 @@ namespace NDSD_Screwdriver
cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource = new CancellationTokenSource();
Task.Run(() => Task.Run(() =>
{ {
while (!cancellationTokenSource.Token.IsCancellationRequested) while (!cancellationTokenSource.Token.IsCancellationRequested)
{ {
//SetNowWorkRow("0000000"); //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); }, cancellationTokenSource.Token);
} }
@ -608,28 +596,8 @@ namespace NDSD_Screwdriver
///// <summary>
///// 等待工作指示灯闪烁进程 System.Timers.Timer timer = new System.Timers.Timer(500); // 设置1秒间隔
///// </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秒间隔
/// <summary> /// <summary>
/// 等待工作指示灯闪烁进程 /// 等待工作指示灯闪烁进程
/// </summary> /// </summary>
@ -637,50 +605,119 @@ namespace NDSD_Screwdriver
{ {
int step = 0; int step = 0;
timer.Elapsed += (sender, e) => timer.Elapsed += (sender, e) =>
{ {
if (step == 0) Set(FlashIndex);
{ RefreshRoll();
step = 1; };
tool.AddMq(new DOperateEntity()
{
port = lightsEntities[FlashIndex].Yellow,
delay = 1
});
}
monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow;
} int step1 = 0;
else if (step == 1) public void Set(int id)
{
var monitorEntitiesCount = monitorEntities.Count;
if (id < monitorEntitiesCount)
{ {
step=0; /// 状态指示 0未操作 2准备操作 1正在操作 3已完成 4超时报警
monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Transparent; int RFIDState = monitorEntities[id].RFIDState;
if (step1 == 0)
{
step1 = 1;
}
RFIDState = monitorEntities[id].RFIDState;
RefreshRoll(); 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;
}
RFIDState = monitorEntities[id].RFIDState;
if (RFIDState == 1)
{
////等待闪烁线程 if ((id+1) < monitorEntitiesCount)
//flashThread = new Thread(() => {
//{ monitorEntities[id + 1].RFIDState = 2;
// while (true) /// 状态指示 0未操作 2准备操作 1正在操作 3已完成 4超时报警
// { }
// DOperate.DTimeOpen(lightsEntities[FlashIndex].Yellow, 1);
// monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Yellow;
// RefreshRoll(); if (dictionary.ContainsKey(monitorEntities[id].RFIDValue))
// Thread.Sleep(1000); {
// monitorEntities[FlashIndex].RowEntitys[2].Color = Brushes.Transparent; var i = dictionary[monitorEntities[id].RFIDValue];
// RefreshRoll(); dictionary[monitorEntities[id].RFIDValue] = i + 1;
// Thread.Sleep(1000); 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;
}
}
}
} }
private int step2 = 0;
/// <summary> /// <summary>
/// 获取Log /// 获取Log
/// </summary> /// </summary>
@ -700,9 +737,9 @@ namespace NDSD_Screwdriver
/// <returns>准备行index</returns> /// <returns>准备行index</returns>
private int GetReadyRowIndex() 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; return i;
} }
@ -716,9 +753,9 @@ namespace NDSD_Screwdriver
/// <returns>工作行index</returns> /// <returns>工作行index</returns>
private int GetNowRowIndex() 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; return i;
} }
@ -726,32 +763,7 @@ namespace NDSD_Screwdriver
return -1; 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 #endregion
} }

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

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

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

@ -2,16 +2,21 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers;
using NewLife.Log; using NewLife.Log;
using TouchSocket.Core; using TouchSocket.Core;
using TouchSocket.Sockets; using TouchSocket.Sockets;
using Timer = System.Timers.Timer;
namespace NDSD_Screwdriver.Tool namespace NDSD_Screwdriver.Tool
{ {
public class QingTcpClient2 public class QingTcpClient2
{ {
public int IsOk { get; set; }
public string updateTime { get; set; }
private int eable = -1; private int eable = -1;
TcpClient tcpClient = new TcpClient(); TcpClient tcpClient = new TcpClient();
private Timer timer1 = null; private Timer timer1 = null;
@ -31,34 +36,42 @@ namespace NDSD_Screwdriver.Tool
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。 //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
var mes = e.ByteBlock.Span.ToString(Encoding.ASCII); var mes = e.ByteBlock.Span.ToString(Encoding.ASCII);
var sb= Sub(mes); var sb = Sub(mes);
switch (sb) // switch (sb)
{ // {
case "0002": // case "0002":
switch (eable) // switch (eable)
{ // {
case 1: // case 1:
client.Send("00200043 \0"); // client.Send("00200043 \0");
break; // break;
case 0: // case 0:
client.Send("00200042 \0"); // client.Send("00200042 \0");
break; // break;
} // }
eable = -1; // eable = -1;
break; // break;
case "0043": // case "0043":
client.Send("00300064001 0000000000\0"); // client.Send("00300064001 0000000000\0");
break; // break;
} //
// case "0065":
XTrace.WriteLine($"客户端接收到信息:{mes}"); // IsOk = mes.Substring(96, 19).ToInt();
// updateTime = mes.Substring(95, 1);
// break;
// }
// XTrace.WriteLine($"客户端接收到信息:{mes}");
return EasyTask.CompletedTask; return EasyTask.CompletedTask;
}; };
tcpClient.Connect(); tcpClient.Connect();
Begin();
Thread.Sleep(200);
Satus();
timer1 = new Timer(); timer1 = new Timer();
@ -75,14 +88,14 @@ namespace NDSD_Screwdriver.Tool
{ {
string mes = ""; string mes = "";
var length = str.TrimStart().Length; var length = str.TrimStart().Length;
if (length>= 9) if (length >= 9)
{ {
mes= str.Substring(5, 4); mes = str.Substring(4, 4);
} }
if (mes == "0005" && length >= 24) if (mes == "0005" && length >= 24)
{ {
mes = str.Substring(21, 4); mes = str.Substring(20, 4);
} }
return mes; return mes;
@ -90,29 +103,33 @@ namespace NDSD_Screwdriver.Tool
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)
{ {
tcpClient.Send("00209999 \0"); tcpClient.Send("00209999 \0");
} }
public void Begin() public void Begin()
{ {
tcpClient.Send("00200001 \0"); tcpClient.Send("00200001 \0");
} }
public void Enable() public void Enable()
{ {
eable = 1; tcpClient.Send("00200043 \0");
} }
public void Close() public void Close()
{ {
eable = 0; tcpClient.Send("00200042 \0");
} }
public void Satus() public void Satus()
{ {
tcpClient.Send("00300064001 0000000000\0"); tcpClient.Send("00300064001 0000000000\0");
} }

@ -30,7 +30,7 @@ namespace NDSD_Screwdriver.Tool
StopBits = System.IO.Ports.StopBits.One //停止位 StopBits = System.IO.Ports.StopBits.One //停止位
}).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter())); }).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter()));
//clientSerialPortClient.Connect(); clientSerialPortClient.Connect();
waitClient = clientSerialPortClient.CreateWaitingClient(new WaitingOptions() waitClient = clientSerialPortClient.CreateWaitingClient(new WaitingOptions()
{ {
@ -48,7 +48,8 @@ namespace NDSD_Screwdriver.Tool
try 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; IRequestInfo requestInfo = responsedData.RequestInfo;
var myFixedHeaderRequestInfo = requestInfo as MyFixedHeaderRequestInfo; var myFixedHeaderRequestInfo = requestInfo as MyFixedHeaderRequestInfo;
return myFixedHeaderRequestInfo?.GetBody(); return myFixedHeaderRequestInfo?.GetBody();

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

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

Loading…
Cancel
Save