增加日志

This commit is contained in:
xhm\HP 2025-04-01 18:15:30 +08:00
parent e08386333a
commit 409089e2ca
21 changed files with 1838 additions and 354 deletions

View File

@ -9,6 +9,9 @@ namespace DH.Commons.Base
{
public class CameraBase : NotifyProperty
{
// public LoggerHelper LoggerHelper { get; set; } = new LoggerHelper();
// 私有字段 + 带通知的属性与DetectionLabel风格一致
private bool _isEnabled = false;
private bool _isallPicEnabled = true;//默认全画幅

View File

@ -191,18 +191,14 @@ namespace DH.Commons.Base
}
public class DetectStationResult
{
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
public string Pid { get; set; }
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 +208,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>
@ -249,9 +248,9 @@ namespace DH.Commons.Base
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 引用。
// Step 1: 标准化字符编码为 Form C (规范组合)
string normalizedString = input.Normalize(NormalizationForm.FormC);

View 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
}
}

View File

@ -8,6 +8,7 @@ namespace DH.Commons.Base
{
public class PLCBase : NotifyProperty
{
// 私有字段
private bool _enable;
private bool _connected;

View File

@ -18,7 +18,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
@ -66,118 +66,8 @@ namespace DH.Commons.Base
}
}
}
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";
}
}

View File

@ -11,7 +11,7 @@
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AntdUI" Version="1.8.9" />

View 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
{
}
}

View File

@ -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
{
@ -303,7 +337,44 @@ 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 PriorityDirection
{
X,

View File

@ -8,6 +8,18 @@ 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;

View 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;
}
}
}

View File

@ -2,16 +2,17 @@
using System.Reflection.Metadata;
using System.Xml.Linq;
using DH.Commons.Base;
using DH.Commons.Enums;
using DVPCameraType;
using OpenCvSharp;
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 +25,15 @@ 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 Do3ThinkCamera()
{
LoggerHelper.LogPath = "D://";
LoggerHelper.LogPrefix = CameraName;
}
@ -130,41 +137,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;
}
@ -411,6 +420,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));
}
}
}

View File

@ -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)
{
@ -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,12 +729,16 @@ 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);
}
@ -702,6 +752,7 @@ namespace DH.Devices.PLC
TurnEnable(false);
OpenHeartbeat(false);
PLCDisConnect();
// LogAsync(DateTime.Now, LogLevel.Information, $"PLC断开连接");
}
public void InitProcessAction() =>
ProcessAction(ConfigModel.GlobalList?.FirstOrDefault()?.InitProcessList?.ToList() ?? new List<PLCItem>());
@ -974,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));
}
}
}

View File

@ -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)

View File

