|
@@ -1,6 +1,7 @@
|
|
|
using Cognex.VisionPro;
|
|
using Cognex.VisionPro;
|
|
|
using Cognex.VisionPro.ToolBlock;
|
|
using Cognex.VisionPro.ToolBlock;
|
|
|
using CSScripting;
|
|
using CSScripting;
|
|
|
|
|
+using NPOI.OpenXml4Net.OPC.Internal;
|
|
|
using NPOI.OpenXmlFormats.Dml.Diagram;
|
|
using NPOI.OpenXmlFormats.Dml.Diagram;
|
|
|
using NPOI.SS.Formula.Eval;
|
|
using NPOI.SS.Formula.Eval;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
using NPOI.SS.Formula.Functions;
|
|
@@ -20,10 +21,13 @@ using System.Collections.ObjectModel;
|
|
|
using System.Drawing;
|
|
using System.Drawing;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.IO.Compression;
|
|
using System.IO.Compression;
|
|
|
|
|
+using System.IO.MemoryMappedFiles;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
|
+using System.Text.Json;
|
|
|
using System.Threading;
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
|
+using System.Web.UI.WebControls;
|
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
|
using Team.FFFeederService.Interfaces;
|
|
using Team.FFFeederService.Interfaces;
|
|
|
using TeamAAS_VP.Controls;
|
|
using TeamAAS_VP.Controls;
|
|
@@ -39,6 +43,7 @@ using TeamAAS_VP.ViewModels.Home;
|
|
|
using TouchSocket.Core;
|
|
using TouchSocket.Core;
|
|
|
using TouchSocket.SerialPorts;
|
|
using TouchSocket.SerialPorts;
|
|
|
using TouchSocket.Sockets;
|
|
using TouchSocket.Sockets;
|
|
|
|
|
+using System.IO.MemoryMappedFiles;
|
|
|
|
|
|
|
|
namespace TeamAAS_VP.Core
|
|
namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
@@ -257,6 +262,23 @@ namespace TeamAAS_VP.Core
|
|
|
set { SetProperty(ref _CurrentDisplayMode, value); }
|
|
set { SetProperty(ref _CurrentDisplayMode, value); }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private string _finalResultStatus = "Pending";
|
|
|
|
|
+ private string _finalResultText = "检测中";
|
|
|
|
|
+
|
|
|
|
|
+ //private string _FinalResultStatus;
|
|
|
|
|
+ public string FinalResultStatus
|
|
|
|
|
+ {
|
|
|
|
|
+ get { return _finalResultStatus; }
|
|
|
|
|
+ set { SetProperty(ref _finalResultStatus, value); }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // private string _FinalResultText;
|
|
|
|
|
+ public string FinalResultText
|
|
|
|
|
+ {
|
|
|
|
|
+ get { return _finalResultText; }
|
|
|
|
|
+ set { SetProperty(ref _finalResultText, value); }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 命令
|
|
#region 命令
|
|
@@ -1369,6 +1391,9 @@ namespace TeamAAS_VP.Core
|
|
|
addressConfig.ManualMode.Address,
|
|
addressConfig.ManualMode.Address,
|
|
|
addressConfig.ClearMode.Address,
|
|
addressConfig.ClearMode.Address,
|
|
|
addressConfig.WorkCt.Address,
|
|
addressConfig.WorkCt.Address,
|
|
|
|
|
+ addressConfig.WorkSpeed.Address,
|
|
|
|
|
+ addressConfig.In_ReadSpeed.Address,
|
|
|
|
|
+ addressConfig.In_WriteSpeed.Address,
|
|
|
};
|
|
};
|
|
|
for (int i = 0; i < 10; i++)
|
|
for (int i = 0; i < 10; i++)
|
|
|
{
|
|
{
|
|
@@ -1481,6 +1506,7 @@ namespace TeamAAS_VP.Core
|
|
|
bool _LastFzCameracheckExe = false;
|
|
bool _LastFzCameracheckExe = false;
|
|
|
bool _LastClearMode = false;
|
|
bool _LastClearMode = false;
|
|
|
bool _Lastworkct = false;
|
|
bool _Lastworkct = false;
|
|
|
|
|
+ Int16 _Lastworkspeed = 0;
|
|
|
Int16 _LastWorkStart = 0;
|
|
Int16 _LastWorkStart = 0;
|
|
|
Int16 _LastWorkDone = 0;
|
|
Int16 _LastWorkDone = 0;
|
|
|
Int16 _LastRequestPosition = 0;
|
|
Int16 _LastRequestPosition = 0;
|
|
@@ -1491,9 +1517,9 @@ namespace TeamAAS_VP.Core
|
|
|
//List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>> _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
|
|
//List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>> _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
|
|
|
|
|
|
|
|
private readonly object _stateLock = new object();
|
|
private readonly object _stateLock = new object();
|
|
|
-
|
|
|
|
|
|
|
+ private SharedSpeedFileHelper _speedFileHelper = new SharedSpeedFileHelper();
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// PLC命令触发时
|
|
|
|
|
|
|
+ /// PLC命令触发时S
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="tuple"></param>
|
|
/// <param name="tuple"></param>
|
|
|
private async void PlcCommandTrigger((string key, string nodeId, object value) tuple)
|
|
private async void PlcCommandTrigger((string key, string nodeId, object value) tuple)
|
|
@@ -2482,6 +2508,8 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"检测执行成功", MessageLevel.Debug);
|
|
SendTaskMessage($"检测执行成功", MessageLevel.Debug);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
|
|
+ FinalResultStatus = "OK";
|
|
|
|
|
+ FinalResultText = "OK";
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
//存在NG
|
|
//存在NG
|
|
@@ -2489,6 +2517,8 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
|
SendTaskMessage($"检测执行失败", MessageLevel.Alarm);
|
|
SendTaskMessage($"检测执行失败", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
|
|
+ FinalResultStatus = "NG";
|
|
|
|
|
+ FinalResultText = "NG";
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2694,7 +2724,63 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //读取写入PLC速度
|
|
|
|
|
+ else if (addressConfig.WorkSpeed.Address.Contains(tuple.nodeId))
|
|
|
|
|
+ {
|
|
|
|
|
+ if (tuple.value is Int16 state)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_Lastworkspeed != state)
|
|
|
|
|
+ {
|
|
|
|
|
+ _Lastworkspeed = state;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (state==1)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. 从PLC读取速度
|
|
|
|
|
+ string speed = plc.ReadNode<string>(string.Format(addressConfig.In_ReadSpeed.Address));
|
|
|
|
|
+ SendTaskMessage($"读取PLC速度:{speed}", MessageLevel.Info);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 写入共享文件
|
|
|
|
|
+ _speedFileHelper.WriteSpeedData(speed, state);
|
|
|
|
|
+ SendTaskMessage($"速度数据已写入共享文件", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"读取PLC速度或写入文件失败: {ex.Message}", MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if(state == 2)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. 从共享文件读取速度数据
|
|
|
|
|
+ var speedData = _speedFileHelper.ReadSpeedData();
|
|
|
|
|
+
|
|
|
|
|
+ if (speedData != null && !string.IsNullOrEmpty(speedData.SpeedValue))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 2. 写入PLC
|
|
|
|
|
+ string address = string.Format(addressConfig.In_WriteSpeed.Address);
|
|
|
|
|
+ plc.WriteNode<string>(address, speedData.SpeedValue);
|
|
|
|
|
|
|
|
|
|
+ SendTaskMessage($"从文件读取速度:{speedData.SpeedValue}, 已写入PLC", MessageLevel.Info);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage("共享文件中没有有效的速度数据", MessageLevel.Alarm);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"读取文件或写入PLC失败: {ex.Message}", MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
// 过站检查
|
|
// 过站检查
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -2706,6 +2792,7 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
|
if (_LastMesCheck[i] != state)
|
|
if (_LastMesCheck[i] != state)
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
_LastMesCheck[i] = state;
|
|
_LastMesCheck[i] = state;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -5749,6 +5836,85 @@ namespace TeamAAS_VP.Core
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region 读取写入plc速度
|
|
|
|
|
+
|
|
|
|
|
+ // 速度数据模型
|
|
|
|
|
+ [Serializable]
|
|
|
|
|
+ public class SpeedData
|
|
|
|
|
+ {
|
|
|
|
|
+ public string SpeedValue { get; set; }
|
|
|
|
|
+ public DateTime UpdateTime { get; set; }
|
|
|
|
|
+ public int State { get; set; }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public class SharedSpeedFileHelper
|
|
|
|
|
+ {
|
|
|
|
|
+ private static readonly object _lockObj = new object();
|
|
|
|
|
+ private readonly string _filePath;
|
|
|
|
|
+
|
|
|
|
|
+ public SharedSpeedFileHelper()
|
|
|
|
|
+ {
|
|
|
|
|
+ string directoryPath = @"Z:\\1111\\2222\\3333";
|
|
|
|
|
+
|
|
|
|
|
+ // 确保目录存在
|
|
|
|
|
+ if (!Directory.Exists(directoryPath))
|
|
|
|
|
+ Directory.CreateDirectory(directoryPath);
|
|
|
|
|
+
|
|
|
|
|
+ _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 写入速度数据
|
|
|
|
|
+ public void WriteSpeedData(string speed, int state)
|
|
|
|
|
+ {
|
|
|
|
|
+ lock (_lockObj)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ var data = new SpeedData
|
|
|
|
|
+ {
|
|
|
|
|
+ SpeedValue = speed,
|
|
|
|
|
+ UpdateTime = DateTime.Now,
|
|
|
|
|
+ State = state
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ string json = JsonSerializer.Serialize(data, new JsonSerializerOptions
|
|
|
|
|
+ {
|
|
|
|
|
+ WriteIndented = true
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ File.WriteAllText(_filePath, json, Encoding.UTF8);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ throw new InvalidOperationException($"写入速度文件失败: {ex.Message}", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 读取速度数据
|
|
|
|
|
+ public SpeedData ReadSpeedData()
|
|
|
|
|
+ {
|
|
|
|
|
+ lock (_lockObj)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!File.Exists(_filePath))
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
|
|
+ string json = File.ReadAllText(_filePath, Encoding.UTF8);
|
|
|
|
|
+ return JsonSerializer.Deserialize<SpeedData>(json);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ throw new InvalidOperationException($"读取速度文件失败: {ex.Message}", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|