From 5f2eefec5e4b821a3c3086dc1b9377c1409498af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=94=84=E5=A4=B4?= Date: Fri, 30 Aug 2024 22:01:54 +0800 Subject: [PATCH] demo --- NDSD-Screwdriver/MainForm.cs | 171 +++++++++++++++++----- NDSD-Screwdriver/NDSD_Screwdriver.csproj | 1 + NDSD-Screwdriver/Tool/QingTcpClient2.cs | 36 ++++- NDSD-Screwdriver/Tool/TighteningResult.cs | 41 ++++++ 4 files changed, 204 insertions(+), 45 deletions(-) create mode 100644 NDSD-Screwdriver/Tool/TighteningResult.cs diff --git a/NDSD-Screwdriver/MainForm.cs b/NDSD-Screwdriver/MainForm.cs index 75a5e5a..2af7ded 100644 --- a/NDSD-Screwdriver/MainForm.cs +++ b/NDSD-Screwdriver/MainForm.cs @@ -21,6 +21,7 @@ using NewLife.Caching; using NewLife.Collections; using System.IO.Ports; using NewLife.Log; +using NewLife.Serialization; namespace NDSD_Screwdriver { @@ -184,6 +185,18 @@ namespace NDSD_Screwdriver private void InitButton_Click(object sender, EventArgs e) { InitTable(); + if (cancellationTokenSource != null) + { + cancellationTokenSource.Cancel(); + cancellationTokenSource.Dispose(); + } + + for (int i = 0; i <=16; i++) + { + DOperateInfo.DClose(i); + Thread.Sleep(300); + } + StartLongRunningTask(); } @@ -558,19 +571,29 @@ namespace NDSD_Screwdriver if (FlashIndex < monitorEntitiesCount) { + // if (FlashIndex > 0) + // { + // SetQian(FlashIndex-1); + // } + monitorEntities[FlashIndex].RFIDState = 1; + RefreshRoll(); } } + else + { + quClient2.Close(); + } } } else { - + var total = DateTime.Now - dateTime; - if (total.TotalSeconds > 2) + if (total.TotalSeconds > 1) { quClient2.Close(); dateTime = DateTime.Now; @@ -601,6 +624,8 @@ namespace NDSD_Screwdriver int step = 0; timer.Elapsed += (sender, e) => { + + Set(FlashIndex); RefreshRoll(); }; @@ -612,6 +637,8 @@ namespace NDSD_Screwdriver int step1 = 0; public void Set(int id) { + + var monitorEntitiesCount = monitorEntities.Count; if (id < monitorEntitiesCount) @@ -627,10 +654,10 @@ namespace NDSD_Screwdriver if (RFIDState == 2) { - // DOperateInfo.DClose(monitorEntities[id].Green); // Thread.Sleep(300); XTrace.WriteLine("亮黄灯延迟"); + Thread.Sleep(200); DOperateInfo.DTimeOpen(monitorEntities[id].Yellow, 1); monitorEntities[id].RowEntitys[2].Color = Brushes.Yellow; } @@ -639,7 +666,7 @@ namespace NDSD_Screwdriver if (RFIDState == 1) { - + timer.Stop(); if ((id+1) < monitorEntitiesCount) { monitorEntities[id + 1].RFIDState = 2; @@ -647,52 +674,58 @@ namespace NDSD_Screwdriver } - 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; - } - + // 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; + // } XTrace.WriteLine("读取Rfid 亮黄灯"); //状态修改 + Thread.Sleep(200); DOperateInfo.DOpen(monitorEntities[FlashIndex].Yellow); - timer.Start(); + monitorEntities[id].RowEntitys[2].Color = Brushes.Yellow; + + + SetQian(FlashIndex); + + timer.Start(); } RFIDState = monitorEntities[id].RFIDState; - if (RFIDState == 3) - { - timer.Stop(); - - quClient2.Close(); - Thread.Sleep(300); - DOperateInfo.DClose(monitorEntities[id].Yellow); - Thread.Sleep(300); - DOperateInfo.DOpen(monitorEntities[id].Green); - - - - monitorEntities[id].RowEntitys[2].Color = Brushes.Green; - monitorEntities[id].RFIDState=100; - - - FlashIndex += 1; - timer.Start(); - } + // if (RFIDState == 3) + // { + // timer.Stop(); + // + // + // Thread.Sleep(300); + // DOperateInfo.DClose(monitorEntities[id].Yellow); + // Thread.Sleep(300); + // DOperateInfo.DOpen(monitorEntities[id].Green); + // + // + // + // monitorEntities[id].RowEntitys[2].Color = Brushes.Green; + // monitorEntities[id].RFIDState=100; + // + // + // FlashIndex += 1; + // timer.Start(); + // } + } @@ -706,12 +739,72 @@ namespace NDSD_Screwdriver monitorEntities[id].RowEntitys[2].Color = Brushes.Transparent; } + + } } } + + private void SetQian(int no) + { + + var ssss = quClient2.gitResult; + + var quClient2TighteningStatus = -1; + if (ssss.IsOk) + { + quClient2TighteningStatus = ssss.TighteningStatus; + + + var monitorEntitiesCount = monitorEntities.Count; + if (no < monitorEntitiesCount) + { + + XTrace.WriteLine(ssss.ToJson()); + + if (quClient2TighteningStatus == 1) + { + + Thread.Sleep(300); + DOperateInfo.DClose(monitorEntities[no].Yellow); + + Thread.Sleep(300); + DOperateInfo.DClose(monitorEntities[no].Red); + Thread.Sleep(300); + DOperateInfo.DOpen(monitorEntities[no].Green); + + monitorEntities[no].RowEntitys[2].Color = Brushes.Green; + FlashIndex += 1; + quClient2.Close(); + ssss.msg = ""; + } + else + { + if (quClient2TighteningStatus == 0) + { + Thread.Sleep(300); + DOperateInfo.DClose(monitorEntities[no].Yellow); + Thread.Sleep(300); + + DOperateInfo.DClose(monitorEntities[no].Green); + Thread.Sleep(300); + + DOperateInfo.DOpen(monitorEntities[no].Red); + + monitorEntities[no].RowEntitys[2].Color = Brushes.Red; + // FlashIndex += 1; + ssss.msg = ""; + } + } + + + + } + } + } private int step2 = 0; /// diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj index 017060b..9f2ce11 100644 --- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj +++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj @@ -127,6 +127,7 @@ + FrmSetting.cs diff --git a/NDSD-Screwdriver/Tool/QingTcpClient2.cs b/NDSD-Screwdriver/Tool/QingTcpClient2.cs index 671e5d8..b001f4a 100644 --- a/NDSD-Screwdriver/Tool/QingTcpClient2.cs +++ b/NDSD-Screwdriver/Tool/QingTcpClient2.cs @@ -13,8 +13,12 @@ namespace NDSD_Screwdriver.Tool { public class QingTcpClient2 { + public TighteningResult gitResult { get; } - public int IsOk { get; set; } + + public int TighteningStatus => gitResult.TighteningStatus; + + public int IsOk { get; set; } = -1; public string updateTime { get; set; } private int eable = -1; @@ -22,6 +26,8 @@ namespace NDSD_Screwdriver.Tool private Timer timer1 = null; public QingTcpClient2(string str = "192.168.5.212:4545") { + gitResult = new TighteningResult(); + tcpClient.Connecting = (client, e) => EasyTask.CompletedTask;//即将连接到服务器,此时已经创建socket,但是还未建立tcp tcpClient.Connected = (client, e) => EasyTask.CompletedTask;//成功连接到服务器 tcpClient.Setup(new TouchSocketConfig() @@ -35,8 +41,18 @@ namespace NDSD_Screwdriver.Tool { //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。 var mes = e.ByteBlock.Span.ToString(Encoding.ASCII); - var sb = Sub(mes); + XTrace.WriteLine("控制器返回:"+mes); + switch (sb) + { + case "0061": + gitResult.msg = mes; + XTrace.WriteLine(gitResult.Timestamp.ToFullString()); + XTrace.WriteLine(gitResult.TighteningStatus.ToString()); + + client.Send("00200062001 \0"); + break; + } // switch (sb) // { @@ -70,7 +86,9 @@ namespace NDSD_Screwdriver.Tool tcpClient.Connect(); Begin(); - Thread.Sleep(200); + + Thread.Sleep(100); + Satus(); @@ -79,6 +97,9 @@ namespace NDSD_Screwdriver.Tool timer1.Elapsed += timer1_Tick; timer1.Interval = 500; //设置时间间隔(毫秒为单位)单位Ms timer1.Start(); + + + } @@ -103,7 +124,6 @@ namespace NDSD_Screwdriver.Tool private void timer1_Tick(object sender, EventArgs e) { - tcpClient.Send("00209999 \0"); } @@ -132,8 +152,12 @@ namespace NDSD_Screwdriver.Tool public void Satus() { - tcpClient.Send("00300064001 0000000000\0"); + tcpClient.Send("00200060001 \0"); + } + public void OK() + { + + tcpClient.Send("00200062001 \0"); } - } } diff --git a/NDSD-Screwdriver/Tool/TighteningResult.cs b/NDSD-Screwdriver/Tool/TighteningResult.cs new file mode 100644 index 0000000..38ceb5b --- /dev/null +++ b/NDSD-Screwdriver/Tool/TighteningResult.cs @@ -0,0 +1,41 @@ +using System; + +namespace NDSD_Screwdriver.Tool +{ + public class TighteningResult + { + public string msg { set; get; } = ""; + + public bool IsOk => msg.Length > 0; + + public int CellID => int.Parse(msg.Substring(22, 4)); + + public int ChannelID => int.Parse(msg.Substring(28, 2)); + public string ControllerName => msg.Substring(32, 25).Trim(); + public string VINNumber => msg.Substring(59, 25).Trim(); + public int JobID => int.Parse(msg.Substring(86, 2)); + public int ParametersetID => int.Parse(msg.Substring(90, 3)); + public int Batchsize => int.Parse(msg.Substring(95, 4)); + public int Batchcounter => int.Parse(msg.Substring(101, 4)); + + // 0=tightening NG, 1=tightening OK + public int TighteningStatus => int.Parse(msg.Substring(107, 1)); + + //0=Low, 1=OK, 2=High + public int Torquestatus => int.Parse(msg.Substring(110, 1)); + public int Anglestatus => int.Parse(msg.Substring(113, 1)); + + public double TorqueMinlimit => double.Parse(msg.Substring(116, 6)) / 100.0; + public double TorqueMaxlimit => double.Parse(msg.Substring(124, 6)) / 100.0; + public double Torquefinaltarget => double.Parse(msg.Substring(132, 6)) / 100.0; + public string strVal => msg.Substring(140, 6); + public double Torque => double.Parse(strVal) / 100.0; + public int AngleMin => int.Parse(msg.Substring(148, 5)); + public int AngleMax => int.Parse(msg.Substring(155, 5)); + public int FinalAngleTarget => int.Parse(msg.Substring(162, 5)); + + public int Angle => int.Parse(strVal); + public DateTime Timestamp => DateTime.Parse($"{msg.Substring(176, 10)} {msg.Substring(187, 8)}"); + + } +} \ No newline at end of file