@ -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;
@ -15,6 +16,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;
@ -70,16 +72,21 @@ namespace DH.Devices.Vision
if (detectConfig == null)
{
LogAsync(DateTime.Now, LogLevel.Exception, $"异常:未能获取检测配置");
//未能获得检测配置
return detectResult;
}
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尺寸测量
@ -111,7 +118,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))
{
@ -193,6 +200,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)
@ -200,9 +209,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;
}
}
@ -280,6 +293,7 @@ namespace DH.Devices.Vision
#endregion
LogAsync(DateTime.Now, LogLevel.Information, $"{detectConfig.Name} 检测结果:{detectResult.ResultState.GetEnumDescription()}");
@ -430,11 +444,13 @@ 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)
{
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;
@ -519,7 +535,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;
@ -534,12 +550,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;
}
}
@ -571,7 +657,7 @@ namespace DH.Devices.Vision
}
catch (Exception ex)
{
LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}预处理异常:{ex.GetExceptionMessage()}");
}
finally
{
@ -582,6 +668,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>
/// 显示检测结果
@ -654,8 +1000,8 @@ namespace DH.Devices.Vision
}
catch (Exception ex)
{
// LogAsync(DateTime.Now, LogLevel.Exception,
// $"{Name}显示{detectResult.DetectName}检测结果异常,{ex.GetExceptionMessage()}");
LogAsync(DateTime.Now, LogLevel.Exception,
$"{Name}显示{detectResult.DetectName}检测结果异常,{ex.GetExceptionMessage()}");
}
finally
{

View File

@ -17,46 +17,6 @@
<ItemGroup>
<PackageReference Include="AntdUI" Version="1.8.9" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.185" />

View File

@ -28,14 +28,14 @@
/// </summary>
private void InitializeComponent()
{
AntdUI.Tabs.StyleLine styleLine2 = new AntdUI.Tabs.StyleLine();
AntdUI.Tabs.StyleCard styleCard2 = new AntdUI.Tabs.StyleCard();
AntdUI.SegmentedItem segmentedItem6 = new AntdUI.SegmentedItem();
AntdUI.Tabs.StyleLine styleLine1 = new AntdUI.Tabs.StyleLine();
AntdUI.Tabs.StyleCard styleCard1 = new AntdUI.Tabs.StyleCard();
AntdUI.SegmentedItem segmentedItem1 = 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();
AntdUI.SegmentedItem segmentedItem2 = new AntdUI.SegmentedItem();
AntdUI.SegmentedItem segmentedItem3 = new AntdUI.SegmentedItem();
AntdUI.SegmentedItem segmentedItem4 = new AntdUI.SegmentedItem();
AntdUI.SegmentedItem segmentedItem5 = new AntdUI.SegmentedItem();
titlebar = new AntdUI.PageHeader();
lbName = new AntdUI.Label();
tabsStas = new AntdUI.Tabs();
@ -58,7 +58,7 @@
panel2 = new AntdUI.Panel();
tabImgDisplay = new AntdUI.Tabs();
panel4 = new AntdUI.Panel();
richTextBox1 = new RichTextBox();
pnlLog = new AntdUI.Panel();
panel6 = new AntdUI.Panel();
lblNum2 = new Label();
label12 = new Label();
@ -125,7 +125,7 @@
tabsStas.Name = "tabsStas";
tabsStas.Pages.Add(tabPage3);
tabsStas.Size = new Size(580, 176);
tabsStas.Style = styleLine2;
tabsStas.Style = styleLine1;
tabsStas.TabIndex = 3;
tabsStas.Text = "tabs3";
//
@ -303,13 +303,13 @@
tabImgDisplay.Location = new Point(0, 0);
tabImgDisplay.Name = "tabImgDisplay";
tabImgDisplay.Size = new Size(1024, 388);
tabImgDisplay.Style = styleCard2;
tabImgDisplay.Style = styleCard1;
tabImgDisplay.TabIndex = 3;
tabImgDisplay.Text = "tabs1";
//
// panel4
//
panel4.Controls.Add(richTextBox1);
panel4.Controls.Add(pnlLog);
panel4.Controls.Add(panel6);
panel4.Dock = DockStyle.Bottom;
panel4.Location = new Point(0, 456);
@ -318,14 +318,14 @@
panel4.TabIndex = 2;
panel4.Text = "panel4";
//
// richTextBox1
// pnlLog
//
richTextBox1.Dock = DockStyle.Fill;
richTextBox1.Location = new Point(0, 0);
richTextBox1.Name = "richTextBox1";
richTextBox1.Size = new Size(719, 112);
richTextBox1.TabIndex = 1;
richTextBox1.Text = "";
pnlLog.Dock = DockStyle.Fill;
pnlLog.Location = new Point(0, 0);
pnlLog.Name = "pnlLog";
pnlLog.Size = new Size(719, 112);
pnlLog.TabIndex = 2;
pnlLog.Text = "panel8";
//
// panel6
//
@ -493,66 +493,66 @@
segmented1.Font = new Font("Microsoft YaHei UI", 9F);
segmented1.ForeColor = Color.White;
segmented1.Full = true;
segmentedItem6.Badge = null;
segmentedItem6.BadgeAlign = AntdUI.TAlignFrom.TR;
segmentedItem6.BadgeBack = null;
segmentedItem6.BadgeMode = false;
segmentedItem6.BadgeOffsetX = 0;
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;
segmentedItem7.BadgeBack = null;
segmentedItem7.BadgeMode = false;
segmentedItem7.BadgeOffsetX = 0;
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;
segmentedItem8.BadgeBack = null;
segmentedItem8.BadgeMode = false;
segmentedItem8.BadgeOffsetX = 0;
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;
segmentedItem9.BadgeBack = null;
segmentedItem9.BadgeMode = false;
segmentedItem9.BadgeOffsetX = 0;
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;
segmentedItem10.BadgeBack = null;
segmentedItem10.BadgeMode = false;
segmentedItem10.BadgeOffsetX = 0;
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);
segmented1.Items.Add(segmentedItem8);
segmented1.Items.Add(segmentedItem9);
segmented1.Items.Add(segmentedItem10);
segmentedItem1.Badge = null;
segmentedItem1.BadgeAlign = AntdUI.TAlignFrom.TR;
segmentedItem1.BadgeBack = null;
segmentedItem1.BadgeMode = false;
segmentedItem1.BadgeOffsetX = 0;
segmentedItem1.BadgeOffsetY = 0;
segmentedItem1.BadgeSize = 0.6F;
segmentedItem1.BadgeSvg = null;
segmentedItem1.IconActiveSvg = resources.GetString("segmentedItem1.IconActiveSvg");
segmentedItem1.IconSvg = resources.GetString("segmentedItem1.IconSvg");
segmentedItem1.Text = "启动";
segmentedItem2.Badge = null;
segmentedItem2.BadgeAlign = AntdUI.TAlignFrom.TR;
segmentedItem2.BadgeBack = null;
segmentedItem2.BadgeMode = false;
segmentedItem2.BadgeOffsetX = 0;
segmentedItem2.BadgeOffsetY = 0;
segmentedItem2.BadgeSize = 0.6F;
segmentedItem2.BadgeSvg = null;
segmentedItem2.IconActiveSvg = resources.GetString("segmentedItem2.IconActiveSvg");
segmentedItem2.IconSvg = resources.GetString("segmentedItem2.IconSvg");
segmentedItem2.Text = "停止";
segmentedItem3.Badge = null;
segmentedItem3.BadgeAlign = AntdUI.TAlignFrom.TR;
segmentedItem3.BadgeBack = null;
segmentedItem3.BadgeMode = false;
segmentedItem3.BadgeOffsetX = 0;
segmentedItem3.BadgeOffsetY = 0;
segmentedItem3.BadgeSize = 0.6F;
segmentedItem3.BadgeSvg = null;
segmentedItem3.IconActiveSvg = resources.GetString("segmentedItem3.IconActiveSvg");
segmentedItem3.IconSvg = resources.GetString("segmentedItem3.IconSvg");
segmentedItem3.Text = "复位";
segmentedItem4.Badge = null;
segmentedItem4.BadgeAlign = AntdUI.TAlignFrom.TR;
segmentedItem4.BadgeBack = null;
segmentedItem4.BadgeMode = false;
segmentedItem4.BadgeOffsetX = 0;
segmentedItem4.BadgeOffsetY = 0;
segmentedItem4.BadgeSize = 0.6F;
segmentedItem4.BadgeSvg = null;
segmentedItem4.IconActiveSvg = resources.GetString("segmentedItem4.IconActiveSvg");
segmentedItem4.IconSvg = resources.GetString("segmentedItem4.IconSvg");
segmentedItem4.Text = "登录";
segmentedItem5.Badge = null;
segmentedItem5.BadgeAlign = AntdUI.TAlignFrom.TR;
segmentedItem5.BadgeBack = null;
segmentedItem5.BadgeMode = false;
segmentedItem5.BadgeOffsetX = 0;
segmentedItem5.BadgeOffsetY = 0;
segmentedItem5.BadgeSize = 0.6F;
segmentedItem5.BadgeSvg = null;
segmentedItem5.IconActiveSvg = resources.GetString("segmentedItem5.IconActiveSvg");
segmentedItem5.IconSvg = resources.GetString("segmentedItem5.IconSvg");
segmentedItem5.Text = "设置";
segmented1.Items.Add(segmentedItem1);
segmented1.Items.Add(segmentedItem2);
segmented1.Items.Add(segmentedItem3);
segmented1.Items.Add(segmentedItem4);
segmented1.Items.Add(segmentedItem5);
segmented1.Location = new Point(0, 0);
segmented1.Name = "segmented1";
segmented1.Size = new Size(491, 68);
@ -626,7 +626,6 @@
private AntdUI.Panel panel2;
private AntdUI.Panel panel4;
private AntdUI.Tabs tabImgDisplay;
private RichTextBox richTextBox1;
private AntdUI.Panel panel6;
private Label lblUPH2;
private Label lblNum2;
@ -635,5 +634,6 @@
private Label label10;
private Label lblstarttime2;
private Label label7;
private AntdUI.Panel pnlLog;
}
}

