Compare commits
15 Commits
5d77eebc67
...
dev_update
Author | SHA1 | Date | |
---|---|---|---|
b2ccd0c91a | |||
4765e0e5bd | |||
ab38ee029a | |||
dbf412713b | |||
67ba78f268 | |||
d63a6c42b3 | |||
babc40d36a | |||
409089e2ca | |||
e08386333a | |||
b19feb5a44 | |||
0865af247a | |||
8d32269ee0 | |||
b4569f8ccc | |||
9e38ea85c8 | |||
3be4b185d6 |
@ -3,12 +3,47 @@ using System.ComponentModel;
|
||||
using System.Drawing.Imaging;
|
||||
using AntdUI;
|
||||
using DH.Commons.Enums;
|
||||
using HalconDotNet;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace DH.Commons.Base
|
||||
{
|
||||
public class MatSet
|
||||
{
|
||||
public DateTime ImageTime { get; set; } = DateTime.Now;
|
||||
|
||||
private string id = "";
|
||||
public string Id
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
id = ImageTime.ToString("HHmmssfff");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
set
|
||||
{
|
||||
id = value;
|
||||
}
|
||||
}
|
||||
public string CameraId { get; set; }
|
||||
public Mat _mat { get; set; } = null;
|
||||
|
||||
public ImageFormat _imageFormat { get; set; } = ImageFormat.Jpeg;
|
||||
public virtual void Dispose()
|
||||
{
|
||||
_mat?.Dispose();
|
||||
_mat = null;
|
||||
|
||||
}
|
||||
}
|
||||
public class CameraBase : NotifyProperty
|
||||
{
|
||||
|
||||
// public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
|
||||
|
||||
// 私有字段 + 带通知的属性(与DetectionLabel风格一致)
|
||||
private bool _isEnabled = false;
|
||||
private bool _isallPicEnabled = true;//默认全画幅
|
||||
|
@ -9,6 +9,7 @@ using AntdUI;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
using System.Text.Json.Serialization;
|
||||
using DH.Commons.Enums;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace DH.Commons.Base
|
||||
{
|
||||
@ -104,20 +105,20 @@ namespace DH.Commons.Base
|
||||
/// </summary>
|
||||
public class DetectionResultDetail
|
||||
{
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
|
||||
public string LabelBGR { get; set; }//识别到对象的标签BGR
|
||||
|
||||
|
||||
|
||||
public int LabelNo { get; set; } // 识别到对象的标签索引
|
||||
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
|
||||
public string LabelName { get; set; }//识别到对象的标签名称
|
||||
|
||||
|
||||
public double Score { get; set; }//识别目标结果的可能性、得分
|
||||
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
|
||||
public string LabelDisplay { get; set; }//识别到对象的 显示信息
|
||||
|
||||
|
||||
@ -138,10 +139,10 @@ namespace DH.Commons.Base
|
||||
public class MLResult
|
||||
{
|
||||
public bool IsSuccess = false;
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
|
||||
public string ResultMessage;
|
||||
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
|
||||
public Bitmap ResultMap;
|
||||
|
||||
public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>();
|
||||
@ -165,8 +166,7 @@ namespace DH.Commons.Base
|
||||
public bool IsGPU;
|
||||
public int GPUId;
|
||||
public float Score_thre;
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
|
||||
public MLInit(string modelFile, bool isGPU, int gpuId, float score_thre)
|
||||
|
||||
|
||||
@ -191,18 +191,32 @@ namespace DH.Commons.Base
|
||||
}
|
||||
public class DetectStationResult
|
||||
{
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
public DateTime ImageTime { get; set; } = DateTime.Now;
|
||||
|
||||
private string id = "";
|
||||
public string Id
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
id = ImageTime.ToString("HHmmssfff");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
set
|
||||
{
|
||||
id = value;
|
||||
}
|
||||
}
|
||||
public string Pid { get; set; }
|
||||
|
||||
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
public string TempPid { get; set; }
|
||||
public string TempPid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测工位名称
|
||||
/// </summary>
|
||||
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
|
||||
public string DetectName { get; set; }
|
||||
|
||||
|
||||
@ -212,8 +226,11 @@ namespace DH.Commons.Base
|
||||
/// </summary>
|
||||
public List<DetectionResultDetail> DetectDetails = new List<DetectionResultDetail>();
|
||||
public List<IShapeElement> DetectionResultShapes = new List<IShapeElement>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 视觉测量结果集合
|
||||
/// </summary>
|
||||
|
||||
public List<IndexedSpec> realSpecs { get; set; } = new List<IndexedSpec>();
|
||||
/// <summary>
|
||||
/// 工位检测结果
|
||||
/// </summary>
|
||||
@ -238,35 +255,24 @@ namespace DH.Commons.Base
|
||||
/// 预处理阶段已经NG
|
||||
/// </summary>
|
||||
public bool IsPreTreatNG { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 检测原图
|
||||
/// </summary>
|
||||
public Bitmap DetectionOriginImage { get; set; }
|
||||
/// <summary>
|
||||
/// 目标检测NG
|
||||
/// </summary>
|
||||
public bool IsObjectDetectNG { get; set; } = false;
|
||||
|
||||
public ImageFormat ImageFormat { get; set; } = ImageFormat.Jpeg;
|
||||
public DateTime EndTime { get; set; }
|
||||
|
||||
public string ImageSaveDirectory { get; set; }
|
||||
public int StationDetectElapsed { get; set; }
|
||||
public static string NormalizeAndClean(string input)
|
||||
{
|
||||
#pragma warning disable CS8603 // 可能返回 null 引用。
|
||||
if (input == null) return null;
|
||||
#pragma warning restore CS8603 // 可能返回 null 引用。
|
||||
public bool SaveOKOriginal = false;
|
||||
public bool SaveNGOriginal = false;
|
||||
public bool SaveOKDetect = false;
|
||||
public bool SaveNGDetect = false;
|
||||
|
||||
// Step 1: 标准化字符编码为 Form C (规范组合)
|
||||
string normalizedString = input.Normalize(NormalizationForm.FormC);
|
||||
|
||||
// Step 2: 移除所有空白字符,包括制表符和换行符
|
||||
string withoutWhitespace = Regex.Replace(normalizedString, @"\s+", "");
|
||||
|
||||
// Step 3: 移除控制字符 (Unicode 控制字符,范围 \u0000 - \u001F 和 \u007F)
|
||||
string withoutControlChars = Regex.Replace(withoutWhitespace, @"[\u0000-\u001F\u007F]+", "");
|
||||
|
||||
// Step 4: 移除特殊的不可见字符(如零宽度空格等)
|
||||
string cleanedString = Regex.Replace(withoutControlChars, @"[\u200B\u200C\u200D\uFEFF]+", "");
|
||||
|
||||
return cleanedString;
|
||||
}
|
||||
|
||||
}
|
||||
public class RelatedCamera : NotifyProperty
|
||||
@ -503,7 +509,7 @@ namespace DH.Commons.Base
|
||||
private AntList<SizeTreatParam> _sizeTreatParamList = new AntList<SizeTreatParam>();
|
||||
|
||||
private CustomizedPoint _showLocation = new CustomizedPoint();
|
||||
|
||||
private string _imageSaveDirectory="D://Images";
|
||||
private bool _saveOKOriginal = false;
|
||||
private bool _saveNGOriginal = false;
|
||||
private bool _saveOKDetect = false;
|
||||
@ -621,7 +627,19 @@ namespace DH.Commons.Base
|
||||
OnPropertyChanged(nameof(IsAddStation));
|
||||
}
|
||||
}
|
||||
|
||||
[Category("图片保存")]
|
||||
[DisplayName("图片保存文件夹")]
|
||||
[Description("图片保存文件夹")]
|
||||
public virtual string ImageSaveDirectory
|
||||
{
|
||||
get => _imageSaveDirectory;
|
||||
set
|
||||
{
|
||||
if (_imageSaveDirectory == value) return;
|
||||
_imageSaveDirectory = value;
|
||||
OnPropertyChanged(nameof(ImageSaveDirectory));
|
||||
}
|
||||
}
|
||||
[Category("1.预处理(视觉算子)")]
|
||||
[DisplayName("预处理-算法文件路径")]
|
||||
public string HalconAlgorithemPath_Pre
|
||||
|
389
DH.Commons/Base/DeviceBase.cs
Normal file
389
DH.Commons/Base/DeviceBase.cs
Normal file
@ -0,0 +1,389 @@
|
||||
|
||||
using DH.Commons.Enums;
|
||||
using OpenCvSharp.Internal;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
using Timer = System.Threading.Timer;
|
||||
|
||||
namespace DH.Commons.Base
|
||||
{
|
||||
public abstract class DeviceBase : IDisposable
|
||||
{
|
||||
#region Event
|
||||
[JsonIgnore]
|
||||
[Browsable(false)]
|
||||
public Action<DateTime, Exception> OnExceptionOccured { get; set; }
|
||||
//public event Action<DateTime, LogLevel, string> OnLog;
|
||||
public event Action<LogMsg> OnLog;
|
||||
// public event Action<IDevice, DeviceState> OnDeviceStateChanged;
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
#endregion
|
||||
|
||||
#region field
|
||||
int RetryTime = 3;
|
||||
/// <summary>
|
||||
/// 和设备暂停状态关联的信号量
|
||||
/// </summary>
|
||||
private readonly ManualResetEvent pauseHandle = new ManualResetEvent(true);
|
||||
readonly Timer stateChangedTimer;
|
||||
#endregion
|
||||
|
||||
#region Property
|
||||
#region State
|
||||
private EnumHelper.DeviceState _currentStateToBe = EnumHelper.DeviceState.DSUninit;
|
||||
/// <summary>
|
||||
/// 当前设备状态
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
internal EnumHelper.DeviceState CurrentStateToBe
|
||||
{
|
||||
get
|
||||
{
|
||||
return _currentStateToBe;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != _currentStateToBe)
|
||||
{
|
||||
var initialState = _currentStateToBe;
|
||||
_currentStateToBe = value;
|
||||
|
||||
if (_currentStateToBe != EnumHelper.DeviceState.DSExcept)
|
||||
{
|
||||
// OnStateChanged(initialState);
|
||||
}
|
||||
else
|
||||
{
|
||||
stateChangedTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//private EnumHelper.DeviceState initialState = EnumHelper.DeviceState.DSUninit;
|
||||
private EnumHelper.DeviceState _currentState = EnumHelper.DeviceState.DSUninit;
|
||||
public EnumHelper.DeviceState CurrentState
|
||||
{
|
||||
get
|
||||
{
|
||||
return _currentState;
|
||||
}
|
||||
set
|
||||
{
|
||||
_currentState = value;
|
||||
|
||||
if (value != EnumHelper.DeviceState.TBD)
|
||||
{
|
||||
// OnDeviceStateChanged?.Invoke(this, _currentState);
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentState"));
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// initialState = _currentState;
|
||||
//}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 设备标识符 从数据库获取
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备名称 从数据库获取
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
//private IInitialConfig initialConfig = null;
|
||||
///// <summary>
|
||||
///// 设备初始化配置 从数据库获取
|
||||
///// </summary>
|
||||
//public virtual IInitialConfig InitialConfig
|
||||
//{
|
||||
// get => initialConfig;
|
||||
// set
|
||||
// {
|
||||
// initialConfig = value;
|
||||
// Id = initialConfig.Id;
|
||||
// Name = initialConfig.Name;
|
||||
|
||||
// LoggerHelper.LogPath = initialConfig.LogPath;
|
||||
// LoggerHelper.LogPrefix = initialConfig.Name;
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region 构造函数
|
||||
public DeviceBase()
|
||||
{
|
||||
RegisterFileWriterException();
|
||||
// stateChangedTimer = new Timer(new TimerCallback(CheckDeviceOpTimeOut), null, Timeout.Infinite, Timeout.Infinite);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 设备抽象方法
|
||||
protected virtual void Init()
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{Name}初始化完成");
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{Name}启动");
|
||||
}
|
||||
|
||||
protected virtual void Stop()
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{Name}停止");
|
||||
}
|
||||
|
||||
//public abstract void AttachToProcess(IProcess process);
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 常用操作封装方法
|
||||
/// </summary>
|
||||
/// <param name="opConfig"></param>
|
||||
/// <returns></returns>
|
||||
//public virtual ResponseMessage RunWrap(IOperationConfig opConfig)
|
||||
//{
|
||||
// ResponseMessage msg = new ResponseMessage();
|
||||
// msg.Message = "设备基类默认操作";
|
||||
// return msg;
|
||||
//}
|
||||
|
||||
#region 状态切换
|
||||
//[DeviceExceptionAspect]
|
||||
//public void StateChange(EnumHelper.DeviceState stateToBe)
|
||||
//{
|
||||
// if (CurrentState == stateToBe)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (!stateToBe.CheckPreStateValid((int)CurrentStateToBe))
|
||||
// {
|
||||
// string currentStateStr = CurrentStateToBe.GetEnumDescription();
|
||||
// string stateToBeStr = stateToBe.GetEnumDescription();
|
||||
// throw new ProcessException($"{InitialConfig.Name}设备的当前状态为{currentStateStr},无法切换至{stateToBeStr}");
|
||||
// }
|
||||
|
||||
// CurrentState = EnumHelper.DeviceState.TBD;
|
||||
// CurrentStateToBe = stateToBe;
|
||||
//}
|
||||
|
||||
//[DeviceExceptionAspect]
|
||||
//private void OnStateChanged(EnumHelper.DeviceState initialState)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// if (CurrentStateToBe != EnumHelper.DeviceState.DSExcept)
|
||||
// {
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (CurrentState == EnumHelper.DeviceState.DSExcept)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new ProcessException($"{InitialConfig.Name}设备操作超时");
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (RetryTime >= 0)
|
||||
// {
|
||||
// if (initialState == CurrentStateToBe)
|
||||
// {
|
||||
// CurrentState = CurrentStateToBe;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// #region 状态切换操作
|
||||
// switch (CurrentStateToBe)
|
||||
// {
|
||||
// case EnumHelper.DeviceState.DSInit:
|
||||
// if (initialState == EnumHelper.DeviceState.DSOpen)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Init();
|
||||
// }
|
||||
// break;
|
||||
// case EnumHelper.DeviceState.DSOpen:
|
||||
// if (initialState == EnumHelper.DeviceState.DSInit)
|
||||
// {
|
||||
// Start();
|
||||
// }
|
||||
// else if (initialState == EnumHelper.DeviceState.DSPause)
|
||||
// {
|
||||
// Resume();
|
||||
// pauseHandle.Set();
|
||||
// }
|
||||
// break;
|
||||
// case EnumHelper.DeviceState.DSPause:
|
||||
// pauseHandle.Reset();
|
||||
// Pause();
|
||||
// break;
|
||||
// case EnumHelper.DeviceState.DSClose:
|
||||
// if (initialState != DeviceState.DSUninit)
|
||||
// {
|
||||
// Stop();
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
// RetryTime = 3;
|
||||
// CurrentState = CurrentStateToBe;
|
||||
// #endregion
|
||||
// }
|
||||
|
||||
// stateChangedTimer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// RetryTime--;
|
||||
// if (RetryTime > 0)
|
||||
// {
|
||||
// OnStateChanged(initialState);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (CurrentState != EnumHelper.DeviceState.DSExcept)
|
||||
// {
|
||||
// RetryTime = 3;
|
||||
// throw new ProcessException($"设备{InitialConfig.Name}的{CurrentStateToBe.GetEnumDescription()}操作重复3次失败", ex, ExceptionLevel.Warning);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void CheckDeviceOpTimeOut(object state)
|
||||
//{
|
||||
// stateChangedTimer?.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
|
||||
// if (CurrentState != EnumHelper.DeviceState.DSExcept)
|
||||
// {
|
||||
// StateChange(EnumHelper.DeviceState.DSExcept);
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region 日志处理
|
||||
private void RegisterFileWriterException()
|
||||
{
|
||||
LoggerHelper.OnLogExceptionRaised -= LoggerHelper_OnLogExceptionRaised;
|
||||
// CSVHelper.OnCSVExceptionRaised -= LoggerHelper_OnLogExceptionRaised;
|
||||
|
||||
LoggerHelper.OnLogExceptionRaised += LoggerHelper_OnLogExceptionRaised;
|
||||
// CSVHelper.OnCSVExceptionRaised += LoggerHelper_OnLogExceptionRaised;
|
||||
}
|
||||
// public CSVHelper CSVHelper { get; set; } = new CSVHelper();
|
||||
|
||||
public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
|
||||
|
||||
public virtual void LogAsync(LogMsg msg)
|
||||
{
|
||||
msg.MsgSource = Name;
|
||||
msg.ThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
//OnLog?.BeginInvoke(msg, null, null);
|
||||
OnLog?.Invoke(msg);
|
||||
|
||||
//if (InitialConfig.IsEnableLog)
|
||||
//{
|
||||
// LoggerHelper.LogAsync(msg);
|
||||
//}
|
||||
}
|
||||
|
||||
public virtual void LogAsync(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogAsync(new LogMsg(dt, logLevel, msg));
|
||||
}
|
||||
private void LoggerHelper_OnLogExceptionRaised(DateTime dt, string msg)
|
||||
{
|
||||
OnLog?.Invoke(new LogMsg(dt, LogLevel.Error, msg));
|
||||
}
|
||||
/// <summary>
|
||||
/// CSV异步数据输出
|
||||
/// </summary>
|
||||
/// <param name="csvFile">CSV输出文件的文件全路径</param>
|
||||
/// <param name="csvData">CSV输出数据</param>
|
||||
/// <param name="csvHead">CSV文件表头</param>
|
||||
public virtual void CSVRecordAsync(string csvFile, string csvData, string csvHead = "")
|
||||
{
|
||||
// CSVHelper.CSVOutputAsync(csvFile, csvData, csvHead);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 报警记录
|
||||
//object _alarmLock = new object();
|
||||
//protected virtual async void SaveAlarmCSVAsync(DateTime now, string deviceName, IWarningSet ws)
|
||||
//{
|
||||
// await Task.Run(() =>
|
||||
// {
|
||||
// LogAsync(now, LogLevel.Warning, $"{ws.WarningCode}-{ws.WarningDescription} {(ws.CurrentStatus ? "发生" : "取消")}");
|
||||
|
||||
// if (string.IsNullOrWhiteSpace(this.InitialConfig.LogPath) || !InitialConfig.IsEnableCSV)
|
||||
// return;
|
||||
|
||||
// string path = Path.Combine(InitialConfig.LogPath, $"Alarm_{Name}_{now.ToString("yyyyMMdd")}.csv");
|
||||
// string head = "Time,Source,AlarmCode,AlarmDescription,AlarmStatus";
|
||||
// string data = $"{now.ToString("HH:mm:ss.fff")},{deviceName},{ws.WarningCode},{ws.WarningDescription},{(ws.CurrentStatus ? "报警发生" : "报警取消")}";
|
||||
// CSVRecordAsync(path, data, head);
|
||||
// });
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region IDisposable Support
|
||||
private bool disposedValue = false; // 要检测冗余调用
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
//释放托管状态(托管对象)。
|
||||
stateChangedTimer?.Dispose();
|
||||
pauseHandle?.Dispose();
|
||||
}
|
||||
|
||||
// TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
|
||||
// TODO: 将大型字段设置为 null。
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 仅当以上 Dispose(bool disposing) 拥有用于释放未托管资源的代码时才替代终结器。
|
||||
// ~DeviceBase()
|
||||
// {
|
||||
// // 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
|
||||
// Dispose(false);
|
||||
// }
|
||||
|
||||
// 添加此代码以正确实现可处置模式。
|
||||
public void Dispose()
|
||||
{
|
||||
// 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
|
||||
Dispose(true);
|
||||
// TODO: 如果在以上内容中替代了终结器,则取消注释以下行。
|
||||
// GC.SuppressFinalize(this);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace DH.Commons.Base
|
||||
{
|
||||
public class PLCBase : NotifyProperty
|
||||
{
|
||||
|
||||
// 私有字段
|
||||
private bool _enable;
|
||||
private bool _connected;
|
||||
|
@ -3,6 +3,7 @@ using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using DH.Commons.Enums;
|
||||
using DH.Commons.Helper;
|
||||
using HalconDotNet;
|
||||
using OpenCvSharp;
|
||||
|
||||
@ -18,7 +19,7 @@ namespace DH.Commons.Base
|
||||
/// Object Detection 目标检测:寻找图像中的物体并进行定位;
|
||||
/// Instance Segmentation 实例分割:定位图中每个物体,并进行像素级标注,区分不同个体;
|
||||
/// </summary>
|
||||
public abstract class VisionEngineBase
|
||||
public abstract class VisionEngineBase : DeviceBase
|
||||
{
|
||||
public List<DetectionConfig> DetectionConfigs = new List<DetectionConfig>();
|
||||
#region event
|
||||
@ -50,134 +51,25 @@ namespace DH.Commons.Base
|
||||
{
|
||||
OnDetectionWarningStop?.Invoke(detectionDes);
|
||||
}
|
||||
|
||||
public ImageSaveHelper ImageSaveHelper { get; set; } = new ImageSaveHelper();
|
||||
public virtual void SaveImageAsync(string fullname, Bitmap saveMap, ImageFormat imageFormat)
|
||||
{
|
||||
if (saveMap != null)
|
||||
{
|
||||
//ImageSaveSet imageSaveSet = new ImageSaveSet()
|
||||
//{
|
||||
// FullName = fullname,
|
||||
// SaveImage = saveMap.CopyBitmap(),
|
||||
// ImageFormat = imageFormat.DeepSerializeClone()
|
||||
//};
|
||||
ImageSaveSet imageSaveSet = new ImageSaveSet()
|
||||
{
|
||||
FullName = fullname,
|
||||
SaveImage = saveMap.CopyBitmap(),
|
||||
ImageFormat = imageFormat.DeepSerializeClone()
|
||||
|
||||
//ImageSaveHelper.ImageSaveAsync(imageSaveSet);
|
||||
};
|
||||
|
||||
ImageSaveHelper.ImageSaveAsync(imageSaveSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class CamModuleXY
|
||||
{
|
||||
[Category("图片行")]
|
||||
[DisplayName("行")]
|
||||
[Description("行")]
|
||||
// [TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))]
|
||||
//[TypeConverter(typeof(CollectionCountConvert))]
|
||||
public int PicRows { get; set; } = 1;
|
||||
|
||||
[Category("图片列")]
|
||||
[DisplayName("列")]
|
||||
[Description("列")]
|
||||
// [TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))]
|
||||
//[TypeConverter(typeof(CollectionCountConvert))]
|
||||
public int PicCols { get; set; } = 1;
|
||||
|
||||
public string GetDisplayText()
|
||||
{
|
||||
return "行:" + PicRows.ToString() + "列:" + PicCols.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
//public class RelatedCamera
|
||||
//{
|
||||
|
||||
// [Category("关联相机")]
|
||||
// [DisplayName("关联相机")]
|
||||
// [Description("关联相机描述")]
|
||||
// //[TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))]
|
||||
// //[TypeConverter(typeof(CollectionCountConvert))]
|
||||
// public string CameraSourceId { get; set; } = "";
|
||||
|
||||
|
||||
// //public string GetDisplayText()
|
||||
// //{
|
||||
// // using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
||||
// // {
|
||||
// // List<IDevice> deviceList = scope.Resolve<List<IDevice>>();
|
||||
// // IDevice CameraDevice = deviceList.FirstOrDefault(dev => dev.Id.Equals(CameraSourceId));
|
||||
|
||||
// // if (CameraDevice != null && CameraDevice is CameraBase)
|
||||
// // {
|
||||
// // return CameraDevice.Name;
|
||||
// // }
|
||||
|
||||
// // }
|
||||
// // return CameraSourceId;
|
||||
// //}
|
||||
//}
|
||||
public class VisionEngineInitialConfigBase //: InitialConfigBase
|
||||
{
|
||||
[Category("深度学习检测配置")]
|
||||
[DisplayName("检测配置集合")]
|
||||
[Description("检测配置集合")]
|
||||
//[TypeConverter(typeof(CollectionCountConvert))]
|
||||
//[Editor(typeof(ComplexCollectionEditor<DetectionConfig>), typeof(UITypeEditor))]
|
||||
public List<DetectionConfig> DetectionConfigs { get; set; } = new List<DetectionConfig>();
|
||||
|
||||
[Category("深度学习检测配置")]
|
||||
[DisplayName("标签分类")]
|
||||
[Description("标签分类,A_NG,B_TBD...")]
|
||||
// [TypeConverter(typeof(CollectionCountConvert))]
|
||||
// [Editor(typeof(ComplexCollectionEditor<RecongnitionLabelCategory>), typeof(UITypeEditor))]
|
||||
public List<RecongnitionLabelCategory> RecongnitionLabelCategoryList { get; set; } = new List<RecongnitionLabelCategory>();
|
||||
|
||||
[Category("深度学习检测配置")]
|
||||
[DisplayName("检测标签定义集合")]
|
||||
[Description("定义检测标签的集合,例如:Seg/Detection模式:断裂、油污、划伤...;Class模式:ok、ng、上面、下面、套环、正常...")]
|
||||
// [TypeConverter(typeof(CollectionCountConvert))]
|
||||
// [Editor(typeof(ComplexCollectionEditor<RecongnitionLabel>), typeof(UITypeEditor))]
|
||||
public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>();
|
||||
|
||||
[Category("深度学习检测配置")]
|
||||
[DisplayName("标签置信度")]
|
||||
[Description("标签置信度,过滤小于改置信度的标签,大于该设置的标签才能识别")]
|
||||
public float Score { get; set; } = 0.5f;
|
||||
|
||||
[Category("深度学习检测配置")]
|
||||
[DisplayName("CPU线程数量")]
|
||||
[Description("用于深度学习的CPU线程数量,不要设置太大,会单独占用线程,影响其他程序运行")]
|
||||
public int CPUNums { get; set; } = 1;
|
||||
|
||||
//[Category("深度学习检测配置")]
|
||||
//[DisplayName("检测项GPU指定")]
|
||||
//[Description("将检测项指定到GPU")]
|
||||
// [TypeConverter(typeof(CollectionCountConvert))]
|
||||
// [Editor(typeof(ComplexCollectionEditor<DetectionGPUConfig>), typeof(UITypeEditor))]
|
||||
// public List<DetectionGPUConfig> DetectionGPUList { get; set; } = new List<DetectionGPUConfig>();
|
||||
|
||||
// [Category("数据保存配置")]
|
||||
//[DisplayName("是否保存检测明细CSV")]
|
||||
//[Description("是否保存 检测明细CSV")]
|
||||
//public override bool IsEnableCSV { get; set; } = true;
|
||||
|
||||
//[Category("数据保存配置")]
|
||||
//[DisplayName("是否保存检测图片")]
|
||||
//[Description("是否保存 检测图片,总开关")]
|
||||
//public bool IsSaveImage { get; set; } = true;
|
||||
|
||||
//[Category("数据保存配置")]
|
||||
//[Description("检测图片 保存文件夹")]
|
||||
//[DisplayName("检测图片保存文件夹")]
|
||||
//[Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
|
||||
//public string ImageSaveDirectory { get; set; } = "D:\\PROJECTS\\X017\\Images";
|
||||
|
||||
//[Category("数据保存配置")]
|
||||
//[Description("检测明细CSV文件夹")]
|
||||
//[DisplayName("检测明细CSV文件夹")]
|
||||
//[Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
|
||||
//public string CSVDataPath { get; set; } = "D:\\PROJECTS\\X017\\Images";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,15 +13,10 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AntdUI" Version="1.8.9" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="OpenCvSharp4" Version="4.10.0.20241108" />
|
||||
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.10.0.20241108" />
|
||||
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.10.0.20241108" />
|
||||
|
64
DH.Commons/Exception/ExceptionHelper.cs
Normal file
64
DH.Commons/Exception/ExceptionHelper.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
|
||||
|
||||
namespace DH.Commons.Helper
|
||||
{
|
||||
public enum ExceptionLevel
|
||||
{
|
||||
Info = 0,
|
||||
Warning = 1,
|
||||
Fatal = 2,
|
||||
}
|
||||
|
||||
//public delegate void OnProcessExceptionRaisedDelegate(DateTime dt, ProcessException ex);
|
||||
//[Serializable]
|
||||
public class ProcessException : Exception
|
||||
{
|
||||
public ExceptionLevel Level { get; set; } = ExceptionLevel.Warning;
|
||||
|
||||
public ProcessException()
|
||||
{
|
||||
}
|
||||
|
||||
public ProcessException(Exception ex, ExceptionLevel lvl = ExceptionLevel.Warning) : base(ex.Message, ex)
|
||||
{
|
||||
Level = lvl;
|
||||
ExceptionNotice();
|
||||
}
|
||||
|
||||
public ProcessException(string error, Exception ex = null, ExceptionLevel lvl = ExceptionLevel.Warning) : base(error, ex)
|
||||
{
|
||||
Level = lvl;
|
||||
ExceptionNotice();
|
||||
}
|
||||
|
||||
public void ExceptionNotice()
|
||||
{
|
||||
//OnProcessExceptionRaised?.Invoke(DateTime.Now, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExceptionHelper
|
||||
{
|
||||
public static LogLevel LogLevel = LogLevel.Information;
|
||||
public static string GetExceptionMessage(this Exception ex)
|
||||
{
|
||||
string msg = "异常信息:" + ex.Message;
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
msg += ";\t内部异常信息:" + ex.InnerException.GetExceptionMessage();
|
||||
}
|
||||
|
||||
if (LogLevel <= LogLevel.Assist)
|
||||
{
|
||||
msg += (";\r\n\t\tStackTrace:" + ex.StackTrace);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public class AuthorityException : ProcessException
|
||||
{
|
||||
}
|
||||
}
|
162
DH.Commons/Helper/AttributeHelper.cs
Normal file
162
DH.Commons/Helper/AttributeHelper.cs
Normal file
@ -0,0 +1,162 @@
|
||||
using DH.Commons.Enums;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
|
||||
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备特性,指示该信息的设备类型,适用于设备信息和配置信息
|
||||
/// </summary>
|
||||
public class DeviceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备类型
|
||||
/// </summary>
|
||||
public string TypeCode { get; set; }
|
||||
|
||||
public string TypeDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 特性修饰类别
|
||||
/// </summary>
|
||||
public DeviceAttributeType AttrType { get; set; }
|
||||
|
||||
public DeviceAttribute(string typeCode, string typeDesc, EnumHelper.DeviceAttributeType attrType)
|
||||
{
|
||||
TypeCode = typeCode;
|
||||
TypeDescription = typeDesc;
|
||||
AttrType = attrType;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预置状态特性 指定该修饰信息的前置状态允许范围
|
||||
/// </summary>
|
||||
public class PreStateAttribute : Attribute
|
||||
{
|
||||
public int PreState { get; set; }
|
||||
public PreStateAttribute(int _preState)
|
||||
{
|
||||
PreState = _preState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查当前待执行操作的前置状态要求是否合法
|
||||
/// </summary>
|
||||
/// <param name="currentState"></param>
|
||||
/// <returns></returns>
|
||||
public bool CheckPreStateValid(int currentState)
|
||||
{
|
||||
return (currentState & PreState) == currentState;
|
||||
}
|
||||
}
|
||||
|
||||
public class ColorSelectAttribute : Attribute
|
||||
{
|
||||
public string SelectedColor { get; set; }
|
||||
public ColorSelectAttribute(string selectedColor)
|
||||
{
|
||||
SelectedColor = selectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
public class FontColorSelectAttribute : Attribute
|
||||
{
|
||||
public string SelectedColor { get; set; }
|
||||
public FontColorSelectAttribute(string selectedColor)
|
||||
{
|
||||
SelectedColor = selectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
public enum InvokeType
|
||||
{
|
||||
/// <summary>
|
||||
/// 不公开调用
|
||||
/// </summary>
|
||||
[Description("不公开调用")]
|
||||
NoneInvoke = 0,
|
||||
/// <summary>
|
||||
/// 测试调用
|
||||
/// </summary>
|
||||
[Description("测试调用")]
|
||||
TestInvoke = 1,
|
||||
/// <summary>
|
||||
/// 标定调用
|
||||
/// </summary>
|
||||
[Description("标定调用")]
|
||||
CalibInvoke = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用来修饰对外开放的调用方法的特性
|
||||
/// 调用方法参数顺序:IOperationConfig,InvokeDevice,SourceDevice
|
||||
/// </summary>
|
||||
public class ProcessMethodAttribute : Attribute
|
||||
{
|
||||
public string MethodCode { get; set; }
|
||||
public string MethodDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否提供人工调用测试
|
||||
/// </summary>
|
||||
public InvokeType InvokeType { get; set; }
|
||||
|
||||
public string DeviceType { get; set; }
|
||||
|
||||
public ProcessMethodAttribute(string deviceType, string code, string description, InvokeType invokeType)
|
||||
{
|
||||
DeviceType = deviceType;
|
||||
MethodCode = code;
|
||||
MethodDesc = description;
|
||||
InvokeType = invokeType;
|
||||
}
|
||||
}
|
||||
|
||||
public class SwitchDisplayAttribute : Attribute
|
||||
{
|
||||
public string SwitchName { get; set; }
|
||||
|
||||
public bool SwithOnStatus { get; set; } = true;
|
||||
|
||||
public SwitchDisplayAttribute(string name, bool status)
|
||||
{
|
||||
SwitchName = name;
|
||||
SwithOnStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
public class ElementAttribute : Attribute
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Desc { get; set; }
|
||||
|
||||
public string IconPath { get; set; }
|
||||
|
||||
public bool IsShowInToolBar { get; set; }
|
||||
|
||||
public ElementAttribute(string desc, string iconPath, bool isShowInToolBar = true, [CallerMemberName] string name = "")
|
||||
{
|
||||
Name = name;
|
||||
Desc = desc;
|
||||
IconPath = iconPath;
|
||||
IsShowInToolBar = isShowInToolBar;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcessAttribute : Attribute
|
||||
{
|
||||
public string ProcessCode { get; set; }
|
||||
public DeviceAttributeType AttrType { get; set; }
|
||||
|
||||
public ProcessAttribute(string stationCode, DeviceAttributeType attrType)
|
||||
{
|
||||
ProcessCode = stationCode;
|
||||
AttrType = attrType;
|
||||
}
|
||||
}
|
||||
}
|
@ -120,6 +120,40 @@ namespace DH.Commons.Enums
|
||||
.FirstOrDefault() as DescriptionAttribute;
|
||||
return attribute?.Description ?? value.ToString();
|
||||
}
|
||||
|
||||
public static System.Drawing.Color GetEnumSelectedColor(this Enum enumObj)
|
||||
{
|
||||
Type t = enumObj.GetType();
|
||||
FieldInfo f = t.GetField(enumObj.ToString());
|
||||
|
||||
ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
||||
if (attr != null)
|
||||
{
|
||||
return System.Drawing.Color.FromName(attr.SelectedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return System.Drawing.Color.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
public static System.Drawing.Color GetEnumSelectedFontColor(this Enum enumObj)
|
||||
{
|
||||
Type t = enumObj.GetType();
|
||||
FieldInfo f = t.GetField(enumObj.ToString());
|
||||
|
||||
var attr = f.GetCustomAttribute<FontColorSelectAttribute>();
|
||||
if (attr != null)
|
||||
{
|
||||
return System.Drawing.Color.FromName(attr.SelectedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return System.Drawing.Color.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Flags]
|
||||
public enum DeviceAttributeType
|
||||
{
|
||||
@ -251,7 +285,38 @@ namespace DH.Commons.Enums
|
||||
[Description("测量结果")]
|
||||
MeasureResult = 31,
|
||||
}
|
||||
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
[Description("详细")]
|
||||
[ColorSelect("White")]
|
||||
[FontColorSelect("Green")]
|
||||
Detail = 2,
|
||||
[Description("信息")]
|
||||
[ColorSelect("White")]
|
||||
[FontColorSelect("Dark")]
|
||||
Information = 3,
|
||||
[Description("辅助")]
|
||||
[ColorSelect("White")]
|
||||
[FontColorSelect("Blue")]
|
||||
Assist = 4,
|
||||
[Description("动作")]
|
||||
[ColorSelect("DarkGreen")]
|
||||
[FontColorSelect("Yellow")]
|
||||
Action = 5,
|
||||
[Description("错误")]
|
||||
[ColorSelect("Orange")]
|
||||
[FontColorSelect("White")]
|
||||
Error = 6,
|
||||
[Description("警报")]
|
||||
[ColorSelect("Brown")]
|
||||
[FontColorSelect("White")]
|
||||
Warning = 7,
|
||||
[Description("异常")]
|
||||
[ColorSelect("Red")]
|
||||
[FontColorSelect("White")]
|
||||
Exception = 8,
|
||||
}
|
||||
//public enum CameraDriverType
|
||||
//{
|
||||
// Halcon,
|
||||
@ -272,6 +337,59 @@ namespace DH.Commons.Enums
|
||||
// NG = -1,
|
||||
// IGNORE = -999,
|
||||
//}
|
||||
public enum DeviceState
|
||||
{
|
||||
TBD = -1,
|
||||
|
||||
[ColorSelect("Gray")]
|
||||
[FontColorSelect("Black")]
|
||||
[Description("未初始化")]
|
||||
DSUninit = 1,
|
||||
|
||||
[ColorSelect("Gold")]
|
||||
[FontColorSelect("White")]
|
||||
[PreState(1 + 2 + 4 + 8 + 32)]
|
||||
[Description("初始化")]
|
||||
DSInit = 2,
|
||||
|
||||
[ColorSelect("Lime")]
|
||||
[FontColorSelect("Black")]
|
||||
[PreState(2 + 4 + 16)]
|
||||
[Description("运行中")]
|
||||
DSOpen = 4,
|
||||
|
||||
[ColorSelect("Gray")]
|
||||
[FontColorSelect("White")]
|
||||
[PreState(1 + 4 + 8 + 16 + 32)]
|
||||
[Description("关闭")]
|
||||
DSClose = 8,
|
||||
|
||||
[ColorSelect("Gold")]
|
||||
[FontColorSelect("White")]
|
||||
[PreState(4 + 16)]
|
||||
[Description("暂停")]
|
||||
DSPause = 16,
|
||||
|
||||
[ColorSelect("Red")]
|
||||
[FontColorSelect("White")]
|
||||
[Description("异常")]
|
||||
DSExcept = 32
|
||||
}
|
||||
public enum RunState
|
||||
{
|
||||
[ColorSelect("Gold")]
|
||||
[Description("空闲")]
|
||||
Idle = 1,
|
||||
[ColorSelect("Lime")]
|
||||
[Description("运行中")]
|
||||
Running = 2,
|
||||
[ColorSelect("Gray")]
|
||||
[Description("停止")]
|
||||
Stop = 3,
|
||||
[ColorSelect("Red")]
|
||||
[Description("宕机")]
|
||||
Down = 99,
|
||||
}
|
||||
|
||||
public enum PriorityDirection
|
||||
{
|
||||
|
107
DH.Commons/Helper/ImageSaveHelper.cs
Normal file
107
DH.Commons/Helper/ImageSaveHelper.cs
Normal file
@ -0,0 +1,107 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DH.Commons.Helper;
|
||||
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
public class ImageSaveHelper
|
||||
{
|
||||
public event Action<DateTime, string> OnImageSaveExceptionRaised;
|
||||
|
||||
//private string baseDirectory = "";
|
||||
//public string BaseDirectory
|
||||
//{
|
||||
// get => baseDirectory;
|
||||
// set
|
||||
// {
|
||||
// baseDirectory = value;
|
||||
// if (string.IsNullOrWhiteSpace(baseDirectory) || !Path.IsPathRooted(baseDirectory))
|
||||
// {
|
||||
// baseDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
public bool EnableImageSave { get; set; } = true;
|
||||
|
||||
public ImageSaveHelper() { }
|
||||
public ImageSaveHelper(bool enableImageSave = true)
|
||||
{
|
||||
EnableImageSave = enableImageSave;
|
||||
}
|
||||
|
||||
|
||||
object lockObj = new object();
|
||||
////耗时操作从 _taskFactory分配线程
|
||||
//public TaskFactory _taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
|
||||
readonly ConcurrentQueue<ImageSaveSet> _imageQueue = new ConcurrentQueue<ImageSaveSet>();
|
||||
Task _saveTask = null;
|
||||
readonly object _saveLock = new object();
|
||||
|
||||
public async void ImageSaveAsync(ImageSaveSet set)
|
||||
{
|
||||
if (!EnableImageSave)
|
||||
return;
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_imageQueue.Enqueue(set);
|
||||
|
||||
lock (_saveLock)
|
||||
{
|
||||
if (_saveTask == null)
|
||||
{
|
||||
_saveTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
while (_imageQueue.Count > 0)
|
||||
{
|
||||
if (_imageQueue.TryDequeue(out ImageSaveSet saveSet))
|
||||
{
|
||||
if (!Directory.Exists(Path.GetDirectoryName(saveSet.FullName)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(saveSet.FullName));
|
||||
}
|
||||
if (saveSet.SaveImage != null)
|
||||
{
|
||||
saveSet.SaveImage.Save(saveSet.FullName, saveSet.ImageFormat);
|
||||
saveSet.SaveImage.Dispose();
|
||||
}
|
||||
saveSet = null;
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnImageSaveExceptionRaised?.Invoke(DateTime.Now, $"图片保存异常:{ex.GetExceptionMessage()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ImageSaveSet
|
||||
{
|
||||
public string FullName { get; set; }//带后缀 全路径
|
||||
|
||||
public Bitmap SaveImage { get; set; }
|
||||
|
||||
public ImageFormat ImageFormat { get; set; } = ImageFormat.Jpeg;
|
||||
}
|
||||
}
|
138
DH.Commons/Helper/LoggerHelper.cs
Normal file
138
DH.Commons/Helper/LoggerHelper.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using DH.Commons.Helper;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
public interface ILogOutput
|
||||
{
|
||||
event Action<LogMsg> OnLogMsgOutput;
|
||||
void LogDisplay(LogMsg msg);
|
||||
}
|
||||
public interface ILogger
|
||||
{
|
||||
event Action<LogMsg> OnLog;
|
||||
LoggerHelper LoggerHelper { get; set; }
|
||||
//void LogAsync(DateTime dt, LogLevel loglevel, string msg);
|
||||
void LogAsync(LogMsg msg);
|
||||
}
|
||||
public class LoggerHelper
|
||||
{
|
||||
public event Action<DateTime, string> OnLogExceptionRaised;
|
||||
|
||||
public string LogPath { get; set; }
|
||||
public string LogPrefix { get; set; }
|
||||
|
||||
LogLevel LogLevel = LogLevel.Information;
|
||||
|
||||
public LoggerHelper() { }
|
||||
public LoggerHelper(string logPath, string logPrefix, LogLevel logLevel = LogLevel.Information)
|
||||
{
|
||||
LogPath = logPath;
|
||||
LogPrefix = logPrefix;
|
||||
|
||||
LogLevel = logLevel;
|
||||
}
|
||||
|
||||
public void SetLogLevel(LogLevel logLevel)
|
||||
{
|
||||
if (LogLevel != logLevel)
|
||||
LogLevel = logLevel;
|
||||
}
|
||||
////耗时操作从 _taskFactory分配线程
|
||||
//public TaskFactory _taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
|
||||
readonly ConcurrentQueue<LogMsg> _logQueue = new ConcurrentQueue<LogMsg>();
|
||||
Task _logTask = null;
|
||||
readonly object _logLock = new object();
|
||||
|
||||
public async void LogAsync(LogMsg msg)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_logQueue.Enqueue(msg);
|
||||
|
||||
lock (_logLock)
|
||||
{
|
||||
if (_logTask == null)
|
||||
{
|
||||
_logTask = Task.Run(async () =>
|
||||
{
|
||||
string filePath = Path.Combine(LogPath, $"{(string.IsNullOrWhiteSpace(LogPrefix) ? "Log_" : ("Log_" + LogPrefix + "_"))}{DateTime.Now.ToString("yyyyMMdd")}.txt");
|
||||
try
|
||||
{
|
||||
if (!StaticHelper.CheckFilesCanUse(filePath))
|
||||
{
|
||||
OnLogExceptionRaised?.Invoke(DateTime.Now, $"日志文件{filePath}被占用,无法写入");
|
||||
return;
|
||||
}
|
||||
using (StreamWriter writer = new StreamWriter(filePath, true, System.Text.Encoding.UTF8))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Directory.Exists(LogPath))
|
||||
{
|
||||
Directory.CreateDirectory(LogPath);
|
||||
}
|
||||
|
||||
while (_logQueue.Count > 0)
|
||||
{
|
||||
if (_logQueue.TryDequeue(out LogMsg log))
|
||||
{
|
||||
if (log.LogLevel >= LogLevel)
|
||||
{
|
||||
writer.WriteLine($"{log.LogTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}[{log.ThreadId}]\t{log.LogLevel.GetEnumDescription()}\t{log.Msg}");
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.Flush();
|
||||
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//OnLogExceptionRaised?.Invoke(DateTime.Now, $"日志文件{filePath}写入异常:/*{ex.GetExceptionMessage()*/}");
|
||||
OnLogExceptionRaised?.Invoke(DateTime.Now, $"日志文件{filePath}写入异常");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void LogAsync(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogAsync(new LogMsg(dt, logLevel, msg));
|
||||
}
|
||||
}
|
||||
|
||||
public class LogMsg
|
||||
{
|
||||
public DateTime LogTime { get; set; }
|
||||
public LogLevel LogLevel { get; set; }
|
||||
//public string Prefix { get; set; }
|
||||
public string Msg { get; set; }
|
||||
|
||||
public string MsgSource { get; set; }
|
||||
|
||||
public int ThreadId { get; set; }
|
||||
|
||||
public LogMsg() { }
|
||||
public LogMsg(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogTime = dt;
|
||||
LogLevel = logLevel;
|
||||
Msg = msg;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{LogTime.ToString("HH:mm:ss.fff")}\t{MsgSource}\t{Msg}";
|
||||
}
|
||||
}
|
||||
}
|
680
DH.Commons/Helper/StaticHelper.cs
Normal file
680
DH.Commons/Helper/StaticHelper.cs
Normal file
@ -0,0 +1,680 @@
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Dynamic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace DH.Commons.Helper
|
||||
{
|
||||
public static class StaticHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 数值转换为byte数组 高位在前,低位在后
|
||||
/// </summary>
|
||||
/// <param name="number"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] IntToBytes(this int number, int size = 2)
|
||||
{
|
||||
byte[] result = new byte[size];
|
||||
|
||||
int temp = size;
|
||||
while (temp > 0)
|
||||
{
|
||||
result[size - temp] = (byte)(number >> ((temp - 1) * 8) & 0xff);
|
||||
|
||||
temp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public static T DeepSerializeClone<T>(this T t)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(t));
|
||||
}
|
||||
/// <summary>
|
||||
/// 字节数组转换为整数
|
||||
/// </summary>
|
||||
/// <param name="data">字节数组</param>
|
||||
/// <param name="HtL">true:数组序号低的在高位 false:数组序号低的在低位</param>
|
||||
/// <returns></returns>
|
||||
public static int BytesToInt(this byte[] data, bool HtL = true)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
int index = i;
|
||||
|
||||
if (HtL)
|
||||
{
|
||||
index = data.Length - 1 - i;
|
||||
}
|
||||
|
||||
res += data[index] << (8 * i);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个类指定的属性值
|
||||
/// </summary>
|
||||
/// <param name="info">object对象</param>
|
||||
/// <param name="field">属性名称</param>
|
||||
/// <returns></returns>
|
||||
public static object GetPropertyValue(object info, string field)
|
||||
{
|
||||
if (info == null) return null;
|
||||
Type t = info.GetType();
|
||||
IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
|
||||
return property.First().GetValue(info, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将32位整形拆分为无符号16位整形
|
||||
/// </summary>
|
||||
/// <param name="num">需要拆分的32位整形</param>
|
||||
/// <param name="bitNum">拆分为16位整形的位数 1或者2</param>
|
||||
/// <param name="HtL">true:高位在前,低位在后;false:高位在后,低位在前</param>
|
||||
/// <returns></returns>
|
||||
public static List<ushort> ParseIntToUnsignShortList(this int num, int bitNum = 2, bool HtL = false)
|
||||
{
|
||||
if (bitNum == 2)
|
||||
{
|
||||
ushort high = (ushort)(num >> 16);
|
||||
ushort low = (ushort)num;
|
||||
|
||||
if (HtL)
|
||||
{
|
||||
return new List<ushort>() { high, low };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<ushort>() { low, high };
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num < 0)
|
||||
{
|
||||
num = ushort.MaxValue + 1 + num;
|
||||
}
|
||||
|
||||
return new List<ushort>() { (ushort)num };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将32位整形数组拆分为无符号16位整形数组
|
||||
/// </summary>
|
||||
/// <param name="list">需要拆分的32位整形</param>
|
||||
/// <param name="bitNum">拆分为16位整形的位数 1或者2</param>
|
||||
/// <param name="HtL">true:高位在前,低位在后;false:高位在后,低位在前</param>
|
||||
/// <returns></returns>
|
||||
public static List<ushort> ParseIntToUnsignShortList(this List<int> list, int bitNum = 2, bool HtL = false)
|
||||
{
|
||||
return list.SelectMany(u => u.ParseIntToUnsignShortList(bitNum, HtL)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将ushort的集合转换为16位带符号整形
|
||||
/// </summary>
|
||||
/// <param name="numList"></param>
|
||||
/// <param name="bitNum">合并的位数 1或者2</param>
|
||||
/// <param name="HtL">true:高位在前,低位在后;false:高位在后,低位在前</param>
|
||||
/// <returns></returns>
|
||||
public static List<int> ParseUnsignShortListToInt(this List<int> numList, int bitNum = 2, bool HtL = false)
|
||||
{
|
||||
if (bitNum == 1)
|
||||
{
|
||||
return numList.ConvertAll(n =>
|
||||
{
|
||||
int num = n;
|
||||
if (num > short.MaxValue)
|
||||
{
|
||||
num = num - ushort.MaxValue - 1;
|
||||
}
|
||||
|
||||
return num;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
List<int> list = new List<int>();
|
||||
for (int i = 0; i < numList.Count; i += 2)
|
||||
{
|
||||
int high = HtL ? numList[i] : numList[i + 1];
|
||||
int low = HtL ? numList[i + 1] : numList[i];
|
||||
list.Add((high << 16) | low);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
//public static T DeepSerializeClone<T>(this T t)
|
||||
//{
|
||||
// return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(t));
|
||||
//}
|
||||
|
||||
public static void DataFrom<T1, T2>(this T1 destT, T2 sourceT, List<string> exceptionProps = null) where T1 : class where T2 : class
|
||||
{
|
||||
if (sourceT == null)
|
||||
{
|
||||
destT = null;
|
||||
return;
|
||||
}
|
||||
|
||||
PropertyInfo[] propDest = destT.GetType().GetProperties();//.Where(p => !(p.GetMethod.IsVirtual && !p.GetMethod.IsFinal)).ToArray();
|
||||
PropertyInfo[] propSource = sourceT.GetType().GetProperties();
|
||||
|
||||
Array.ForEach(propDest, prop =>
|
||||
{
|
||||
if (exceptionProps == null || !exceptionProps.Contains(prop.Name))
|
||||
{
|
||||
if (prop.CanWrite)
|
||||
{
|
||||
PropertyInfo propS = propSource.FirstOrDefault(p => p.Name == prop.Name);
|
||||
if (propS != null && propS.CanRead)
|
||||
{
|
||||
prop.SetValue(destT, propS.GetValue(sourceT));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//RtlMoveMemory
|
||||
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
|
||||
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
|
||||
[HandleProcessCorruptedStateExceptions]
|
||||
//public static Bitmap CopyBitmap(this Bitmap source)
|
||||
//{
|
||||
// Bitmap clone = new Bitmap(source.Width, source.Height, source.PixelFormat);
|
||||
// try
|
||||
// {
|
||||
// int PixelSize = Bitmap.GetPixelFormatSize(source.PixelFormat) / 8;
|
||||
// if (PixelSize == 1)
|
||||
// {
|
||||
// ColorPalette cp = clone.Palette;
|
||||
// for (int i = 0; i < 256; i++)
|
||||
// {
|
||||
// cp.Entries[i] = Color.FromArgb(255, i, i, i);
|
||||
// }
|
||||
// clone.Palette = cp;
|
||||
// }
|
||||
|
||||
// Rectangle rect = new Rectangle(0, 0, source.Width, source.Height);
|
||||
// BitmapData sourceData = source.LockBits(rect, ImageLockMode.ReadWrite, source.PixelFormat);
|
||||
// BitmapData cloneData = clone.LockBits(rect, ImageLockMode.ReadWrite, source.PixelFormat);
|
||||
// if (source.Width % 4 == 0)
|
||||
// {
|
||||
// unsafe
|
||||
// {
|
||||
// CopyMemory(cloneData.Scan0, sourceData.Scan0, (uint)(sourceData.Stride * sourceData.Height));
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Parallel.For(0, source.Height, h =>
|
||||
// {
|
||||
// unsafe
|
||||
// {
|
||||
// CopyMemory(cloneData.Scan0 + h * sourceData.Stride, sourceData.Scan0 + h * sourceData.Stride, (uint)sourceData.Width);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// clone.UnlockBits(cloneData);
|
||||
// source.UnlockBits(sourceData);
|
||||
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// return clone;
|
||||
// }
|
||||
|
||||
// return clone;
|
||||
//}
|
||||
public static Bitmap CopyBitmap(this Bitmap source)
|
||||
{
|
||||
Bitmap clone = new Bitmap(source.Width, source.Height, source.PixelFormat);
|
||||
|
||||
try
|
||||
{
|
||||
int pixelSize = Bitmap.GetPixelFormatSize(source.PixelFormat) / 8;
|
||||
if (pixelSize == 1)
|
||||
{
|
||||
ColorPalette cp = clone.Palette;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
cp.Entries[i] = Color.FromArgb(255, i, i, i);
|
||||
}
|
||||
clone.Palette = cp;
|
||||
}
|
||||
|
||||
Rectangle rect = new Rectangle(0, 0, source.Width, source.Height);
|
||||
BitmapData sourceData = source.LockBits(rect, ImageLockMode.ReadOnly, source.PixelFormat);
|
||||
BitmapData cloneData = clone.LockBits(rect, ImageLockMode.WriteOnly, source.PixelFormat);
|
||||
|
||||
int stride = sourceData.Stride;
|
||||
int height = sourceData.Height;
|
||||
|
||||
if (stride % 4 == 0)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
CopyMemory(cloneData.Scan0, sourceData.Scan0, (uint)(stride * height));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parallel.For(0, height, h =>
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
CopyMemory(cloneData.Scan0 + h * stride, sourceData.Scan0 + h * stride, (uint)stride);
|
||||
}
|
||||
});
|
||||
}
|
||||
source.UnlockBits(sourceData); clone.UnlockBits(cloneData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ // Handle or log exception if needed
|
||||
} return clone; }
|
||||
|
||||
|
||||
public static Bitmap BitmapDeepClone(Bitmap source)
|
||||
{
|
||||
Bitmap clone = new Bitmap(source.Width, source.Height, source.PixelFormat);
|
||||
|
||||
try
|
||||
{
|
||||
int PixelSize = Bitmap.GetPixelFormatSize(source.PixelFormat) / 8;
|
||||
if (PixelSize == 1)
|
||||
{
|
||||
ColorPalette cp = clone.Palette;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
cp.Entries[i] = Color.FromArgb(255, i, i, i);
|
||||
}
|
||||
clone.Palette = cp;
|
||||
}
|
||||
Rectangle rect = new Rectangle(0, 0, source.Width, source.Height);
|
||||
BitmapData source_bitmap = source.LockBits(rect, ImageLockMode.ReadWrite, source.PixelFormat);
|
||||
BitmapData destination_bitmap = clone.LockBits(rect, ImageLockMode.ReadWrite, clone.PixelFormat);
|
||||
|
||||
int depth_width = source_bitmap.Width * PixelSize;
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* source_ptr = (byte*)source_bitmap.Scan0;
|
||||
byte* destination_ptr = (byte*)destination_bitmap.Scan0;
|
||||
|
||||
int offset = source_bitmap.Stride - depth_width;
|
||||
|
||||
for (int i = 0; i < source_bitmap.Height; i++)
|
||||
{
|
||||
for (int j = 0; j < depth_width; j++, source_ptr++, destination_ptr++)
|
||||
{
|
||||
*destination_ptr = *source_ptr;
|
||||
}
|
||||
|
||||
source_ptr += offset;
|
||||
destination_ptr += offset;
|
||||
}
|
||||
}
|
||||
|
||||
source.UnlockBits(source_bitmap);
|
||||
clone.UnlockBits(destination_bitmap);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Bitmap HConnectBitmap(this Bitmap map1, Bitmap map2)
|
||||
{
|
||||
Bitmap connectImage = null;
|
||||
if (map1 == null || map2 == null)
|
||||
return null;
|
||||
//横向拼接
|
||||
int width = map1.Width + map2.Width;
|
||||
//高度不变
|
||||
int height = Math.Max(map1.Height, map2.Height);
|
||||
connectImage = new Bitmap(width, height);
|
||||
using (Graphics graph = Graphics.FromImage(connectImage))
|
||||
{
|
||||
graph.DrawImage(connectImage, width, height);
|
||||
graph.Clear(System.Drawing.Color.White);
|
||||
graph.DrawImage(map1, 0, 0);
|
||||
graph.DrawImage(map2, map1.Width, 0);
|
||||
}
|
||||
return connectImage;
|
||||
}
|
||||
|
||||
public static IntPtr FloatToIntptr(float[] bytes)
|
||||
{
|
||||
GCHandle hObject = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
return hObject.AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
// 将Btimap类转换为byte[]类函数
|
||||
public static byte[] GetBGRValues(Bitmap bmp, out int stride)
|
||||
{
|
||||
var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||
var bmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, bmp.PixelFormat);
|
||||
stride = bmpData.Stride;
|
||||
var rowBytes = bmpData.Width * Image.GetPixelFormatSize(bmp.PixelFormat) / 8;
|
||||
var imgBytes = bmp.Height * rowBytes;
|
||||
byte[] rgbValues = new byte[imgBytes];
|
||||
IntPtr ptr = bmpData.Scan0;
|
||||
for (var i = 0; i < bmp.Height; i++)
|
||||
{
|
||||
Marshal.Copy(ptr, rgbValues, i * rowBytes, rowBytes);
|
||||
ptr += bmpData.Stride;
|
||||
}
|
||||
bmp.UnlockBits(bmpData);
|
||||
return rgbValues;
|
||||
}
|
||||
/// <summary>
|
||||
/// 缺陷灰度图转彩色图像函数
|
||||
/// </summary>
|
||||
/// <param name="src">灰度图</param>
|
||||
/// <returns>返回构造的伪彩色图像</returns>
|
||||
public static Bitmap GrayMapToColorMap(this Bitmap src, Dictionary<int, Color> indexColorDict = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Stopwatch sw = new Stopwatch();
|
||||
//sw.Start();
|
||||
|
||||
Bitmap dest = new Bitmap(src.Width, src.Height, PixelFormat.Format32bppArgb);
|
||||
|
||||
int destHeight = dest.Height;
|
||||
int destWidth = dest.Width;
|
||||
|
||||
Rectangle rect = new Rectangle(0, 0, destWidth, destHeight);
|
||||
BitmapData bmpDataDest = dest.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
BitmapData bmpDataSrc = src.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
|
||||
int strideDest = bmpDataDest.Stride;
|
||||
|
||||
int strideSrc = bmpDataSrc.Stride;
|
||||
unsafe
|
||||
{
|
||||
byte* pDest = (byte*)bmpDataDest.Scan0.ToPointer();
|
||||
byte* pSrc = (byte*)bmpDataSrc.Scan0.ToPointer();
|
||||
|
||||
Parallel.For(0, destHeight, y =>
|
||||
{
|
||||
Parallel.For(0, destWidth, x =>
|
||||
{
|
||||
int pixel = pSrc[y * strideSrc + x];
|
||||
int startIndex = y * strideDest + x * 4;
|
||||
if (pixel >= 0 && pixel <= 63)
|
||||
{
|
||||
Color color = Color.Red;
|
||||
if (indexColorDict != null && indexColorDict.ContainsKey(pixel))
|
||||
{
|
||||
color = indexColorDict[pixel];
|
||||
}
|
||||
|
||||
byte R = color.R;
|
||||
byte G = color.G;
|
||||
byte B = color.B;
|
||||
|
||||
pDest[startIndex] = B;
|
||||
pDest[startIndex + 1] = G;
|
||||
pDest[startIndex + 2] = R;
|
||||
pDest[startIndex + 3] = 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
pDest[startIndex] = 255;
|
||||
pDest[startIndex + 1] = 255;
|
||||
pDest[startIndex + 2] = 255;
|
||||
pDest[startIndex + 3] = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
dest.UnlockBits(bmpDataDest);
|
||||
src.UnlockBits(bmpDataSrc);
|
||||
|
||||
//sw.Stop();
|
||||
//Console.WriteLine($"转换耗时:{sw.ElapsedMilliseconds}");
|
||||
|
||||
return dest;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Sort<T>(this ObservableCollection<T> collection) where T : IComparable<T>
|
||||
{
|
||||
List<T> sortedList = collection.OrderByDescending(x => x).ToList();//这里用降序
|
||||
for (int i = 0; i < sortedList.Count(); i++)
|
||||
{
|
||||
collection.Move(collection.IndexOf(sortedList[i]), i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得字符串中开始和结束字符串中间的值
|
||||
/// </summary>
|
||||
/// <param name="sourse"></param>
|
||||
/// <param name="startstr"></param>
|
||||
/// <param name="endstr"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMidString(string sourse, string startstr, string endstr)
|
||||
{
|
||||
string result = string.Empty;
|
||||
int startindex, endindex;
|
||||
try
|
||||
{
|
||||
startindex = sourse.IndexOf(startstr);
|
||||
if (startindex == -1)
|
||||
return result;
|
||||
string tmpstr = sourse.Substring(startindex + startstr.Length);
|
||||
endindex = tmpstr.IndexOf(endstr);
|
||||
if (endindex == -1)
|
||||
return result;
|
||||
result = tmpstr.Remove(endindex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得字符串中开始和结束字符串中间的值
|
||||
/// </summary>
|
||||
/// <param name="t">字符串</param>
|
||||
/// <param name="k">开始</param>
|
||||
/// <param name="j">结束</param>
|
||||
/// <returns></returns>
|
||||
private static string GetMidString2(string sourse, string startstr, string endstr) //截取指定文本,和易语言的取文本中间差不多
|
||||
{
|
||||
try //异常捕捉
|
||||
{
|
||||
var kn = sourse.IndexOf(startstr, StringComparison.Ordinal) + startstr.Length;
|
||||
var jn = sourse.IndexOf(endstr, kn, StringComparison.Ordinal);
|
||||
return sourse.Substring(kn, jn - kn);
|
||||
}
|
||||
catch //如果发现未知的错误,比如上面的代码出错了,就执行下面这句代码
|
||||
{
|
||||
return ""; //返回空
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 布尔类型转换为整型
|
||||
public static int ToInt(this object obj)
|
||||
{
|
||||
if (Convert.ToBoolean(obj) == true)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 整型转换为布尔类型
|
||||
public static bool ToBool(this object obj)
|
||||
{
|
||||
if (Convert.ToInt32(obj) == 1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static object GetProperty(this object o, string member)
|
||||
{
|
||||
if (o == null) throw new ArgumentNullException("o");
|
||||
if (member == null) throw new ArgumentNullException("member");
|
||||
Type scope = o.GetType();
|
||||
IDynamicMetaObjectProvider provider = o as IDynamicMetaObjectProvider;
|
||||
if (provider != null)
|
||||
{
|
||||
ParameterExpression param = Expression.Parameter(typeof(object));
|
||||
DynamicMetaObject mobj = provider.GetMetaObject(param);
|
||||
GetMemberBinder binder = (GetMemberBinder)Microsoft.CSharp.RuntimeBinder.Binder.GetMember(0, member, scope, new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(0, null) });
|
||||
DynamicMetaObject ret = mobj.BindGetMember(binder);
|
||||
BlockExpression final = Expression.Block(
|
||||
Expression.Label(CallSiteBinder.UpdateLabel),
|
||||
ret.Expression
|
||||
);
|
||||
LambdaExpression lambda = Expression.Lambda(final, param);
|
||||
Delegate del = lambda.Compile();
|
||||
return del.DynamicInvoke(o);
|
||||
}
|
||||
else
|
||||
{
|
||||
return o.GetType().GetProperty(member, BindingFlags.Public | BindingFlags.Instance).GetValue(o, null);
|
||||
}
|
||||
}
|
||||
|
||||
#region 检测文件状态及操作方式选择
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern IntPtr _lopen(string lpPathName, int iReadWrite);
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern bool CloseHandle(IntPtr hObject);
|
||||
private const int OF_READWRITE = 2;
|
||||
private const int OF_SHARE_DENY_NONE = 0x40;
|
||||
private static readonly IntPtr HFILE_ERROR = new IntPtr(-1);
|
||||
/// <summary>
|
||||
/// 检测文件是否只读或被使用
|
||||
/// </summary>
|
||||
/// <param name="FileNames">要检测的文件</param>
|
||||
/// <returns>true可用,false在用或只读</returns>
|
||||
public static bool CheckFilesCanUse(string fileName)
|
||||
{
|
||||
if (!File.Exists(fileName))
|
||||
return true;//文件不存在
|
||||
if ((File.GetAttributes(fileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||
return false; //文件只读
|
||||
IntPtr vHandle = _lopen(fileName, OF_READWRITE | OF_SHARE_DENY_NONE);
|
||||
if (vHandle == HFILE_ERROR)
|
||||
{
|
||||
CloseHandle(vHandle);
|
||||
return false; //文件被占用
|
||||
}
|
||||
|
||||
CloseHandle(vHandle); //文件没被占用
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定文件夹下所有的文件名称
|
||||
/// </summary>
|
||||
/// <param name="folderName">指定文件夹名称,绝对路径</param>
|
||||
/// <param name="fileFilter">文件类型过滤,根据文件后缀名,如:*,*.txt,*.xls</param>
|
||||
/// <param name="isContainSubFolder">是否包含子文件夹</param>
|
||||
/// <returns>ArrayList数组,为所有需要的文件路径名称</returns>
|
||||
public static List<FileInfo> GetAllFilesByFolder(string folderName, string fileFilter, bool isContainSubFolder = false)
|
||||
{
|
||||
List<FileInfo> resList = new List<FileInfo>();
|
||||
try
|
||||
{
|
||||
DirectoryInfo currDir = new DirectoryInfo(folderName);//当前目录
|
||||
FileInfo[] currFiles = currDir.GetFiles(fileFilter);//当前目录文件
|
||||
foreach (FileInfo file in currFiles)
|
||||
{
|
||||
if (fileFilter.ToLower().IndexOf(file.Extension.ToLower()) >= 0)
|
||||
{
|
||||
resList.Add(file);
|
||||
}
|
||||
}
|
||||
if (isContainSubFolder)
|
||||
{
|
||||
string[] subFolders = Directory.GetDirectories(folderName);
|
||||
foreach (string subFolder in subFolders)
|
||||
{
|
||||
resList.AddRange(GetAllFilesByFolder(subFolder, fileFilter));//递归
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
return resList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定文件夹下所有的文件名称,不过滤文件类型
|
||||
/// </summary>
|
||||
/// <param name="folderName">指定文件夹名称,绝对路径</param>
|
||||
/// <param name="isContainSubFolder">是否包含子文件夹</param>
|
||||
/// <returns>ArrayList数组,为所有需要的文件路径名称</returns>
|
||||
public static List<FileInfo> GetAllFilesByFolder(string folderName, bool isContainSubFolder)
|
||||
{
|
||||
return GetAllFilesByFolder(folderName, "*", isContainSubFolder);
|
||||
}
|
||||
}
|
||||
|
||||
public class Compare<T, C> : IEqualityComparer<T>
|
||||
{
|
||||
private Func<T, C> _getField;
|
||||
public Compare(Func<T, C> getfield)
|
||||
{
|
||||
_getField = getfield;
|
||||
}
|
||||
public bool Equals(T x, T y)
|
||||
{
|
||||
return EqualityComparer<C>.Default.Equals(_getField(x), _getField(y));
|
||||
}
|
||||
public int GetHashCode(T obj)
|
||||
{
|
||||
return EqualityComparer<C>.Default.GetHashCode(_getField(obj));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ObjectExtensions
|
||||
{
|
||||
public static IEnumerable<T> DistinctBy<T, C>(this IEnumerable<T> source, Func<T, C> getfield)
|
||||
{
|
||||
return source.Distinct(new Compare<T, C>(getfield));
|
||||
}
|
||||
|
||||
public static IQueryable<T> DistinctBy<T, C>(this IQueryable<T> source, Func<T, C> getfield)
|
||||
{
|
||||
return source.Distinct(new Compare<T, C>(getfield));
|
||||
}
|
||||
}
|
||||
}
|
109
DH.Commons/Interface/Spec.cs
Normal file
109
DH.Commons/Interface/Spec.cs
Normal file
@ -0,0 +1,109 @@
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing.Design;
|
||||
|
||||
namespace DH.Commons.Enums
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 标准配置
|
||||
/// </summary>
|
||||
public class Spec
|
||||
{
|
||||
[Category("通用配置")]
|
||||
[Description("标准代码")]
|
||||
public virtual string Code { get; set; }
|
||||
|
||||
[Category("通用配置")]
|
||||
[Description("启用状态,true:启用;false:禁用")]
|
||||
[DisplayName("启用状态")]
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
[Category("标准配置")]
|
||||
[Description("标准值")]
|
||||
[DisplayName("标准值")]
|
||||
public double StandardValue { get; set; }
|
||||
|
||||
[Category("标准配置")]
|
||||
[Description("正公差")]
|
||||
[DisplayName("正公差")]
|
||||
public double Tolrenance_Positive { get; set; }
|
||||
|
||||
[Category("标准配置")]
|
||||
[Description("负公差")]
|
||||
[DisplayName("负公差")]
|
||||
public double Tolrenance_Negative { get; set; }
|
||||
|
||||
protected double? actualValue = null;
|
||||
[Browsable(false)]
|
||||
|
||||
public virtual double? ActualValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return actualValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
//if (actualValue != value && value != null)
|
||||
if (value != null)
|
||||
{
|
||||
if (value.Value >= (StandardValue - Tolrenance_Negative) && value.Value <= (StandardValue + Tolrenance_Positive))
|
||||
{
|
||||
MeasureResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MeasureResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
actualValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
|
||||
public bool? MeasureResult { get; set; } = null;
|
||||
|
||||
|
||||
public Spec Copy()
|
||||
{
|
||||
Spec spec = new Spec();
|
||||
|
||||
spec.Code = this.Code;
|
||||
spec.IsEnabled = this.IsEnabled;
|
||||
spec.StandardValue = this.StandardValue;
|
||||
spec.Tolrenance_Positive = this.Tolrenance_Positive;
|
||||
spec.Tolrenance_Negative = this.Tolrenance_Negative;
|
||||
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class IndexedSpec : Spec
|
||||
{
|
||||
[Category("数据源配置")]
|
||||
[Description("数据源输出索引")]
|
||||
[DisplayName("数据源输出索引")]
|
||||
public int OutputIndex { get; set; }
|
||||
|
||||
public new IndexedSpec Copy()
|
||||
{
|
||||
IndexedSpec spec = new IndexedSpec();
|
||||
|
||||
spec.Code = this.Code;
|
||||
spec.IsEnabled = this.IsEnabled;
|
||||
spec.StandardValue = this.StandardValue;
|
||||
spec.Tolrenance_Positive = this.Tolrenance_Positive;
|
||||
spec.Tolrenance_Negative = this.Tolrenance_Negative;
|
||||
|
||||
spec.OutputIndex = this.OutputIndex;
|
||||
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
}
|
26
DH.Commons/Models/ProductSummary.cs
Normal file
26
DH.Commons/Models/ProductSummary.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.Commons.Models
|
||||
{
|
||||
public class CameraSummary
|
||||
{
|
||||
public string CameraName { get; set; } // 相机名称
|
||||
public int TiggerCount { get; set; } //触发数
|
||||
public int OKCount { get; set; } // OK 数
|
||||
public int NGCount { get; set; } // NG 数
|
||||
public int TotalCount => OKCount + NGCount; // 总检测数量
|
||||
public string YieldStr => $"{Yield:f2} %"; // 良率(字符串形式)
|
||||
public double Yield => OKCount + NGCount > 0 ? (double)OKCount / (OKCount + NGCount) * 100 : 0;
|
||||
}
|
||||
|
||||
public class ProductSummary
|
||||
{
|
||||
public int ProductAmount { get; set; }
|
||||
public string ResultDesc { get; set; }
|
||||
public string PercentStr { get; set; }
|
||||
}
|
||||
}
|
@ -1,17 +1,21 @@
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Xml.Linq;
|
||||
using DH.Commons.Base;
|
||||
using DH.Commons.Enums;
|
||||
using DH.Commons.Helper;
|
||||
using DVPCameraType;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.Extensions;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
|
||||
|
||||
|
||||
namespace DH.Devices.Camera
|
||||
{
|
||||
|
||||
public class Do3ThinkCamera : CameraBase
|
||||
public class Do3ThinkCamera : CameraBase, ILogger
|
||||
{
|
||||
|
||||
private dvpCameraInfo stDevInfo = new dvpCameraInfo();
|
||||
@ -24,9 +28,17 @@ namespace DH.Devices.Camera
|
||||
public dvpStreamFormat dvpStreamFormat = dvpStreamFormat.S_RGB24;
|
||||
public int m_CamCount = 0;
|
||||
public Double m_dfDisplayCount = 0;
|
||||
|
||||
public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
|
||||
public event Action<LogMsg> OnLog;
|
||||
public ConcurrentDictionary<string, MatSet> _imageSetList = new ConcurrentDictionary<string, MatSet>();
|
||||
|
||||
|
||||
public Do3ThinkCamera()
|
||||
{
|
||||
|
||||
LoggerHelper.LogPath = "D://";
|
||||
LoggerHelper.LogPrefix = CameraName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -130,41 +142,43 @@ namespace DH.Devices.Camera
|
||||
throw new Exception($"Start grabbing failed:{nRet:x8}");
|
||||
}
|
||||
//// 曝光
|
||||
//if (IIConfig.DefaultExposure != 0)
|
||||
//{
|
||||
// SetExposure(IIConfig.DefaultExposure);
|
||||
//}
|
||||
if (Exposure != 0)
|
||||
{
|
||||
SetExposure(Exposure);
|
||||
}
|
||||
//// 增益
|
||||
//if (IIConfig.Gain >= 0)
|
||||
//{
|
||||
// SetGain(IIConfig.Gain);
|
||||
//}
|
||||
//SetPictureRoi(IIConfig.VelocityPara.A_Pic_X, IIConfig.VelocityPara.A_Pic_Y, IIConfig.VelocityPara.Width, IIConfig.VelocityPara.Hight);
|
||||
if (Gain >= 0)
|
||||
{
|
||||
SetGain(Gain);
|
||||
}
|
||||
//全画幅
|
||||
if(!IsAllPicEnabled)
|
||||
SetPictureRoi((int)ROIX, (int)ROIY, (int)ROIW, (int)ROIH);
|
||||
|
||||
//// 设置 触发延迟
|
||||
//if (IIConfig.TriggerDelay > 0)
|
||||
//{
|
||||
// nRet = DVPCamera.dvpSetTriggerDelay(m_handle, IIConfig.TriggerDelay);
|
||||
// if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
// {
|
||||
// throw new Exception("Set TriggerDelay failed!");
|
||||
// }
|
||||
//}
|
||||
if (TriggerDelay > 0)
|
||||
{
|
||||
nRet = DVPCamera.dvpSetTriggerDelay(m_handle, TriggerDelay);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception("Set TriggerDelay failed!");
|
||||
}
|
||||
}
|
||||
|
||||
//// 信号消抖
|
||||
//if (IIConfig.LineDebouncerTime > 0)
|
||||
//{
|
||||
// nRet = DVPCamera.dvpSetTriggerJitterFilter(m_handle, IIConfig.LineDebouncerTime);
|
||||
// if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
// {
|
||||
// throw new Exception($"LineDebouncerTime set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
if (LineDebouncerTime > 0)
|
||||
{
|
||||
nRet = DVPCamera.dvpSetTriggerJitterFilter(m_handle, LineDebouncerTime);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception($"LineDebouncerTime set failed:{nRet}");
|
||||
}
|
||||
}
|
||||
|
||||
//IIConfig.PropertyChanged -= IIConfig_PropertyChanged;
|
||||
//IIConfig.PropertyChanged += IIConfig_PropertyChanged;
|
||||
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -351,9 +365,17 @@ namespace DH.Devices.Camera
|
||||
break;
|
||||
}
|
||||
Mat smat = cvImage.Clone();
|
||||
var imageSet = new MatSet
|
||||
{
|
||||
|
||||
_mat = smat,
|
||||
|
||||
};
|
||||
InitialImageSet(imageSet);
|
||||
OnHImageOutput?.Invoke(DateTime.Now, this, smat);
|
||||
|
||||
|
||||
//存图
|
||||
DisplayAndSaveOriginImage(imageSet.Id,SnapshotCount);
|
||||
|
||||
|
||||
|
||||
@ -369,7 +391,86 @@ namespace DH.Devices.Camera
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public void InitialImageSet(MatSet set)
|
||||
{
|
||||
//if (saveOption != null)
|
||||
//{
|
||||
// set.ImageSaveOption = saveOption.Copy();
|
||||
//}
|
||||
|
||||
//set.IsOriginSaved = !set.ImageSaveOption.IsSaveOriginImage;
|
||||
//set.IsFitSaved = !set.ImageSaveOption.IsSaveFitImage;
|
||||
//set.IsAddtionalSaved = string.IsNullOrWhiteSpace(set.ImageSaveOption.AddtionalSaveType);
|
||||
set.CameraId = this.CameraName;
|
||||
|
||||
set.ImageTime = DateTime.Now;
|
||||
_imageSetList[set.Id] = set;
|
||||
}
|
||||
|
||||
public virtual async void DisplayAndSaveOriginImage(string imgSetId, int _counter)
|
||||
{
|
||||
MatSet set = _imageSetList.Values.FirstOrDefault(u => u.Id == imgSetId);
|
||||
|
||||
if (set != null && set._mat != null)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Bitmap showImage = set._mat.ToBitmap();
|
||||
// showImage.Save("D:/test333.bmp");
|
||||
// Marshal.Copy(pbyteImageBuffer, 0, (IntPtr)lAddrImage, (int)dwBufferSize);
|
||||
// Bitmap saveImage = showImage?.CopyBitmap();
|
||||
// saveImage.Save("d://TEST444.BMP");
|
||||
// OnShowImageUpdated?.Invoke(this, showImage, imgSetId);
|
||||
if (IsSavePicEnabled)
|
||||
{
|
||||
string fullname = Path.Combine(ImageSaveDirectory, $"{CameraName}_{_counter:D7}_{set.Id}.{set._imageFormat.ToString().ToLower()}");
|
||||
ImageSaveAsync(fullname, showImage);
|
||||
}
|
||||
|
||||
//释放 himage
|
||||
ClearImageSet(set);
|
||||
});
|
||||
}
|
||||
}
|
||||
static object _imageSetLock = new object();
|
||||
public void ClearImageSet(MatSet set)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool flag = false;
|
||||
lock (_imageSetLock)
|
||||
{
|
||||
flag = _imageSetList.TryRemove(set.Id, out set);
|
||||
if (flag)
|
||||
{
|
||||
set.Dispose();
|
||||
}
|
||||
//LogAsync(DateTime.Now, $"{Name}移除图片信息{(flag ? "成功" : "失败")},当前缓存数量:{_imageSetList.Count}", "");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"清理图片缓存异常,当前缓存数量{_imageSetList.Count},{ex.GetExceptionMessage()}");
|
||||
}
|
||||
}
|
||||
public ImageSaveHelper ImageSaveHelper { get; set; } = new ImageSaveHelper();
|
||||
public virtual void ImageSaveAsync(string fullName, Bitmap map)
|
||||
{
|
||||
if (!IsSavePicEnabled)
|
||||
{
|
||||
map?.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
ImageSaveSet imageSaveSet = new ImageSaveSet()
|
||||
{
|
||||
FullName = fullName,
|
||||
SaveImage = map,
|
||||
|
||||
};
|
||||
|
||||
ImageSaveHelper.ImageSaveAsync(imageSaveSet);
|
||||
}
|
||||
public override bool CameraDisConnect()
|
||||
{
|
||||
try
|
||||
@ -411,6 +512,22 @@ namespace DH.Devices.Camera
|
||||
|
||||
}
|
||||
|
||||
public void LogAsync(LogMsg msg)
|
||||
{
|
||||
msg.MsgSource = CameraName;
|
||||
msg.ThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
//OnLog?.BeginInvoke(msg, null, null);
|
||||
OnLog?.Invoke(msg);
|
||||
|
||||
//if (InitialConfig.IsEnableLog)
|
||||
{
|
||||
LoggerHelper.LogAsync(msg);
|
||||
}
|
||||
}
|
||||
public void LogAsync(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogAsync(new LogMsg(dt, logLevel, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,11 @@ using HslCommunication;
|
||||
using HslCommunication.Enthernet;
|
||||
using HslCommunication.Profinet.XINJE;
|
||||
using OpenCvSharp;
|
||||
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
|
||||
|
||||
namespace DH.Devices.PLC
|
||||
{
|
||||
public class XinJEPLCTcpNet : PLCBase
|
||||
public class XinJEPLCTcpNet : PLCBase, ILogger
|
||||
{
|
||||
private static XinJEPLCTcpNet _instance;
|
||||
public static XinJEPLCTcpNet Instance
|
||||
@ -31,13 +32,18 @@ namespace DH.Devices.PLC
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
|
||||
public event Action<LogMsg> OnLog;
|
||||
private XinJETcpNet TcpNet = new XinJETcpNet();
|
||||
|
||||
public override bool PLCConnect()
|
||||
{
|
||||
try
|
||||
{
|
||||
LoggerHelper.LogPath = "D://";
|
||||
LoggerHelper.LogPrefix = "PLC";
|
||||
|
||||
TcpNet.IpAddress = IP;
|
||||
TcpNet.Port = Port;
|
||||
TcpNet.ConnectTimeOut = 5000;
|
||||
@ -63,11 +69,13 @@ namespace DH.Devices.PLC
|
||||
Connected = true;
|
||||
//初始化流程
|
||||
InitProcess();
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{IP}:{Port}PLC连接成功");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Connected = false;
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC初始化失败");
|
||||
throw new Exception($"{IP}:{Port}PLC连接失败!");
|
||||
}
|
||||
|
||||
@ -76,6 +84,7 @@ namespace DH.Devices.PLC
|
||||
catch(Exception ex)
|
||||
{
|
||||
Connected = false;
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"{IP}:{Port}PLC连接失败!失败原因:{ex.ToString()}");
|
||||
throw new Exception($"{IP}:{Port}PLC连接失败!失败原因:{ex.ToString()}");
|
||||
}
|
||||
|
||||
@ -95,18 +104,20 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取int16失败,地址{address}");
|
||||
throw new Exception($"PLC操作读取int16失败,地址{address}");
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取int16失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作读取int16失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -125,17 +136,20 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取int32失败,地址{address}");
|
||||
|
||||
throw new Exception($"PLC操作读取int32失败,地址{address}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取int32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作读取int32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -155,6 +169,7 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取uint16失败,地址{address}");
|
||||
|
||||
throw new Exception($"PLC操作读取uint16失败,地址{address}");
|
||||
|
||||
@ -162,12 +177,14 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取uint16失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作读取uint16失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -186,17 +203,20 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作uint32失败,地址{address}");
|
||||
|
||||
throw new Exception($"PLC操作uint32失败,地址{address}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取uint32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作读取uint32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -216,16 +236,19 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取float失败,地址{address}");
|
||||
throw new Exception($"PLC操作读取float失败,地址{address}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取float失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作读取float失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -243,16 +266,19 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取bool失败,地址{address}");
|
||||
throw new Exception($"PLC操作读取bool失败,地址{address}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作读取bool失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作读取bool失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -291,6 +317,7 @@ namespace DH.Devices.PLC
|
||||
repeatTime--;
|
||||
if (repeatTime <= 0)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作写入uint32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作写入uint32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -298,6 +325,8 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
return false;
|
||||
@ -336,6 +365,7 @@ namespace DH.Devices.PLC
|
||||
repeatTime--;
|
||||
if (repeatTime <= 0)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作写入uint16失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作写入uint16失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -343,6 +373,8 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
return false;
|
||||
@ -383,6 +415,7 @@ namespace DH.Devices.PLC
|
||||
repeatTime--;
|
||||
if (repeatTime <= 0)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作写入int32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作写入int32失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -476,6 +509,7 @@ namespace DH.Devices.PLC
|
||||
repeatTime--;
|
||||
if (repeatTime <= 0)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作写入float失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作写入float失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -483,6 +517,8 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
return false;
|
||||
@ -519,6 +555,7 @@ namespace DH.Devices.PLC
|
||||
repeatTime--;
|
||||
if (repeatTime <= 0)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC操作写入bool失败,地址{address},失败原因:{ex.ToString()}");
|
||||
throw new Exception($"PLC操作写入bool失败,地址{address},失败原因:{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
@ -528,6 +565,7 @@ namespace DH.Devices.PLC
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Error, $"PLC未连接,地址{address}");
|
||||
throw new Exception($"PLC未连接,地址{address}");
|
||||
}
|
||||
|
||||
@ -537,12 +575,14 @@ namespace DH.Devices.PLC
|
||||
|
||||
public override bool PLCDisConnect()
|
||||
{
|
||||
|
||||
if (Connected)
|
||||
{
|
||||
|
||||
var res = TcpNet.ConnectClose();
|
||||
if (res.IsSuccess)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{IP}:{Port}停止");
|
||||
Connected = false;
|
||||
return true;
|
||||
}
|
||||
@ -575,6 +615,7 @@ namespace DH.Devices.PLC
|
||||
/// int,int 轴号 捕获位置
|
||||
/// </summary>
|
||||
public event Action<int, uint> OnNewPieces;
|
||||
|
||||
|
||||
public void NewPieces(int axisIndex, uint pieceNumber)
|
||||
{
|
||||
@ -593,7 +634,7 @@ namespace DH.Devices.PLC
|
||||
|
||||
if (pLCItem == null)
|
||||
return;
|
||||
WriteBool(pLCItem.Name, true);
|
||||
WriteBool(pLCItem.Address, true);
|
||||
await Task.Delay(900); // 非阻塞,等待1秒
|
||||
}
|
||||
}
|
||||
@ -635,7 +676,7 @@ namespace DH.Devices.PLC
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"转盘{0}产品入列 {piecesCountDic[0]} size:{sum}");
|
||||
if (tmpPieceNumber != piecesCount + 1)
|
||||
{
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"入列触发丢失\t{tmpPieceNumber}");
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"入列触发丢失\t{tmpPieceNumber}");
|
||||
// Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}\t板卡{station}产品入列触发丢失,{piecesCountDic[station]}\t{tmpPieceNumber}");
|
||||
|
||||
}
|
||||
@ -660,20 +701,25 @@ namespace DH.Devices.PLC
|
||||
{
|
||||
//启用心跳
|
||||
OpenHeartbeat(true);
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"启用心跳");
|
||||
//状态复位
|
||||
StatusReset();
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"状态复位");
|
||||
//关闭定位
|
||||
VisionPos(false);
|
||||
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"关闭定位");
|
||||
//写入流程加载点位配置
|
||||
InitProcessAction();
|
||||
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"写入流程加载点位配置");
|
||||
//计数清零
|
||||
CountToZero();
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"计数清零");
|
||||
//停止转盘
|
||||
TurnStart(false);
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"停止转盘");
|
||||
//转盘使能
|
||||
TurnEnable(true);
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"启用心跳-状态复位-关闭定位-写入流程加载点位配置-计数清零-停止转盘-转盘使能");
|
||||
//开启入料监听
|
||||
MonitorPieces();
|
||||
|
||||
@ -683,17 +729,31 @@ namespace DH.Devices.PLC
|
||||
{
|
||||
//状态复位
|
||||
StatusReset();
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"状态复位");
|
||||
//关闭定位
|
||||
VisionPos(false);
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"关闭定位");
|
||||
//写入流程启动点位配置
|
||||
StartProcessAction();
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"写入流程加载点位配置");
|
||||
//计数清零
|
||||
CountToZero();
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"状态复位-关闭定位-写入流程加载点位配置-计数清零");
|
||||
//转盘启动
|
||||
TurnStart(true);
|
||||
}
|
||||
|
||||
|
||||
public void CloseProcess()
|
||||
{
|
||||
StatusReset();
|
||||
VisionPos(false);
|
||||
CountToZero();
|
||||
TurnStart(false);
|
||||
TurnEnable(false);
|
||||
OpenHeartbeat(false);
|
||||
PLCDisConnect();
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"PLC断开连接");
|
||||
}
|
||||
public void InitProcessAction() =>
|
||||
ProcessAction(ConfigModel.GlobalList?.FirstOrDefault()?.InitProcessList?.ToList() ?? new List<PLCItem>());
|
||||
|
||||
@ -965,5 +1025,23 @@ namespace DH.Devices.PLC
|
||||
WriteUInt16($"D{currentRegister}", value);
|
||||
|
||||
}
|
||||
|
||||
public void LogAsync(LogMsg msg)
|
||||
{
|
||||
msg.MsgSource = "PLC";
|
||||
msg.ThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
//OnLog?.BeginInvoke(msg, null, null);
|
||||
OnLog?.Invoke(msg);
|
||||
|
||||
//if (InitialConfig.IsEnableLog)
|
||||
{
|
||||
LoggerHelper.LogAsync(msg);
|
||||
}
|
||||
}
|
||||
public void LogAsync(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogAsync(new LogMsg(dt, logLevel, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,14 @@
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -104,18 +104,18 @@ namespace DH.Devices.Vision
|
||||
// json = "{\"FastDetResult\":[{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654843,\"rect\":[175,99,110,594]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654589,\"rect\":[2608,19,104,661]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.654285,\"rect\":[1275,19,104,662]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.620762,\"rect\":[1510,95,107,600]},{\"cls_id\":0,\"cls\":\"liewen\",\"fScore\":0.617812,\"rect\":[2844,93,106,602]}]}";
|
||||
//
|
||||
Console.WriteLine("检测结果JSON:" + json);
|
||||
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
|
||||
|
||||
HYoloResult detResult = JsonConvert.DeserializeObject<HYoloResult>(json);
|
||||
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
|
||||
|
||||
if (detResult == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int iNum = detResult.HYolo.Count;
|
||||
#pragma warning disable CS0219 // 变量已被赋值,但从未使用过它的值
|
||||
|
||||
int IokNum = 0;
|
||||
#pragma warning restore CS0219 // 变量已被赋值,但从未使用过它的值
|
||||
|
||||
for (int ix = 0; ix < iNum; ix++)
|
||||
{
|
||||
var det = detResult.HYolo[ix];
|
||||
@ -145,7 +145,6 @@ namespace DH.Devices.Vision
|
||||
Mat originMat = new Mat();
|
||||
Mat detectMat = new Mat();
|
||||
|
||||
#pragma warning disable CS0168 // 声明了变量,但从未使用过
|
||||
try
|
||||
{
|
||||
if (req.mImage == null)
|
||||
|
@ -281,7 +281,7 @@ namespace DH.Devices.Vision
|
||||
|
||||
// GC.Collect();
|
||||
}
|
||||
#pragma warning restore CS0168 // 声明了变量,但从未使用过
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using DH.Commons.Base;
|
||||
using DH.Commons.Enums;
|
||||
using DH.Commons.Helper;
|
||||
using DH.UI.Model.Winform;
|
||||
using HalconDotNet;
|
||||
using OpenCvSharp;
|
||||
@ -7,6 +8,8 @@ using OpenCvSharp.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Text;
|
||||
@ -15,6 +18,7 @@ using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using XKRS.UI.Model.Winform;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
|
||||
using ResultState = DH.Commons.Base.ResultState;
|
||||
|
||||
|
||||
@ -36,7 +40,20 @@ namespace DH.Devices.Vision
|
||||
// ImageSaveHelper.OnImageSaveExceptionRaised += ImageSaveHelper_OnImageSaveExceptionRaised;
|
||||
// base.Init();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
SimboStationMLEngineList.ToList().ForEach(sm =>
|
||||
{
|
||||
if (sm.IsUseGPU)
|
||||
{
|
||||
sm.StationMLEngine.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
sm.StationMLEngine.Dispose2();
|
||||
}
|
||||
});
|
||||
}
|
||||
//private void ImageSaveHelper_OnImageSaveExceptionRaised(DateTime dt, string msg)
|
||||
//{
|
||||
// LogAsync(new LogMsg(dt, LogLevel.Error, msg));
|
||||
@ -57,16 +74,30 @@ namespace DH.Devices.Vision
|
||||
|
||||
if (detectConfig == null)
|
||||
{
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"异常:未能获取检测配置");
|
||||
//未能获得检测配置
|
||||
return detectResult;
|
||||
}
|
||||
detectResult.DetectName = detectConfig.Name;
|
||||
detectResult.ImageSaveDirectory=detectConfig.ImageSaveDirectory;
|
||||
detectResult.SaveNGDetect=detectConfig.SaveNGDetect;
|
||||
detectResult.SaveNGOriginal=detectConfig.SaveNGOriginal;
|
||||
detectResult.SaveOKDetect=detectConfig.SaveOKDetect;
|
||||
detectResult.SaveOKOriginal=detectConfig.SaveOKOriginal;
|
||||
Mat OriginImage = originImgSet.Clone();
|
||||
detectResult.DetectionOriginImage = CopyBitmapWithLockBits(OriginImage.ToBitmap());
|
||||
//detectResult.DetectionOriginImage = originImgSet.Clone().ToBitmap();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
#region 1.预处理
|
||||
|
||||
sw.Start();
|
||||
using (Mat PreTMat = originImgSet.Clone())
|
||||
{
|
||||
PreTreated(detectConfig, detectResult, PreTMat);
|
||||
PreTreated2(detectConfig, detectResult, PreTMat);
|
||||
}
|
||||
sw.Stop();
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"产品:{detectResult.Pid} {detectConfig.Name}预处理耗时:{sw.ElapsedMilliseconds}ms。SpecsResults:{string.Join(";", detectResult.realSpecs.Select(u => $"{u.Code} {u.ActualValue}"))}");
|
||||
// 工位2尺寸测量
|
||||
|
||||
|
||||
|
||||
@ -98,7 +129,7 @@ namespace DH.Devices.Vision
|
||||
}
|
||||
|
||||
#region 2.深度学习推理
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} 模型检测执行");
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} 模型检测执行");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(detectConfig.ModelPath))
|
||||
{
|
||||
@ -140,8 +171,8 @@ namespace DH.Devices.Vision
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference BEGIN");
|
||||
mlWatch.Start();
|
||||
//20230802改成多线程推理 RunInferenceFixed
|
||||
|
||||
var result = mlSet.StationMLEngine.RunInference(req);
|
||||
// MLResult result = new MLResult();
|
||||
var result = mlSet.StationMLEngine.RunInference(req);
|
||||
// var result = mlSet.StationMLEngine.RunInferenceFixed(req);
|
||||
mlWatch.Stop();
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 产品{detectResult.TempPid} RunInference END");
|
||||
@ -180,6 +211,8 @@ namespace DH.Devices.Vision
|
||||
|
||||
if (result == null || (result != null && !result.IsSuccess))
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"CoreInx:{mlSet.GPUNo} 产品:{detectResult.Pid} {detectConfig.Name} 模型检测异常,{result?.ResultMessage}");
|
||||
|
||||
detectResult.IsMLDetectDone = false;
|
||||
}
|
||||
if (result != null && result.IsSuccess)
|
||||
@ -187,9 +220,13 @@ namespace DH.Devices.Vision
|
||||
detectResult.DetectDetails = result.ResultDetails;
|
||||
if (detectResult.DetectDetails != null)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"CoreInx:{mlSet.GPUNo} 产品:{detectResult.Pid} {detectResult.DetectName} 模型检测总耗时:{mlWatch.ElapsedMilliseconds} ms {result.ResultMessage},{string.Join(";", detectResult.DetectDetails.Select(u => $"{u.LabelName} X:{u.Rect.X} Y:{u.Rect.Y} Area:{u.Area.ToString("f2")} W:{u.Rect.Width} H:{u.Rect.Height}"))}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"CoreInx:{mlSet.GPUNo} 产品:{detectResult.Pid} {detectConfig.Name} 模型检测异常返回 null");
|
||||
|
||||
detectResult.IsMLDetectDone = false;
|
||||
}
|
||||
}
|
||||
@ -231,22 +268,22 @@ namespace DH.Devices.Vision
|
||||
}
|
||||
|
||||
|
||||
foreach (IGrouping<ResultState, DetectionFilter> group in conditionList)
|
||||
{
|
||||
bool b = group.ToList().Any(f =>
|
||||
{
|
||||
return f.FilterOperation(d);
|
||||
});
|
||||
//foreach (IGrouping<ResultState, DetectionFilter> group in conditionList)
|
||||
//{
|
||||
// bool b = group.ToList().Any(f =>
|
||||
// {
|
||||
// return f.FilterOperation(d);
|
||||
// });
|
||||
|
||||
|
||||
if (b)
|
||||
{
|
||||
d.FinalResult = group.Key;
|
||||
break;
|
||||
}
|
||||
// if (b)
|
||||
// {
|
||||
// d.FinalResult = group.Key;
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
});
|
||||
#endregion
|
||||
#region 5.统计缺陷过滤结果或预处理直接NG
|
||||
@ -267,6 +304,7 @@ namespace DH.Devices.Vision
|
||||
#endregion
|
||||
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 检测结果:{detectResult.ResultState.GetEnumDescription()}");
|
||||
|
||||
|
||||
|
||||
@ -417,12 +455,14 @@ namespace DH.Devices.Vision
|
||||
{
|
||||
// throw new ProcessException("异常:模型加载异常", null);
|
||||
}
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"模型加载成功;是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}");
|
||||
LogAsync(DateTime.Now, LogLevel.Information, $"模型加载成功;是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//throw new ProcessException($"异常:是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}模型加载异常:{ex.GetExceptionMessage()}");
|
||||
// LogAsync(DateTime.Now, LogLevel.Error, $"模型加载成功;是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}");
|
||||
|
||||
throw new ProcessException($"异常:是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}模型加载异常:{ex.GetExceptionMessage()}");
|
||||
}
|
||||
return mLEngineSet;
|
||||
}
|
||||
@ -506,7 +546,7 @@ namespace DH.Devices.Vision
|
||||
if (!tool.RunProcedure(out string errorMsg, out _))
|
||||
{
|
||||
// detectResult.PreTreatedFlag = false;
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}预处理异常,{errorMsg}");
|
||||
detectResult.IsPreTreatDone = false;
|
||||
|
||||
|
||||
@ -521,12 +561,82 @@ namespace DH.Devices.Vision
|
||||
// detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag = preTreatRet == 1;
|
||||
//detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag = true;
|
||||
// detectResult.VisionImageSet.PreTreatedTime = DateTime.Now;
|
||||
|
||||
for (int i = 0; i < detectConfig.OUTPreTreatParams.Count; i++)
|
||||
switch (preTreatRet)
|
||||
{
|
||||
var param = detectConfig.OUTPreTreatParams[i];
|
||||
tool.InputTupleDic[param.Name] = double.Parse(param.Value);
|
||||
case 0: // 预处理算法无异常
|
||||
{
|
||||
|
||||
for (int i = 0; i < detectConfig.OUTPreTreatParams.Count; i++)
|
||||
{
|
||||
|
||||
var param = detectConfig.OUTPreTreatParams[i];
|
||||
|
||||
var Value = tool.GetResultTuple(param.Name);
|
||||
|
||||
// 显示结果
|
||||
IndexedSpec specRCricularity = new()
|
||||
{
|
||||
Code = param.Name,
|
||||
ActualValue = Value
|
||||
};
|
||||
detectResult.realSpecs.Add(specRCricularity);
|
||||
}
|
||||
detectResult.IsPreTreatNG = false;
|
||||
detectResult.IsPreTreatDone = true;
|
||||
}
|
||||
break;
|
||||
case -111: // 检测结果为NG
|
||||
{
|
||||
/// detectResult.VisionImageSet.DetectionResultImage =
|
||||
// tool.GetResultObject("OUTPUT_PreTreatedImage").ConvertHImageToBitmap();
|
||||
for (int i = 0; i < detectConfig.OUTPreTreatParams.Count; i++)
|
||||
{
|
||||
|
||||
var param = detectConfig.OUTPreTreatParams[i];
|
||||
|
||||
var Value = tool.GetResultTuple(param.Name);
|
||||
|
||||
// 显示结果
|
||||
IndexedSpec specRCricularity = new()
|
||||
{
|
||||
Code = param.Name,
|
||||
ActualValue = Value
|
||||
};
|
||||
detectResult.realSpecs.Add(specRCricularity);
|
||||
}
|
||||
// 结果为NG
|
||||
detectResult.ResultState = ResultState.DetectNG;
|
||||
detectResult.IsPreTreatNG = true;
|
||||
detectResult.IsPreTreatDone = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case -999: // 算法异常
|
||||
{
|
||||
// 算法异常时,结果图
|
||||
// detectResult.VisionImageSet.DetectionResultImage =
|
||||
// tool.GetResultObject("OUTPUT_PreTreatedImage").ConvertHImageToBitmap();
|
||||
|
||||
for (int i = 0; i < detectConfig.OUTPreTreatParams.Count; i++)
|
||||
{
|
||||
|
||||
|
||||
var param = detectConfig.OUTPreTreatParams[i];
|
||||
// 显示结果
|
||||
IndexedSpec specRCricularity = new()
|
||||
{
|
||||
Code = param.Name,
|
||||
ActualValue = -1,
|
||||
};
|
||||
detectResult.realSpecs.Add(specRCricularity);
|
||||
}
|
||||
|
||||
// 结果保持TBD
|
||||
detectResult.IsPreTreatDone = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -558,7 +668,7 @@ namespace DH.Devices.Vision
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}预处理异常:{ex.GetExceptionMessage()}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -569,6 +679,266 @@ namespace DH.Devices.Vision
|
||||
}
|
||||
|
||||
}
|
||||
public void PreTreated2(DetectionConfig detectConfig, DetectStationResult detectResult,Mat MhImage)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (detectConfig.SizeTreatParamList != null && detectConfig.SizeTreatParamList.Count > 0)
|
||||
{
|
||||
foreach (var preTreat in detectConfig.SizeTreatParamList)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(preTreat.PrePath))
|
||||
{
|
||||
string toolKey = preTreat.PrePath;
|
||||
if (!HalconToolDict.ContainsKey(toolKey))
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}未获取预处理{preTreat.PreName}算法");
|
||||
return;
|
||||
}
|
||||
//Mean_Thre Deviation_Thre Mean_standard Deviation_standard
|
||||
var tool = HalconToolDict[toolKey];
|
||||
|
||||
//tool.InputTupleDic["Mean_Thre"] = 123;
|
||||
List<PreTreatParam> PreParams = new List<PreTreatParam>();
|
||||
preoutparms(PreParams, preTreat.ResultShow);
|
||||
for (int i = 0; i < PreParams.Count(); i++)
|
||||
{
|
||||
var param = PreParams[i];
|
||||
if (param.Value.Contains(","))
|
||||
{
|
||||
string[] strings = param.Value.Split(",");
|
||||
float[] array = strings.Select(s => float.Parse(s)).ToArray();
|
||||
HTuple hTupleArray = new HTuple(array);
|
||||
|
||||
tool.InputTupleDic[param.Name] = hTupleArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
tool.InputTupleDic[param.Name] = double.Parse(param.Value);// param.Value.ToInt();
|
||||
}
|
||||
|
||||
IndexedSpec spec1 = new IndexedSpec();
|
||||
|
||||
switch (preTreat.PreType)
|
||||
{
|
||||
case SizeEnum.线线测量:
|
||||
|
||||
break;
|
||||
case SizeEnum.线圆测量:
|
||||
|
||||
break;
|
||||
case SizeEnum.圆形测量:
|
||||
break;
|
||||
case SizeEnum.高度测量:
|
||||
spec1.Code = $"in-{param.Name}";
|
||||
spec1.ActualValue = double.Parse(param.Value);
|
||||
break;
|
||||
case SizeEnum.直线测量:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
detectResult.realSpecs.Add(spec1);
|
||||
}
|
||||
//// 指定保存路径
|
||||
//string filePath = @"D:\saved_image.jpg"; // 你可以根据需要更改路径和文件名
|
||||
|
||||
//// 使用WriteImage保存图像
|
||||
//detectResult.VisionImageSet.HImage.WriteImage("jpeg", 0, filePath); // "jpeg" 表示图像格式,0表示不使用压缩
|
||||
HObject obj = OpenCVHelper.MatToHImage(MhImage);
|
||||
HImage hImage = HalconHelper.ConvertHObjectToHImage(obj);
|
||||
tool.InputImageDic["INPUT_Image"] = hImage;
|
||||
if (!tool.RunProcedure(out string errorMsg, out _))
|
||||
{
|
||||
// detectResult.VisionImageSet.PreTreatedFlag = false;
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}预处理异常,{errorMsg}");
|
||||
detectResult.IsPreTreatDone = false;
|
||||
|
||||
// HandleDetectDone(detectResult, detectConfig);
|
||||
return;
|
||||
}
|
||||
|
||||
var preTreatRet = tool.GetResultTuple("OUTPUT_Flag").I;
|
||||
//double MatchScore = 1;
|
||||
//MatchScore = tool.GetResultTuple("MatchScore");
|
||||
|
||||
|
||||
detectResult.IsPreTreatDone = preTreatRet == 1;
|
||||
// detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag = true;
|
||||
// detectResult.VisionImageSet.PreTreatedTime = DateTime.Now;
|
||||
|
||||
|
||||
//IndexedSpec spec1 = new IndexedSpec();
|
||||
//spec1.Code = "score";
|
||||
//spec1.ActualValue = MatchScore;
|
||||
|
||||
|
||||
//detectResult.realSpecs.Add(spec1);
|
||||
;
|
||||
|
||||
|
||||
// 2023/10/16 新增预处理结果反馈,如果预处理结果为NG,直接返回
|
||||
if (preTreatRet != 0)
|
||||
{
|
||||
detectResult.ResultState = ResultState.DetectNG;
|
||||
|
||||
detectResult.IsPreTreatNG = true;
|
||||
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
switch (preTreat.PreType)
|
||||
{
|
||||
case SizeEnum.线线测量:
|
||||
isPreOutparams(ref detectResult, preTreat, tool, ref preTreatRet);
|
||||
break;
|
||||
case SizeEnum.线圆测量:
|
||||
isPreOutparams(ref detectResult, preTreat, tool, ref preTreatRet);
|
||||
break;
|
||||
case SizeEnum.圆形测量:
|
||||
break;
|
||||
case SizeEnum.高度测量:
|
||||
{
|
||||
|
||||
isPreOutparams(ref detectResult, preTreat, tool, ref preTreatRet);
|
||||
}
|
||||
break;
|
||||
case SizeEnum.直线测量:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}尺寸预处理异常:{ex.GetExceptionMessage()}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
//detectResult.VisionImageSet.HImage?.Dispose();
|
||||
//detectResult.VisionImageSet.HImage = null;
|
||||
}
|
||||
}
|
||||
public void isPreOutparams(ref DetectStationResult detectResult, SizeTreatParam preTreat, HDevEngineTool tool, ref int preTreatRet)
|
||||
{
|
||||
List<PreTreatParam> PreParams = new List<PreTreatParam>();
|
||||
preoutparms(PreParams, preTreat.OutResultShow);
|
||||
|
||||
for (int i = 0; i < PreParams.Count; i++)
|
||||
{
|
||||
var param = PreParams[i];
|
||||
double dParam = double.Parse(param.Value);
|
||||
double heights = tool.GetResultTuple(param.Name).D;
|
||||
switch (preTreat.PreType)
|
||||
{
|
||||
case SizeEnum.高度测量:
|
||||
|
||||
|
||||
IndexedSpec spec2 = new IndexedSpec();
|
||||
spec2.Code = $"out-{param.Name}";
|
||||
spec2.ActualValue = Convert.ToDouble(param.Value);
|
||||
|
||||
|
||||
detectResult.realSpecs.Add(spec2);
|
||||
|
||||
|
||||
IndexedSpec spec1 = new IndexedSpec();
|
||||
spec1.Code = $"actual-{param.Name}";
|
||||
spec1.ActualValue = heights;
|
||||
|
||||
|
||||
detectResult.realSpecs.Add(spec1);
|
||||
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((heights > dParam - preTreat.PrePix) && (heights < dParam + preTreat.PrePix))
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
preTreatRet = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preTreatRet != 0)
|
||||
{
|
||||
detectResult.ResultState = ResultState.DetectNG;
|
||||
|
||||
detectResult.IsPreTreatNG = true;
|
||||
//detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void preoutparms(List<PreTreatParam> preTreatParams, string defectRows)
|
||||
{
|
||||
// 解析 ReslutShow 字符串,构建 PreTreatParam 列表
|
||||
if (!string.IsNullOrEmpty(defectRows))
|
||||
{
|
||||
var keyValuePairs = defectRows.Split(';');
|
||||
|
||||
foreach (var pair in keyValuePairs)
|
||||
{
|
||||
var parts = pair.Split(':');
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
PreTreatParam param;
|
||||
if (parts[1].Trim().Contains(","))
|
||||
{
|
||||
param = new PreTreatParam
|
||||
{
|
||||
Name = parts[0].Trim(), // 去除多余的空格
|
||||
Value = parts[1].Trim() // 转换为 double,失败则为0
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
double dvalue = double.TryParse(parts[1].Trim(), out double value) ? value : 0;
|
||||
|
||||
param = new PreTreatParam
|
||||
{
|
||||
Name = parts[0].Trim(), // 去除多余的空格
|
||||
Value = dvalue.ToString() // 转换为 double,失败则为0
|
||||
};
|
||||
}
|
||||
|
||||
preTreatParams.Add(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示检测结果
|
||||
@ -593,15 +963,15 @@ namespace DH.Devices.Vision
|
||||
});
|
||||
}
|
||||
|
||||
//if (detectResult.realSpecs != null && detectResult.realSpecs?.Count > 0)
|
||||
//{
|
||||
// detectResult.realSpecs.ForEach(d =>
|
||||
// {
|
||||
// displayTxt +=
|
||||
// $"{d.Code} :{d.ActualValue} \r\n";
|
||||
// });
|
||||
//}
|
||||
Bitmap resultMask=result.ToBitmap();
|
||||
if (detectResult.realSpecs != null && detectResult.realSpecs?.Count > 0)
|
||||
{
|
||||
detectResult.realSpecs.ForEach(d =>
|
||||
{
|
||||
displayTxt +=
|
||||
$"{d.Code} :{d.ActualValue} \r\n";
|
||||
});
|
||||
}
|
||||
Bitmap resultMask =result.ToBitmap();
|
||||
//if (detectResult.VisionImageSet.DetectionResultImage == null && detectResult.VisionImageSet.SizeResultImage == null)
|
||||
//{
|
||||
// return;
|
||||
@ -635,14 +1005,14 @@ namespace DH.Devices.Vision
|
||||
List<IShapeElement> detectionResultShapesClone = new List<IShapeElement>(detectionResultShapes);
|
||||
|
||||
DetectionDone(DetectionId, resultMask, detectionResultShapes);
|
||||
|
||||
//SaveDetectResultImageAsync(detectResult);
|
||||
//detectResult.DetectionOriginImage = CopyBitmapWithLockBits(resultMask);
|
||||
SaveDetectResultImageAsync(detectResult);
|
||||
// SaveDetectResultCSVAsync(detectResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// LogAsync(DateTime.Now, LogLevel.Exception,
|
||||
// $"{Name}显示{detectResult.DetectName}检测结果异常,{ex.GetExceptionMessage()}");
|
||||
//LogAsync(DateTime.Now, LogLevel.Exception,
|
||||
// $"{Name}显示{detectResult.DetectName}检测结果异常,{ex.GetExceptionMessage()}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -651,6 +1021,343 @@ namespace DH.Devices.Vision
|
||||
}
|
||||
});
|
||||
}
|
||||
public static Bitmap CopyBitmapWithLockBits(Bitmap original)
|
||||
{
|
||||
Bitmap copy = new Bitmap(original.Width, original.Height, original.PixelFormat);
|
||||
BitmapData originalData = original.LockBits(
|
||||
new Rectangle(0, 0, original.Width, original.Height),
|
||||
ImageLockMode.ReadOnly,
|
||||
original.PixelFormat
|
||||
);
|
||||
BitmapData copyData = copy.LockBits(
|
||||
new Rectangle(0, 0, copy.Width, copy.Height),
|
||||
ImageLockMode.WriteOnly,
|
||||
copy.PixelFormat
|
||||
);
|
||||
int bytesPerPixel = Image.GetPixelFormatSize(original.PixelFormat) / 8;
|
||||
int byteCount = originalData.Stride * original.Height;
|
||||
byte[] buffer = new byte[byteCount];
|
||||
System.Runtime.InteropServices.Marshal.Copy(originalData.Scan0, buffer, 0, byteCount);
|
||||
System.Runtime.InteropServices.Marshal.Copy(buffer, 0, copyData.Scan0, byteCount);
|
||||
original.UnlockBits(originalData);
|
||||
copy.UnlockBits(copyData);
|
||||
return copy;
|
||||
}
|
||||
/// <summary>
|
||||
///图片异步保存
|
||||
/// </summary>
|
||||
public void SaveDetectResultImageAsync1(DetectStationResult detectResult)
|
||||
{
|
||||
string format = detectResult.ImageFormat.ToString().ToLower();
|
||||
|
||||
if(detectResult.ImageSaveDirectory!=null)
|
||||
{
|
||||
if (!Directory.Exists(detectResult.ImageSaveDirectory))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//根目录
|
||||
string rootPath = Path.Combine(detectResult.ImageSaveDirectory,
|
||||
DateTime.Now.ToString("yyyyMMdd"), detectResult.DetectName);
|
||||
|
||||
if (detectResult.ResultState != ResultState.OK)
|
||||
{
|
||||
|
||||
// NG原图
|
||||
if (detectResult.SaveNGOriginal && detectResult.DetectionOriginImage != null)
|
||||
{
|
||||
string prefix = Path.Combine(rootPath, "NGRawImages", detectResult.ResultLabel);
|
||||
string fullname = Path.Combine(prefix, $"{detectResult.Pid}_NGRawImage_{detectResult.DetectName}_{detectResult.Id}.{format}");
|
||||
SaveImageAsync(fullname, detectResult.DetectionOriginImage, detectResult.ImageFormat);
|
||||
}
|
||||
|
||||
|
||||
//NG结果图
|
||||
if (detectResult.SaveOKDetect && detectResult.DetectionOriginImage != null)
|
||||
{
|
||||
// 没有预处理,则保存原始图+检测结果图
|
||||
// if (detectResult.VisionImageSet.PreTreatedBitmap == null)
|
||||
{
|
||||
//string displayTxt = detectResult.ResultState.ToString() + "\r\n";
|
||||
string displayTxt = "";
|
||||
detectResult.DetectDetails.ForEach(d =>
|
||||
{
|
||||
displayTxt += $"{d.LabelName} score:{d.Score.ToString("f2")} area:{d.Area.ToString("f2")}\r\n";
|
||||
});
|
||||
if (detectResult.realSpecs != null && detectResult.realSpecs?.Count > 0)
|
||||
{
|
||||
detectResult.realSpecs.ForEach(d =>
|
||||
{
|
||||
displayTxt +=
|
||||
$"{d.Code} score:{d.ActualValue} \r\n";
|
||||
});
|
||||
}
|
||||
Bitmap resultMask = detectResult.DetectionOriginImage.CopyBitmap();
|
||||
|
||||
Bitmap preTreatedBitmap = detectResult.DetectionOriginImage.CopyBitmap();
|
||||
|
||||
//List<IShapeElement> detectionResultShapes = new List<IShapeElement>(detectResult.DetectionResultShapes);
|
||||
//DetectResultDisplay resultDisplay = new DetectResultDisplay(detectResult, resultMask, displayTxt);
|
||||
//detectionResultShapes.Add(resultDisplay);
|
||||
|
||||
Bitmap resultMap = GetResultImage(resultMask, detectResult.DetectionResultShapes);
|
||||
|
||||
|
||||
// resultDisplay.Dispose();
|
||||
//detectionResultShapes.Clear();
|
||||
|
||||
|
||||
Bitmap detectionFitImage = StaticHelper.HConnectBitmap(preTreatedBitmap, resultMap);
|
||||
|
||||
string prefix = Path.Combine(rootPath, "NGFitImages", detectResult.ResultLabel);
|
||||
Directory.CreateDirectory(prefix); // 自动创建所有缺失的目录
|
||||
string fullname = Path.Combine(prefix, $"{detectResult.Pid}_NGFitImage_{detectResult.DetectName}_{detectResult.Id}.{format}");
|
||||
|
||||
|
||||
|
||||
// SaveImageAsync(fullname, detectionFitImage, detectResult.ImageFormat);
|
||||
// 使用回调或 Task.ContinueWith 确保保存完成后再释放资源
|
||||
//SaveImageAsync(fullname, detectionFitImage, detectResult.ImageFormat)
|
||||
// .ContinueWith(t =>
|
||||
// {
|
||||
// resultMask?.Dispose();
|
||||
// preTreatedBitmap?.Dispose();
|
||||
// resultMap?.Dispose();
|
||||
// detectionFitImage?.Dispose();
|
||||
// }, TaskScheduler.Default);
|
||||
|
||||
resultMask?.Dispose();
|
||||
preTreatedBitmap?.Dispose();
|
||||
resultMap?.Dispose();
|
||||
detectionFitImage?.Dispose();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // OK原图
|
||||
if (detectResult.SaveOKOriginal && detectResult.DetectionOriginImage != null)
|
||||
{
|
||||
string prefix = Path.Combine(rootPath, "OKRawImages", detectResult.ResultLabel);
|
||||
string fullname = Path.Combine(prefix, $"{detectResult.Pid}_OKRawImage_{detectResult.DetectName}_{detectResult.Id}.{format}");
|
||||
SaveImageAsync(fullname, detectResult.DetectionOriginImage, detectResult.ImageFormat);
|
||||
}
|
||||
|
||||
//ok结果图
|
||||
if (detectResult.SaveOKDetect && detectResult.DetectionOriginImage != null)
|
||||
{
|
||||
// 没有预处理,则保存原始图+检测结果图
|
||||
// if (detectResult.VisionImageSet.PreTreatedBitmap == null)
|
||||
{
|
||||
//string displayTxt = detectResult.ResultState.ToString() + "\r\n";
|
||||
string displayTxt = "";
|
||||
detectResult.DetectDetails.ForEach(d =>
|
||||
{
|
||||
displayTxt += $"{d.LabelName} score:{d.Score.ToString("f2")} area:{d.Area.ToString("f2")}\r\n";
|
||||
});
|
||||
if (detectResult.realSpecs != null && detectResult.realSpecs?.Count > 0)
|
||||
{
|
||||
detectResult.realSpecs.ForEach(d =>
|
||||
{
|
||||
displayTxt +=
|
||||
$"{d.Code} score:{d.ActualValue} \r\n";
|
||||
});
|
||||
}
|
||||
Bitmap resultMask = detectResult.DetectionOriginImage.CopyBitmap();
|
||||
|
||||
Bitmap preTreatedBitmap = detectResult.DetectionOriginImage.CopyBitmap();
|
||||
|
||||
List<IShapeElement> detectionResultShapes = new List<IShapeElement>(detectResult.DetectionResultShapes);
|
||||
DetectResultDisplay resultDisplay = new DetectResultDisplay(detectResult, resultMask, displayTxt);
|
||||
detectionResultShapes.Add(resultDisplay);
|
||||
|
||||
Bitmap resultMap = GetResultImage(resultMask, detectionResultShapes);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Bitmap detectionFitImage = StaticHelper.HConnectBitmap(preTreatedBitmap, resultMap);
|
||||
|
||||
string prefix = Path.Combine(rootPath, "OKFitImages", detectResult.ResultLabel);
|
||||
string fullname = Path.Combine(prefix, $"{detectResult.Pid}_" +
|
||||
$"OKFitImage_{detectResult.DetectName}_{detectResult.Id}.{format}");
|
||||
|
||||
|
||||
|
||||
SaveImageAsync(fullname, detectionFitImage, detectResult.ImageFormat);
|
||||
|
||||
//resultDisplay.Dispose();
|
||||
//detectionResultShapes.Clear();
|
||||
//resultMask?.Dispose();
|
||||
//preTreatedBitmap?.Dispose();
|
||||
//resultMap?.Dispose();
|
||||
//detectionFitImage?.Dispose();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual Bitmap GetResultImage(Bitmap baseImage, List<IShapeElement> eleList)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 重新生成画布 避免 无法从带有索引像素格式的图像创建graphics对象
|
||||
Bitmap image = new Bitmap(baseImage.Width, baseImage.Height);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(image))
|
||||
{
|
||||
g.DrawImage(baseImage, 0, 0);
|
||||
|
||||
// 创建临时拷贝避免共享状态
|
||||
// var tempElements = eleList.Select(e => e.Clone()).Cast<IShapeElement>().ToList();
|
||||
|
||||
eleList.ForEach(e =>
|
||||
{
|
||||
e.State = ElementState.Normal;
|
||||
e.Draw(g);
|
||||
});
|
||||
}
|
||||
return image;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Exception, $"获取叠加结果图片异常:{ex.GetExceptionMessage()}");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SaveDetectResultImageAsync(DetectStationResult detectResult)
|
||||
{
|
||||
if (detectResult.ImageSaveDirectory == null) return;
|
||||
|
||||
string format = detectResult.ImageFormat.ToString().ToLower();
|
||||
string rootPath = Path.Combine(detectResult.ImageSaveDirectory,
|
||||
DateTime.Now.ToString("yyyyMMdd"), detectResult.DetectName);
|
||||
|
||||
try
|
||||
{
|
||||
if (detectResult.ResultState != ResultState.OK)
|
||||
{
|
||||
SaveNGImages(detectResult, rootPath, format);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveOKImages(detectResult, rootPath, format);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Logger.Error($"保存检测结果失败: {ex.Message}");
|
||||
}
|
||||
finally {
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
private void SaveNGImages(DetectStationResult result, string rootPath, string format)
|
||||
{
|
||||
// NG 原图
|
||||
if (result.SaveNGOriginal && result.DetectionOriginImage != null)
|
||||
{
|
||||
string prefix = Path.Combine(rootPath, "NGRawImages", result.ResultLabel);
|
||||
Directory.CreateDirectory(prefix);
|
||||
string fullname = Path.Combine(prefix, $"{result.Pid}_NGRawImage_{result.DetectName}_{result.Id}.{format}");
|
||||
SaveImageAsync(fullname, result.DetectionOriginImage, result.ImageFormat);
|
||||
}
|
||||
|
||||
// NG 结果图
|
||||
if (result.SaveOKDetect && result.DetectionOriginImage != null)
|
||||
{
|
||||
string displayTxt = BuildDisplayText(result);
|
||||
using (Bitmap resultMask = result.DetectionOriginImage.CopyBitmap())
|
||||
using (Bitmap preTreatedBitmap = result.DetectionOriginImage.CopyBitmap())
|
||||
{
|
||||
var detectionResultShapes = new List<IShapeElement>()
|
||||
{
|
||||
new DetectResultDisplay(result, resultMask, displayTxt)
|
||||
};
|
||||
|
||||
using (Bitmap resultMap = GetResultImage(resultMask, detectionResultShapes))
|
||||
using (Bitmap detectionFitImage = StaticHelper.HConnectBitmap(preTreatedBitmap, resultMap))
|
||||
{
|
||||
string prefix = Path.Combine(rootPath, "NGFitImages", result.ResultLabel);
|
||||
Directory.CreateDirectory(prefix);
|
||||
string fullname = Path.Combine(prefix, $"{result.Pid}_NGFitImage_{result.DetectName}_{result.Id}.{format}");
|
||||
SaveImageAsync(fullname, detectionFitImage, result.ImageFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void SaveOKImages(DetectStationResult result, string rootPath, string format)
|
||||
{
|
||||
// OK 原图
|
||||
if (result.SaveOKOriginal && result.DetectionOriginImage != null)
|
||||
{
|
||||
string prefix = Path.Combine(rootPath, "OKRawImages", result.ResultLabel);
|
||||
Directory.CreateDirectory(prefix);
|
||||
string fullname = Path.Combine(prefix, $"{result.Pid}_OKRawImage_{result.DetectName}_{result.Id}.{format}");
|
||||
SaveImageAsync(fullname, result.DetectionOriginImage, result.ImageFormat);
|
||||
}
|
||||
|
||||
// OK 结果图
|
||||
if (result.SaveOKDetect && result.DetectionOriginImage != null)
|
||||
{
|
||||
string displayTxt = BuildDisplayText(result);
|
||||
using (Bitmap resultMask = result.DetectionOriginImage.CopyBitmap())
|
||||
using (Bitmap preTreatedBitmap = result.DetectionOriginImage.CopyBitmap())
|
||||
{
|
||||
var detectionResultShapes = new List<IShapeElement>()
|
||||
{
|
||||
new DetectResultDisplay(result, resultMask, displayTxt)
|
||||
};
|
||||
|
||||
using (Bitmap resultMap = GetResultImage(resultMask, detectionResultShapes))
|
||||
using (Bitmap detectionFitImage = StaticHelper.HConnectBitmap(preTreatedBitmap, resultMap))
|
||||
{
|
||||
string prefix = Path.Combine(rootPath, "OKFitImages", result.ResultLabel);
|
||||
Directory.CreateDirectory(prefix);
|
||||
string fullname = Path.Combine(prefix, $"{result.Pid}_OKFitImage_{result.DetectName}_{result.Id}.{format}");
|
||||
SaveImageAsync(fullname, detectionFitImage, result.ImageFormat);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string BuildDisplayText(DetectStationResult result)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
result.DetectDetails.ForEach(d => sb.AppendLine($"{d.LabelName} score:{d.Score:f2} area:{d.Area:f2}"));
|
||||
if (result.realSpecs?.Count > 0)
|
||||
{
|
||||
result.realSpecs.ForEach(d => sb.AppendLine($"{d.Code} score:{d.ActualValue}"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,14 @@
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Optimize>False</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DH.Commons\DH.Commons.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -580,7 +580,7 @@ namespace DH.UI.Model.Winform
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public Rectangle BaseRectangle { get; set; }
|
||||
EnumHelper.ElementState IShapeElement.State { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
|
||||
public abstract bool IsMouseHover(PointF p);
|
||||
|
||||
|
@ -12,51 +12,7 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AntdUI" Version="1.8.9" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.185" />
|
||||
|
724
DHSoftware/MainWindow.Designer.cs
generated
724
DHSoftware/MainWindow.Designer.cs
generated
@ -28,32 +28,41 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AntdUI.Tabs.StyleCard styleCard3 = new AntdUI.Tabs.StyleCard();
|
||||
AntdUI.Tabs.StyleCard styleCard4 = new AntdUI.Tabs.StyleCard();
|
||||
AntdUI.Tabs.StyleLine styleLine2 = new AntdUI.Tabs.StyleLine();
|
||||
AntdUI.Tabs.StyleCard styleCard2 = new AntdUI.Tabs.StyleCard();
|
||||
AntdUI.SegmentedItem segmentedItem6 = new AntdUI.SegmentedItem();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow));
|
||||
AntdUI.SegmentedItem segmentedItem7 = new AntdUI.SegmentedItem();
|
||||
AntdUI.SegmentedItem segmentedItem8 = new AntdUI.SegmentedItem();
|
||||
AntdUI.SegmentedItem segmentedItem9 = new AntdUI.SegmentedItem();
|
||||
AntdUI.SegmentedItem segmentedItem10 = new AntdUI.SegmentedItem();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow));
|
||||
titlebar = new AntdUI.PageHeader();
|
||||
tabsStas=new AntdUI.Tabs();
|
||||
tabPage3=new AntdUI.TabPage();
|
||||
lbName = new AntdUI.Label();
|
||||
pageHeader1 = new AntdUI.PageHeader();
|
||||
labuph = new Label();
|
||||
tabMain=new AntdUI.TabPage();
|
||||
divider2 = new AntdUI.Divider();
|
||||
tabsStas = new AntdUI.Tabs();
|
||||
tabPage3 = new AntdUI.TabPage();
|
||||
panel7 = new Panel();
|
||||
tabMain = new AntdUI.TabPage();
|
||||
panelmain = new AntdUI.Panel();
|
||||
panel2 = new AntdUI.Panel();
|
||||
panel4 = new AntdUI.Panel();
|
||||
panel6 = new AntdUI.Panel();
|
||||
splitContainer1 = new SplitContainer();
|
||||
splitContainer2 = new SplitContainer();
|
||||
splitter2 = new AntdUI.Splitter();
|
||||
tabImgDisplay = new AntdUI.Tabs();
|
||||
richTextBox1 = new RichTextBox();
|
||||
tabsConfig = new AntdUI.Tabs();
|
||||
tabPage2 = new AntdUI.TabPage();
|
||||
splitter1 = new AntdUI.Splitter();
|
||||
pnlLog = new AntdUI.Panel();
|
||||
panel6 = new AntdUI.Panel();
|
||||
tableLayoutstatistics = new TableLayoutPanel();
|
||||
dgvCamreaNums = new DataGridView();
|
||||
panelNums = new AntdUI.Panel();
|
||||
tableLayoutNums = new TableLayoutPanel();
|
||||
dgvProductNums = new DataGridView();
|
||||
tableLayoutPanel3 = new TableLayoutPanel();
|
||||
lblTotalTime = new Label();
|
||||
label1 = new Label();
|
||||
label12 = new Label();
|
||||
lblUPH = new Label();
|
||||
lblStartTime = new Label();
|
||||
lblOEE_Total = new Label();
|
||||
label10 = new Label();
|
||||
label7 = new Label();
|
||||
panel2 = new AntdUI.Panel();
|
||||
panel1 = new AntdUI.Panel();
|
||||
panel3 = new AntdUI.Panel();
|
||||
btnDeleteProject = new AntdUI.Button();
|
||||
@ -61,35 +70,27 @@
|
||||
btnLoadProject = new AntdUI.Button();
|
||||
sltProjects = new AntdUI.Select();
|
||||
segmented1 = new AntdUI.Segmented();
|
||||
panel5 = new Panel();
|
||||
panel7 = new Panel();
|
||||
label2 = new Label();
|
||||
lblNum = new Label();
|
||||
lblUPH = new Label();
|
||||
label4 = new Label();
|
||||
lblstarttime = new Label();
|
||||
label6 = new Label();
|
||||
lblNowtime = new Label();
|
||||
label8 = new Label();
|
||||
titlebar.SuspendLayout();
|
||||
pageHeader1.SuspendLayout();
|
||||
tabsStas.SuspendLayout();
|
||||
tabPage3.SuspendLayout();
|
||||
panelmain.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
panel4.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)splitter2).BeginInit();
|
||||
splitter2.Panel1.SuspendLayout();
|
||||
splitter2.Panel2.SuspendLayout();
|
||||
splitter2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)splitter1).BeginInit();
|
||||
splitter1.Panel1.SuspendLayout();
|
||||
splitter1.Panel2.SuspendLayout();
|
||||
splitter1.SuspendLayout();
|
||||
panel6.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
||||
splitContainer1.Panel1.SuspendLayout();
|
||||
splitContainer1.Panel2.SuspendLayout();
|
||||
splitContainer1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer2).BeginInit();
|
||||
splitContainer2.Panel1.SuspendLayout();
|
||||
splitContainer2.Panel2.SuspendLayout();
|
||||
splitContainer2.SuspendLayout();
|
||||
tabsConfig.SuspendLayout();
|
||||
tableLayoutstatistics.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dgvCamreaNums).BeginInit();
|
||||
panelNums.SuspendLayout();
|
||||
tableLayoutNums.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dgvProductNums).BeginInit();
|
||||
tableLayoutPanel3.SuspendLayout();
|
||||
panel1.SuspendLayout();
|
||||
panel3.SuspendLayout();
|
||||
panel5.SuspendLayout();
|
||||
panel7.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// titlebar
|
||||
@ -122,127 +123,33 @@
|
||||
lbName.Text = "";
|
||||
lbName.TextAlign = ContentAlignment.MiddleRight;
|
||||
//
|
||||
// pageHeader1
|
||||
// tabsStas
|
||||
//
|
||||
pageHeader1.Controls.Add(labuph);
|
||||
pageHeader1.Controls.Add(divider2);
|
||||
pageHeader1.DividerShow = true;
|
||||
pageHeader1.Dock = DockStyle.Bottom;
|
||||
pageHeader1.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
pageHeader1.Location = new Point(0, 608);
|
||||
pageHeader1.Name = "pageHeader1";
|
||||
pageHeader1.Size = new Size(1024, 40);
|
||||
pageHeader1.TabIndex = 7;
|
||||
pageHeader1.Text = "UPH";
|
||||
tabsStas.Dock = DockStyle.Fill;
|
||||
tabsStas.Location = new Point(0, 0);
|
||||
tabsStas.Name = "tabsStas";
|
||||
tabsStas.Pages.Add(tabPage3);
|
||||
tabsStas.Size = new Size(580, 176);
|
||||
tabsStas.Style = styleLine2;
|
||||
tabsStas.TabIndex = 3;
|
||||
tabsStas.Text = "tabs3";
|
||||
//
|
||||
// labuph
|
||||
// tabPage3
|
||||
//
|
||||
labuph.AutoSize = true;
|
||||
labuph.Location = new Point(59, 10);
|
||||
labuph.Name = "labuph";
|
||||
labuph.Size = new Size(64, 21);
|
||||
labuph.TabIndex = 1;
|
||||
labuph.Text = "100000";
|
||||
tabPage3.Controls.Add(panel7);
|
||||
tabPage3.Location = new Point(3, 3);
|
||||
tabPage3.Name = "tabPage3";
|
||||
tabPage3.Size = new Size(574, 170);
|
||||
tabPage3.TabIndex = 0;
|
||||
tabPage3.Text = "日志";
|
||||
//
|
||||
// divider2
|
||||
// panel7
|
||||
//
|
||||
divider2.Dock = DockStyle.Top;
|
||||
divider2.Location = new Point(0, 0);
|
||||
divider2.Name = "divider2";
|
||||
divider2.OrientationMargin = 0F;
|
||||
divider2.Size = new Size(1024, 10);
|
||||
divider2.TabIndex = 0;
|
||||
divider2.Text = "";
|
||||
//
|
||||
// panelmain
|
||||
//
|
||||
panelmain.Controls.Add(panel2);
|
||||
panelmain.Controls.Add(panel1);
|
||||
panelmain.Dock = DockStyle.Fill;
|
||||
panelmain.Location = new Point(0, 40);
|
||||
panelmain.Margin = new Padding(0);
|
||||
panelmain.Name = "panelmain";
|
||||
panelmain.Size = new Size(1024, 568);
|
||||
panelmain.TabIndex = 8;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
panel2.Controls.Add(panel4);
|
||||
panel2.Dock = DockStyle.Fill;
|
||||
panel2.Location = new Point(0, 68);
|
||||
panel2.Name = "panel2";
|
||||
panel2.Size = new Size(1024, 500);
|
||||
panel2.TabIndex = 1;
|
||||
panel2.Text = "panel2";
|
||||
//
|
||||
// panel4
|
||||
//
|
||||
panel4.Controls.Add(panel6);
|
||||
panel4.Dock = DockStyle.Fill;
|
||||
panel4.Location = new Point(0, 0);
|
||||
panel4.Name = "panel4";
|
||||
panel4.Size = new Size(1024, 500);
|
||||
panel4.TabIndex = 1;
|
||||
panel4.Text = "panel4";
|
||||
//
|
||||
// panel6
|
||||
//
|
||||
panel6.Controls.Add(splitContainer1);
|
||||
panel6.Dock = DockStyle.Fill;
|
||||
panel6.Location = new Point(0, 0);
|
||||
panel6.Name = "panel6";
|
||||
panel6.Size = new Size(1024, 500);
|
||||
panel6.TabIndex = 1;
|
||||
panel6.Text = "panel6";
|
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
splitContainer1.BackColor = SystemColors.Control;
|
||||
splitContainer1.Dock = DockStyle.Fill;
|
||||
splitContainer1.Location = new Point(0, 0);
|
||||
splitContainer1.Name = "splitContainer1";
|
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
splitContainer1.Panel1.Controls.Add(splitContainer2);
|
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
splitContainer1.Panel2.BackColor = SystemColors.ButtonFace;
|
||||
splitContainer1.Panel2.Controls.Add(tabsConfig);
|
||||
splitContainer1.Size = new Size(1024, 500);
|
||||
splitContainer1.SplitterDistance = 606;
|
||||
splitContainer1.SplitterIncrement = 2;
|
||||
splitContainer1.SplitterWidth = 10;
|
||||
splitContainer1.TabIndex = 0;
|
||||
//
|
||||
// splitContainer2
|
||||
//
|
||||
splitContainer2.Dock = DockStyle.Fill;
|
||||
splitContainer2.Location = new Point(0, 0);
|
||||
splitContainer2.Name = "splitContainer2";
|
||||
splitContainer2.Orientation = Orientation.Horizontal;
|
||||
//
|
||||
// splitContainer2.Panel1
|
||||
//
|
||||
splitContainer2.Panel1.Controls.Add(tabImgDisplay);
|
||||
//
|
||||
// splitContainer2.Panel2
|
||||
//
|
||||
splitContainer2.Panel2.Controls.Add(richTextBox1);
|
||||
splitContainer2.Size = new Size(606, 500);
|
||||
splitContainer2.SplitterDistance = 320;
|
||||
splitContainer2.TabIndex = 0;
|
||||
//
|
||||
// tabImgDisplay
|
||||
//
|
||||
tabImgDisplay.Dock = DockStyle.Fill;
|
||||
tabImgDisplay.Location = new Point(0, 0);
|
||||
tabImgDisplay.Name = "tabImgDisplay";
|
||||
tabImgDisplay.Size = new Size(606, 320);
|
||||
tabImgDisplay.Style = styleCard3;
|
||||
tabImgDisplay.TabIndex = 1;
|
||||
tabImgDisplay.Text = "tabs1";
|
||||
panel7.Dock = DockStyle.Fill;
|
||||
panel7.Location = new Point(0, 0);
|
||||
panel7.Name = "panel7";
|
||||
panel7.Size = new Size(574, 170);
|
||||
panel7.TabIndex = 2;
|
||||
//
|
||||
// tabMain
|
||||
//
|
||||
@ -252,54 +159,289 @@
|
||||
tabMain.TabIndex = 0;
|
||||
tabMain.Text = "检测";
|
||||
//
|
||||
// tabsStas
|
||||
// panelmain
|
||||
//
|
||||
tabsStas.Dock = DockStyle.Fill;
|
||||
tabsStas.Location = new Point(0, 0);
|
||||
tabsStas.Name = "tabsStas";
|
||||
tabsStas.Pages.Add(tabPage3);
|
||||
tabsStas.Size = new Size(580, 176);
|
||||
tabsStas.TabIndex = 3;
|
||||
tabsStas.Text = "tabs3";
|
||||
panelmain.Controls.Add(splitter2);
|
||||
panelmain.Controls.Add(panel2);
|
||||
panelmain.Controls.Add(panel1);
|
||||
panelmain.Dock = DockStyle.Fill;
|
||||
panelmain.Location = new Point(0, 40);
|
||||
panelmain.Margin = new Padding(0);
|
||||
panelmain.Name = "panelmain";
|
||||
panelmain.Size = new Size(1024, 631);
|
||||
panelmain.TabIndex = 8;
|
||||
//
|
||||
// tabPage3
|
||||
// splitter2
|
||||
//
|
||||
tabPage3.Controls.Add(panel7);
|
||||
tabPage3.Controls.Add(panel5);
|
||||
tabPage3.Location = new Point(3, 28);
|
||||
tabPage3.Name = "tabPage3";
|
||||
tabPage3.Size = new Size(574, 145);
|
||||
tabPage3.TabIndex = 0;
|
||||
tabPage3.Text = "日志";
|
||||
splitter2.Dock = DockStyle.Fill;
|
||||
splitter2.Location = new Point(0, 68);
|
||||
splitter2.Name = "splitter2";
|
||||
splitter2.Orientation = Orientation.Horizontal;
|
||||
//
|
||||
// richTextBox1
|
||||
// splitter2.Panel1
|
||||
//
|
||||
richTextBox1.Dock = DockStyle.Fill;
|
||||
richTextBox1.Location = new Point(0, 0);
|
||||
richTextBox1.Name = "richTextBox1";
|
||||
richTextBox1.Size = new Size(374, 145);
|
||||
richTextBox1.TabIndex = 0;
|
||||
richTextBox1.Text = "";
|
||||
richTextBox1.TextChanged += richTextBox1_TextChanged;
|
||||
splitter2.Panel1.Controls.Add(tabImgDisplay);
|
||||
//
|
||||
// tabsConfig
|
||||
// splitter2.Panel2
|
||||
//
|
||||
tabsConfig.Dock = DockStyle.Fill;
|
||||
tabsConfig.Location = new Point(0, 0);
|
||||
tabsConfig.Name = "tabsConfig";
|
||||
tabsConfig.Pages.Add(tabPage2);
|
||||
tabsConfig.Size = new Size(408, 500);
|
||||
tabsConfig.Style = styleCard4;
|
||||
tabsConfig.TabIndex = 2;
|
||||
tabsConfig.Text = "tabs2";
|
||||
splitter2.Panel2.Controls.Add(splitter1);
|
||||
splitter2.Size = new Size(1024, 563);
|
||||
splitter2.SplitterDistance = 442;
|
||||
splitter2.TabIndex = 4;
|
||||
//
|
||||
// tabPage2
|
||||
// tabImgDisplay
|
||||
//
|
||||
tabPage2.Location = new Point(3, 28);
|
||||
tabPage2.Name = "tabPage2";
|
||||
tabPage2.Size = new Size(402, 469);
|
||||
tabPage2.TabIndex = 0;
|
||||
tabPage2.Text = "配置";
|
||||
tabImgDisplay.Dock = DockStyle.Fill;
|
||||
tabImgDisplay.Location = new Point(0, 0);
|
||||
tabImgDisplay.Name = "tabImgDisplay";
|
||||
tabImgDisplay.Size = new Size(1024, 442);
|
||||
tabImgDisplay.Style = styleCard2;
|
||||
tabImgDisplay.TabIndex = 3;
|
||||
tabImgDisplay.Text = "tabs1";
|
||||
//
|
||||
// splitter1
|
||||
//
|
||||
splitter1.Dock = DockStyle.Fill;
|
||||
splitter1.Location = new Point(0, 0);
|
||||
splitter1.Name = "splitter1";
|
||||
//
|
||||
// splitter1.Panel1
|
||||
//
|
||||
splitter1.Panel1.Controls.Add(pnlLog);
|
||||
//
|
||||
// splitter1.Panel2
|
||||
//
|
||||
splitter1.Panel2.Controls.Add(panel6);
|
||||
splitter1.Size = new Size(1024, 117);
|
||||
splitter1.SplitterDistance = 332;
|
||||
splitter1.TabIndex = 3;
|
||||
//
|
||||
// pnlLog
|
||||
//
|
||||
pnlLog.Dock = DockStyle.Fill;
|
||||
pnlLog.Location = new Point(0, 0);
|
||||
pnlLog.Name = "pnlLog";
|
||||
pnlLog.Size = new Size(332, 117);
|
||||
pnlLog.TabIndex = 2;
|
||||
pnlLog.Text = "panel8";
|
||||
//
|
||||
// panel6
|
||||
//
|
||||
panel6.Controls.Add(tableLayoutstatistics);
|
||||
panel6.Dock = DockStyle.Fill;
|
||||
panel6.Location = new Point(0, 0);
|
||||
panel6.Name = "panel6";
|
||||
panel6.Size = new Size(688, 117);
|
||||
panel6.TabIndex = 0;
|
||||
panel6.Text = "panel6";
|
||||
//
|
||||
// tableLayoutstatistics
|
||||
//
|
||||
tableLayoutstatistics.ColumnCount = 2;
|
||||
tableLayoutstatistics.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
tableLayoutstatistics.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
tableLayoutstatistics.Controls.Add(dgvCamreaNums, 0, 0);
|
||||
tableLayoutstatistics.Controls.Add(panelNums, 1, 0);
|
||||
tableLayoutstatistics.Dock = DockStyle.Fill;
|
||||
tableLayoutstatistics.Location = new Point(0, 0);
|
||||
tableLayoutstatistics.Name = "tableLayoutstatistics";
|
||||
tableLayoutstatistics.RowCount = 1;
|
||||
tableLayoutstatistics.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
||||
tableLayoutstatistics.Size = new Size(688, 117);
|
||||
tableLayoutstatistics.TabIndex = 9;
|
||||
//
|
||||
// dgvCamreaNums
|
||||
//
|
||||
dgvCamreaNums.AllowUserToAddRows = false;
|
||||
dgvCamreaNums.AllowUserToDeleteRows = false;
|
||||
dgvCamreaNums.AllowUserToResizeColumns = false;
|
||||
dgvCamreaNums.AllowUserToResizeRows = false;
|
||||
dgvCamreaNums.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dgvCamreaNums.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
||||
dgvCamreaNums.BackgroundColor = SystemColors.Control;
|
||||
dgvCamreaNums.BorderStyle = BorderStyle.None;
|
||||
dgvCamreaNums.CellBorderStyle = DataGridViewCellBorderStyle.SunkenHorizontal;
|
||||
dgvCamreaNums.ColumnHeadersHeight = 4;
|
||||
dgvCamreaNums.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
||||
dgvCamreaNums.ColumnHeadersVisible = false;
|
||||
dgvCamreaNums.Dock = DockStyle.Fill;
|
||||
dgvCamreaNums.Location = new Point(3, 3);
|
||||
dgvCamreaNums.MultiSelect = false;
|
||||
dgvCamreaNums.Name = "dgvCamreaNums";
|
||||
dgvCamreaNums.ReadOnly = true;
|
||||
dgvCamreaNums.RowHeadersVisible = false;
|
||||
dgvCamreaNums.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dgvCamreaNums.Size = new Size(338, 111);
|
||||
dgvCamreaNums.TabIndex = 9;
|
||||
//
|
||||
// panelNums
|
||||
//
|
||||
panelNums.Controls.Add(tableLayoutNums);
|
||||
panelNums.Dock = DockStyle.Fill;
|
||||
panelNums.Location = new Point(347, 3);
|
||||
panelNums.Name = "panelNums";
|
||||
panelNums.Size = new Size(338, 111);
|
||||
panelNums.TabIndex = 8;
|
||||
panelNums.Text = "panel4";
|
||||
//
|
||||
// tableLayoutNums
|
||||
//
|
||||
tableLayoutNums.ColumnCount = 1;
|
||||
tableLayoutNums.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
|
||||
tableLayoutNums.Controls.Add(dgvProductNums, 0, 0);
|
||||
tableLayoutNums.Controls.Add(tableLayoutPanel3, 0, 1);
|
||||
tableLayoutNums.Dock = DockStyle.Fill;
|
||||
tableLayoutNums.Location = new Point(0, 0);
|
||||
tableLayoutNums.Name = "tableLayoutNums";
|
||||
tableLayoutNums.RowCount = 2;
|
||||
tableLayoutNums.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
||||
tableLayoutNums.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
||||
tableLayoutNums.Size = new Size(338, 111);
|
||||
tableLayoutNums.TabIndex = 8;
|
||||
//
|
||||
// dgvProductNums
|
||||
//
|
||||
dgvProductNums.AllowUserToAddRows = false;
|
||||
dgvProductNums.AllowUserToDeleteRows = false;
|
||||
dgvProductNums.AllowUserToResizeColumns = false;
|
||||
dgvProductNums.AllowUserToResizeRows = false;
|
||||
dgvProductNums.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dgvProductNums.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
||||
dgvProductNums.BackgroundColor = SystemColors.Control;
|
||||
dgvProductNums.BorderStyle = BorderStyle.None;
|
||||
dgvProductNums.CellBorderStyle = DataGridViewCellBorderStyle.SunkenHorizontal;
|
||||
dgvProductNums.ColumnHeadersHeight = 4;
|
||||
dgvProductNums.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
||||
dgvProductNums.ColumnHeadersVisible = false;
|
||||
dgvProductNums.Dock = DockStyle.Fill;
|
||||
dgvProductNums.Location = new Point(3, 3);
|
||||
dgvProductNums.MultiSelect = false;
|
||||
dgvProductNums.Name = "dgvProductNums";
|
||||
dgvProductNums.ReadOnly = true;
|
||||
dgvProductNums.RowHeadersVisible = false;
|
||||
dgvProductNums.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dgvProductNums.Size = new Size(332, 49);
|
||||
dgvProductNums.TabIndex = 10;
|
||||
//
|
||||
// tableLayoutPanel3
|
||||
//
|
||||
tableLayoutPanel3.ColumnCount = 4;
|
||||
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 81F));
|
||||
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 75F));
|
||||
tableLayoutPanel3.Controls.Add(lblTotalTime, 1, 1);
|
||||
tableLayoutPanel3.Controls.Add(label1, 2, 1);
|
||||
tableLayoutPanel3.Controls.Add(label12, 0, 1);
|
||||
tableLayoutPanel3.Controls.Add(lblUPH, 3, 1);
|
||||
tableLayoutPanel3.Controls.Add(lblStartTime, 1, 0);
|
||||
tableLayoutPanel3.Controls.Add(lblOEE_Total, 3, 0);
|
||||
tableLayoutPanel3.Controls.Add(label10, 0, 0);
|
||||
tableLayoutPanel3.Controls.Add(label7, 2, 0);
|
||||
tableLayoutPanel3.Dock = DockStyle.Fill;
|
||||
tableLayoutPanel3.Location = new Point(3, 58);
|
||||
tableLayoutPanel3.Name = "tableLayoutPanel3";
|
||||
tableLayoutPanel3.RowCount = 2;
|
||||
tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
||||
tableLayoutPanel3.Size = new Size(332, 50);
|
||||
tableLayoutPanel3.TabIndex = 11;
|
||||
//
|
||||
// lblTotalTime
|
||||
//
|
||||
lblTotalTime.AutoSize = true;
|
||||
lblTotalTime.Dock = DockStyle.Fill;
|
||||
lblTotalTime.Location = new Point(91, 25);
|
||||
lblTotalTime.Name = "lblTotalTime";
|
||||
lblTotalTime.Size = new Size(82, 25);
|
||||
lblTotalTime.TabIndex = 15;
|
||||
lblTotalTime.Text = "0";
|
||||
lblTotalTime.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Dock = DockStyle.Fill;
|
||||
label1.Location = new Point(179, 25);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(75, 25);
|
||||
label1.TabIndex = 8;
|
||||
label1.Text = "UPH";
|
||||
label1.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label12
|
||||
//
|
||||
label12.AutoSize = true;
|
||||
label12.Dock = DockStyle.Fill;
|
||||
label12.Location = new Point(3, 25);
|
||||
label12.Name = "label12";
|
||||
label12.Size = new Size(82, 25);
|
||||
label12.TabIndex = 14;
|
||||
label12.Text = "运行时间";
|
||||
label12.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lblUPH
|
||||
//
|
||||
lblUPH.AutoSize = true;
|
||||
lblUPH.Dock = DockStyle.Fill;
|
||||
lblUPH.Location = new Point(260, 25);
|
||||
lblUPH.Name = "lblUPH";
|
||||
lblUPH.Size = new Size(69, 25);
|
||||
lblUPH.TabIndex = 9;
|
||||
lblUPH.Text = "0";
|
||||
lblUPH.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lblStartTime
|
||||
//
|
||||
lblStartTime.AutoSize = true;
|
||||
lblStartTime.Dock = DockStyle.Fill;
|
||||
lblStartTime.Location = new Point(91, 0);
|
||||
lblStartTime.Name = "lblStartTime";
|
||||
lblStartTime.Size = new Size(82, 25);
|
||||
lblStartTime.TabIndex = 11;
|
||||
lblStartTime.Text = "0";
|
||||
lblStartTime.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lblOEE_Total
|
||||
//
|
||||
lblOEE_Total.AutoSize = true;
|
||||
lblOEE_Total.Dock = DockStyle.Fill;
|
||||
lblOEE_Total.Location = new Point(260, 0);
|
||||
lblOEE_Total.Name = "lblOEE_Total";
|
||||
lblOEE_Total.Size = new Size(69, 25);
|
||||
lblOEE_Total.TabIndex = 13;
|
||||
lblOEE_Total.Text = "0";
|
||||
lblOEE_Total.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label10
|
||||
//
|
||||
label10.AutoSize = true;
|
||||
label10.Dock = DockStyle.Fill;
|
||||
label10.Location = new Point(3, 0);
|
||||
label10.Name = "label10";
|
||||
label10.Size = new Size(82, 25);
|
||||
label10.TabIndex = 12;
|
||||
label10.Text = "开始时间";
|
||||
label10.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label7
|
||||
//
|
||||
label7.AutoSize = true;
|
||||
label7.Dock = DockStyle.Fill;
|
||||
label7.Location = new Point(179, 0);
|
||||
label7.Name = "label7";
|
||||
label7.Size = new Size(75, 25);
|
||||
label7.TabIndex = 10;
|
||||
label7.Text = "总计数";
|
||||
label7.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
panel2.Location = new Point(511, 86);
|
||||
panel2.Name = "panel2";
|
||||
panel2.Size = new Size(814, 364);
|
||||
panel2.TabIndex = 3;
|
||||
panel2.Text = "panel2";
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
@ -386,8 +528,6 @@
|
||||
segmentedItem6.BadgeOffsetY = 0;
|
||||
segmentedItem6.BadgeSize = 0.6F;
|
||||
segmentedItem6.BadgeSvg = null;
|
||||
segmentedItem6.IconActiveSvg = resources.GetString("segmentedItem6.IconActiveSvg");
|
||||
segmentedItem6.IconSvg = resources.GetString("segmentedItem6.IconSvg");
|
||||
segmentedItem6.Text = "启动";
|
||||
segmentedItem7.Badge = null;
|
||||
segmentedItem7.BadgeAlign = AntdUI.TAlignFrom.TR;
|
||||
@ -397,8 +537,6 @@
|
||||
segmentedItem7.BadgeOffsetY = 0;
|
||||
segmentedItem7.BadgeSize = 0.6F;
|
||||
segmentedItem7.BadgeSvg = null;
|
||||
segmentedItem7.IconActiveSvg = resources.GetString("segmentedItem7.IconActiveSvg");
|
||||
segmentedItem7.IconSvg = resources.GetString("segmentedItem7.IconSvg");
|
||||
segmentedItem7.Text = "停止";
|
||||
segmentedItem8.Badge = null;
|
||||
segmentedItem8.BadgeAlign = AntdUI.TAlignFrom.TR;
|
||||
@ -408,8 +546,6 @@
|
||||
segmentedItem8.BadgeOffsetY = 0;
|
||||
segmentedItem8.BadgeSize = 0.6F;
|
||||
segmentedItem8.BadgeSvg = null;
|
||||
segmentedItem8.IconActiveSvg = resources.GetString("segmentedItem8.IconActiveSvg");
|
||||
segmentedItem8.IconSvg = resources.GetString("segmentedItem8.IconSvg");
|
||||
segmentedItem8.Text = "复位";
|
||||
segmentedItem9.Badge = null;
|
||||
segmentedItem9.BadgeAlign = AntdUI.TAlignFrom.TR;
|
||||
@ -419,8 +555,6 @@
|
||||
segmentedItem9.BadgeOffsetY = 0;
|
||||
segmentedItem9.BadgeSize = 0.6F;
|
||||
segmentedItem9.BadgeSvg = null;
|
||||
segmentedItem9.IconActiveSvg = resources.GetString("segmentedItem9.IconActiveSvg");
|
||||
segmentedItem9.IconSvg = resources.GetString("segmentedItem9.IconSvg");
|
||||
segmentedItem9.Text = "登录";
|
||||
segmentedItem10.Badge = null;
|
||||
segmentedItem10.BadgeAlign = AntdUI.TAlignFrom.TR;
|
||||
@ -430,8 +564,6 @@
|
||||
segmentedItem10.BadgeOffsetY = 0;
|
||||
segmentedItem10.BadgeSize = 0.6F;
|
||||
segmentedItem10.BadgeSvg = null;
|
||||
segmentedItem10.IconActiveSvg = resources.GetString("segmentedItem10.IconActiveSvg");
|
||||
segmentedItem10.IconSvg = resources.GetString("segmentedItem10.IconSvg");
|
||||
segmentedItem10.Text = "设置";
|
||||
segmented1.Items.Add(segmentedItem6);
|
||||
segmented1.Items.Add(segmentedItem7);
|
||||
@ -445,109 +577,11 @@
|
||||
segmented1.Text = "segmented1";
|
||||
segmented1.SelectIndexChanged += segmented1_SelectIndexChanged;
|
||||
//
|
||||
// panel5
|
||||
//
|
||||
panel5.Controls.Add(lblNowtime);
|
||||
panel5.Controls.Add(label8);
|
||||
panel5.Controls.Add(lblstarttime);
|
||||
panel5.Controls.Add(label6);
|
||||
panel5.Controls.Add(lblUPH);
|
||||
panel5.Controls.Add(label4);
|
||||
panel5.Controls.Add(lblNum);
|
||||
panel5.Controls.Add(label2);
|
||||
panel5.Dock = DockStyle.Right;
|
||||
panel5.Location = new Point(374, 0);
|
||||
panel5.Name = "panel5";
|
||||
panel5.Size = new Size(200, 145);
|
||||
panel5.TabIndex = 1;
|
||||
//
|
||||
// panel7
|
||||
//
|
||||
panel7.Controls.Add(richTextBox1);
|
||||
panel7.Dock = DockStyle.Fill;
|
||||
panel7.Location = new Point(0, 0);
|
||||
panel7.Name = "panel7";
|
||||
panel7.Size = new Size(374, 145);
|
||||
panel7.TabIndex = 2;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(7, 75);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(32, 17);
|
||||
label2.TabIndex = 0;
|
||||
label2.Text = "总数";
|
||||
//
|
||||
// lblNum
|
||||
//
|
||||
lblNum.AutoSize = true;
|
||||
lblNum.Location = new Point(70, 75);
|
||||
lblNum.Name = "lblNum";
|
||||
lblNum.Size = new Size(15, 17);
|
||||
lblNum.TabIndex = 1;
|
||||
lblNum.Text = "0";
|
||||
//
|
||||
// lblUPH
|
||||
//
|
||||
lblUPH.AutoSize = true;
|
||||
lblUPH.Location = new Point(70, 105);
|
||||
lblUPH.Name = "lblUPH";
|
||||
lblUPH.Size = new Size(15, 17);
|
||||
lblUPH.TabIndex = 3;
|
||||
lblUPH.Text = "0";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(7, 105);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(33, 17);
|
||||
label4.TabIndex = 2;
|
||||
label4.Text = "UPH";
|
||||
//
|
||||
// lblstarttime
|
||||
//
|
||||
lblstarttime.AutoSize = true;
|
||||
lblstarttime.Location = new Point(69, 15);
|
||||
lblstarttime.Name = "lblstarttime";
|
||||
lblstarttime.Size = new Size(15, 17);
|
||||
lblstarttime.TabIndex = 5;
|
||||
lblstarttime.Text = "0";
|
||||
//
|
||||
// label6
|
||||
//
|
||||
label6.AutoSize = true;
|
||||
label6.Location = new Point(7, 15);
|
||||
label6.Name = "label6";
|
||||
label6.Size = new Size(56, 17);
|
||||
label6.TabIndex = 4;
|
||||
label6.Text = "开始时间";
|
||||
//
|
||||
// lblNowtime
|
||||
//
|
||||
lblNowtime.AutoSize = true;
|
||||
lblNowtime.Location = new Point(69, 41);
|
||||
lblNowtime.Name = "lblNowtime";
|
||||
lblNowtime.Size = new Size(15, 17);
|
||||
lblNowtime.TabIndex = 7;
|
||||
lblNowtime.Text = "0";
|
||||
//
|
||||
// label8
|
||||
//
|
||||
label8.AutoSize = true;
|
||||
label8.Location = new Point(7, 41);
|
||||
label8.Name = "label8";
|
||||
label8.Size = new Size(56, 17);
|
||||
label8.TabIndex = 6;
|
||||
label8.Text = "此刻时间";
|
||||
//
|
||||
// MainWindow
|
||||
//
|
||||
ClientSize = new Size(1024, 648);
|
||||
ClientSize = new Size(1024, 671);
|
||||
ControlBox = false;
|
||||
Controls.Add(panelmain);
|
||||
Controls.Add(pageHeader1);
|
||||
Controls.Add(titlebar);
|
||||
Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
Icon = (Icon)resources.GetObject("$this.Icon");
|
||||
@ -558,47 +592,38 @@
|
||||
FormClosing += MainWindow_FormClosing;
|
||||
Load += MainWindow_Load;
|
||||
titlebar.ResumeLayout(false);
|
||||
pageHeader1.ResumeLayout(false);
|
||||
pageHeader1.PerformLayout();
|
||||
tabsStas.ResumeLayout(false);
|
||||
tabPage3.ResumeLayout(false);
|
||||
panelmain.ResumeLayout(false);
|
||||
panel2.ResumeLayout(false);
|
||||
panel4.ResumeLayout(false);
|
||||
splitter2.Panel1.ResumeLayout(false);
|
||||
splitter2.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)splitter2).EndInit();
|
||||
splitter2.ResumeLayout(false);
|
||||
splitter1.Panel1.ResumeLayout(false);
|
||||
splitter1.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)splitter1).EndInit();
|
||||
splitter1.ResumeLayout(false);
|
||||
panel6.ResumeLayout(false);
|
||||
splitContainer1.Panel1.ResumeLayout(false);
|
||||
splitContainer1.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
|
||||
splitContainer1.ResumeLayout(false);
|
||||
splitContainer2.Panel1.ResumeLayout(false);
|
||||
splitContainer2.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)splitContainer2).EndInit();
|
||||
splitContainer2.ResumeLayout(false);
|
||||
tabsConfig.ResumeLayout(false);
|
||||
tableLayoutstatistics.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dgvCamreaNums).EndInit();
|
||||
panelNums.ResumeLayout(false);
|
||||
tableLayoutNums.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dgvProductNums).EndInit();
|
||||
tableLayoutPanel3.ResumeLayout(false);
|
||||
tableLayoutPanel3.PerformLayout();
|
||||
panel1.ResumeLayout(false);
|
||||
panel3.ResumeLayout(false);
|
||||
panel5.ResumeLayout(false);
|
||||
panel5.PerformLayout();
|
||||
panel7.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private AntdUI.PageHeader titlebar;
|
||||
private AntdUI.PageHeader pageHeader1;
|
||||
private AntdUI.Divider divider2;
|
||||
private AntdUI.Panel panelmain;
|
||||
private AntdUI.Panel panel1;
|
||||
private AntdUI.Segmented segmented1;
|
||||
private AntdUI.Panel panel2;
|
||||
private AntdUI.Panel panel4;
|
||||
private AntdUI.Panel panel6;
|
||||
private Label labuph;
|
||||
private AntdUI.Splitter splitter1;
|
||||
private SplitContainer splitContainer1;
|
||||
private SplitContainer splitContainer2;
|
||||
private AntdUI.Tabs tabImgDisplay;
|
||||
private AntdUI.Tabs tabsConfig;
|
||||
private AntdUI.TabPage tabPage2;
|
||||
|
||||
private AntdUI.Label lbName;
|
||||
private AntdUI.Panel panel3;
|
||||
private AntdUI.Button btnDeleteProject;
|
||||
@ -606,19 +631,36 @@
|
||||
private AntdUI.Button btnLoadProject;
|
||||
public AntdUI.Select sltProjects;
|
||||
private Panel panel7;
|
||||
private Panel panel5;
|
||||
private Label lblNum;
|
||||
private Label label2;
|
||||
private Label lblNowtime;
|
||||
private Label label8;
|
||||
private Label lblstarttime;
|
||||
private Label label6;
|
||||
private Label lblUPH;
|
||||
// private Panel panel5;
|
||||
// private Label lblNum;
|
||||
// private Label label2;
|
||||
// private Label lblNowtime;
|
||||
// private Label label8;
|
||||
// private Label lblstarttime;
|
||||
// private Label label6;
|
||||
// private Label lblUPH;
|
||||
private Label label4;
|
||||
private RichTextBox richTextBox1;
|
||||
private AntdUI.TabPage tabPage3;
|
||||
private AntdUI.TabPage tabMain;
|
||||
private AntdUI.Tabs tabsStas;
|
||||
private AntdUI.Panel panel2;
|
||||
private AntdUI.Tabs tabImgDisplay;
|
||||
private AntdUI.Panel panel6;
|
||||
private AntdUI.Panel pnlLog;
|
||||
private AntdUI.Splitter splitter2;
|
||||
private TableLayoutPanel tableLayoutstatistics;
|
||||
private AntdUI.Panel panelNums;
|
||||
private DataGridView dgvCamreaNums;
|
||||
private TableLayoutPanel tableLayoutNums;
|
||||
private Label label1;
|
||||
private Label lblTotalTime;
|
||||
private Label lblUPH;
|
||||
private Label label12;
|
||||
private Label label7;
|
||||
private Label lblOEE_Total;
|
||||
private Label lblStartTime;
|
||||
private Label label10;
|
||||
private DataGridView dgvProductNums;
|
||||
private TableLayoutPanel tableLayoutPanel3;
|
||||
}
|
||||
}
|
@ -14,15 +14,19 @@ using DHSoftware.Utils;
|
||||
using DHSoftware.Views;
|
||||
using DVPCameraType;
|
||||
using HalconDotNet;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using Microsoft.Win32;
|
||||
using OpenCvSharp;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@ -32,13 +36,23 @@ using XKRS.UI.Device.Winform;
|
||||
using static AntdUI.Math3D;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
using Camera = DHSoftware.Models.Camera;
|
||||
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
|
||||
using ResultState = DH.Commons.Base.ResultState;
|
||||
using Timer = System.Threading.Timer;
|
||||
|
||||
namespace DHSoftware
|
||||
{
|
||||
public partial class MainWindow : AntdUI.Window
|
||||
{
|
||||
System.Windows.Forms.Timer _refreshUITimer = new System.Windows.Forms.Timer();
|
||||
private Dictionary<string, List<string>> _cameraRelatedDetectionDict = null;
|
||||
public event Action<LogMsg> OnLog;
|
||||
|
||||
public List<CameraSummary> CameraSummaries { get; set; } = new List<CameraSummary>();
|
||||
public List<ProductSummary> ProductSummaries { get; set; } = new List<ProductSummary>();
|
||||
static object _productSummaryLock = new object();
|
||||
public event Action<DateTime, object, string> OnUpdateResult;
|
||||
public event Action<DateTime, object, string> OnUpdateCamResult;
|
||||
|
||||
private string _loginName;
|
||||
|
||||
@ -170,8 +184,7 @@ namespace DHSoftware
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
//refreshTimer.Start();
|
||||
InitialCameraSumsView(); //refreshTimer.Start();
|
||||
//初始化数据
|
||||
InitData();
|
||||
//绑定事件
|
||||
@ -182,6 +195,317 @@ namespace DHSoftware
|
||||
//userControlFrm.Dock = DockStyle.Fill;
|
||||
//tabPage2.Controls.Add(userControlFrm);
|
||||
}
|
||||
//#region OEE
|
||||
// public event Action<RunState> OnProcessRunStateChanged;
|
||||
#region INotifyPropertyChanged
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public virtual void Set<T>(ref T field, T newValue, [CallerMemberName] string propName = null)
|
||||
{
|
||||
if (!field.Equals(newValue))
|
||||
{
|
||||
field = newValue;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Properties
|
||||
private int uph = 0;
|
||||
private int upm = 0;
|
||||
|
||||
private DateTime? startTime = null;
|
||||
private TimeSpan runTime = new TimeSpan();
|
||||
private TimeSpan idleTime = new TimeSpan();
|
||||
private TimeSpan downTime = new TimeSpan();
|
||||
private TimeSpan totalTime = new TimeSpan();
|
||||
private int qty_OEE = 0;
|
||||
private int qty_OEE_OK = 0;
|
||||
private float oee = 0;
|
||||
|
||||
public int UPH
|
||||
{
|
||||
get => uph;
|
||||
set => Set(ref uph, value);
|
||||
}
|
||||
public int UPM
|
||||
{
|
||||
get => upm;
|
||||
set => Set(ref upm, value);
|
||||
}
|
||||
public DateTime? StartTime
|
||||
{
|
||||
get => startTime;
|
||||
set => Set(ref startTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有效运行时间
|
||||
/// </summary>
|
||||
public TimeSpan RunTime
|
||||
{
|
||||
get => runTime;
|
||||
set => Set(ref runTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 空闲待机时间
|
||||
/// </summary>
|
||||
public TimeSpan IdleTime
|
||||
{
|
||||
get => idleTime;
|
||||
set => Set(ref idleTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 故障宕机时间
|
||||
/// </summary>
|
||||
public TimeSpan DownTime
|
||||
{
|
||||
get => downTime;
|
||||
set => Set(ref downTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 总开机时间
|
||||
/// </summary>
|
||||
public TimeSpan TotalTime
|
||||
{
|
||||
get => totalTime;
|
||||
set => Set(ref totalTime, value);
|
||||
}
|
||||
|
||||
public float OEE
|
||||
{
|
||||
get => oee;
|
||||
set => Set(ref oee, value);
|
||||
}
|
||||
#endregion
|
||||
#region Timer
|
||||
System.Threading.Timer _runTimer = null;
|
||||
System.Threading.Timer _idleTimer = null;
|
||||
System.Threading.Timer _downTimer = null;
|
||||
System.Threading.Timer _checkIdleTimer = null;
|
||||
//System.Threading.Timer _calculateTimer = null;
|
||||
|
||||
private RunState? currentState = null;
|
||||
public RunState? CurrentState
|
||||
{
|
||||
get => currentState;
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (value.Value == RunState.Running)
|
||||
{
|
||||
_checkIdleTimer?.Change(10 * 1000, -1);
|
||||
}
|
||||
|
||||
if (currentState != value.Value)
|
||||
{
|
||||
switch (currentState)
|
||||
{
|
||||
case RunState.Idle:
|
||||
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Idle, false);
|
||||
break;
|
||||
case RunState.Down:
|
||||
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Down, false);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (value.Value)
|
||||
{
|
||||
case RunState.Stop:
|
||||
_runTimer?.Change(-1, -1);
|
||||
_idleTimer?.Change(-1, -1);
|
||||
_downTimer?.Change(-1, -1);
|
||||
break;
|
||||
case RunState.Running:
|
||||
_idleTimer?.Change(-1, -1);
|
||||
_downTimer?.Change(-1, -1);
|
||||
_runTimer?.Change(0, 1000);
|
||||
break;
|
||||
case RunState.Idle:
|
||||
_runTimer?.Change(-1, -1);
|
||||
_downTimer?.Change(-1, -1);
|
||||
_idleTimer?.Change(0, 1000);
|
||||
|
||||
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Idle, true);
|
||||
break;
|
||||
case RunState.Down:
|
||||
_idleTimer?.Change(-1, -1);
|
||||
_runTimer?.Change(-1, -1);
|
||||
_downTimer?.Change(0, 1000);
|
||||
|
||||
//AddRunEventInBuffer(DateTime.Now, RunEvent_EventType.Down, true);
|
||||
break;
|
||||
}
|
||||
|
||||
currentState = value;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckIdleTimeStart(object state)
|
||||
{
|
||||
if (CurrentState == RunState.Running)
|
||||
{
|
||||
RunTime = RunTime.Add(new TimeSpan(0, 0, 0 - 10));
|
||||
IdleTime = IdleTime.Add(new TimeSpan(0, 0, 10));
|
||||
|
||||
CurrentState = RunState.Idle;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitialOEEStatistic()
|
||||
{
|
||||
InitialStatisticTimers();
|
||||
ResetOEETimeDistribute();
|
||||
ResetProductSummaries();
|
||||
}
|
||||
|
||||
public void ResetProductSummaries()
|
||||
{
|
||||
ProductSummaries = new List<ProductSummary>();
|
||||
}
|
||||
private void InitialStatisticTimers()
|
||||
{
|
||||
if (_checkIdleTimer == null)
|
||||
{
|
||||
_checkIdleTimer = new Timer(new TimerCallback(CheckIdleTimeStart), null, -1, -1);
|
||||
}
|
||||
|
||||
if (_runTimer == null)
|
||||
{
|
||||
_runTimer = new System.Threading.Timer(RunTimerCallBack, null, -1, -1);
|
||||
}
|
||||
|
||||
if (_idleTimer == null)
|
||||
{
|
||||
_idleTimer = new System.Threading.Timer(IdleTimerCallBack, null, -1, -1);
|
||||
}
|
||||
|
||||
if (_downTimer == null)
|
||||
{
|
||||
_downTimer = new System.Threading.Timer(DownTimerCallBack, null, -1, -1);
|
||||
}
|
||||
|
||||
StartTime = DateTime.Now;
|
||||
DownTime = IdleTime = RunTime = new TimeSpan(0, 0, 0);
|
||||
CurrentState = RunState.Running;
|
||||
}
|
||||
|
||||
private void DownTimerCallBack(object state)
|
||||
{
|
||||
DownTime = DownTime.Add(new TimeSpan(0, 0, 1));
|
||||
GetTotalTime();
|
||||
}
|
||||
|
||||
private void IdleTimerCallBack(object state)
|
||||
{
|
||||
IdleTime = IdleTime.Add(new TimeSpan(0, 0, 1));
|
||||
GetTotalTime();
|
||||
}
|
||||
|
||||
private void RunTimerCallBack(object state)
|
||||
{
|
||||
RunTime = RunTime.Add(new TimeSpan(0, 0, 1));
|
||||
GetTotalTime();
|
||||
}
|
||||
|
||||
private void GetTotalTime()
|
||||
{
|
||||
TotalTime = RunTime + IdleTime + DownTime;
|
||||
}
|
||||
|
||||
public void ResetOEETimeDistribute()
|
||||
{
|
||||
StartTime = DateTime.Now;
|
||||
DownTime = IdleTime = RunTime = new TimeSpan(0, 0, 0);
|
||||
|
||||
ProductNum_Total = ProductNum_OK = 0;
|
||||
}
|
||||
|
||||
public void CloseStatisticTimers()
|
||||
{
|
||||
CloseTimer(ref _checkIdleTimer);
|
||||
CloseTimer(ref _runTimer);
|
||||
CloseTimer(ref _idleTimer);
|
||||
CloseTimer(ref _downTimer);
|
||||
|
||||
CurrentState = RunState.Stop;
|
||||
}
|
||||
|
||||
private void CloseTimer(ref System.Threading.Timer timer)
|
||||
{
|
||||
timer?.Change(-1, -1);
|
||||
timer?.Dispose();
|
||||
timer = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CameraSum
|
||||
private void InitialCameraSumsView()
|
||||
{
|
||||
dgvProductNums.AutoGenerateColumns = false;
|
||||
|
||||
dgvProductNums.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.World);
|
||||
|
||||
dgvProductNums.DataSource = null;
|
||||
dgvProductNums.DataSource = ProductSummaries;
|
||||
|
||||
|
||||
dgvCamreaNums.AutoGenerateColumns = false;
|
||||
|
||||
dgvCamreaNums.DefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.World);
|
||||
|
||||
dgvCamreaNums.DataSource = null;
|
||||
dgvCamreaNums.Columns.Clear();
|
||||
|
||||
// 添加 CCD 列
|
||||
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "CCD",
|
||||
DataPropertyName = "CameraName"
|
||||
});
|
||||
|
||||
// 添加 合格 列
|
||||
var okColumn = new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "合格",
|
||||
DataPropertyName = "OKCount"
|
||||
};
|
||||
okColumn.DefaultCellStyle.ForeColor = Color.LightGreen; // 设置背景为绿色
|
||||
dgvCamreaNums.Columns.Add(okColumn);
|
||||
|
||||
// 添加 不合格 列
|
||||
var ngColumn = new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "不合格",
|
||||
DataPropertyName = "NGCount"
|
||||
};
|
||||
ngColumn.DefaultCellStyle.ForeColor = Color.LightCoral; // 设置背景为红色
|
||||
dgvCamreaNums.Columns.Add(ngColumn);
|
||||
|
||||
// 添加 总数 列
|
||||
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "总数",
|
||||
DataPropertyName = "TotalCount"
|
||||
|
||||
});
|
||||
|
||||
// 添加 良率 列
|
||||
dgvCamreaNums.Columns.Add(new DataGridViewTextBoxColumn
|
||||
{
|
||||
HeaderText = "良率",
|
||||
DataPropertyName = "YieldStr"
|
||||
});
|
||||
|
||||
dgvCamreaNums.DataSource = new BindingList<CameraSummary>(CameraSummaries);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 窗体对象实例
|
||||
@ -261,14 +585,23 @@ namespace DHSoftware
|
||||
var cameraBase = ConfigModel.CameraBaseList[i];
|
||||
if (cameraBase.CamType == EnumCamType.度申Do3think)
|
||||
{
|
||||
Do3ThinkCamera cam = new Do3ThinkCamera();
|
||||
|
||||
|
||||
Do3ThinkCamera cam =new Do3ThinkCamera();
|
||||
cam.IsSavePicEnabled = cameraBase.IsSavePicEnabled;
|
||||
cam.CameraName = cameraBase.CameraName;
|
||||
cam.CameraIP = cameraBase.CameraIP;
|
||||
cam.IsEnabled = cameraBase.IsEnabled;
|
||||
cam.ImageSaveDirectory = "D://Cam1//";
|
||||
Cameras.Add(cam);
|
||||
cam.CameraConnect();
|
||||
cam.OnHImageOutput += OnCameraHImageOutput;
|
||||
if(cameraBase.IsEnabled)
|
||||
{
|
||||
cam.OnLog -= _visionEngine_OnLog;
|
||||
cam.OnLog += _visionEngine_OnLog;
|
||||
cam.CameraConnect();
|
||||
cam.OnHImageOutput += OnCameraHImageOutput;
|
||||
}
|
||||
|
||||
}
|
||||
else if (cameraBase.CamType == EnumCamType.海康hik)
|
||||
{
|
||||
@ -299,12 +632,14 @@ namespace DHSoftware
|
||||
PLC.PLCName = plcBase.PLCName;
|
||||
PLC.PLCItemList = plcBase.PLCItemList;
|
||||
PLC.Port = plcBase.Port;
|
||||
PLC.OnLog -= _visionEngine_OnLog;
|
||||
PLC.OnLog += _visionEngine_OnLog;
|
||||
PLC.PLCConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FrmLog frmLog;
|
||||
public void InitModel()
|
||||
{
|
||||
Dectection.Clear();
|
||||
@ -322,10 +657,11 @@ namespace DHSoftware
|
||||
detectionConfig.ModelHeight = detection.ModelHeight;
|
||||
detectionConfig.In_lable_path = detection.In_lable_path;
|
||||
detectionConfig.IsEnabled = detection.IsEnabled;
|
||||
detectionConfig.ShowLocation.X = (i + 1) % 5+ (i + 1) / 5;
|
||||
// detectionConfig.ShowLocation.X = detection.ShowLocation.X;
|
||||
detectionConfig.ShowLocation.Y = (i + 1) / 5+1;
|
||||
// detectionConfig.ShowLocation.Y = detection.ShowLocation.Y;
|
||||
|
||||
detectionConfig.ShowLocation.X = (i + 1) % 5 + (i + 1) / 5;
|
||||
// detectionConfig.ShowLocation.X = detection.ShowLocation.X;
|
||||
detectionConfig.ShowLocation.Y = (i + 1) / 5 + 1;
|
||||
// detectionConfig.ShowLocation.Y = detection.ShowLocation.Y;
|
||||
DetectionConfigs.Add(detectionConfig);
|
||||
}
|
||||
}
|
||||
@ -350,22 +686,130 @@ namespace DHSoftware
|
||||
});
|
||||
string inferenceDevice = "CPU";
|
||||
|
||||
frmLog = new FrmLog();
|
||||
frmLog.Dock = DockStyle.Fill;
|
||||
pnlLog.Controls.Add(frmLog);
|
||||
//
|
||||
_visionEngine = new SimboVisionDriver();
|
||||
_visionEngine.DetectionConfigs = DetectionConfigs;
|
||||
|
||||
_visionEngine.OnLog += _visionEngine_OnLog;
|
||||
//初始化模型 加载模型
|
||||
_visionEngine.Init();
|
||||
|
||||
CtrlVisionRunBase ctrlVisionRun = new CtrlVisionRunBase(_visionEngine);
|
||||
ctrlVisionRun.Dock = DockStyle.Fill;
|
||||
tabImgDisplay.Controls.Add(ctrlVisionRun);
|
||||
|
||||
}
|
||||
|
||||
private void _visionEngine_OnLog(LogMsg msg)
|
||||
{
|
||||
OnLog?.Invoke(msg);
|
||||
LogDisplay(msg);
|
||||
}
|
||||
private void LogDisplay(LogMsg msg)
|
||||
{
|
||||
|
||||
frmLog?.LogDisplay(msg);
|
||||
}
|
||||
public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
|
||||
public virtual void LogAsync(LogMsg msg)
|
||||
{
|
||||
//if (IConfig != null)
|
||||
//{
|
||||
// LoggerHelper.SetLogLevel(IConfig.DefaultLogLevel);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// LoggerHelper.SetLogLevel(LogLevel.Assist);
|
||||
//}
|
||||
|
||||
msg.ThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
OnLog?.Invoke(msg);
|
||||
//if (IConfig?.IsLogEnabled ?? true)
|
||||
//{
|
||||
LoggerHelper.LogAsync(msg);
|
||||
//}
|
||||
}
|
||||
public virtual void LogAsync(DateTime dt, LogLevel logLevel, string msg)
|
||||
{
|
||||
LogAsync(new LogMsg(dt, logLevel, msg));
|
||||
|
||||
}
|
||||
private void BindEventHandler()
|
||||
{
|
||||
btnAddProject.Click += BtnAddProject_Click;
|
||||
btnDeleteProject.Click += BtnDeleteProject_Click;
|
||||
btnLoadProject.Click += BtnLoadProject_Click;
|
||||
LoggerHelper.LogPath = "D://";
|
||||
LoggerHelper.LogPrefix = "Process";
|
||||
OnLog -= LogDisplay;
|
||||
OnLog += LogDisplay;
|
||||
|
||||
OnUpdateCamResult -= UpdateCamResult;
|
||||
|
||||
OnUpdateCamResult += UpdateCamResult;
|
||||
OnUpdateResult -= UpdateResult;
|
||||
OnUpdateResult += UpdateResult;
|
||||
Load += (s, e) =>
|
||||
{
|
||||
_refreshUITimer.Interval = 1000;
|
||||
_refreshUITimer.Tick += _refreshUITimer_Tick;
|
||||
_refreshUITimer.Enabled = true;
|
||||
};
|
||||
}
|
||||
private void _refreshUITimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
_refreshUITimer.Enabled = false;
|
||||
|
||||
if (this != null)
|
||||
{
|
||||
lblStartTime.Text = StartTime == null ? "" : StartTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
lblTotalTime.Text = TotalTime.ToString(); // 运行时间
|
||||
// lblRunTime.Text = RunTime.ToString(); // 有效时间
|
||||
// lblIdleTime.Text = ProcessControl.IdleTime.ToString(); // 空闲时间
|
||||
// lblDownTime.Text = ProcessControl.DownTime.ToString(); // 宕机时间
|
||||
|
||||
lblOEE_Total.Text =ProductNum_Total.ToString();
|
||||
//lblOEE_OK.Text = ProcessControl.ProductNum_OK.ToString();
|
||||
}
|
||||
|
||||
_refreshUITimer.Enabled = true;
|
||||
}
|
||||
private void UpdateCamResult(DateTime updateTime, object objData, string customMessage)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
|
||||
BindingList<CameraSummary> cameraSummaries = new BindingList<CameraSummary>(CameraSummaries);
|
||||
dgvCamreaNums.DataSource = cameraSummaries;
|
||||
|
||||
}));
|
||||
|
||||
}
|
||||
private void UpdateResult(DateTime updateTime, object objData, string result)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
//dgvProductNums.DataSource = null;
|
||||
|
||||
BindingList<ProductSummary> productSummaries = new BindingList<ProductSummary>(ProductSummaries);
|
||||
|
||||
dgvProductNums.DataSource = productSummaries;
|
||||
|
||||
//if (dgvProductNums.Rows.Count > 0)
|
||||
//{
|
||||
// dgvProductNums.Height = dgvProductNums.Rows[0].Height * dgvProductNums.Rows.Count + 15;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// dgvProductNums.Height = 15;
|
||||
//}
|
||||
|
||||
//lblOEE_Rate.Text = ProcessControl.OEE.ToString("f2") + " %";
|
||||
lblUPH.Text = UPH.ToString();
|
||||
}));
|
||||
}
|
||||
|
||||
private void BtnDeleteProject_Click(object? sender, EventArgs e)
|
||||
@ -513,7 +957,10 @@ namespace DHSoftware
|
||||
camera.CameraDisConnect();
|
||||
}
|
||||
if (PLC != null)
|
||||
PLC.PLCDisConnect();
|
||||
{
|
||||
PLC.CloseProcess();
|
||||
}
|
||||
_visionEngine.Stop();//释放模型
|
||||
CloseWindow.Instance.Close();// 关闭提示窗口
|
||||
//Application.Exit();
|
||||
System.Environment.Exit(0);
|
||||
@ -575,26 +1022,28 @@ namespace DHSoftware
|
||||
|
||||
private void HandleStartButton()
|
||||
{
|
||||
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候...");
|
||||
StartProcess();
|
||||
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void StartProcess()
|
||||
{
|
||||
ProcessstartTime= DateTime.Now;
|
||||
lblstarttime.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
ProcessstartTime = DateTime.Now;
|
||||
lblStartTime.Text = ProcessstartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
//计数清零
|
||||
PieceCount = 0;
|
||||
|
||||
|
||||
|
||||
if (PLC?.Enable == true)
|
||||
{
|
||||
PLC.OnNewPieces -= MainMotion_NewPieces;
|
||||
PLC.OnNewPieces += MainMotion_NewPieces;
|
||||
}
|
||||
|
||||
ConfigModel.CameraBaseList.ForEach(d =>
|
||||
Cameras.ForEach(d =>
|
||||
{
|
||||
if (d is CameraBase cam)
|
||||
{
|
||||
@ -685,24 +1134,20 @@ namespace DHSoftware
|
||||
|
||||
// ProductBaseCount = _MGSCameraList.Count;
|
||||
|
||||
for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
|
||||
{
|
||||
ConcurrentDictionary<uint, ProductData> products = new ConcurrentDictionary<uint, ProductData>();
|
||||
_productLists.Add(products);
|
||||
}
|
||||
|
||||
InitialOEEStatistic();
|
||||
//流程执行时PLC
|
||||
PLC.StartProcess();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private uint PieceCount = 0;
|
||||
private List<ConcurrentDictionary<uint, ProductData>> _productLists = new List<ConcurrentDictionary<uint, ProductData>>();
|
||||
private int ProductListMulti = 2;
|
||||
private int ProductListMulti = 1;
|
||||
private int ProductBaseCount = 0;
|
||||
|
||||
private int PieceNumberToIndex(uint pn)
|
||||
@ -731,12 +1176,10 @@ namespace DHSoftware
|
||||
{
|
||||
ProductData pData = new ProductData("", pieceNumber, ProductBaseCount);
|
||||
_productLists[index][pieceNumber] = pData;
|
||||
LogAsync(DateTime.Now, LogLevel.Action, $">> 轴{axisIndex}新产品{pieceNumber}加入队列{index}----板卡计数{PieceCount}");
|
||||
|
||||
}
|
||||
string logStr = $"时间:{DateTime.Now} 轴{axisIndex}新产品{pieceNumber}加入队列{index}----入料计数{PieceCount}\n";
|
||||
Task.Run(() =>
|
||||
{
|
||||
//this.BeginInvoke(new MethodInvoker(delegate () { richTextBox1.AppendText(logStr); }));
|
||||
});
|
||||
|
||||
DateTime dtNow = DateTime.Now;
|
||||
UpdateCT(null, (float)(dtNow - _ctTime).TotalSeconds);
|
||||
_ctTime = dtNow;
|
||||
@ -794,8 +1237,8 @@ namespace DHSoftware
|
||||
}
|
||||
else
|
||||
{
|
||||
// Thread.Sleep(20);
|
||||
await Task.Delay(20);
|
||||
Thread.Sleep(20);
|
||||
//await Task.Delay(20);
|
||||
}
|
||||
retryTimes--;
|
||||
}
|
||||
@ -812,22 +1255,7 @@ namespace DHSoftware
|
||||
|
||||
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
|
||||
localImageSet.Dispose();
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
//重新生成实例 销毁之前的实例
|
||||
|
||||
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine(productNumber + "提前推出" + camera.CameraName);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -836,23 +1264,10 @@ namespace DHSoftware
|
||||
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
|
||||
{
|
||||
localImageSet.Dispose();
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
|
||||
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
//重新生成实例 销毁之前的实例
|
||||
|
||||
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine(productNumber + "提前推出" + camera.CameraName);
|
||||
}
|
||||
// LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber},但是没有推理1");
|
||||
|
||||
LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.CameraName} 找到产品{productNumber},但是没有推理1");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -860,12 +1275,13 @@ namespace DHSoftware
|
||||
double totalTime = 0.0;
|
||||
List<ResultState> resultStates = new List<ResultState>();
|
||||
List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
|
||||
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
for (int i = 0; i < detectionDict.Count; i++)
|
||||
{
|
||||
string detectionId = detectionDict[i];
|
||||
|
||||
// 1. 预处理
|
||||
|
||||
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
|
||||
{
|
||||
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId);
|
||||
@ -875,6 +1291,9 @@ namespace DHSoftware
|
||||
product.ResultCollection.Add(temp1);
|
||||
}
|
||||
}
|
||||
stopwatch.Stop();
|
||||
if (product.ResultCollection.Count != 0)
|
||||
UpdateResultoverride(dt, camera, resultStates, totalTime, _cameraRelatedDetectionDict.Keys.Count);
|
||||
|
||||
product.InferenceOne();
|
||||
|
||||
@ -884,32 +1303,22 @@ namespace DHSoftware
|
||||
{
|
||||
return;
|
||||
}
|
||||
ProductNum_Total++;
|
||||
CalculateOEE();
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
UpdateResultPro(DateTime.Now, null, product.ProductResult.GetEnumDescription());
|
||||
|
||||
|
||||
#region 6. 统计产品结果
|
||||
|
||||
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
|
||||
? ResultState.B_NG
|
||||
: ResultState.OK;
|
||||
if (product.ProductResult == ResultState.OK)
|
||||
{
|
||||
PLC.Blowing(productNumber, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
PLC.Blowing(productNumber, 2);
|
||||
}
|
||||
//if (product.ProductResult == ResultState.OK)
|
||||
//{
|
||||
// PLC.Blowing(productNumber, 1);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// PLC.Blowing(productNumber, 2);
|
||||
//}
|
||||
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
|
||||
product.ProductLabel = product.ProductResult.GetEnumDescription();
|
||||
|
||||
@ -935,13 +1344,13 @@ namespace DHSoftware
|
||||
$"当前队列产品数量:{tmpDic.Count}";
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
// int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
richTextBox1.AppendText(logStr);
|
||||
// richTextBox1.AppendText(logStr);
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
richTextBox1.ScrollToCaret();
|
||||
// richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
//richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
}
|
||||
else
|
||||
@ -953,13 +1362,13 @@ namespace DHSoftware
|
||||
$"当前队列产品数量:{tmpDic.Count}";
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
//int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
|
||||
|
||||
richTextBox1.AppendText(logStr);
|
||||
// richTextBox1.AppendText(logStr);
|
||||
|
||||
// 设置回原来的滚动位置
|
||||
richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
richTextBox1.ScrollToCaret();
|
||||
// richTextBox1.SelectionStart = richTextBox1.TextLength;
|
||||
//richTextBox1.ScrollToCaret();
|
||||
}));
|
||||
//重新生成实例 销毁之前的实例
|
||||
var saveData = temp.GetProductData();
|
||||
@ -988,49 +1397,155 @@ namespace DHSoftware
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SetResult()
|
||||
public virtual void AddOKProduct(string resultStr)
|
||||
{
|
||||
//// detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag
|
||||
////2024-02-29 目标检测不能全是NG
|
||||
//if (IsPreTreatNG || IsObjectDetectNG)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
if (resultStr.ToLower() == "ok")
|
||||
{
|
||||
ProductNum_OK++;
|
||||
}
|
||||
}
|
||||
public async Task UpdateResultoverride(DateTime dt, CameraBase objData, List<ResultState> resultStr, double total, int _cameraDictCount)
|
||||
{
|
||||
// CurrentState = RunState.Running;
|
||||
|
||||
|
||||
|
||||
// 根据相机名称找到对应的信息(假设有一个字典或其他集合保存相机相关信息)
|
||||
var cameraName = objData?.CameraName; // 假设 CameraBase 有 Name 属性
|
||||
if (string.IsNullOrEmpty(cameraName))
|
||||
{
|
||||
throw new ArgumentException("相机名称不能为空");
|
||||
}
|
||||
|
||||
|
||||
|
||||
lock (_cameraSummaryLock)
|
||||
{
|
||||
// 查找或添加相机统计项
|
||||
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == cameraName)
|
||||
?? new CameraSummary { CameraName = cameraName };
|
||||
|
||||
if (!CameraSummaries.Contains(summary))
|
||||
{
|
||||
CameraSummaries.Add(summary);
|
||||
}
|
||||
|
||||
if (resultStr.Any(u => u.ToString().ToLower() == "ok"))
|
||||
{
|
||||
summary.OKCount++;
|
||||
}
|
||||
|
||||
else /*if (resultStr.Equals("TBD", StringComparison.OrdinalIgnoreCase))*/
|
||||
{
|
||||
summary.NGCount++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
OnUpdateCamResult?.Invoke(dt, objData, "");
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UpdateResultPro(DateTime dt, object objData, string resultStr)
|
||||
{
|
||||
CurrentState = RunState.Running;
|
||||
|
||||
ProductNum_Total++;
|
||||
AddOKProduct(resultStr);
|
||||
|
||||
|
||||
|
||||
lock (_productSummaryLock)
|
||||
{
|
||||
var product = ProductSummaries.FirstOrDefault(u => u.ResultDesc == resultStr);
|
||||
if (product != null)
|
||||
{
|
||||
product.ProductAmount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
product = new ProductSummary();
|
||||
product.ResultDesc = resultStr;
|
||||
product.ProductAmount = 1;
|
||||
|
||||
ProductSummaries.Add(product);
|
||||
}
|
||||
|
||||
int totalNum = ProductSummaries.Sum(p => p.ProductAmount);
|
||||
ProductSummaries.ForEach(p => p.PercentStr = ((double)p.ProductAmount * 100.0 / totalNum).ToString("f2") + " %");
|
||||
}
|
||||
|
||||
CalculateOEE();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
OnUpdateResult?.Invoke(dt, objData, resultStr);
|
||||
});
|
||||
lock (_cameraSummaryLock)
|
||||
{
|
||||
// 查找或添加相机统计项
|
||||
var summary = CameraSummaries.FirstOrDefault(c => c.CameraName == "合计")
|
||||
?? new CameraSummary { CameraName = "合计" };
|
||||
|
||||
summary.OKCount = ProductNum_OK;
|
||||
summary.NGCount = ProductNum_Total - ProductNum_OK;
|
||||
if (!CameraSummaries.Contains(summary))
|
||||
{
|
||||
CameraSummaries.Add(summary);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
await Task.Run(() =>
|
||||
{
|
||||
OnUpdateCamResult?.Invoke(dt, objData, "合计");
|
||||
});
|
||||
|
||||
|
||||
//if (IsPreTreatDone && IsMLDetectDone && IsAfterTreatDone)
|
||||
//{
|
||||
// ResultState = ResultState.OK;
|
||||
// ResultLabel = ResultState.OK.GetEnumDescription();
|
||||
//}
|
||||
}
|
||||
|
||||
private void HandleStopButton()
|
||||
{
|
||||
Cameras.Clear();
|
||||
Dectection.Clear();
|
||||
// Cameras.Clear();
|
||||
// Dectection.Clear();
|
||||
// Add the code for the "停止" button click here
|
||||
PLC.TurnStart(false);
|
||||
CurrentMachine = true;
|
||||
//sLDMotion.Stop();
|
||||
}
|
||||
|
||||
public int UPH = 0;
|
||||
|
||||
|
||||
public void CalculateOEE()
|
||||
{
|
||||
TimeSpan timeSpan = DateTime.Now - ProcessstartTime;
|
||||
|
||||
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
|
||||
//UPM = (int)UPH / 60;
|
||||
this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
if (TotalTime.TotalHours == 0)
|
||||
{
|
||||
lblNowtime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
label1.Text = UPH.ToString();
|
||||
lblUPH.Text = UPH.ToString();
|
||||
lblNum.Text = ProductNum_Total.ToString();
|
||||
labuph.Text = UPH.ToString();
|
||||
}));
|
||||
UPH = 0;
|
||||
UPM = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
UPH = (int)(ProductNum_Total / RunTime.TotalHours) + 100;
|
||||
UPM = (int)UPH / 60;
|
||||
}
|
||||
|
||||
|
||||
//TimeSpan timeSpan = DateTime.Now - ProcessstartTime;
|
||||
|
||||
//UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
|
||||
////UPM = (int)UPH / 60;
|
||||
//this.BeginInvoke(new MethodInvoker(delegate ()
|
||||
//{
|
||||
// lblNowtime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
// lblUPH.Text = UPH.ToString();
|
||||
// lblNum.Text = ProductNum_Total.ToString();
|
||||
|
||||
//}));
|
||||
}
|
||||
|
||||
private void HandleResetButton()
|
||||
@ -1061,5 +1576,10 @@ namespace DHSoftware
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
@ -117,36 +117,6 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="segmentedItem6.IconActiveSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M731.818667 500.280889L386.844444 239.729778a14.677333 14.677333 0 0 0-23.495111 11.719111v521.159111a14.677333 14.677333 0 0 0 23.495111 11.662222l344.860445-260.608a14.677333 14.677333 0 0 0 0.113778-23.381333z" fill="#FFFFFF"/><path d="M512 1024a512 512 0 1 1 512-512 512.568889 512.568889 0 0 1-512 512z m0-946.915556A434.915556 434.915556 0 1 0 946.915556 512 435.427556 435.427556 0 0 0 512 77.084444z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem6.IconSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M731.818667 500.280889L386.844444 239.729778a14.677333 14.677333 0 0 0-23.495111 11.719111v521.159111a14.677333 14.677333 0 0 0 23.495111 11.662222l344.860445-260.608a14.677333 14.677333 0 0 0 0.113778-23.381333z" fill="#FFFFFF"/><path d="M512 1024a512 512 0 1 1 512-512 512.568889 512.568889 0 0 1-512 512z m0-946.915556A434.915556 434.915556 0 1 0 946.915556 512 435.427556 435.427556 0 0 0 512 77.084444z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem7.IconActiveSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M365.014704 657.815846H657.084939V365.74561H365.014704V657.815846zm584.140471-146.035118c0-240.906781-197.125482-438.105353-438.105353-438.105353-240.979872 0-438.105353 197.198572-438.105354 438.105353 0 240.979872 197.125482 438.178444 438.105354 438.178444 240.979872 0 438.105353-197.198572 438.105353-438.178444zM511.634547 0.730906c281.399001 0 511.634547 230.235546 511.634547 511.634547s-230.235546 511.634547-511.634547 511.634547-511.634547-230.235546-511.634547-511.634547 230.235546-511.634547 511.634547-511.634547z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem7.IconSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M365.014704 657.815846H657.084939V365.74561H365.014704V657.815846zm584.140471-146.035118c0-240.906781-197.125482-438.105353-438.105353-438.105353-240.979872 0-438.105353 197.198572-438.105354 438.105353 0 240.979872 197.125482 438.178444 438.105354 438.178444 240.979872 0 438.105353-197.198572 438.105353-438.178444zM511.634547 0.730906c281.399001 0 511.634547 230.235546 511.634547 511.634547s-230.235546 511.634547-511.634547 511.634547-511.634547-230.235546-511.634547-511.634547 230.235546-511.634547 511.634547-511.634547z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem8.IconActiveSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/><path d="M527.36 351.744V292.864L410.624 380.416 527.36 468.48V410.624c72.192 8.192 124.416 73.216 116.224 145.408-8.192 72.192-73.216 124.416-145.408 116.224-66.56-7.168-117.248-64-117.248-131.072-0.512-5.12-0.512-9.728 0-14.848H323.584c-0.512 5.12-0.512 9.728 0 14.848 0 104.96 85.504 189.952 190.464 189.952s189.952-85.504 189.952-190.464c-0.512-99.328-77.312-181.76-176.64-188.928z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem8.IconSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/><path d="M527.36 351.744V292.864L410.624 380.416 527.36 468.48V410.624c72.192 8.192 124.416 73.216 116.224 145.408-8.192 72.192-73.216 124.416-145.408 116.224-66.56-7.168-117.248-64-117.248-131.072-0.512-5.12-0.512-9.728 0-14.848H323.584c-0.512 5.12-0.512 9.728 0 14.848 0 104.96 85.504 189.952 190.464 189.952s189.952-85.504 189.952-190.464c-0.512-99.328-77.312-181.76-176.64-188.928z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem9.IconActiveSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/><path transform="scale(0.8) translate(128,128)" d="M960.853333 903.816533a463.633067 463.633067 0 0 0-11.264-39.185066c-1.536-4.539733-3.413333-8.942933-5.051733-13.448534a484.078933 484.078933 0 0 0-9.557333-24.4736c-2.2528-5.188267-4.881067-10.274133-7.338667-15.394133-3.413333-7.099733-6.8608-14.165333-10.6496-21.0944-2.901333-5.3248-6.075733-10.513067-9.181867-15.701333-2.423467-4.061867-4.573867-8.226133-7.133866-12.219734-1.604267-2.4576-3.413333-4.778667-5.0176-7.202133-1.501867-2.218667-2.730667-4.608-4.266667-6.792533-0.4096-0.6144-1.058133-0.887467-1.501867-1.4336a461.482667 461.482667 0 0 0-90.385066-96.768c-13.5168-10.786133-27.7504-20.48-42.257067-29.5936-0.477867-0.341333-0.7168-0.8192-1.194667-1.1264-3.6864-2.286933-7.509333-4.3008-11.264-6.485334-4.266667-2.491733-8.4992-5.051733-12.868266-7.441066-6.826667-3.6864-13.789867-7.099733-20.753067-10.478934-3.618133-1.7408-7.202133-3.618133-10.8544-5.290666a449.194667 449.194667 0 0 0-31.607467-12.731734c-0.7168-0.273067-1.365333-0.6144-2.082133-0.8192-3.140267-1.1264-6.417067-1.911467-9.557333-2.935466-4.164267-1.399467-8.328533-2.833067-12.561067-4.096a259.9936 259.9936 0 0 0 129.194667-225.450667 260.061867 260.061867 0 0 0-76.629334-185.002667 259.9936 259.9936 0 0 0-185.002666-76.629333H512h-0.034133a259.857067 259.857067 0 0 0-185.002667 76.629333 259.925333 259.925333 0 0 0-76.629333 185.002667 259.584 259.584 0 0 0 76.629333 185.002667c15.906133 15.940267 33.655467 29.2864 52.565333 40.448-4.266667 1.262933-8.430933 2.730667-12.663466 4.096-3.140267 1.058133-6.3488 1.8432-9.489067 2.935466-0.7168 0.238933-1.365333 0.580267-2.048 0.8192-10.683733 3.822933-21.265067 8.0896-31.675733 12.765867-3.584 1.604267-7.0656 3.4816-10.615467 5.154133-7.099733 3.413333-14.165333 6.826667-21.0944 10.615467-4.266667 2.321067-8.3968 4.8128-12.561067 7.2704-3.822933 2.218667-7.748267 4.266667-11.502933 6.621867-0.512 0.3072-0.750933 0.8192-1.2288 1.160533-14.506667 9.147733-28.706133 18.807467-42.222933 29.559467a459.6736 459.6736 0 0 0-90.385067 96.768c-0.443733 0.546133-1.092267 0.8192-1.501867 1.4336-1.536 2.184533-2.7648 4.573867-4.266666 6.792533-1.604267 2.423467-3.447467 4.744533-5.0176 7.202133-2.56 3.9936-4.7104 8.157867-7.133867 12.219734-3.106133 5.188267-6.280533 10.376533-9.181867 15.701333-3.7888 6.929067-7.202133 13.994667-10.6496 21.0944-2.4576 5.12-5.051733 10.205867-7.338666 15.394133-3.515733 8.021333-6.519467 16.247467-9.557334 24.4736-1.672533 4.5056-3.549867 8.9088-5.051733 13.448534-4.3008 12.868267-8.0896 25.941333-11.264 39.185066-3.072 12.970667 2.594133 25.770667 13.073067 32.802134a31.3344 31.3344 0 0 0 9.966933 4.608 30.9248 30.9248 0 0 0 34.030933-15.2576 30.446933 30.446933 0 0 0 3.345067-7.7824c2.833067-11.844267 6.178133-23.483733 10.0352-34.9184 0.6144-1.8432 1.399467-3.549867 2.013867-5.358934 3.447467-9.762133 7.133867-19.456 11.332266-28.945066 0.512-1.160533 1.1264-2.2528 1.6384-3.447467 4.7104-10.308267 9.728-20.48 15.291734-30.344533l0.068266-0.1024a402.773333 402.773333 0 0 1 19.694934-31.4368l0.136533-0.375467a397.4144 397.4144 0 0 1 116.599467-111.2064c0.136533-0.1024 0.3072-0.068267 0.443733-0.170667a397.824 397.824 0 0 1 94.993067-42.973866c2.7648-0.8192 5.495467-1.7408 8.2944-2.491734 5.7344-1.604267 11.5712-3.003733 17.373866-4.334933a367.8208 367.8208 0 0 1 47.342934-7.953067c3.8912-0.443733 7.7824-0.9216 11.6736-1.2288 10.410667-0.785067 20.8896-1.3312 31.505066-1.3312s21.060267 0.546133 31.505067 1.3312c3.8912 0.3072 7.816533 0.785067 11.707733 1.2288a361.3696 361.3696 0 0 1 47.240534 7.953067c5.870933 1.3312 11.707733 2.730667 17.5104 4.334933 2.696533 0.750933 5.358933 1.6384 8.021333 2.4576 33.348267 10.103467 65.365333 24.405333 95.197867 43.008 0.136533 0.1024 0.3072 0.068267 0.443733 0.170667a396.151467 396.151467 0 0 1 116.599467 111.2064c0.1024 0.136533 0.1024 0.273067 0.170666 0.375467 13.687467 19.7632 25.3952 40.5504 35.191467 62.1568l1.467733 3.037866c4.3008 9.659733 8.055467 19.592533 11.605334 29.5936 0.546133 1.604267 1.2288 3.106133 1.774933 4.7104 3.822933 11.4688 7.236267 23.176533 10.0352 35.0208a31.061333 31.061333 0 0 0 60.450133-14.336zm-249.275733-560.2304A199.850667 199.850667 0 0 1 512 543.197867a199.850667 199.850667 0 0 1-199.5776-199.611734A199.816533 199.816533 0 0 1 512 144.008533a199.816533 199.816533 0 0 1 199.5776 199.5776z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem9.IconSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/><path transform="scale(0.8) translate(128,128)" d="M960.853333 903.816533a463.633067 463.633067 0 0 0-11.264-39.185066c-1.536-4.539733-3.413333-8.942933-5.051733-13.448534a484.078933 484.078933 0 0 0-9.557333-24.4736c-2.2528-5.188267-4.881067-10.274133-7.338667-15.394133-3.413333-7.099733-6.8608-14.165333-10.6496-21.0944-2.901333-5.3248-6.075733-10.513067-9.181867-15.701333-2.423467-4.061867-4.573867-8.226133-7.133866-12.219734-1.604267-2.4576-3.413333-4.778667-5.0176-7.202133-1.501867-2.218667-2.730667-4.608-4.266667-6.792533-0.4096-0.6144-1.058133-0.887467-1.501867-1.4336a461.482667 461.482667 0 0 0-90.385066-96.768c-13.5168-10.786133-27.7504-20.48-42.257067-29.5936-0.477867-0.341333-0.7168-0.8192-1.194667-1.1264-3.6864-2.286933-7.509333-4.3008-11.264-6.485334-4.266667-2.491733-8.4992-5.051733-12.868266-7.441066-6.826667-3.6864-13.789867-7.099733-20.753067-10.478934-3.618133-1.7408-7.202133-3.618133-10.8544-5.290666a449.194667 449.194667 0 0 0-31.607467-12.731734c-0.7168-0.273067-1.365333-0.6144-2.082133-0.8192-3.140267-1.1264-6.417067-1.911467-9.557333-2.935466-4.164267-1.399467-8.328533-2.833067-12.561067-4.096a259.9936 259.9936 0 0 0 129.194667-225.450667 260.061867 260.061867 0 0 0-76.629334-185.002667 259.9936 259.9936 0 0 0-185.002666-76.629333H512h-0.034133a259.857067 259.857067 0 0 0-185.002667 76.629333 259.925333 259.925333 0 0 0-76.629333 185.002667 259.584 259.584 0 0 0 76.629333 185.002667c15.906133 15.940267 33.655467 29.2864 52.565333 40.448-4.266667 1.262933-8.430933 2.730667-12.663466 4.096-3.140267 1.058133-6.3488 1.8432-9.489067 2.935466-0.7168 0.238933-1.365333 0.580267-2.048 0.8192-10.683733 3.822933-21.265067 8.0896-31.675733 12.765867-3.584 1.604267-7.0656 3.4816-10.615467 5.154133-7.099733 3.413333-14.165333 6.826667-21.0944 10.615467-4.266667 2.321067-8.3968 4.8128-12.561067 7.2704-3.822933 2.218667-7.748267 4.266667-11.502933 6.621867-0.512 0.3072-0.750933 0.8192-1.2288 1.160533-14.506667 9.147733-28.706133 18.807467-42.222933 29.559467a459.6736 459.6736 0 0 0-90.385067 96.768c-0.443733 0.546133-1.092267 0.8192-1.501867 1.4336-1.536 2.184533-2.7648 4.573867-4.266666 6.792533-1.604267 2.423467-3.447467 4.744533-5.0176 7.202133-2.56 3.9936-4.7104 8.157867-7.133867 12.219734-3.106133 5.188267-6.280533 10.376533-9.181867 15.701333-3.7888 6.929067-7.202133 13.994667-10.6496 21.0944-2.4576 5.12-5.051733 10.205867-7.338666 15.394133-3.515733 8.021333-6.519467 16.247467-9.557334 24.4736-1.672533 4.5056-3.549867 8.9088-5.051733 13.448534-4.3008 12.868267-8.0896 25.941333-11.264 39.185066-3.072 12.970667 2.594133 25.770667 13.073067 32.802134a31.3344 31.3344 0 0 0 9.966933 4.608 30.9248 30.9248 0 0 0 34.030933-15.2576 30.446933 30.446933 0 0 0 3.345067-7.7824c2.833067-11.844267 6.178133-23.483733 10.0352-34.9184 0.6144-1.8432 1.399467-3.549867 2.013867-5.358934 3.447467-9.762133 7.133867-19.456 11.332266-28.945066 0.512-1.160533 1.1264-2.2528 1.6384-3.447467 4.7104-10.308267 9.728-20.48 15.291734-30.344533l0.068266-0.1024a402.773333 402.773333 0 0 1 19.694934-31.4368l0.136533-0.375467a397.4144 397.4144 0 0 1 116.599467-111.2064c0.136533-0.1024 0.3072-0.068267 0.443733-0.170667a397.824 397.824 0 0 1 94.993067-42.973866c2.7648-0.8192 5.495467-1.7408 8.2944-2.491734 5.7344-1.604267 11.5712-3.003733 17.373866-4.334933a367.8208 367.8208 0 0 1 47.342934-7.953067c3.8912-0.443733 7.7824-0.9216 11.6736-1.2288 10.410667-0.785067 20.8896-1.3312 31.505066-1.3312s21.060267 0.546133 31.505067 1.3312c3.8912 0.3072 7.816533 0.785067 11.707733 1.2288a361.3696 361.3696 0 0 1 47.240534 7.953067c5.870933 1.3312 11.707733 2.730667 17.5104 4.334933 2.696533 0.750933 5.358933 1.6384 8.021333 2.4576 33.348267 10.103467 65.365333 24.405333 95.197867 43.008 0.136533 0.1024 0.3072 0.068267 0.443733 0.170667a396.151467 396.151467 0 0 1 116.599467 111.2064c0.1024 0.136533 0.1024 0.273067 0.170666 0.375467 13.687467 19.7632 25.3952 40.5504 35.191467 62.1568l1.467733 3.037866c4.3008 9.659733 8.055467 19.592533 11.605334 29.5936 0.546133 1.604267 1.2288 3.106133 1.774933 4.7104 3.822933 11.4688 7.236267 23.176533 10.0352 35.0208a31.061333 31.061333 0 0 0 60.450133-14.336zm-249.275733-560.2304A199.850667 199.850667 0 0 1 512 543.197867a199.850667 199.850667 0 0 1-199.5776-199.611734A199.816533 199.816533 0 0 1 512 144.008533a199.816533 199.816533 0 0 1 199.5776 199.5776z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem10.IconActiveSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/><path d="M437.314 840.84l-18.967-5.795c-43.935-13.425-84.182-35.551-119.623-65.767l-15.203-12.962 11.199-16.544c17.376-25.668 17.938-59.158 1.433-85.319-14.356-22.787-39.028-36.385-66.006-36.385-4.102 0-8.229 0.328-12.267 0.974l-19.752 3.158-5.301-19.288c-8.196-29.823-12.353-59.896-12.353-89.381 0-19.675 1.863-39.491 5.694-60.582l3.652-20.105 20.349 1.862c2.343 0.214 4.726 0.323 7.081 0.323 29.007 0 55.436-15.908 68.974-41.516 14.941-28.2 11.264-62.223-9.356-86.694l-13.166-15.625L278.1 276.7c38.694-38.954 86.677-68.095 138.76-84.273l19.741-6.132 7.631 19.211c11.88 29.908 40.312 49.234 72.432 49.234 32.097 0 60.521-19.328 72.413-49.241l7.632-19.197 19.73 6.122c43.968 13.642 84.295 36.164 119.862 66.938l15.414 13.337-11.883 16.561c-18.636 25.975-19.684 60.166-2.671 87.105 14.369 22.78 39.055 36.373 66.04 36.372 4.344 0 8.71-0.366 12.978-1.087l20.143-3.403 5.176 19.762c7.539 28.792 11.362 57.566 11.362 85.522 0 21.328-2.143 43.048-6.365 64.554l-3.859 19.65-19.952-1.709a77.999 77.999 0 0 0-6.612-0.281c-28.998 0-55.44 15.917-69.009 41.542-14.47 27.405-11.311 60.816 8.063 85.095l12.496 15.661-14.222 14.111c-38.674 38.378-86.551 67.041-138.455 82.892l-18.968 5.792-7.988-18.152c-12.462-28.318-40.459-46.617-71.325-46.617-30.883 0-58.893 18.299-71.36 46.619l-7.99 18.152zm-95.455-94.18c22.324 16.82 46.59 30.174 72.469 39.881 22.445-34.023 60.731-55.125 102.336-55.125 41.59 0 79.862 21.1 102.303 55.12 32.745-12.298 63.249-30.557 89.663-53.667-19.709-35.774-20.525-79.555-1.04-116.455 19.699-37.203 56.634-61.386 98.053-64.883 1.705-12.731 2.565-25.453 2.565-38 0-18.339-1.923-37.155-5.729-56.144-42.123-0.241-80.616-21.581-103.077-57.189-22.944-36.331-25.024-81.029-6.697-118.768-22.165-16.932-46.203-30.4-71.788-40.221-8.847 14.328-20.577 26.719-34.618 36.447-20.522 14.219-44.602 21.735-69.635 21.735-25.044 0-49.131-7.516-69.657-21.734-14.042-9.727-25.773-22.116-34.618-36.441-32.551 12.503-62.856 30.935-89.106 54.196 21.198 36.233 22.547 80.974 2.407 118.987-19.71 37.285-56.808 61.499-98.402 64.875-1.45 11.713-2.161 23.035-2.161 34.255 0 19.715 2.166 39.792 6.449 59.894 41.851 0.474 80.029 21.785 102.35 57.214 22.218 35.217 24.782 78.871 7.933 116.023z" fill="#FFFFFF"/><path d="M516.664 633.864c-66.246 0-120.141-53.897-120.141-120.147 0-66.249 53.895-120.146 120.141-120.146 66.237 0 120.127 53.897 120.127 120.146 0 66.25-53.89 120.147-120.127 120.147zm0-195.641c-41.625 0-75.488 33.866-75.488 75.494s33.863 75.495 75.488 75.495c41.617 0 75.475-33.867 75.475-75.495s-33.858-75.494-75.475-75.494z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<data name="segmentedItem10.IconSvg" xml:space="preserve">
|
||||
<value><svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0zm0 963.584c-249.344 0-451.584-202.24-451.584-451.584S262.656 60.416 512 60.416s451.584 202.24 451.584 451.584-202.24 451.584-451.584 451.584z" fill="#FFFFFF"/><path d="M437.314 840.84l-18.967-5.795c-43.935-13.425-84.182-35.551-119.623-65.767l-15.203-12.962 11.199-16.544c17.376-25.668 17.938-59.158 1.433-85.319-14.356-22.787-39.028-36.385-66.006-36.385-4.102 0-8.229 0.328-12.267 0.974l-19.752 3.158-5.301-19.288c-8.196-29.823-12.353-59.896-12.353-89.381 0-19.675 1.863-39.491 5.694-60.582l3.652-20.105 20.349 1.862c2.343 0.214 4.726 0.323 7.081 0.323 29.007 0 55.436-15.908 68.974-41.516 14.941-28.2 11.264-62.223-9.356-86.694l-13.166-15.625L278.1 276.7c38.694-38.954 86.677-68.095 138.76-84.273l19.741-6.132 7.631 19.211c11.88 29.908 40.312 49.234 72.432 49.234 32.097 0 60.521-19.328 72.413-49.241l7.632-19.197 19.73 6.122c43.968 13.642 84.295 36.164 119.862 66.938l15.414 13.337-11.883 16.561c-18.636 25.975-19.684 60.166-2.671 87.105 14.369 22.78 39.055 36.373 66.04 36.372 4.344 0 8.71-0.366 12.978-1.087l20.143-3.403 5.176 19.762c7.539 28.792 11.362 57.566 11.362 85.522 0 21.328-2.143 43.048-6.365 64.554l-3.859 19.65-19.952-1.709a77.999 77.999 0 0 0-6.612-0.281c-28.998 0-55.44 15.917-69.009 41.542-14.47 27.405-11.311 60.816 8.063 85.095l12.496 15.661-14.222 14.111c-38.674 38.378-86.551 67.041-138.455 82.892l-18.968 5.792-7.988-18.152c-12.462-28.318-40.459-46.617-71.325-46.617-30.883 0-58.893 18.299-71.36 46.619l-7.99 18.152zm-95.455-94.18c22.324 16.82 46.59 30.174 72.469 39.881 22.445-34.023 60.731-55.125 102.336-55.125 41.59 0 79.862 21.1 102.303 55.12 32.745-12.298 63.249-30.557 89.663-53.667-19.709-35.774-20.525-79.555-1.04-116.455 19.699-37.203 56.634-61.386 98.053-64.883 1.705-12.731 2.565-25.453 2.565-38 0-18.339-1.923-37.155-5.729-56.144-42.123-0.241-80.616-21.581-103.077-57.189-22.944-36.331-25.024-81.029-6.697-118.768-22.165-16.932-46.203-30.4-71.788-40.221-8.847 14.328-20.577 26.719-34.618 36.447-20.522 14.219-44.602 21.735-69.635 21.735-25.044 0-49.131-7.516-69.657-21.734-14.042-9.727-25.773-22.116-34.618-36.441-32.551 12.503-62.856 30.935-89.106 54.196 21.198 36.233 22.547 80.974 2.407 118.987-19.71 37.285-56.808 61.499-98.402 64.875-1.45 11.713-2.161 23.035-2.161 34.255 0 19.715 2.166 39.792 6.449 59.894 41.851 0.474 80.029 21.785 102.35 57.214 22.218 35.217 24.782 78.871 7.933 116.023z" fill="#FFFFFF"/><path d="M516.664 633.864c-66.246 0-120.141-53.897-120.141-120.147 0-66.249 53.895-120.146 120.141-120.146 66.237 0 120.127 53.897 120.127 120.146 0 66.25-53.89 120.147-120.127 120.147zm0-195.641c-41.625 0-75.488 33.866-75.488 75.494s33.863 75.495 75.488 75.495c41.617 0 75.475-33.867 75.475-75.495s-33.858-75.494-75.475-75.494z" fill="#FFFFFF"/></svg></value>
|
||||
</data>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
|
148
DHSoftware/Views/FrmLog.Designer.cs
generated
Normal file
148
DHSoftware/Views/FrmLog.Designer.cs
generated
Normal file
@ -0,0 +1,148 @@
|
||||
namespace DHSoftware.Views
|
||||
{
|
||||
partial class FrmLog
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.tsmiClearLog = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.tsmiLogLevels = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tsmiLogSources = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tsmiClearLog2 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.lvLog = new System.Windows.Forms.ListView();
|
||||
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.contextMenuStrip1.SuspendLayout();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.tsmiClearLog});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(125, 26);
|
||||
//
|
||||
// tsmiClearLog
|
||||
//
|
||||
this.tsmiClearLog.Name = "tsmiClearLog";
|
||||
this.tsmiClearLog.Size = new System.Drawing.Size(124, 22);
|
||||
this.tsmiClearLog.Text = "清空日志";
|
||||
this.tsmiClearLog.Click += new System.EventHandler(this.tsmiClearLog_Click);
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.tsmiLogLevels,
|
||||
this.tsmiLogSources,
|
||||
this.tsmiClearLog2});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(800, 25);
|
||||
this.menuStrip1.TabIndex = 3;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// tsmiLogLevels
|
||||
//
|
||||
this.tsmiLogLevels.Name = "tsmiLogLevels";
|
||||
this.tsmiLogLevels.Size = new System.Drawing.Size(68, 21);
|
||||
this.tsmiLogLevels.Text = "日志级别";
|
||||
//
|
||||
// tsmiLogSources
|
||||
//
|
||||
this.tsmiLogSources.Name = "tsmiLogSources";
|
||||
this.tsmiLogSources.Size = new System.Drawing.Size(68, 21);
|
||||
this.tsmiLogSources.Text = "日志来源";
|
||||
//
|
||||
// tsmiClearLog2
|
||||
//
|
||||
this.tsmiClearLog2.Name = "tsmiClearLog2";
|
||||
this.tsmiClearLog2.Size = new System.Drawing.Size(68, 21);
|
||||
this.tsmiClearLog2.Text = "清空日志";
|
||||
this.tsmiClearLog2.Click += new System.EventHandler(this.tsmiClearLog2_Click);
|
||||
//
|
||||
// lvLog
|
||||
//
|
||||
this.lvLog.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.lvLog.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.lvLog.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.columnHeader1,
|
||||
this.columnHeader2,
|
||||
this.columnHeader3});
|
||||
this.lvLog.ContextMenuStrip = this.contextMenuStrip1;
|
||||
this.lvLog.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.lvLog.FullRowSelect = true;
|
||||
this.lvLog.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
|
||||
this.lvLog.HideSelection = false;
|
||||
this.lvLog.Location = new System.Drawing.Point(0, 25);
|
||||
this.lvLog.MultiSelect = false;
|
||||
this.lvLog.Name = "lvLog";
|
||||
this.lvLog.Size = new System.Drawing.Size(800, 463);
|
||||
this.lvLog.TabIndex = 5;
|
||||
this.lvLog.UseCompatibleStateImageBehavior = false;
|
||||
this.lvLog.View = System.Windows.Forms.View.Details;
|
||||
this.lvLog.SizeChanged += new System.EventHandler(this.lvLog_SizeChanged);
|
||||
//
|
||||
// columnHeader1
|
||||
//
|
||||
this.columnHeader1.Width = 80;
|
||||
//
|
||||
// FrmLog
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
this.ClientSize = new System.Drawing.Size(800, 488);
|
||||
this.Controls.Add(this.lvLog);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
//this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "FrmLog";
|
||||
this.Text = "日志";
|
||||
this.contextMenuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiClearLog;
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiLogLevels;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiLogSources;
|
||||
private System.Windows.Forms.ListView lvLog;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader1;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader2;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader3;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiClearLog2;
|
||||
//private System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem;
|
||||
}
|
||||
}
|
236
DHSoftware/Views/FrmLog.cs
Normal file
236
DHSoftware/Views/FrmLog.cs
Normal file
@ -0,0 +1,236 @@
|
||||
|
||||
using XKRS.UI.Model.Winform;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
using DH.Commons.Enums;
|
||||
|
||||
|
||||
namespace DHSoftware.Views
|
||||
{
|
||||
|
||||
public partial class FrmLog : UserControl
|
||||
{
|
||||
public FrmLog()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
lvLog.ShowItemToolTips = true;
|
||||
|
||||
this.Load += (s, e) =>
|
||||
{
|
||||
_showLevels.Clear();
|
||||
tsmiLogLevels.DropDownItems.Clear();
|
||||
JsonConvert.DeserializeObject<List<dynamic>>(JsonConvert.SerializeObject(EnumHelper.GetEnumListByType(typeof(LogLevel)))).ForEach(d =>
|
||||
{
|
||||
LogLevel lvl = (LogLevel)((int)d.Value);
|
||||
ToolStripMenuItem item = new ToolStripMenuItem(d.Desc.ToString());
|
||||
item.CheckOnClick = true;
|
||||
item.Checked = true;
|
||||
item.Tag = lvl;
|
||||
item.CheckedChanged += LevelItem_CheckedChanged;
|
||||
|
||||
item.BackColor = lvl.GetEnumSelectedColor();
|
||||
item.ForeColor = lvl.GetEnumSelectedFontColor();
|
||||
tsmiLogLevels.DropDownItems.Add(item);
|
||||
_showLevels.Add(lvl);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//public override void OnProcessUpdated()
|
||||
//{
|
||||
|
||||
|
||||
// Invoke(new Action(() =>
|
||||
// {
|
||||
// _showDevice.Clear();
|
||||
// tsmiLogSources.DropDownItems.Clear();
|
||||
// ToolStripMenuItem processItem = new ToolStripMenuItem(SOURCE_PROCESS);
|
||||
// processItem.CheckOnClick = true;
|
||||
// processItem.Checked = true;
|
||||
// processItem.CheckedChanged += SourceItem_CheckedChanged;
|
||||
// tsmiLogSources.DropDownItems.Add(processItem);
|
||||
// _showDevice.Add(SOURCE_PROCESS);
|
||||
|
||||
// Process.DeviceCollection.ForEach(d =>
|
||||
// {
|
||||
// ToolStripMenuItem item = new ToolStripMenuItem(d.Name);
|
||||
// item.CheckOnClick = true;
|
||||
// item.Checked = true;
|
||||
// item.CheckedChanged += SourceItem_CheckedChanged;
|
||||
// tsmiLogSources.DropDownItems.Add(item);
|
||||
// _showDevice.Add(d.Name);
|
||||
// });
|
||||
// }));
|
||||
//}
|
||||
|
||||
private void LevelItem_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
_showLevels.Clear();
|
||||
foreach (ToolStripMenuItem item in tsmiLogLevels.DropDownItems)
|
||||
{
|
||||
if (item.Checked)
|
||||
{
|
||||
LogLevel lv = (LogLevel)Convert.ToInt32(item.Tag);
|
||||
_showLevels.Add(lv);
|
||||
}
|
||||
}
|
||||
|
||||
RefreshLogs();
|
||||
}
|
||||
|
||||
private void SourceItem_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
_showDevice.Clear();
|
||||
foreach (ToolStripMenuItem item in tsmiLogSources.DropDownItems)
|
||||
{
|
||||
if (item.Checked)
|
||||
{
|
||||
_showDevice.Add(item.Text);
|
||||
}
|
||||
}
|
||||
RefreshLogs();
|
||||
}
|
||||
//public TaskFactory _taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning);
|
||||
readonly ConcurrentQueue<LogMsg> _logQueue = new ConcurrentQueue<LogMsg>();
|
||||
Task _logTask = null;
|
||||
static readonly object _logLock = new object();
|
||||
|
||||
List<LogMsg> _logBuffer = new List<LogMsg>();
|
||||
List<LogLevel> _showLevels = new List<LogLevel>();
|
||||
List<string> _showDevice = new List<string>();
|
||||
const string SOURCE_PROCESS = "流程";
|
||||
const int LOG_NUM_LIMIT = 20;
|
||||
|
||||
public void LogDisplay(LogMsg msg)
|
||||
{
|
||||
_logQueue.Enqueue(msg);
|
||||
|
||||
lock (_logLock)
|
||||
{
|
||||
if (_logTask == null)
|
||||
{
|
||||
_logTask = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
bool isNeedScroll = false;
|
||||
while (_logQueue.TryDequeue(out LogMsg log))
|
||||
{
|
||||
_logBuffer.Add(log);
|
||||
|
||||
if (_showLevels.Contains(log.LogLevel) && (_showDevice.Count == 0 || (string.IsNullOrWhiteSpace(log.MsgSource) && _showDevice.Contains(SOURCE_PROCESS)) || _showDevice.Contains(log.MsgSource)))
|
||||
{
|
||||
isNeedScroll = true;
|
||||
|
||||
ListViewItem item = new ListViewItem($"{log.LogTime.ToString("HH:mm:ss.fff")}");
|
||||
item.SubItems.Add($"{log.MsgSource}[{log.ThreadId}]");
|
||||
item.SubItems.Add(log.Msg);
|
||||
|
||||
item.ToolTipText = log.Msg;
|
||||
item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
|
||||
item.BackColor = log.LogLevel.GetEnumSelectedColor();
|
||||
|
||||
lvLog.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (_logBuffer.Count > LOG_NUM_LIMIT * 2)
|
||||
{
|
||||
_logBuffer = _logBuffer.Skip(_logBuffer.Count - LOG_NUM_LIMIT).ToList();
|
||||
RefreshLogs();
|
||||
isNeedScroll = true;
|
||||
}
|
||||
|
||||
if (isNeedScroll && lvLog.Items.Count > 0)
|
||||
{
|
||||
RefreshLvLayout();
|
||||
}
|
||||
}));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshLogs()
|
||||
{
|
||||
lvLog.Items.Clear();
|
||||
|
||||
_logBuffer.ForEach(log =>
|
||||
{
|
||||
if (_showLevels.Contains(log.LogLevel) && ((string.IsNullOrWhiteSpace(log.MsgSource) && _showDevice.Contains(SOURCE_PROCESS)) || _showDevice.Contains(log.MsgSource)))
|
||||
{
|
||||
ListViewItem item = new ListViewItem($"{log.LogTime.ToString("HH:mm:ss.fff")}");
|
||||
item.SubItems.Add($"{log.MsgSource}[{log.ThreadId}]");
|
||||
item.SubItems.Add(log.Msg);
|
||||
|
||||
item.ToolTipText = log.Msg;
|
||||
item.ForeColor = log.LogLevel.GetEnumSelectedFontColor();
|
||||
item.BackColor = log.LogLevel.GetEnumSelectedColor();
|
||||
|
||||
lvLog.Items.Add(item);
|
||||
}
|
||||
});
|
||||
|
||||
RefreshLvLayout();
|
||||
}
|
||||
|
||||
private void lvLog_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
RefreshLvLayout();
|
||||
}
|
||||
|
||||
int width_1stCol = 80;
|
||||
|
||||
public event Action<LogMsg> OnLogMsgOutput;
|
||||
|
||||
private void RefreshLvLayout()
|
||||
{
|
||||
if (lvLog.Columns.Count <= 0)
|
||||
return;
|
||||
|
||||
lvLog.Columns[0].Width = width_1stCol;
|
||||
if (lvLog.Width <= lvLog.Height)
|
||||
{
|
||||
lvLog.Columns[1].Width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
lvLog.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
||||
}
|
||||
lvLog.Columns[2].Width = lvLog.Width - width_1stCol - lvLog.Columns[1].Width - 10;
|
||||
|
||||
if (lvLog.Items.Count > 0)
|
||||
lvLog.EnsureVisible(lvLog.Items.Count - 1);
|
||||
}
|
||||
|
||||
private void tsmiClearLog_Click(object sender, EventArgs e)
|
||||
{
|
||||
lvLog.Items.Clear();
|
||||
}
|
||||
|
||||
private void tsmiClearLog2_Click(object sender, EventArgs e)
|
||||
{
|
||||
lvLog.Items.Clear();
|
||||
}
|
||||
}
|
||||
}
|
126
DHSoftware/Views/FrmLog.resx
Normal file
126
DHSoftware/Views/FrmLog.resx
Normal file
@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>182, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -73,32 +73,48 @@ namespace DHSoftware
|
||||
public ProductData( string batchNO, uint pieceNumber, int inferenceLeft = -1) : this(pieceNumber)
|
||||
{
|
||||
InferenceLeft = inferenceLeft;
|
||||
_countdownEvent = new CountdownEvent(inferenceLeft);
|
||||
//_countdownEvent = new CountdownEvent(inferenceLeft);
|
||||
|
||||
BatchNO = batchNO;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void InferenceOne()
|
||||
{
|
||||
//lock (_inferenceLock)
|
||||
//{
|
||||
// Interlocked.Decrement(ref InferenceLeft);
|
||||
//}
|
||||
//public void InferenceOne()
|
||||
//{
|
||||
// //lock (_inferenceLock)
|
||||
// //{
|
||||
// // Interlocked.Decrement(ref InferenceLeft);
|
||||
// //}
|
||||
|
||||
|
||||
_countdownEvent.Signal();
|
||||
// _countdownEvent.Signal();
|
||||
|
||||
//}
|
||||
|
||||
//public bool InferenceFinished()
|
||||
//{
|
||||
// //lock (_inferenceLock)
|
||||
// //{
|
||||
// // return 0 == InferenceLeft;
|
||||
// //}
|
||||
// return _countdownEvent.CurrentCount == 0; // 判断计数器是否为 0
|
||||
//}
|
||||
public void InferenceOne()
|
||||
{
|
||||
lock (_inferenceLock)
|
||||
{
|
||||
Interlocked.Decrement(ref InferenceLeft);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public bool InferenceFinished()
|
||||
{
|
||||
//lock (_inferenceLock)
|
||||
//{
|
||||
// return 0 == InferenceLeft;
|
||||
//}
|
||||
return _countdownEvent.CurrentCount == 0; // 判断计数器是否为 0
|
||||
lock (_inferenceLock)
|
||||
{
|
||||
return 0 == InferenceLeft;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user