View File

@ -14,6 +14,7 @@ using DHSoftware.Utils;
using DHSoftware.Views;
using DVPCameraType;
using HalconDotNet;
using Microsoft.VisualBasic.Logging;
using Microsoft.Win32;
using OpenCvSharp;
using SqlSugar;
@ -33,6 +34,7 @@ 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;
namespace DHSoftware
@ -40,7 +42,7 @@ namespace DHSoftware
public partial class MainWindow : AntdUI.Window
{
private Dictionary<string, List<string>> _cameraRelatedDetectionDict = null;
public event Action<LogMsg> OnLog;
private string _loginName;
public string LoginName
@ -262,12 +264,15 @@ namespace DHSoftware
var cameraBase = ConfigModel.CameraBaseList[i];
if (cameraBase.CamType == EnumCamType.Do3think)
{
Do3ThinkCamera cam = new Do3ThinkCamera();
cam.CameraName = cameraBase.CameraName;
cam.CameraIP = cameraBase.CameraIP;
cam.IsEnabled = cameraBase.IsEnabled;
Cameras.Add(cam);
cam.OnLog -= _visionEngine_OnLog;
cam.OnLog += _visionEngine_OnLog;
cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput;
}
@ -300,12 +305,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();
@ -323,6 +330,7 @@ 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;
@ -351,22 +359,66 @@ 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;
}
private void BtnDeleteProject_Click(object? sender, EventArgs e)
@ -579,7 +631,9 @@ namespace DHSoftware
private void HandleStartButton()
{
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候...");
StartProcess();
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!");
}
@ -731,12 +785,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;
@ -812,22 +864,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,20 +873,20 @@ namespace DHSoftware
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
//this.BeginInvoke(new MethodInvoker(delegate ()
//{
// // int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
// // richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
// // 设置回原来的滚动位置
// // richTextBox1.SelectionStart = richTextBox1.TextLength;
// // richTextBox1.ScrollToCaret();
//}));
////重新生成实例 销毁之前的实例
// LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber}但是没有推理1");
LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.CameraName} 找到产品{productNumber}但是没有推理1");
return;
}
@ -863,7 +900,7 @@ namespace DHSoftware
{
string detectionId = detectionDict[i];
// 1. 预处理
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
{
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId);
@ -888,13 +925,13 @@ namespace DHSoftware
// CalculateOEE();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
//int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
//richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
// richTextBox1.SelectionStart = richTextBox1.TextLength;
// richTextBox1.ScrollToCaret();
}));
#region 6.
@ -935,13 +972,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 +990,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();

View File

@ -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,34 +117,34 @@
<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">
<data name="segmentedItem1.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem6.IconSvg" xml:space="preserve">
<data name="segmentedItem1.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem7.IconActiveSvg" xml:space="preserve">
<data name="segmentedItem2.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem7.IconSvg" xml:space="preserve">
<data name="segmentedItem2.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem8.IconActiveSvg" xml:space="preserve">
<data name="segmentedItem3.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem8.IconSvg" xml:space="preserve">
<data name="segmentedItem3.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem9.IconActiveSvg" xml:space="preserve">
<data name="segmentedItem4.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem9.IconSvg" xml:space="preserve">
<data name="segmentedItem4.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem10.IconActiveSvg" xml:space="preserve">
<data name="segmentedItem5.IconActiveSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<data name="segmentedItem10.IconSvg" xml:space="preserve">
<data name="segmentedItem5.IconSvg" xml:space="preserve">
<value>&lt;svg viewBox="0 0 1027 1024" xmlns="http://www.w3.org/2000/svg" width="200" height="200"&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;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"/&gt;&lt;/svg&gt;</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

148
DHSoftware/Views/FrmLog.Designer.cs generated Normal file
View 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
View 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();
}
}
}

View 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>