diff --git a/PLCSharpWpf/App.xaml b/PLCSharpWpf/App.xaml index 44f5d2d..c72b6e9 100644 --- a/PLCSharpWpf/App.xaml +++ b/PLCSharpWpf/App.xaml @@ -1,9 +1,7 @@  + xmlns:prism="http://prismlibrary.com/" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> diff --git a/PLCSharpWpf/App.xaml.cs b/PLCSharpWpf/App.xaml.cs index 2b9d0c4..f380d36 100644 --- a/PLCSharpWpf/App.xaml.cs +++ b/PLCSharpWpf/App.xaml.cs @@ -1,7 +1,5 @@ using DryIoc; using PLCSharp.Core.Prism; -using System.Text.Json; -using System.Text.Json.Nodes; using PLCSharp.Models; using PLCSharp.VVMs.Authority; using PLCSharp.VVMs.MainWindow; @@ -12,10 +10,10 @@ using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using System.Text.Json.Nodes; using System.Threading; using System.Windows; - namespace PLCSharp { /// @@ -59,7 +57,6 @@ namespace PLCSharp _ = containerRegistry.RegisterSingleton(model); } - //注册导航特性的类到导航 var views = from t in Assembly.GetExecutingAssembly().GetTypes() where t.GetCustomAttribute() is not null @@ -86,9 +83,6 @@ namespace PLCSharp { containerRegistry.RegisterForNavigation(dialog, dialog.Name); } - - - } //第2执行 @@ -126,8 +120,6 @@ namespace PLCSharp navigteItem.UserLevel = page.UserLevel; navigteItem.Index = page.Index; navigate.NavigateList.Add(navigteItem); - - } //反射需要弹出的窗口 var dialogs = from t in Assembly.GetExecutingAssembly().GetTypes() @@ -135,7 +127,6 @@ namespace PLCSharp select t; foreach (var dialog in dialogs) { - var page = dialog.GetCustomAttribute(); var navigteItem = Container.Resolve(); navigteItem.ViewName = page.ViewName; @@ -144,7 +135,6 @@ namespace PLCSharp navigteItem.UserLevel = page.UserLevel; navigteItem.Index = page.Index; navigate.DialogList.Add(navigteItem); - } var window = Container.Resolve(); @@ -166,6 +156,7 @@ namespace PLCSharp return window; } + /// /// 自动寻找ViewModel并绑定到View,要求ViewModel命名为View的全名加上ViewModel,比如MainWindow的ViewModel命名为MainWindowViewModel /// @@ -181,12 +172,12 @@ namespace PLCSharp return Type.GetType(viewModelName); }); } + /// /// 加载环境变量 /// private static void LoadConfig() { - if (!Directory.Exists("./Config/")) { Directory.CreateDirectory("./Config/"); @@ -211,23 +202,17 @@ namespace PLCSharp } catch (Exception) { - } - } - - } - [LibraryImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] -#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods private static partial bool ShowWindowAsync(IntPtr hWnd, int cmdShow); + #pragma warning restore VSTHRD200 // Use "Async" suffix for async methods [DllImport("User32.dll")] - private static extern bool SetForegroundWindow(IntPtr hWnd); /// @@ -235,50 +220,42 @@ namespace PLCSharp /// public static void ForegroundWindow() { - Process currentProcess = Process.GetCurrentProcess(); foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName)) { if (process.Id != currentProcess.Id) { - // 将现有实例的窗口切换到前台 IntPtr hWnd = process.MainWindowHandle; if (hWnd != IntPtr.Zero) { - ShowWindowAsync(hWnd, 9); SetForegroundWindow(hWnd); - } break; } } } - - private void RegisterEvents() { - // 后台线程异常的捕获方法 + // 后台线程异常的捕获方法 TaskScheduler.UnobservedTaskException += (sender, args) => { - RecordLog(args.Exception.ToString()); args.SetObserved(); }; - // 全局异常的捕获方法 + // 全局异常的捕获方法 AppDomain.CurrentDomain.UnhandledException += (sender, args) => { - RecordLog(args.ExceptionObject.ToString()); - }; } + /// /// 记录日志 /// @@ -287,7 +264,6 @@ namespace PLCSharp { lock (this) { - var path = Environment.CurrentDirectory + @"\DebugLog\"; //文件夹路径 var paths = path + DateTime.Now.ToString("yyyyMMdd") + ".txt"; //文件路径 以年月日为名称 @@ -310,7 +286,6 @@ namespace PLCSharp fs.Flush(); fs.Close(); } - } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Common/CellState.cs b/PLCSharpWpf/Core/Common/CellState.cs index 3e7f910..e11e842 100644 --- a/PLCSharpWpf/Core/Common/CellState.cs +++ b/PLCSharpWpf/Core/Common/CellState.cs @@ -2,7 +2,6 @@ namespace PLCSharp.Core.Common { - public enum CellState { 无料 = 0, @@ -20,8 +19,8 @@ namespace PLCSharp.Core.Common /// public class CellInfo : BindableBase { - private int _Index; + /// /// 单元格索引 /// @@ -32,6 +31,7 @@ namespace PLCSharp.Core.Common } private int _Row; + /// /// 行号 /// @@ -42,6 +42,7 @@ namespace PLCSharp.Core.Common } private int _Column; + /// /// 列号 /// @@ -52,6 +53,7 @@ namespace PLCSharp.Core.Common } private CellState _State; + /// /// 状态标志 /// @@ -67,6 +69,7 @@ namespace PLCSharp.Core.Common } private string _Info; + /// /// 附加信息 /// @@ -77,6 +80,7 @@ namespace PLCSharp.Core.Common } private string _Tag; + /// /// 标签 /// @@ -87,7 +91,5 @@ namespace PLCSharp.Core.Common } public event EventHandler _CellChanged; - - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Common/ErrorLog.cs b/PLCSharpWpf/Core/Common/ErrorLog.cs index 5855ca5..8a5a020 100644 --- a/PLCSharpWpf/Core/Common/ErrorLog.cs +++ b/PLCSharpWpf/Core/Common/ErrorLog.cs @@ -1,4 +1,4 @@ -using Prism.Mvvm; +using Prism.Mvvm; using System.ComponentModel.DataAnnotations; namespace PLCSharp.Core.Common @@ -8,7 +8,6 @@ namespace PLCSharp.Core.Common /// public class ErrorLog : BindableBase { - /// /// 唯一标识 /// @@ -22,10 +21,10 @@ namespace PLCSharp.Core.Common { Message = message; Time = DateTime.Now; - } private string _Message; + /// /// 消息内容 /// @@ -36,6 +35,7 @@ namespace PLCSharp.Core.Common } private DateTime _Time; + /// /// Time /// @@ -46,6 +46,7 @@ namespace PLCSharp.Core.Common } private bool _IsConfirm; + /// /// IsConfirm /// @@ -55,4 +56,4 @@ namespace PLCSharp.Core.Common set { SetProperty(ref _IsConfirm, value); } } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Common/FlowModel.cs b/PLCSharpWpf/Core/Common/FlowModel.cs index 7715cbd..383c2eb 100644 --- a/PLCSharpWpf/Core/Common/FlowModel.cs +++ b/PLCSharpWpf/Core/Common/FlowModel.cs @@ -5,9 +5,8 @@ /// public class FlowModel { - - private int _Step; + /// /// 当前执行的步骤序号 /// @@ -22,7 +21,6 @@ } } - /// /// 当前步骤的开始时间 /// @@ -32,28 +30,32 @@ /// 整个流程的开始时间 /// public DateTime FlowStarTime { get; set; } = DateTime.Now; + /// /// 是否完成 /// public bool Done { get; set; } + /// /// 流程是否正常结束(默认 false,正常结束时置 true) /// public bool IsSuccess { get; set; } + /// /// 失败原因(非空表示异常结束) /// public string? FailMessage { get; set; } + /// /// 单个步骤超时时间(秒),默认 5 秒 /// public double TimeoutSeconds { get; set; } = 5; + /// /// 默认构造函数,自动调用 Reset 初始化 /// public FlowModel() { - Reset(); } @@ -69,6 +71,7 @@ StepTime = DateTime.Now; FlowStarTime = DateTime.Now; } + /// /// 检查当前步骤是否已超时 /// @@ -89,7 +92,6 @@ return FlowStarTime.AddSeconds(second) < DateTime.Now; } - public Task TaskBool { get; set; } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Common/TitleState.cs b/PLCSharpWpf/Core/Common/TitleState.cs index a31ab9b..92e3ae3 100644 --- a/PLCSharpWpf/Core/Common/TitleState.cs +++ b/PLCSharpWpf/Core/Common/TitleState.cs @@ -1,4 +1,4 @@ -using Prism.Mvvm; +using Prism.Mvvm; using System.Windows.Media; namespace PLCSharp.Core.Common @@ -9,6 +9,7 @@ namespace PLCSharp.Core.Common public class TitleState : BindableBase { private string _Info = ""; + /// /// Info /// @@ -19,6 +20,7 @@ namespace PLCSharp.Core.Common } private Brush _Background = Brushes.White; + /// /// Background /// @@ -28,4 +30,4 @@ namespace PLCSharp.Core.Common set { SetProperty(ref _Background, value); } } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Prism/CoreAttribute.cs b/PLCSharpWpf/Core/Prism/CoreAttribute.cs index 4420e0a..363181a 100644 --- a/PLCSharpWpf/Core/Prism/CoreAttribute.cs +++ b/PLCSharpWpf/Core/Prism/CoreAttribute.cs @@ -1,27 +1,19 @@ -namespace PLCSharp.Core.Prism +namespace PLCSharp.Core.Prism { /// /// 标志此特性的类会被注册为单例 /// [AttributeUsage(AttributeTargets.Class)] - public class ModelAttribute : Attribute { - - - } - /// /// 标志此特性的类会被注册为弹出窗口 /// [AttributeUsage(AttributeTargets.Class)] public class DialogAttribute : Attribute { - - - } /// @@ -30,7 +22,6 @@ namespace PLCSharp.Core.Prism [AttributeUsage(AttributeTargets.Class)] public class DialogMenuAttribute : Attribute { - /// /// 视图名称 /// @@ -60,7 +51,6 @@ namespace PLCSharp.Core.Prism /// 当前索引 /// public int Index { get; set; } - } /// @@ -98,6 +88,5 @@ namespace PLCSharp.Core.Prism /// 当前索引 /// public int Index { get; set; } - } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/Prism/DataGridScrollToBottomBehavior.cs b/PLCSharpWpf/Core/Prism/DataGridScrollToBottomBehavior.cs index ab189dd..e461522 100644 --- a/PLCSharpWpf/Core/Prism/DataGridScrollToBottomBehavior.cs +++ b/PLCSharpWpf/Core/Prism/DataGridScrollToBottomBehavior.cs @@ -1,4 +1,4 @@ -using Microsoft.Xaml.Behaviors; +using Microsoft.Xaml.Behaviors; using System.ComponentModel; using System.Windows.Controls; @@ -8,7 +8,7 @@ namespace PLCSharp.Core.Prism /// ClassName: ListBoxScrollToBottomBehavior /// Description:列表框滚动条行为 /// Author: luc - /// CreatTime: 2022/12/12 18:11:48 + /// CreatTime: 2022/12/12 18:11:48 /// public class DataGridScrollToBottomBehavior : Behavior { @@ -46,5 +46,4 @@ namespace PLCSharp.Core.Prism AssociatedObject.ScrollIntoView(AssociatedObject.Items[^1]); } } - -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Prism/DialogAwareBase.cs b/PLCSharpWpf/Core/Prism/DialogAwareBase.cs index 3c0f34e..0c1e9e6 100644 --- a/PLCSharpWpf/Core/Prism/DialogAwareBase.cs +++ b/PLCSharpWpf/Core/Prism/DialogAwareBase.cs @@ -17,11 +17,10 @@ namespace PLCSharp.Core.Prism public DialogAwareBase(IContainerExtension container, IEventAggregator ea, IDialogService dialogService) { _EventAggregator = ea; - } - private string _Title = ""; + /// /// 标题 /// @@ -30,7 +29,9 @@ namespace PLCSharp.Core.Prism get { return _Title; } set { SetProperty(ref _Title, value); } } + private DelegateCommand _closeDialogCommand; + /// /// 关闭对话框命令 /// @@ -114,16 +115,18 @@ namespace PLCSharp.Core.Prism } } } + /// /// 事件聚合器,用于发送消息和通知 /// protected readonly IEventAggregator _EventAggregator; + /// /// 发送错误消息到日志和界面 /// /// 错误消息内容 /// 消息类型(记录、对话框提示等) - public void SendErr(string msg, ShowType type,ErrType errType) + public void SendErr(string msg, ShowType type, ErrType errType) { _EventAggregator.GetEvent().Publish(new() { @@ -142,6 +145,7 @@ namespace PLCSharp.Core.Prism { SendErr(msg, ShowType.Record, ErrType.Error); } + /// /// 发送弹出故障消息 /// diff --git a/PLCSharpWpf/Core/Prism/MessageEvent.cs b/PLCSharpWpf/Core/Prism/MessageEvent.cs index 0bf3138..2dfb99b 100644 --- a/PLCSharpWpf/Core/Prism/MessageEvent.cs +++ b/PLCSharpWpf/Core/Prism/MessageEvent.cs @@ -29,8 +29,7 @@ namespace PLCSharp.Core.Prism /// public ShowType Type { get; set; } - - public ErrType ErrType { get; set; } + public ErrType ErrType { get; set; } } /// @@ -63,16 +62,16 @@ namespace PLCSharp.Core.Prism public enum ShowType { - - /// /// 记录 /// Record = 1, + /// /// 弹出 /// ShowDialog = 2, + /// /// 弹出并记录 /// @@ -81,16 +80,14 @@ namespace PLCSharp.Core.Prism public enum ErrType { - - /// /// 普通信息 /// Info = 1, + /// /// 故障 /// Error = 2, - } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/Prism/ModelBase.cs b/PLCSharpWpf/Core/Prism/ModelBase.cs index 9f9ae88..a7bb31f 100644 --- a/PLCSharpWpf/Core/Prism/ModelBase.cs +++ b/PLCSharpWpf/Core/Prism/ModelBase.cs @@ -16,21 +16,25 @@ namespace PLCSharp.Core.Prism /// _EventAggregator /// protected readonly IEventAggregator _EventAggregator; + /// /// 对话框服务 /// [NotMapped] public readonly IDialogService _dialogService; + /// /// _container /// [NotMapped] public readonly IContainerExtension _container; + /// /// _DatasContext /// [NotMapped] public DatasContext _DatasContext { get; set; } + /// /// 模型Base /// @@ -41,10 +45,8 @@ namespace PLCSharp.Core.Prism _EventAggregator = ea; _dialogService = dialogService; AppDomain.CurrentDomain.ProcessExit += OnExit; - } - /// /// OnExit /// @@ -52,8 +54,8 @@ namespace PLCSharp.Core.Prism /// e protected virtual void OnExit(object sender, EventArgs e) { - } + /// /// 发送消息到事件总线 /// @@ -69,14 +71,16 @@ namespace PLCSharp.Core.Prism Content = msg }); } + /// /// 发送故障信息 /// /// msg - public void SendErr(string msg ) + public void SendErr(string msg) { SendErr(msg, ShowType.Record, ErrType.Error); } + /// /// 发送弹出故障消息 /// @@ -103,6 +107,5 @@ namespace PLCSharp.Core.Prism { SendErr(msg, ShowType.ShowDialogAndRecord, ErrType.Info); } - } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/Prism/NavigateItem.cs b/PLCSharpWpf/Core/Prism/NavigateItem.cs index 123d056..2b29d36 100644 --- a/PLCSharpWpf/Core/Prism/NavigateItem.cs +++ b/PLCSharpWpf/Core/Prism/NavigateItem.cs @@ -1,4 +1,4 @@ -using PLCSharp.VVMs.Authority; +using PLCSharp.VVMs.Authority; using Prism.Commands; using Prism.Dialogs; using Prism.Mvvm; @@ -16,8 +16,8 @@ namespace PLCSharp.Core.Prism public NavigateItem(IDialogService dialogService) { _dialogService = dialogService; - } + private string _ViewName; /// @@ -89,42 +89,37 @@ namespace PLCSharp.Core.Prism return Index.CompareTo(other.Index); } - private DelegateCommand _Open; + /// /// 打开 /// public DelegateCommand Open => _Open ??= new DelegateCommand(ExecuteOpen); - void ExecuteOpen() + private void ExecuteOpen() { if (ShowList.Contains(ViewName) == false) { ShowList.Add(ViewName); try { - - _dialogService.Show(ViewName, r => { if (ShowList.Contains(ViewName)) { - ShowList.Remove(ViewName); } - }); } catch (Exception) { - ShowList.Remove(ViewName); } } } private List ShowList = []; - IDialogService _dialogService { get; set; } + private IDialogService _dialogService { get; set; } } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/Prism/ObservableDictionary.cs b/PLCSharpWpf/Core/Prism/ObservableDictionary.cs index d377bcd..02c678d 100644 --- a/PLCSharpWpf/Core/Prism/ObservableDictionary.cs +++ b/PLCSharpWpf/Core/Prism/ObservableDictionary.cs @@ -1,4 +1,5 @@ #nullable enable + using System.Collections.Specialized; using System.ComponentModel; @@ -32,6 +33,7 @@ namespace PLCSharp.Core.Prism } public event NotifyCollectionChangedEventHandler? CollectionChanged; + public event PropertyChangedEventHandler? PropertyChanged; #region 遮蔽基类成员以拦截修改 @@ -40,10 +42,12 @@ namespace PLCSharp.Core.Prism /// Keys /// public new KeyCollection Keys => base.Keys; + /// /// Values /// public new ValueCollection Values => base.Values; + /// /// 数量 /// @@ -123,7 +127,7 @@ namespace PLCSharp.Core.Prism /// 返回布尔值 public new bool TryGetValue(TKey key, out TValue value) => base.TryGetValue(key, out value!); - #endregion + #endregion 遮蔽基类成员以拦截修改 #region SetValue(被 indexer setter 调用) @@ -149,7 +153,7 @@ namespace PLCSharp.Core.Prism } } - #endregion + #endregion SetValue(被 indexer setter 调用) #region 事件通知 @@ -186,7 +190,7 @@ namespace PLCSharp.Core.Prism PropertyChanged?.Invoke(this, e); } - #endregion + #endregion 事件通知 #region 辅助方法 @@ -228,6 +232,6 @@ namespace PLCSharp.Core.Prism return ContainsKey(key) ? base[key] : default!; } - #endregion + #endregion 辅助方法 } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Resources/Iconfont/Icon.cs b/PLCSharpWpf/Core/Resources/Iconfont/Icon.cs index 05ba2bd..05d6a91 100644 --- a/PLCSharpWpf/Core/Resources/Iconfont/Icon.cs +++ b/PLCSharpWpf/Core/Resources/Iconfont/Icon.cs @@ -1,4 +1,4 @@ -namespace PLCSharp.Core.Resources.Iconfont +namespace PLCSharp.Core.Resources.Iconfont { /// /// Icon @@ -9,262 +9,325 @@ namespace PLCSharp.Core.Resources.Iconfont /// 方向圆_向上 /// public static string 方向圆_向上 = "\ue61a"; + /// /// 方向圆_向下 /// public static string 方向圆_向下 = "\ue61d"; + /// /// 方向圆_向右 /// public static string 方向圆_向右 = "\ue61e"; + /// /// 方向圆_向左 /// public static string 方向圆_向左 = "\ue620"; + /// /// 方向_向下 /// public static string 方向_向下 = "\ue615"; + /// /// 方向_向上 /// public static string 方向_向上 = "\ue617"; + /// /// 方向_向左 /// public static string 方向_向左 = "\ue618"; + /// /// 方向_向右 /// public static string 方向_向右 = "\ue619"; + /// /// 操作_温度 /// public static string 操作_温度 = "\ue626"; + /// /// 拍照_线性 /// public static string 拍照_线性 = "\ue8d1"; + /// /// 停止 /// public static string 停止 = "\ue611"; + /// /// 功能 /// public static string 功能 = "\ue612"; + /// /// 操作_打印 /// public static string 操作_打印 = "\ue738"; + /// /// 操作日志 /// public static string 操作日志 = "\ue664"; + /// /// 气缸 /// public static string 气缸 = "\ue616"; + /// /// 伺服电机 /// public static string 伺服电机 = "\ue609"; + /// /// 拆线简 /// public static string 拆线简 = "\ue64a"; + /// /// 折线 /// public static string 折线 = "\ue878"; + /// /// 饼图 /// public static string 饼图 = "\ue66b"; + /// /// 仪表盘 /// public static string 仪表盘 = "\ueab4"; + /// /// 服务 /// public static string 服务 = "\ue6d8"; + /// /// 工具 /// public static string 工具 = "\ue614"; + /// /// 网络系统 /// public static string 网络系统 = "\ue62e"; + /// /// 管理员 /// public static string 管理员 = "\ue62a"; + /// /// 紧急告警 /// public static string 紧急告警 = "\ue678"; + /// /// 记录 /// public static string 记录 = "\ue604"; + /// /// 告警 /// public static string 告警 = "\uec35"; + /// /// 历史记录 /// public static string 历史记录 = "\ue605"; + /// /// 咨询记录 /// public static string 咨询记录 = "\ue68c"; + /// /// 时钟 /// public static string 时钟 = "\ue75b"; + /// /// 告警记录 /// public static string 告警记录 = "\ue66a"; + /// /// 告警灯 /// public static string 告警灯 = "\ue61f"; + /// /// 权限 /// public static string 权限 = "\ue610"; + /// /// 权限管理 /// public static string 权限管理 = "\ue64c"; + /// /// 转换 /// public static string 转换 = "\ue61b"; + /// /// 服务器 /// public static string 服务器 = "\ue687"; + /// /// 配方方案 /// public static string 配方方案 = "\ue681"; + /// /// 人和钥匙 /// public static string 人和钥匙 = "\ue61c"; + /// /// 安全密钥 /// public static string 安全密钥 = "\ue665"; + /// /// 配置 /// public static string 配置 = "\ue659"; + /// /// 查询 /// public static string 查询 = "\ue660"; + /// /// 主页 /// public static string 主页 = "\ue622"; + /// /// 关闭 /// public static string 关闭 = "\ueca0"; + /// /// 最小化 /// public static string 最小化 = "\ue650"; + /// /// 菜单 /// public static string 菜单 = "\ue790"; + /// /// 最大化2 /// public static string 最大化2 = "\ue623"; + /// /// 设置 /// public static string 设置 = "\ue8b8"; + /// /// 调试 /// public static string 调试 = "\ueb61"; + /// /// 编辑 /// public static string 编辑 = "\ueb62"; + /// /// 警告 /// public static string 警告 = "\ueb65"; + /// /// 人机交互 /// public static string 人机交互 = "\ueb67"; + /// /// 使用文档 /// public static string 使用文档 = "\ueb68"; + /// /// 数据看板 /// public static string 数据看板 = "\ueb6b"; + /// /// 账号权限管理 /// public static string 账号权限管理 = "\ueb6e"; + /// /// 园区运维 /// public static string 园区运维 = "\ueb6f"; + /// /// 自定义 /// public static string 自定义 = "\ueb71"; + /// /// 载入中 /// public static string 载入中 = "\ueb80"; + /// /// 图表_柱状图 /// public static string 图表_柱状图 = "\ueb96"; + /// /// 形状_图片 /// public static string 形状_图片 = "\ueb98"; + /// /// 组织群组 /// public static string 组织群组 = "\uebd8"; + /// /// 打开 /// public static string 打开 = "\uebdf"; + /// /// 控件已选 /// public static string 控件已选 = "\uebf0"; + /// /// 刷新 /// public static string 刷新 = "\uec08"; + /// /// 搜索放大 /// public static string 搜索放大 = "\uec32"; + /// /// 最大化 /// public static string 最大化 = "\ue673"; - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Resources/Iconfont/demo.css b/PLCSharpWpf/Core/Resources/Iconfont/demo.css index 8b9d690..730925d 100644 --- a/PLCSharpWpf/Core/Resources/Iconfont/demo.css +++ b/PLCSharpWpf/Core/Resources/Iconfont/demo.css @@ -1,4 +1,4 @@ -/* Logo 字体 */ +/* Logo 字体 */ @font-face { font-family: "iconfont logo"; src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834'); diff --git a/PLCSharpWpf/Core/Resources/Iconfont/iconfont.css b/PLCSharpWpf/Core/Resources/Iconfont/iconfont.css index b373517..445c676 100644 --- a/PLCSharpWpf/Core/Resources/Iconfont/iconfont.css +++ b/PLCSharpWpf/Core/Resources/Iconfont/iconfont.css @@ -1,4 +1,4 @@ -@font-face { +@font-face { font-family: "iconfont"; /* Project id 3928252 */ src: url('iconfont.woff2?t=1701616831575') format('woff2'), url('iconfont.woff?t=1701616831575') format('woff'), url('iconfont.ttf?t=1701616831575') format('truetype'); } diff --git a/PLCSharpWpf/Core/Tools/BitTool.cs b/PLCSharpWpf/Core/Tools/BitTool.cs index d4ef2eb..984e868 100644 --- a/PLCSharpWpf/Core/Tools/BitTool.cs +++ b/PLCSharpWpf/Core/Tools/BitTool.cs @@ -1,11 +1,10 @@ -namespace PLCSharp.Core.Tools +namespace PLCSharp.Core.Tools { /// /// Bit工具 /// public static class BitTool { - #region uint /// @@ -66,7 +65,9 @@ namespace PLCSharp.Core.Tools intValue &= ~(uint)val; } - #endregion + #endregion uint + + #region int @@ -128,7 +129,9 @@ namespace PLCSharp.Core.Tools intValue &= ~val; } - #endregion + #endregion int + + #region byte @@ -204,7 +207,6 @@ namespace PLCSharp.Core.Tools byteValue &= (byte)~val; } - #endregion - + #endregion byte } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/BoolToValueConverter.cs b/PLCSharpWpf/Core/Tools/BoolToValueConverter.cs index 9f5b7d5..e5183b3 100644 --- a/PLCSharpWpf/Core/Tools/BoolToValueConverter.cs +++ b/PLCSharpWpf/Core/Tools/BoolToValueConverter.cs @@ -1,4 +1,4 @@ -using System.Globalization; +using System.Globalization; using System.Windows; using System.Windows.Data; @@ -10,11 +10,8 @@ namespace PLCSharp.Core.Tools public class BoolToValueConverter : IValueConverter { - #region IValueConverter Members - - /// /// 转换 /// @@ -26,19 +23,14 @@ namespace PLCSharp.Core.Tools public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if ((bool)value) return parameter; - else return DependencyProperty.UnsetValue; - } - - /// /// 转换Back /// @@ -50,14 +42,9 @@ namespace PLCSharp.Core.Tools public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - return Equals(value, parameter); - } - - - #endregion - + #endregion IValueConverter Members } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/Copy.cs b/PLCSharpWpf/Core/Tools/Copy.cs index 9c5266b..cd58586 100644 --- a/PLCSharpWpf/Core/Tools/Copy.cs +++ b/PLCSharpWpf/Core/Tools/Copy.cs @@ -1,7 +1,4 @@ - - -using System.Linq.Expressions; - +using System.Linq.Expressions; namespace PLCSharp.Core.Tools { @@ -11,6 +8,7 @@ namespace PLCSharp.Core.Tools public static class Copy { private static readonly Dictionary _cache = []; + /// /// DeepCopy /// @@ -32,7 +30,6 @@ namespace PLCSharp.Core.Tools var binding = Expression.Bind(property, propertyAccess); bindings.Add(binding); } - } var memberInit = Expression.MemberInit(Expression.New(type), bindings); @@ -42,11 +39,8 @@ namespace PLCSharp.Core.Tools func = lambda.Compile(); _cache[type] = func; - } return ((Func)func)(obj); } - } - -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/FileTools.cs b/PLCSharpWpf/Core/Tools/FileTools.cs index c4312e3..01b7b6b 100644 --- a/PLCSharpWpf/Core/Tools/FileTools.cs +++ b/PLCSharpWpf/Core/Tools/FileTools.cs @@ -1,4 +1,4 @@ -using System.Windows.Media.Imaging; +using System.Windows.Media.Imaging; namespace PLCSharp.Core.Tools { @@ -7,9 +7,6 @@ namespace PLCSharp.Core.Tools /// public class FileTools { - - - /// /// 获取图像 /// @@ -24,6 +21,5 @@ namespace PLCSharp.Core.Tools bmp.Freeze(); return bmp; } - } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/JsonOptions.cs b/PLCSharpWpf/Core/Tools/JsonOptions.cs index 6771d34..072dbcb 100644 --- a/PLCSharpWpf/Core/Tools/JsonOptions.cs +++ b/PLCSharpWpf/Core/Tools/JsonOptions.cs @@ -1,4 +1,5 @@ -#nullable enable +#nullable enable + using System.Text.Json; namespace PLCSharp.Core.Tools @@ -25,4 +26,4 @@ namespace PLCSharp.Core.Tools WriteIndented = true, }; } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/NetTool.cs b/PLCSharpWpf/Core/Tools/NetTool.cs index e9df77c..dcdc516 100644 --- a/PLCSharpWpf/Core/Tools/NetTool.cs +++ b/PLCSharpWpf/Core/Tools/NetTool.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using System.Net.NetworkInformation; using System.Text.RegularExpressions; @@ -10,6 +10,7 @@ namespace PLCSharp.Core.Tools public static class NetTool { private static readonly Ping Ping = new(); + /// /// PingIPAsync /// @@ -34,12 +35,10 @@ namespace PLCSharp.Core.Tools } catch { - return false; } } - /// /// PingIP /// @@ -49,8 +48,6 @@ namespace PLCSharp.Core.Tools { lock (Ping) { - - var isip = IPAddress.TryParse(ip, out var ipAddress); if (isip == false) { @@ -63,16 +60,14 @@ namespace PLCSharp.Core.Tools } try { - var result = Ping.Send(ipAddress); return result.Status == IPStatus.Success; } catch { - return false; } } } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/StringTool.cs b/PLCSharpWpf/Core/Tools/StringTool.cs index 73aa44f..4a3798c 100644 --- a/PLCSharpWpf/Core/Tools/StringTool.cs +++ b/PLCSharpWpf/Core/Tools/StringTool.cs @@ -1,4 +1,4 @@ -using System.Text; +using System.Text; namespace PLCSharp.Core.Tools { @@ -30,4 +30,4 @@ namespace PLCSharp.Core.Tools return newRandom.ToString(); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/WpfTool.cs b/PLCSharpWpf/Core/Tools/WpfTool.cs index 53d650c..09f0263 100644 --- a/PLCSharpWpf/Core/Tools/WpfTool.cs +++ b/PLCSharpWpf/Core/Tools/WpfTool.cs @@ -12,7 +12,8 @@ namespace PLCSharp.Core.Tools public class WpfTool { private readonly ConcurrentQueue PointsQueue = new(); - readonly List Points = []; + private readonly List Points = []; + /// /// 执行绘制Async /// @@ -67,15 +68,12 @@ namespace PLCSharp.Core.Tools var scale = Math.Max(scaley, scalex); foreach (var point in points) { - graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.White), new Rectangle((int)(point.X / scale), (int)(point.Y / scale), 1, 1)); - } graphics.Flush(); writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height)); writeableBitmap.Unlock(); - }); } } @@ -104,7 +102,6 @@ namespace PLCSharp.Core.Tools System.Windows.Media.Color color = System.Windows.Media.Color.FromArgb(255, red, green, blue); return color; - } /// @@ -134,4 +131,4 @@ namespace PLCSharp.Core.Tools return null; } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/Tools/XPoint.cs b/PLCSharpWpf/Core/Tools/XPoint.cs index dce0262..2623ad2 100644 --- a/PLCSharpWpf/Core/Tools/XPoint.cs +++ b/PLCSharpWpf/Core/Tools/XPoint.cs @@ -10,6 +10,7 @@ namespace PLCSharp.Core.Tools public class XPoint : BindableBase, IEquatable { private double _X; + /// /// X坐标 /// @@ -20,6 +21,7 @@ namespace PLCSharp.Core.Tools } private double _Y; + /// /// Y /// @@ -30,6 +32,7 @@ namespace PLCSharp.Core.Tools } private double _Z; + /// /// Z /// @@ -40,6 +43,7 @@ namespace PLCSharp.Core.Tools } private double _Angle; + /// /// U /// @@ -49,8 +53,6 @@ namespace PLCSharp.Core.Tools set { SetProperty(ref _Angle, Math.Round(value, 6)); } } - - /// /// 获取Offs点位 /// @@ -82,7 +84,9 @@ namespace PLCSharp.Core.Tools && Math.Abs(Z - other.Z) < 1e-9 && Math.Abs(Angle - other.Angle) < 1e-9; } + public override bool Equals(object? obj) => Equals(obj as XPoint); + public override int GetHashCode() => HashCode.Combine(X, Y, Z, Angle); public static bool operator ==(XPoint? left, XPoint? right) @@ -102,6 +106,5 @@ namespace PLCSharp.Core.Tools { return $"X:{X:F6},Y:{Y:F6},Z:{Z:F6},Angle:{Angle:F6}"; } - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ImageEdit.xaml b/PLCSharpWpf/Core/UserControls/ImageEdit.xaml index 2cd00bc..08f038d 100644 --- a/PLCSharpWpf/Core/UserControls/ImageEdit.xaml +++ b/PLCSharpWpf/Core/UserControls/ImageEdit.xaml @@ -77,7 +77,6 @@ Text="100%" VerticalAlignment="Center" Foreground="Wheat" /> - ? _roiTcs; private TaskCompletionSource? _rotateRoiTcs; private TaskCompletionSource? _lineTcs; + // --- 圆形状态 --- private System.Windows.Shapes.Ellipse? _tempCircle; // 橡皮筋圆形预览 + private CircleROI? _pendingCircle; // 左键松开后创建、等待右键确认的圆形 private string? _circleAdjustMode; // null/"move"/"radius" private TaskCompletionSource? _circleTcs; @@ -498,12 +502,12 @@ namespace PLCSharp.Core.UserControls else if (ImageSource.Format == System.Windows.Media.PixelFormats.Bgr24) { int off = py * stride + px * 3; - pixelval.Text = $"R:{buf[off+2]} G:{buf[off+1]} B:{buf[off]}"; + pixelval.Text = $"R:{buf[off + 2]} G:{buf[off + 1]} B:{buf[off]}"; } else if (ImageSource.Format == System.Windows.Media.PixelFormats.Bgra32) { int off = py * stride + px * 4; - pixelval.Text = $"R:{buf[off+2]} G:{buf[off+1]} B:{buf[off]}"; + pixelval.Text = $"R:{buf[off + 2]} G:{buf[off + 1]} B:{buf[off]}"; } else { @@ -524,10 +528,12 @@ namespace PLCSharp.Core.UserControls _pendingLine.StartX = position.X + _adjustOffset.X; _pendingLine.StartY = position.Y + _adjustOffset.Y; break; + case "end": _pendingLine.EndX = position.X + _adjustOffset.X; _pendingLine.EndY = position.Y + _adjustOffset.Y; break; + case "move": _pendingLine.StartX += dx; _pendingLine.StartY += dy; @@ -549,6 +555,7 @@ namespace PLCSharp.Core.UserControls _pendingCircle.CenterX += position.X - previousMousePoint.X; _pendingCircle.CenterY += position.Y - previousMousePoint.Y; break; + case "radius": double r = DistanceTo(position, _pendingCircle.CenterX, _pendingCircle.CenterY); if (r >= 1) @@ -701,7 +708,7 @@ namespace PLCSharp.Core.UserControls } } - #endregion + #endregion 拖动和画 #region 直线辅助方法 @@ -863,7 +870,7 @@ namespace PLCSharp.Core.UserControls _tempArrow = null; } - #endregion + #endregion 直线辅助方法 #region 圆形辅助方法 @@ -891,8 +898,10 @@ namespace PLCSharp.Core.UserControls const double crossSize = 6; var crossH = new System.Windows.Shapes.Line { - X1 = cx - crossSize, Y1 = cy, - X2 = cx + crossSize, Y2 = cy, + X1 = cx - crossSize, + Y1 = cy, + X2 = cx + crossSize, + Y2 = cy, Stroke = Brushes.Lime, StrokeThickness = 2, Tag = tag, @@ -900,8 +909,10 @@ namespace PLCSharp.Core.UserControls mainBox1.Children.Add(crossH); var crossV = new System.Windows.Shapes.Line { - X1 = cx, Y1 = cy - crossSize, - X2 = cx, Y2 = cy + crossSize, + X1 = cx, + Y1 = cy - crossSize, + X2 = cx, + Y2 = cy + crossSize, Stroke = Brushes.Lime, StrokeThickness = 2, Tag = tag, @@ -911,8 +922,10 @@ namespace PLCSharp.Core.UserControls // 半径指示线(从圆心到圆周) var radiusLine = new System.Windows.Shapes.Line { - X1 = cx, Y1 = cy, - X2 = cx + r, Y2 = cy, + X1 = cx, + Y1 = cy, + X2 = cx + r, + Y2 = cy, Stroke = Brushes.Lime, StrokeThickness = 1, StrokeDashArray = new DoubleCollection { 3, 3 }, @@ -923,7 +936,8 @@ namespace PLCSharp.Core.UserControls // 端点圆(圆心可拖拽点 + 圆周可拖拽点) var epCenter = new Ellipse { - Width = 10, Height = 10, + Width = 10, + Height = 10, Fill = Brushes.White, Stroke = Brushes.Lime, StrokeThickness = 2, @@ -935,7 +949,8 @@ namespace PLCSharp.Core.UserControls var epEdge = new Ellipse { - Width = 10, Height = 10, + Width = 10, + Height = 10, Fill = Brushes.White, Stroke = Brushes.Lime, StrokeThickness = 2, @@ -995,7 +1010,7 @@ namespace PLCSharp.Core.UserControls } } - #endregion + #endregion 圆形辅助方法 } /// @@ -1018,18 +1033,22 @@ namespace PLCSharp.Core.UserControls /// 启动X /// public double StartX { get; set; } + /// /// 启动Y /// public double StartY { get; set; } + /// /// EndX /// public double EndX { get; set; } + /// /// EndY /// public double EndY { get; set; } + /// /// Tag /// @@ -1045,17 +1064,20 @@ namespace PLCSharp.Core.UserControls /// 圆心X /// public double CenterX { get; set; } + /// /// 圆心Y /// public double CenterY { get; set; } + /// /// 半径 /// public double Radius { get; set; } + /// /// Tag /// public string? Tag { get; set; } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs b/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs index ee44c73..7377a92 100644 --- a/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs +++ b/PLCSharpWpf/Core/UserControls/ImageEditExtensions.cs @@ -1,4 +1,4 @@ -using System.Windows.Controls; +using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; @@ -79,4 +79,4 @@ internal static class ImageEditExtensions }; imageEdit.Draw(crossV); } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml b/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml index 6eeadb0..e8bfad4 100644 --- a/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml +++ b/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml @@ -7,5 +7,4 @@ mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - - + \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml.cs b/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml.cs index 0326307..e0e0b84 100644 --- a/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml.cs +++ b/PLCSharpWpf/Core/UserControls/PasswordBoxNew.xaml.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; namespace PLCSharp.Core.UserControls @@ -21,8 +21,6 @@ namespace PLCSharp.Core.UserControls Text = ((PasswordBox)sender).Password; } - - /// /// Text /// @@ -45,7 +43,6 @@ namespace PLCSharp.Core.UserControls if (obj.Text == "") obj.passwordBox.Password = obj.Text; - } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateAdorner.cs b/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateAdorner.cs index 2341581..97344ba 100644 --- a/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateAdorner.cs +++ b/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateAdorner.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; @@ -58,4 +58,4 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner return visuals[index]; } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateChrome.cs b/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateChrome.cs index 901d8ef..03c9e27 100644 --- a/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateChrome.cs +++ b/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeRotateChrome.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner @@ -13,4 +13,4 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner DefaultStyleKeyProperty.OverrideMetadata(typeof(ResizeRotateChrome), new FrameworkPropertyMetadata(typeof(ResizeRotateChrome))); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeThumb.cs b/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeThumb.cs index a5f5133..2e4f949 100644 --- a/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeThumb.cs +++ b/PLCSharpWpf/Core/UserControls/ROI/DiagramDesigner/ResizeThumb.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Documents; @@ -42,7 +42,6 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner rotateTransform = designerItem.RenderTransform as RotateTransform; angle = rotateTransform != null ? rotateTransform.Angle * Math.PI / 180.0 : 0.0d; - } } } @@ -61,16 +60,20 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner Canvas.SetLeft(designerItem, Canvas.GetLeft(designerItem) - deltaVertical * transformOrigin.Y * Math.Sin(-angle)); designerItem.Height -= deltaVertical; break; + case VerticalAlignment.Top: deltaVertical = Math.Min(e.VerticalChange, designerItem.ActualHeight - designerItem.MinHeight); Canvas.SetTop(designerItem, Canvas.GetTop(designerItem) + deltaVertical * Math.Cos(-angle) + transformOrigin.Y * deltaVertical * (1 - Math.Cos(-angle))); Canvas.SetLeft(designerItem, Canvas.GetLeft(designerItem) + deltaVertical * Math.Sin(-angle) - transformOrigin.Y * deltaVertical * Math.Sin(-angle)); designerItem.Height -= deltaVertical; break; + case VerticalAlignment.Center: break; + case VerticalAlignment.Stretch: break; + default: break; } @@ -83,16 +86,20 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner Canvas.SetLeft(designerItem, Canvas.GetLeft(designerItem) + deltaHorizontal * Math.Cos(angle) + transformOrigin.X * deltaHorizontal * (1 - Math.Cos(angle))); designerItem.Width -= deltaHorizontal; break; + case HorizontalAlignment.Right: deltaHorizontal = Math.Min(-e.HorizontalChange, designerItem.ActualWidth - designerItem.MinWidth); Canvas.SetTop(designerItem, Canvas.GetTop(designerItem) - transformOrigin.X * deltaHorizontal * Math.Sin(angle)); Canvas.SetLeft(designerItem, Canvas.GetLeft(designerItem) + deltaHorizontal * transformOrigin.X * (1 - Math.Cos(angle))); designerItem.Width -= deltaHorizontal; break; + case HorizontalAlignment.Center: break; + case HorizontalAlignment.Stretch: break; + default: break; } @@ -114,7 +121,6 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner rrr.RectWidth = designerItem.Width; rrr.RectHeight = designerItem.Height; } - } e.Handled = true; @@ -134,4 +140,4 @@ namespace PLCSharp.Core.UserControls.ROI.DiagramDesigner } } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml b/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml index 8df5bfe..ab6e496 100644 --- a/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml +++ b/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml @@ -59,7 +59,6 @@ - diff --git a/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml.cs b/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml.cs index bc15de1..28f6cc1 100644 --- a/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml.cs +++ b/PLCSharpWpf/Core/UserControls/ROI/RectROI.xaml.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; namespace PLCSharp.Core.UserControls.ROI @@ -46,4 +46,4 @@ namespace PLCSharp.Core.UserControls.ROI public static readonly DependencyProperty LeftProperty = DependencyProperty.Register(nameof(Left), typeof(double), typeof(RectROI)); } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/ROI/RotateRectROI.xaml.cs b/PLCSharpWpf/Core/UserControls/ROI/RotateRectROI.xaml.cs index 8bab9a8..263ef13 100644 --- a/PLCSharpWpf/Core/UserControls/ROI/RotateRectROI.xaml.cs +++ b/PLCSharpWpf/Core/UserControls/ROI/RotateRectROI.xaml.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; namespace PLCSharp.Core.UserControls.ROI @@ -94,6 +94,5 @@ namespace PLCSharp.Core.UserControls.ROI /// public static readonly DependencyProperty RectAngleProperty = DependencyProperty.Register("RectAngle", typeof(double), typeof(RotateRectROI), new PropertyMetadata(0d)); - } } \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/SimpleCell.xaml b/PLCSharpWpf/Core/UserControls/SimpleCell.xaml index 4005711..8f2a1a1 100644 --- a/PLCSharpWpf/Core/UserControls/SimpleCell.xaml +++ b/PLCSharpWpf/Core/UserControls/SimpleCell.xaml @@ -29,7 +29,6 @@ - @@ -37,7 +36,6 @@ - @@ -66,4 +64,4 @@ - + \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/SimpleCell.xaml.cs b/PLCSharpWpf/Core/UserControls/SimpleCell.xaml.cs index 4d8b24b..551b993 100644 --- a/PLCSharpWpf/Core/UserControls/SimpleCell.xaml.cs +++ b/PLCSharpWpf/Core/UserControls/SimpleCell.xaml.cs @@ -1,6 +1,4 @@ - -using System.Windows.Controls; - +using System.Windows.Controls; namespace PLCSharp.Core.UserControls { @@ -16,8 +14,5 @@ namespace PLCSharp.Core.UserControls { InitializeComponent(); } - } - - -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Core/UserControls/SimpleCellViewModel.cs b/PLCSharpWpf/Core/UserControls/SimpleCellViewModel.cs index 871e3a4..c050af8 100644 --- a/PLCSharpWpf/Core/UserControls/SimpleCellViewModel.cs +++ b/PLCSharpWpf/Core/UserControls/SimpleCellViewModel.cs @@ -2,6 +2,7 @@ using Prism.Commands; using Prism.Mvvm; using System.Windows.Media; + namespace PLCSharp.Core.UserControls { /// @@ -9,18 +10,17 @@ namespace PLCSharp.Core.UserControls /// public class SimpleCellViewModel : BindableBase { - private DelegateCommand _MenuItemCommand; + /// /// 菜单项Command /// public DelegateCommand MenuItemCommand => _MenuItemCommand ??= new DelegateCommand(ExecuteMenuItemCommand); - void ExecuteMenuItemCommand(object state) + private void ExecuteMenuItemCommand(object state) { CellInfo.State = (CellState)state; - } /// @@ -45,6 +45,7 @@ namespace PLCSharp.Core.UserControls } private Brush _Background; + /// /// 背景画刷 /// @@ -53,7 +54,9 @@ namespace PLCSharp.Core.UserControls get { return _Background; } set { SetProperty(ref _Background, value); } } + private CellInfo _CellInfo; + /// /// 单元格信息 /// @@ -62,7 +65,5 @@ namespace PLCSharp.Core.UserControls get { return _CellInfo; } set { SetProperty(ref _CellInfo, value); } } - - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/DictionaryCore.xaml b/PLCSharpWpf/DictionaryCore.xaml index 121bb9a..8fee424 100644 --- a/PLCSharpWpf/DictionaryCore.xaml +++ b/PLCSharpWpf/DictionaryCore.xaml @@ -1,4 +1,6 @@ - + Core/Resources/Iconfont/#iconfont @@ -116,6 +118,4 @@ - - \ No newline at end of file diff --git a/PLCSharpWpf/GlobalSuppressions.cs b/PLCSharpWpf/GlobalSuppressions.cs index 1e5f099..1998190 100644 --- a/PLCSharpWpf/GlobalSuppressions.cs +++ b/PLCSharpWpf/GlobalSuppressions.cs @@ -10,4 +10,4 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Style", "IDE0305:简化集合初始化")] [assembly: SuppressMessage("Usage", "VSTHRD003:Avoid awaiting foreign Tasks")] [assembly: SuppressMessage("Usage", "VSTHRD001:Avoid legacy thread switching APIs")] -[assembly: SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits")] +[assembly: SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits")] \ No newline at end of file diff --git a/PLCSharpWpf/Models/DatasContext.cs b/PLCSharpWpf/Models/DatasContext.cs index ceb7272..e59a2b1 100644 --- a/PLCSharpWpf/Models/DatasContext.cs +++ b/PLCSharpWpf/Models/DatasContext.cs @@ -26,33 +26,38 @@ namespace PLCSharp.Models { this.Database.EnsureCreated(); this.EnsureCreatingMissingTables(); - } /// /// Users /// public DbSet Users { get; set; } + /// /// Recipes /// public DbSet Recipes { get; set; } + /// /// 系统全局变量集合 /// public DbSet SystemVariables { get; set; } + /// /// 用户全局变量集合 /// public DbSet Variables { get; set; } + /// /// Workflows /// public DbSet Workflows { get; set; } + /// /// VisionFunctions /// public DbSet VisionFunctions { get; set; } + /// /// 全局图像列表 /// @@ -62,22 +67,27 @@ namespace PLCSharp.Models /// 局部图像列表 /// public DbSet LocalImageDatas { get; set; } + /// /// 连接模型· /// public DbSet Connects { get; set; } + /// /// Cameras /// public DbSet Cameras { get; set; } + /// /// Controllers /// public DbSet Controllers { get; set; } + /// /// Axes /// public DbSet Axes { get; set; } + /// /// 轴Points /// @@ -92,10 +102,12 @@ namespace PLCSharp.Models /// 插补Groups /// public DbSet InterpolationGroups { get; set; } + /// /// DI /// public DbSet DI { get; set; } + /// /// DQ /// @@ -105,32 +117,37 @@ namespace PLCSharp.Models /// Robots /// public DbSet Robots { get; set; } + /// /// 机器人Points /// public DbSet RobotPoints { get; set; } + /// /// 机器人矩阵 /// public DbSet RobotMatrices { get; set; } + /// /// 错误Logs /// public DbSet ErrorLogs { get; set; } + /// /// CustomControls /// public DbSet CustomControls { get; set; } + /// /// CanvasConfigs /// public DbSet CanvasConfigs { get; set; } - /// /// CurrentRecipe /// public Recipe CurrentRecipe { get; set; } + /// /// OnConfiguring /// @@ -139,6 +156,7 @@ namespace PLCSharp.Models => options.UseSqlite(@"Data Source=./Config/Datas.db"); private object _dbLock = new(); + /// /// 保存 /// @@ -148,11 +166,9 @@ namespace PLCSharp.Models { SaveChanges(); } - } } - /// /// DbContextExtensions /// @@ -176,6 +192,7 @@ namespace PLCSharp.Models CheckTableExistsAndCreateIfMissing(dbContext, entityName); } } + private static void CheckTableExistsAndCreateIfMissing(DbContext dbContext, string entityName) { var defaultSchema = dbContext.Model.GetDefaultSchema(); @@ -197,8 +214,7 @@ namespace PLCSharp.Models var first = $"{scriptStart} {tableScript.First()}"; if (first is not null) dbContext.Database.ExecuteSqlRaw(first); - } } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Models/GlobalModel.Homepage.cs b/PLCSharpWpf/Models/GlobalModel.Homepage.cs index 66b3b21..75856cb 100644 --- a/PLCSharpWpf/Models/GlobalModel.Homepage.cs +++ b/PLCSharpWpf/Models/GlobalModel.Homepage.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using PLCSharp.Core.UserControls; using PLCSharp.VVMs.Homepage; using Prism.Commands; @@ -12,7 +12,9 @@ namespace PLCSharp.Models public partial class GlobalModel { #region 主页面 + private ObservableCollection _CustomControls = []; + /// /// 配置项 /// @@ -51,18 +53,14 @@ namespace PLCSharp.Models if (control != null) { - if (control.UIElement is ImageEdit imageEdit) { - return imageEdit; } else { - return null; } - } else { @@ -70,7 +68,9 @@ namespace PLCSharp.Models } } } + private CustomControl _SelectedCustControl; + /// /// 配置项 /// @@ -81,6 +81,7 @@ namespace PLCSharp.Models } private CanvasConfig _CurrentCanvasConfig; + /// /// 配置项 /// @@ -91,15 +92,15 @@ namespace PLCSharp.Models } private DelegateCommand _Apply; + /// /// Apply /// public DelegateCommand Apply => _Apply ??= new DelegateCommand(ExecuteApply); - void ExecuteApply() + private void ExecuteApply() { - var config = _DatasContext.CanvasConfigs.Where(c => c.RecipeID == CurrentRecipe.ID).FirstOrDefault(); if (config != null) { @@ -109,7 +110,6 @@ namespace PLCSharp.Models else { _DatasContext.CanvasConfigs.Add(CurrentCanvasConfig); - } //发布重新加载主页面通知 _EventAggregator.GetEvent().Publish(new() @@ -118,6 +118,7 @@ namespace PLCSharp.Models }); _DatasContext.Save(); } - #endregion + + #endregion 主页面 } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Models/GlobalModel.Logging.cs b/PLCSharpWpf/Models/GlobalModel.Logging.cs index 4dc41b7..7e3c88e 100644 --- a/PLCSharpWpf/Models/GlobalModel.Logging.cs +++ b/PLCSharpWpf/Models/GlobalModel.Logging.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Common; +using PLCSharp.Core.Common; using PLCSharp.Core.Prism; using Prism.Dialogs; using System.Collections.ObjectModel; @@ -12,6 +12,7 @@ namespace PLCSharp.Models public partial class GlobalModel { #region 日志 + private ObservableCollection _ErrorLogs = []; /// @@ -22,7 +23,9 @@ namespace PLCSharp.Models get { return _ErrorLogs; } set { SetProperty(ref _ErrorLogs, value); } } + private TitleState _CurrentState = new(); + /// /// TitleState /// @@ -48,14 +51,14 @@ namespace PLCSharp.Models TitleState.Background = Brushes.Red; _DatasContext.ErrorLogs.Add(newLog); ShowLog(); - } + private readonly object loglock = new(); + private void ShowLog() { lock (loglock) { - var showLog = _DatasContext.ErrorLogs.Where(e => e.Time.AddDays(1) >= DateTime.Now).OrderByDescending(l => l.Time).Take(30).ToList(); foreach (var item in showLog) @@ -69,7 +72,7 @@ namespace PLCSharp.Models var confirmedLog = ErrorLogs.Where(e => e.IsConfirm).ToList(); - //清理已确认的日志 + //清理已确认的日志 foreach (var item in confirmedLog) { ErrorLogs.Remove(item); @@ -100,6 +103,7 @@ namespace PLCSharp.Models } }); } + private void ErrMessageReceived(Message message) { switch (message.Type) @@ -112,16 +116,18 @@ namespace PLCSharp.Models case ShowType.ShowDialog: ErrorLogDialog(message); break; + case ShowType.ShowDialogAndRecord: AddErrorLog(message); ErrorLogDialog(message); break; + default: break; } - } - #endregion + + #endregion 日志 } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Models/GlobalModel.Recipes.cs b/PLCSharpWpf/Models/GlobalModel.Recipes.cs index 2a69ef0..2dfab00 100644 --- a/PLCSharpWpf/Models/GlobalModel.Recipes.cs +++ b/PLCSharpWpf/Models/GlobalModel.Recipes.cs @@ -1,4 +1,4 @@ -using MiniExcelLibs; +using MiniExcelLibs; using PLCSharp.Core.Prism; using PLCSharp.Core.Tools; using PLCSharp.VVMs.GlobalVariables; @@ -21,8 +21,8 @@ namespace PLCSharp.Models { #region 配方 - private Recipe _CurrentRecipe; + /// /// 当前配方 /// @@ -36,7 +36,9 @@ namespace PLCSharp.Models _DatasContext.CurrentRecipe = value; } } + private Recipe _RecipeSelected; + /// /// 选中的配方 /// @@ -47,6 +49,7 @@ namespace PLCSharp.Models } private ObservableCollection _Recipes = []; + /// /// 配方集合 /// @@ -57,18 +60,19 @@ namespace PLCSharp.Models } #region 配方管理 + private DelegateCommand _RecipeManage; + /// /// Recipe管理 /// public DelegateCommand RecipeManage => _RecipeManage ??= new DelegateCommand(ExecuteRecipeManage); - void ExecuteRecipeManage(string cmd) + private void ExecuteRecipeManage(string cmd) { if (ModeState.State.Execute) { - SendInfoDialog($"无法在运行状态操作配方,请先停止"); return; } @@ -100,13 +104,11 @@ namespace PLCSharp.Models } } - foreach (var item in Recipes) { if (!_DatasContext.Recipes.Any(h => h.ID == item.ID)) { _DatasContext.Recipes.Add(item); - } else { @@ -195,8 +197,6 @@ namespace PLCSharp.Models } } - - break; case "Copy": @@ -796,10 +796,10 @@ namespace PLCSharp.Models } } break; - } } - #endregion + + #endregion 配方管理 private void RecipeChanged(Message message) { @@ -813,7 +813,6 @@ namespace PLCSharp.Models } catch (Exception) { - } } // 重新加载画布配置和自定义控件 @@ -831,7 +830,6 @@ namespace PLCSharp.Models foreach (var item in currRecipeCustomControls) { CustomControls.Add(item.DeepCopy()); - } _EventAggregator.GetEvent().Publish(new() @@ -841,7 +839,7 @@ namespace PLCSharp.Models //加载当前配方的全局变量列表 VariablesModel.LoadRecipe(CurrentRecipe.ID); - + //加载当前配方的视觉功能列表 VisionsModel.LoadRecipe(CurrentRecipe.ID); @@ -862,7 +860,6 @@ namespace PLCSharp.Models itemcopy.Compile.Execute(); itemcopy.Start(this); } - } private void RecipeCopy() @@ -950,7 +947,6 @@ namespace PLCSharp.Models } // 插补列表 - var interpolationGroups = _DatasContext.InterpolationGroups.Where(c => c.RecipeID == RecipeSelected.ID); foreach (var item in interpolationGroups) { @@ -1015,6 +1011,7 @@ namespace PLCSharp.Models SendInfoDialog($"复制失败: {ex.Message}"); } } - #endregion + + #endregion 配方 } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Models/GlobalModel.State.cs b/PLCSharpWpf/Models/GlobalModel.State.cs index ee4fb1f..dc379a8 100644 --- a/PLCSharpWpf/Models/GlobalModel.State.cs +++ b/PLCSharpWpf/Models/GlobalModel.State.cs @@ -11,7 +11,9 @@ namespace PLCSharp.Models public partial class GlobalModel { #region 模式与状态 + private ModeState _ModeState = new(); + /// /// ModeState /// @@ -39,10 +41,8 @@ namespace PLCSharp.Models item.Exception = false; } } - + ModeState.Run(); - - } catch (Exception ex) { @@ -55,6 +55,7 @@ namespace PLCSharp.Models Thread.Sleep(1); } } - #endregion + + #endregion 模式与状态 } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/Models/GlobalModel.cs b/PLCSharpWpf/Models/GlobalModel.cs index 7e8f4ae..e07cf6f 100644 --- a/PLCSharpWpf/Models/GlobalModel.cs +++ b/PLCSharpWpf/Models/GlobalModel.cs @@ -1,27 +1,18 @@ -using MiniExcelLibs; -using PLCSharp.Core.Common; -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using PLCSharp.Core.Tools; -using PLCSharp.Core.UserControls; using PLCSharp.VVMs.Connects; using PLCSharp.VVMs.GlobalVariables; -using PLCSharp.VVMs.Homepage; using PLCSharp.VVMs.ModeState; using PLCSharp.VVMs.MotionController; using PLCSharp.VVMs.Recipe; using PLCSharp.VVMs.Robots; using PLCSharp.VVMs.Vision; using PLCSharp.VVMs.Workflows; -using Prism.Commands; using Prism.Dialogs; using Prism.Events; using Prism.Ioc; -using System.Collections.ObjectModel; using System.ComponentModel; -using System.Threading; using System.Windows; -using System.Windows.Media; - namespace PLCSharp.Models { @@ -49,7 +40,6 @@ namespace PLCSharp.Models foreach (var item in _DatasContext.Recipes) { Recipes.Add(item.DeepCopy()); - } if (Recipes.Count == 0) @@ -118,15 +108,12 @@ namespace PLCSharp.Models ThreadOption.UIThread, false, (filter) => filter.Target.Contains("Exit")); - } private void Exit(Message message) { - if (ModeState.State.Execute) { - SendInfoDialog("无法退出,请先停止运行!"); return; } @@ -146,7 +133,6 @@ namespace PLCSharp.Models #region 全局变量 - /// /// 获取变量 /// @@ -159,13 +145,15 @@ namespace PLCSharp.Models return variable; } - #endregion + #endregion 全局变量 #region 硬件 + /// /// 连接模型 /// public ConnectsModel Connects { get; set; } + /// /// Controllers模型 /// @@ -181,7 +169,6 @@ namespace PLCSharp.Models /// public VariablesModel VariablesModel { get; set; } - /// /// 获取连接 /// @@ -194,6 +181,7 @@ namespace PLCSharp.Models return connect; } + /// /// 获取Robot /// @@ -206,6 +194,7 @@ namespace PLCSharp.Models return robot; } + /// /// 获取VisionFunction /// @@ -216,6 +205,7 @@ namespace PLCSharp.Models return VisionsModel.VisionFunctions.FirstOrDefault(v => v.Name == name) ?? throw new Exception("视觉功能未配置!"); } + /// /// 获取图像数据 /// @@ -229,14 +219,15 @@ namespace PLCSharp.Models return imageData; } - - #endregion + #endregion 硬件 #region 任务 + /// /// Workflows模型 /// public WorkflowsModel WorkflowsModel { get; set; } + /// /// 视觉模型 /// @@ -251,7 +242,7 @@ namespace PLCSharp.Models { return WorkflowsModel.Workflows.FirstOrDefault(t => t.Name == name); } - #endregion + #endregion 任务 } } \ No newline at end of file diff --git a/PLCSharpWpf/Models/NavigateModel.cs b/PLCSharpWpf/Models/NavigateModel.cs index 5b38703..468d13c 100644 --- a/PLCSharpWpf/Models/NavigateModel.cs +++ b/PLCSharpWpf/Models/NavigateModel.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using PLCSharp.VVMs.Authority; using Prism.Dialogs; using Prism.Events; @@ -31,11 +31,9 @@ namespace PLCSharp.Models private void UserChageReceived(Message message) { - NavigateListShow.Clear(); var nl = NavigateList.OrderBy(n => n.Index); - foreach (var item in nl) { item.Display = Login.CurrentUser.Authority >= item.UserLevel; @@ -47,17 +45,16 @@ namespace PLCSharp.Models var dl = DialogList.OrderBy(n => n.Index); - foreach (var item in dl) { item.Display = Login.CurrentUser.Authority >= item.UserLevel; if (item.Display) { DialogListShow.Add(item); } } - } private ObservableCollection _NavigateListShow = []; + /// /// Navigate列表显示 /// @@ -67,7 +64,6 @@ namespace PLCSharp.Models set { SetProperty(ref _NavigateListShow, value); } } - private ObservableCollection _NavigateList = []; /// /// 导航页列表 @@ -80,6 +76,7 @@ namespace PLCSharp.Models } private ObservableCollection _DialogList = []; + /// /// 配置项 /// @@ -90,6 +87,7 @@ namespace PLCSharp.Models } private ObservableCollection _DialogListShow = []; + /// /// 配置项 /// @@ -99,8 +97,8 @@ namespace PLCSharp.Models set { SetProperty(ref _DialogListShow, value); } } - private NavigateItem _DialogTarget; + /// /// 配置项 /// @@ -113,9 +111,7 @@ namespace PLCSharp.Models if (value is not null) { - // _dialogService.Show(value.ViewName); - } } } @@ -172,6 +168,7 @@ namespace PLCSharp.Models //将导航目标发到区域 _regionManager.RequestNavigate("ContentRegionCore", navigatePath); } + /// /// NavigateToAsync /// @@ -199,8 +196,5 @@ namespace PLCSharp.Models /// 登录 /// public LoginModel Login { get; set; } - - - } } \ No newline at end of file diff --git a/PLCSharpWpf/Properties/AssemblyInfo.cs b/PLCSharpWpf/Properties/AssemblyInfo.cs index bef8c69..547949d 100644 --- a/PLCSharpWpf/Properties/AssemblyInfo.cs +++ b/PLCSharpWpf/Properties/AssemblyInfo.cs @@ -1,11 +1,10 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; [assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)] // 在此类的 SDK 样式项目中,现在,在此文件中早前定义的几个程序集属性将在生成期间自动添加,并使用在项目属性中定义的值进行填充。有关包含的属性以及如何定制此过程的详细信息,请参阅 // https://aka.ms/assembly-info-properties - // 将 ComVisible 设置为 false 会使此程序集中的类型对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,请将该类型的 ComVisible // 属性设置为 true。 @@ -13,4 +12,4 @@ using System.Runtime.InteropServices; // 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID。 -[assembly: Guid("4953e9f0-4cb5-486a-a3b2-637dcafd456c")] +[assembly: Guid("4953e9f0-4cb5-486a-a3b2-637dcafd456c")] \ No newline at end of file diff --git a/PLCSharpWpf/SDK/Camera/MvCameraControl.Net.XML b/PLCSharpWpf/SDK/Camera/MvCameraControl.Net.XML index 319ee63..575382c 100644 --- a/PLCSharpWpf/SDK/Camera/MvCameraControl.Net.XML +++ b/PLCSharpWpf/SDK/Camera/MvCameraControl.Net.XML @@ -1,4 +1,4 @@ - + MvCameraControl.Net @@ -46,27 +46,27 @@ - 组掩码 + 组掩码 - 只有设置成1时Action Time才有效,非1时无效 + 只有设置成1时Action Time才有效,非1时无效 - 预定的时间,和主频有关 + 预定的时间,和主频有关 - 广播包地址 + 广播包地址 - 等待ACK的超时时间,如果为0表示不需要ACK + 等待ACK的超时时间,如果为0表示不需要ACK @@ -76,7 +76,7 @@ - 指定的网卡IP + 指定的网卡IP @@ -96,7 +96,7 @@ - 设备枚举类,支持枚举GigE Vision、USB3 Vision相机,及采集卡上的相机(GigE Vision、CameraLink、CoaXPress、XoFlink) + 设备枚举类,支持枚举GigE Vision、USB3 Vision相机,及采集卡上的相机(GigE Vision、CameraLink、CoaXPress、XoFlink) @@ -109,10 +109,10 @@ 设备接口类型为MV_GIGE_DEVICE时,枚举所有GigE设备,包含虚拟GigE设备和采集卡上的GigE设备。 设备接口类型为MV_USB_DEVICE时,枚举所有USB设备,包含虚拟USB设备。 - + 设备列表的内存是在SDK内部分配的,调用该接口时会进行设备列表内存的释放和申请,避免多线程枚举操作。 - - 枚举到设备后,通过创建设备实例。 + + 枚举到设备后,通过创建设备实例。 @@ -126,10 +126,10 @@ 设备接口类型为MV_GIGE_DEVICE时,枚举所有GigE设备,包含虚拟GigE设备和采集卡上的GigE设备。 设备接口类型为MV_USB_DEVICE时,枚举所有USB设备,包含虚拟USB设备。 - + 设备列表的内存是在SDK内部分配的,调用该接口时会进行设备列表内存的释放和申请,避免多线程枚举操作。 - - 枚举到设备后,通过创建设备实例。 + + 枚举到设备后,通过创建设备实例。 @@ -144,10 +144,10 @@ 设备接口类型为MV_GIGE_DEVICE时,仅枚举网络上的网口相机,不包含虚拟GigE相机和采集卡上的相机 设备接口类型为MV_USB_DEVICE时,枚举普通USB设备,不包含虚拟USB设备。 - + 设备列表的内存是在SDK内部分配的,调用该接口时会进行设备列表内存的释放和申请,避免多线程枚举操作。 - - 枚举到设备后,通过创建设备实例。 + + 枚举到设备后,通过创建设备实例。 @@ -160,21 +160,21 @@ - 设置GigE设备枚举超时时间,范围 1-UINT_MAX(包括1,不包括UINT_MAX) + 设置GigE设备枚举超时时间,范围 1-UINT_MAX(包括1,不包括UINT_MAX) 超时时间 成功,返回MV_OK;失败,返回错误码 - 设置枚举命令的回复包类型 + 设置枚举命令的回复包类型 回复包类型(默认广播),0-单播,1-广播 成功,返回MV_OK;失败,返回错误码 - 获取主机串口列表 + 获取主机串口列表 串口列表 成功,返回MV_OK;失败,返回错误码 @@ -188,7 +188,7 @@ - 发出动作命令 + 发出动作命令 动作命令信息 动作命令返回信息列表 @@ -199,7 +199,7 @@ - 获取GigE设备组播状态 + 获取GigE设备组播状态 设备信息 组播状态(true:组播状态;false:非组播) @@ -226,7 +226,7 @@ 创建设备对象 设备信息 - 成功-返回设备实例,失败-抛出异常 + 成功-返回设备实例,失败-抛出异常 @@ -234,14 +234,14 @@ 设备IP地址 网口IP地址 - 成功-返回设备实例,失败-抛出异常 + 成功-返回设备实例,失败-抛出异常 - 通过GenTL设备信息创建设备句柄 + 通过GenTL设备信息创建设备句柄 设备信息 - 成功-返回设备实例,失败-抛出异常 + 成功-返回设备实例,失败-抛出异常 @@ -402,17 +402,17 @@ - 事件端点 + 事件端点 - 供应商ID号 + 供应商ID号 - 产品ID号 + 产品ID号 @@ -512,7 +512,7 @@ - 独占权限,其他APP只允许读CCP寄存器 + 独占权限,其他APP只允许读CCP寄存器 @@ -522,27 +522,27 @@ - 控制权限,其他APP允许读所有寄存器 + 控制权限,其他APP允许读所有寄存器 - 可以从5模式下抢占权限,然后以控制权限打开 + 可以从5模式下抢占权限,然后以控制权限打开 - 以可被抢占的控制权限打开 + 以可被抢占的控制权限打开 - 可以从5模式下抢占权限,然后以可被抢占的控制权限打开 + 可以从5模式下抢占权限,然后以可被抢占的控制权限打开 - 读模式打开设备,适用于控制权限下 + 读模式打开设备,适用于控制权限下 @@ -587,7 +587,7 @@ - 已接收数据大小 [统计StartGrabbing和StopGrabbing之间的数据量] + 已接收数据大小 [统计StartGrabbing和StopGrabbing之间的数据量] @@ -602,17 +602,17 @@ - 已接收的帧数 + 已接收的帧数 - 请求重发包数 + 请求重发包数 - 重发包数 + 重发包数 @@ -642,22 +642,22 @@ - 单播 + 单播 - 组播 + 组播 - 局域网内广播 + 局域网内广播 - 子网内广播 + 子网内广播 @@ -672,12 +672,12 @@ - 设置了单播,但本实例不接收图像数据 + 设置了单播,但本实例不接收图像数据 - 组播模式,但本实例不接收图像数据 + 组播模式,但本实例不接收图像数据 @@ -790,17 +790,17 @@ - 设备本地升级 + 设备本地升级 升级文件路径 成功,返回MV_OK;失败,返回错误码 - 通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回,响应时间可能较长。 + 通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回,响应时间可能较长。 - 获取升级进度 + 获取升级进度 升级进度 成功,返回MV_OK;失败,返回错误码 @@ -846,9 +846,9 @@ - 配置IP方式 + 配置IP方式 - IP配置类型 + IP配置类型 成功,返回MV_OK;失败,返回错误码 @@ -860,21 +860,21 @@ - 获取网络传输信息 + 获取网络传输信息 网络传输信息 成功,返回MV_OK;失败,返回错误码 - 设置GVSP取流超时时间 + 设置GVSP取流超时时间 超时时间(MS),默认30ms,范围:>10ms 成功,返回MV_OK;失败,返回错误码 - 获取GVSP取流超时时间 + 获取GVSP取流超时时间 超时时间(MS) 成功,返回MV_OK;失败,返回错误码 @@ -888,7 +888,7 @@ - 获取GVCP命令超时时间 + 获取GVCP命令超时时间 超时时间(MS) 成功,返回MV_OK;失败,返回错误码 @@ -902,7 +902,7 @@ - 获取重传GVCP命令次数 + 获取重传GVCP命令次数 重传次数 成功,返回MV_OK;失败,返回错误码 @@ -918,41 +918,41 @@ - 设置重传命令最大尝试次数 + 设置重传命令最大尝试次数 重传命令最大尝试次数,默认值20 成功,返回MV_OK;失败,返回错误码 - 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 + 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 - 获取重传命令最大尝试次数 + 获取重传命令最大尝试次数 传命令最大尝试次数 成功,返回MV_OK;失败,返回错误码 - 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 + 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 - 设置同一重传包多次请求之间的时间间隔 + 设置同一重传包多次请求之间的时间间隔 同一重传包多次请求之间的时间间隔,默认10ms 成功,返回MV_OK;失败,返回错误码 - 获取同一重传包多次请求之间的时间间隔 + 获取同一重传包多次请求之间的时间间隔 同一重传包多次请求之间的时间间隔(以毫秒为单位) 成功,返回MV_OK;失败,返回错误码 - 设置传输模式,可以为单播模式、组播模式等 + 设置传输模式,可以为单播模式、组播模式等 传输模式 组播地址,组播模式下有意义 @@ -966,29 +966,29 @@ - 设置U3V的传输包大小 + 设置U3V的传输包大小 传输的包大小,单位:Byte,默认为1M,范围:Windows[0x400, 0x400000], Linux[0x400, 0x200000] 成功,返回MV_OK;失败,返回错误码 - 增加传输包大小可以适当降低取流时的CPU占用率。但不同的PC和不同USB扩展卡存在不同的兼容性,如果该参数设置过大可能会出现取不到图像的风险。 + 增加传输包大小可以适当降低取流时的CPU占用率。但不同的PC和不同USB扩展卡存在不同的兼容性,如果该参数设置过大可能会出现取不到图像的风险。 - 获取U3V的传输包大小 + 获取U3V的传输包大小 传输的包大小, 单位:Byte 成功,返回MV_OK;失败,返回错误码 - 设置U3V的传输通道个数 + 设置U3V的传输通道个数 传输通道个数,范围:1-10 成功,返回MV_OK;失败,返回错误码 - 可根据PC的性能、设备出图帧率、图像大小和内存使用率等因素对该参数进行调节。但不同的PC和不同的USB扩展卡存在不同的兼容性。 + 可根据PC的性能、设备出图帧率、图像大小和内存使用率等因素对该参数进行调节。但不同的PC和不同的USB扩展卡存在不同的兼容性。 @@ -1003,7 +1003,7 @@ - 设置U3V的事件缓存节点个数 + 设置U3V的事件缓存节点个数 事件缓存节点个数,范围:1-64 成功,返回MV_OK;失败,返回错误码 @@ -1013,14 +1013,14 @@ - 设置U3V相机同步读写超时时间,范围为1000~UINT,默认1000 ms + 设置U3V相机同步读写超时时间,范围为1000~UINT,默认1000 ms 同步读写超时时间 成功,返回MV_OK;失败,返回错误码 - 获取U3V相机同步读写超时时间 + 获取U3V相机同步读写超时时间 同步读写超时时间 成功,返回MV_OK;失败,返回错误码 @@ -1089,23 +1089,23 @@ - 设置设备波特率 + 设置设备波特率 波特率 成功,返回MV_OK;失败,返回错误码 - 获取设备波特率 + 获取设备波特率 波特率 成功,返回MV_OK;失败,返回错误码 - 获取设备与主机间连接支持的波特率 + 获取设备与主机间连接支持的波特率 - 所支持波特率的或运算结果,单个波特率参考 + 所支持波特率的或运算结果,单个波特率参考 成功,返回MV_OK;失败,返回错误码 @@ -1491,7 +1491,7 @@ - 流通道序号 + 流通道序号 @@ -1647,7 +1647,7 @@ - 通过GenTL枚举Interfaces + 通过GenTL枚举Interfaces GenTL的cti文件路径 Interfaces列表 @@ -1655,18 +1655,18 @@ - 通过GenTL Interface枚举设备 + 通过GenTL Interface枚举设备 Interface信息 设备列表 成功,返回MV_OK;失败,返回错误码 - 枚举到设备后,通过创建设备实例。 + 枚举到设备后,通过创建设备实例。 - 卸载cti库 + 卸载cti库 枚举卡时加载的cti文件路径 成功,返回MV_OK;失败,返回错误码 @@ -1825,14 +1825,14 @@ - 无损解码 + 无损解码 输入图像及帧信息 输出图像及帧信息。图像使用完之后需调用Dispose方法及时释放内存,防止内存快速上涨。 成功,返回MV_OK;失败,返回错误码 将从相机中取到的无损压缩码流解码成裸数据,同时支持解析当前相机实时图像的水印信息(如果输入的无损码流不是当前相机或者不是实时取流的,则水印解析可能异常)。 - 若解码失败,请检查以下情况:(1)需要CPU支持 SSE AVX指令集(2)若当前帧异常(丢包等),可能导致解码异常(3)相机出图异常,即使不丢包也会异常。 + 若解码失败,请检查以下情况:(1)需要CPU支持 SSE AVX指令集(2)若当前帧异常(丢包等),可能导致解码异常(3)相机出图异常,即使不丢包也会异常。 @@ -1847,7 +1847,7 @@ 成功,返回MV_OK;失败,返回错误码 将从相机中取到的无损压缩码流解码成裸数据,同时支持解析当前相机实时图像的水印信息(如果输入的无损码流不是当前相机或者不是实时取流的,则水印解析可能异常)。 - 若解码失败,请检查以下情况:(1)需要CPU支持 SSE AVX指令集(2)若当前帧异常(丢包等),可能导致解码异常(3)相机出图异常,即使不丢包也会异常。 + 若解码失败,请检查以下情况:(1)需要CPU支持 SSE AVX指令集(2)若当前帧异常(丢包等),可能导致解码异常(3)相机出图异常,即使不丢包也会异常。 @@ -2010,7 +2010,7 @@ - 显示一帧图像 + 显示一帧图像 窗口句柄 图像信息 @@ -2054,7 +2054,7 @@ - 在图像上绘制矩形 + 在图像上绘制矩形 矩形框 线条颜色 @@ -2063,7 +2063,7 @@ - 在图像上绘制圆形 + 在图像上绘制圆形 圆形信息 线条颜色 @@ -2072,7 +2072,7 @@ - 在图像上绘制线条 + 在图像上绘制线条 线条信息 线条颜色 @@ -2126,7 +2126,7 @@ - 保存图像到文件,支持BMP、JPG、PNG、TIFF格式图像 + 保存图像到文件,支持BMP、JPG、PNG、TIFF格式图像 文件路径 图像数据 @@ -2197,17 +2197,17 @@ - 设备本地升级 + 设备本地升级 升级文件路径 成功,返回MV_OK;失败,返回错误码 - 通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回,响应时间可能较长。 + 通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回,响应时间可能较长。 - 获取升级进度 + 获取升级进度 升级进度 成功,返回MV_OK;失败,返回错误码 @@ -2240,13 +2240,13 @@ - 枚举采集卡 + 枚举采集卡 采集卡接口类型 采集卡列表 成功,返回MV_OK;失败,返回错误码 - 枚举到采集卡后,通过创建采集卡实例。 + 枚举到采集卡后,通过创建采集卡实例。 @@ -2259,14 +2259,14 @@ 根据采集卡信息创建采集卡实例 采集卡信息 - 成功-返回采集卡实例,失败-抛出异常 + 成功-返回采集卡实例,失败-抛出异常 根据采集卡ID创建采集卡实例 采集卡ID - 成功-返回采集卡实例,失败-抛出异常 + 成功-返回采集卡实例,失败-抛出异常 @@ -2300,17 +2300,17 @@ - 采集卡接口类型, + 采集卡接口类型, - 采集卡的PCIE插槽信息 + 采集卡的PCIE插槽信息 - 采集卡ID + 采集卡ID @@ -2380,7 +2380,7 @@ - 图像重构方式 + 图像重构方式 @@ -2412,7 +2412,7 @@ 旋转角度 成功,返回MV_OK;失败,返回错误码 - 该接口只支持MONO8/RGB24/BGR24格式数据的90/180/270度旋转。 + 该接口只支持MONO8/RGB24/BGR24格式数据的90/180/270度旋转。 @@ -2456,7 +2456,7 @@ - 图像对比度调节 + 图像对比度调节 输入图像 输出图像。图像使用完之后需调用Dispose方法及时释放内存,防止内存快速上涨。 @@ -2565,23 +2565,23 @@ - 设置设备波特率 + 设置设备波特率 波特率 成功,返回MV_OK;失败,返回错误码 - 获取设备波特率 + 获取设备波特率 波特率 成功,返回MV_OK;失败,返回错误码 - 获取设备与主机间连接支持的波特率 + 获取设备与主机间连接支持的波特率 - 所支持波特率的或运算结果,单个波特率参考 + 所支持波特率的或运算结果,单个波特率参考 成功,返回MV_OK;失败,返回错误码 @@ -2645,7 +2645,7 @@ - 通过GenTL设备信息创建设备句柄 + 通过GenTL设备信息创建设备句柄 设备信息 成功,返回MV_OK;失败,返回错误码 @@ -2847,17 +2847,17 @@ - 事件端点 + 事件端点 - 供应商ID号 + 供应商ID号 - 产品ID号 + 产品ID号 @@ -3107,7 +3107,7 @@ - 流通道序号 + 流通道序号 @@ -3232,21 +3232,21 @@ - 获取网络传输信息 + 获取网络传输信息 网络传输信息 成功,返回MV_OK;失败,返回错误码 - 设置GVSP取流超时时间 + 设置GVSP取流超时时间 超时时间(MS),默认30ms,范围:>=10ms 成功,返回MV_OK;失败,返回错误码 - 获取GVSP取流超时时间 + 获取GVSP取流超时时间 超时时间(MS) 成功,返回MV_OK;失败,返回错误码 @@ -3260,7 +3260,7 @@ - 获取GVCP命令超时时间 + 获取GVCP命令超时时间 超时时间(MS) 成功,返回MV_OK;失败,返回错误码 @@ -3274,7 +3274,7 @@ - 获取重传GVCP命令次数 + 获取重传GVCP命令次数 重传次数 成功,返回MV_OK;失败,返回错误码 @@ -3290,41 +3290,41 @@ - 设置重传命令最大尝试次数 + 设置重传命令最大尝试次数 重传命令最大尝试次数,默认值20 成功,返回MV_OK;失败,返回错误码 - 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 + 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 - 获取重传命令最大尝试次数 + 获取重传命令最大尝试次数 传命令最大尝试次数 成功,返回MV_OK;失败,返回错误码 - 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 + 该接口必须在调用开启重传包功能之后调用,否则失败且返回MV_E_CALLORDER。 - 设置同一重传包多次请求之间的时间间隔 + 设置同一重传包多次请求之间的时间间隔 同一重传包多次请求之间的时间间隔,默认10ms 成功,返回MV_OK;失败,返回错误码 - 获取同一重传包多次请求之间的时间间隔 + 获取同一重传包多次请求之间的时间间隔 成功,返回MV_OK;失败,返回错误码 - 设置传输模式,可以为单播模式、组播模式等 + 设置传输模式,可以为单播模式、组播模式等 组播地址,组播模式下有意义 @@ -3434,17 +3434,17 @@ - 设备本地升级 + 设备本地升级 升级文件路径 成功,返回MV_OK;失败,返回错误码 - 通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回,响应时间可能较长。 + 通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回,响应时间可能较长。 - 获取升级进度 + 获取升级进度 升级进度 成功,返回MV_OK;失败,返回错误码 @@ -3458,17 +3458,17 @@ - 采集卡接口类型, + 采集卡接口类型, - 采集卡的PCIE插槽信息 + 采集卡的PCIE插槽信息 - 采集卡ID + 采集卡ID @@ -4246,7 +4246,7 @@ 用户自定义名字 - + @@ -6549,7 +6549,7 @@ - 无效 + 无效 @@ -6719,7 +6719,7 @@ - [IN] 降噪强度(0-100) + [IN] 降噪强度(0-100) @@ -7159,7 +7159,6 @@ - @@ -7310,7 +7309,7 @@ Visible for experts or Gurus - + @@ -7384,7 +7383,7 @@ - 节点错误类型 + 节点错误类型 @@ -7850,7 +7849,7 @@ 最大值 - + @@ -8419,7 +8418,6 @@ - @@ -8792,7 +8790,7 @@ - 串口数量 + 串口数量 @@ -9884,7 +9882,7 @@ - 反初始化SDK,释放资源 + 反初始化SDK,释放资源 成功,返回MV_OK;失败,返回错误码 @@ -9940,29 +9938,29 @@ - 设置U3V的传输包大小 + 设置U3V的传输包大小 传输的包大小,单位:Byte,默认为1M,范围:Windows[0x400, 0x400000], Linux[0x400, 0x200000] 成功,返回MV_OK;失败,返回错误码 - 增加传输包大小可以适当降低取流时的CPU占用率。但不同的PC和不同USB扩展卡存在不同的兼容性,如果该参数设置过大可能会出现取不到图像的风险。 + 增加传输包大小可以适当降低取流时的CPU占用率。但不同的PC和不同USB扩展卡存在不同的兼容性,如果该参数设置过大可能会出现取不到图像的风险。 - 获取U3V的传输包大小 + 获取U3V的传输包大小 传输的包大小, 单位:Byte 成功,返回MV_OK;失败,返回错误码 - 设置U3V的传输通道个数 + 设置U3V的传输通道个数 传输通道个数,范围:1-10 成功,返回MV_OK;失败,返回错误码 - 可根据PC的性能、设备出图帧率、图像大小和内存使用率等因素对该参数进行调节。但不同的PC和不同的USB扩展卡存在不同的兼容性。 + 可根据PC的性能、设备出图帧率、图像大小和内存使用率等因素对该参数进行调节。但不同的PC和不同的USB扩展卡存在不同的兼容性。 @@ -9977,7 +9975,7 @@ - 设置U3V的事件缓存节点个数 + 设置U3V的事件缓存节点个数 事件缓存节点个数,范围:1-64 成功,返回MV_OK;失败,返回错误码 @@ -9987,14 +9985,14 @@ - 设置U3V相机同步读写超时时间,范围为1000~UINT,默认1000 ms + 设置U3V相机同步读写超时时间,范围为1000~UINT,默认1000 ms 同步读写超时时间 成功,返回MV_OK;失败,返回错误码 - 获取U3V相机同步读写超时时间 + 获取U3V相机同步读写超时时间 同步读写超时时间 成功,返回MV_OK;失败,返回错误码 @@ -10028,32 +10026,32 @@ - 不可实现 + 不可实现 - 不可用 + 不可用 - 只写 + 只写 - 只读 + 只读 - 读写 + 读写 - 未定义 + 未定义 @@ -10068,22 +10066,22 @@ - Value + Value - Base + Base - Integer + Integer - Boolean + Boolean @@ -10093,22 +10091,22 @@ - Float + Float - String + String - Register + Register - Category + Category @@ -10118,12 +10116,12 @@ - EnumEntry + EnumEntry - Port + Port @@ -10277,7 +10275,7 @@ 成功,返回MV_OK;失败,返回错误码 - 在加载工业相机节点时需要读取GenICam配置文件,该接口可以起到清除GenICam缓存的功能。 + 在加载工业相机节点时需要读取GenICam配置文件,该接口可以起到清除GenICam缓存的功能。 @@ -10290,7 +10288,7 @@ - 设置Integer型属性值 + 设置Integer型属性值 属性键值,如设置宽度信息则为"Width" 属性值 @@ -10298,7 +10296,7 @@ - 获取Enumeration属性值 + 获取Enumeration属性值 属性键值,如获取像素格式信息则为"PixelFormat" 属性值 @@ -10306,7 +10304,7 @@ - 设置Enumeration属性值 + 设置Enumeration属性值 属性键值,如设置像素格式信息则为"PixelFormat" Enum型节点的值 @@ -10322,7 +10320,7 @@ - 获取Float属性值 + 获取Float属性值 属性键值 属性值 @@ -10330,7 +10328,7 @@ - 设置Float型属性值 + 设置Float型属性值 属性键值 属性值 @@ -10338,7 +10336,7 @@ - 获取Boolean属性值 + 获取Boolean属性值 属性键值 属性值 @@ -10346,7 +10344,7 @@ - 设置Boolean型属性值 + 设置Boolean型属性值 属性键值 属性值 @@ -10354,7 +10352,7 @@ - 获取String属性值 + 获取String属性值 属性键值 属性值 @@ -10362,7 +10360,7 @@ - 设置String型属性值 + 设置String型属性值 属性键值 属性值 @@ -10370,21 +10368,21 @@ - 设置Command型属性值 + 设置Command型属性值 属性键值 成功,返回MV_OK;失败,返回错误码 - 导入设备属性文件 + 导入设备属性文件 文件路径 成功,返回MV_OK;失败,返回错误码 - 导入设备属性文件并保存错误信息列表 + 导入设备属性文件并保存错误信息列表 文件路径 导入失败的节点信息 @@ -10407,7 +10405,7 @@ 存放读到的内存值(GEV设备内存值是按照大端模式存储的,其它协议设备按照小端存储) 成功,返回MV_OK;失败,返回错误码 - 访问设备,读取某段寄存器的数据。 + 访问设备,读取某段寄存器的数据。 @@ -10419,19 +10417,19 @@ 待写入的内存值(注意GEV设备内存值要按照大端模式存储,其它协议设备按照小端存储) 成功,返回MV_OK;失败,返回错误码 - 访问设备,把一段数据写入某段寄存器。 + 访问设备,把一段数据写入某段寄存器。 - 获取设备属性树XML + 获取设备属性树XML 设备xml 成功,返回MV_OK;失败,返回错误码 - 获得当前节点的访问模式 + 获得当前节点的访问模式 节点名称 节点的访问模式 @@ -10439,7 +10437,7 @@ - 获得当前节点的类型 + 获得当前节点的类型 节点名称 节点类型 @@ -10463,7 +10461,7 @@ - 将文件写入设备 + 将文件写入设备 设备文件名 本地文件路径 @@ -10479,7 +10477,7 @@ - 获取文件存取的进度 + 获取文件存取的进度 已完成的长度 总长度 @@ -10517,26 +10515,26 @@ - 不启用 + 不启用 - Gamma值 + Gamma值 Gamma曲线 - 8位,长度:256*sizeof(unsigned char) + 8位,长度:256*sizeof(unsigned char) 10位,长度:1024*sizeof(unsigned short) 12位,长度:4096*sizeof(unsigned short) - 16位,长度:65536*sizeof(unsigned short) + 16位,长度:65536*sizeof(unsigned short) - linear RGB to sRGB + linear RGB to sRGB @@ -10556,17 +10554,17 @@ - Gamma值[0.1, 4.0] + Gamma值[0.1, 4.0] - Gamma曲线缓存 + Gamma曲线缓存 - Gamma曲线长度 + Gamma曲线长度 @@ -10576,12 +10574,12 @@ - 是否启用CCM + 是否启用CCM - CCM矩阵[-65536~65536],必须是Int32[9] + CCM矩阵[-65536~65536],必须是Int32[9] @@ -10601,60 +10599,60 @@ 图像插值算法 成功,返回MV_OK;失败,返回错误码 - 设置内部图像转换接口的Bayer插值算法类型参数,、使用的插值算法是该接口所设定的 + 设置内部图像转换接口的Bayer插值算法类型参数,、使用的插值算法是该接口所设定的 - 插值算法平滑使能设置 + 插值算法平滑使能设置 平滑使能(默认关闭) 成功,返回MV_OK;失败,返回错误码 - 设置内部图像转换接口的Bayer插值平滑使能参数,、使用的插值算法是该接口所设定的。 + 设置内部图像转换接口的Bayer插值平滑使能参数,、使用的插值算法是该接口所设定的。 - 设置Bayer格式的Gamma值 + 设置Bayer格式的Gamma值 Gamma值:0.1 ~ 4.0 成功,返回MV_OK;失败,返回错误码 - 设置该值后,、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 + 设置该值后,、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 - 设置Mono8/Bayer8/10/12/16格式的Gamma值 + 设置Mono8/Bayer8/10/12/16格式的Gamma值 像素格式 Gamma值:0.1 ~ 4.0 成功,返回MV_OK;失败,返回错误码 - 设置Mono8的gamma值后,再调用将Mono8转成Mono8时gamma值起效。 - 设置Bayer8/10/12/16的gamma值后,、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 - 该接口兼容接口,新增支持Mono8像素格式 + 设置Mono8的gamma值后,再调用将Mono8转成Mono8时gamma值起效。 + 设置Bayer8/10/12/16的gamma值后,、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 + 该接口兼容接口,新增支持Mono8像素格式 - 设置Bayer格式的Gamma信息 + 设置Bayer格式的Gamma信息 Gamma参数 成功,返回MV_OK;失败,返回错误码 - 设置该信息后,在、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 + 设置该信息后,在、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 - 设置Bayer格式的CCM使能和矩阵,量化系数默认1024 + 设置Bayer格式的CCM使能和矩阵,量化系数默认1024 CCM参数 成功,返回MV_OK;失败,返回错误码 - 开启CCM并设置CCM矩阵后,在、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 + 开启CCM并设置CCM矩阵后,在、将Bayer8/10/12/16格式转成RGB24/48, RGBA32/64,BGR24/48,BGRA32/64时起效。 @@ -10749,7 +10747,7 @@ - 从旧到新一帧一帧的获取图像(默认为该策略) + 从旧到新一帧一帧的获取图像(默认为该策略) @@ -10759,12 +10757,12 @@ - 从输出缓存列表中获取最新的OutputQueueSize帧图像,其中OutputQueueSize范围为1-ImageNodeNum,可用 SetOutputQueueSize()接口设置。ImageNodeNum默认为1,可调用SetImageNodeNum()接口设置。 OutputQueueSize设置成1等同于LatestImagesOnly策略,OutputQueueSize设置成ImageNodeNum等同于OneByOne策略。 + 从输出缓存列表中获取最新的OutputQueueSize帧图像,其中OutputQueueSize范围为1-ImageNodeNum,可用 SetOutputQueueSize()接口设置。ImageNodeNum默认为1,可调用SetImageNodeNum()接口设置。 OutputQueueSize设置成1等同于LatestImagesOnly策略,OutputQueueSize设置成ImageNodeNum等同于OneByOne策略。 - 在调用取流接口时忽略输出缓存列表中所有图像,并等待设备即将生成的一帧图像。该策略只支持GigE设备,不支持U3V设备 + 在调用取流接口时忽略输出缓存列表中所有图像,并等待设备即将生成的一帧图像。该策略只支持GigE设备,不支持U3V设备 @@ -10911,7 +10909,7 @@ - 本帧丢包数 + 本帧丢包数 @@ -10964,7 +10962,7 @@ - 获取当前图像缓存区的有效图像个数 + 获取当前图像缓存区的有效图像个数 有效图像个数 成功,返回MV_OK;失败,返回错误码 @@ -10984,14 +10982,14 @@ - 设置输出缓存个数(只有在 StreamGrabStrategy.LatestImages 策略下才有效,范围:1-ImageNodeNum) + 设置输出缓存个数(只有在 StreamGrabStrategy.LatestImages 策略下才有效,范围:1-ImageNodeNum) 输出缓存个数 成功,返回MV_OK;失败,返回错误码 - 停止取流 + 停止取流 成功,返回MV_OK;失败,返回错误码 @@ -11005,19 +11003,19 @@ - 释放图像缓存(此接口用于释放不再使用的图像缓存,与 IStreamGrabber.FreeImageBuffer() 配套使用) + 释放图像缓存(此接口用于释放不再使用的图像缓存,与 IStreamGrabber.FreeImageBuffer() 配套使用) 图像数据和图像数据 成功,返回MV_OK;失败,返回错误码 - 清除取流数据缓存 + 清除取流数据缓存 成功,返回MV_OK;失败,返回错误码 该接口允许用户在不停止取流的时候,就能清除缓存中不需要的图像。 - 该接口在连续模式切触发模式后,可以清除历史数据。 + 该接口在连续模式切触发模式后,可以清除历史数据。 @@ -11052,12 +11050,12 @@ - 帧率fps(大于1/16) + 帧率fps(大于1/16) - 码率kbps(128-16*1024) + 码率kbps(128-16*1024) @@ -11080,14 +11078,14 @@ - 输入录像数据 + 输入录像数据 图像数据 成功,返回MV_OK;失败,返回错误码 - 停止录像 + 停止录像 成功,返回MV_OK;失败,返回错误码 @@ -11686,7 +11684,7 @@ Get SDK Version Always return 4 Bytes of version number |Main |Sub |Rev |Test| - 8bits 8bits 8bits 8bits + 8bits 8bits 8bits 8bits @@ -12126,7 +12124,7 @@ - Get File Access Progress + Get File Access Progress File access Progress Success, return MV_OK. Failure, return error code @@ -12333,7 +12331,7 @@ Get device baudrate, using one of the CL_BAUDRATE_XXXX value - Return pointer of baud rate to user. + Return pointer of baud rate to user. Refer to the 'CameraParams.h' for parameter definitions, for example, #define MV_CAML_BAUDRATE_9600 0x00000001 Success, return MV_OK. Failure, return error code @@ -12341,7 +12339,7 @@ Get supported baudrates of the combined device and host interface - Return pointer of the supported baudrates to user. 'OR' operation results of the supported baudrates. + Return pointer of the supported baudrates to user. 'OR' operation results of the supported baudrates. Refer to the 'CameraParams.h' for single value definitions, for example, #define MV_CAML_BAUDRATE_9600 0x00000001 Success, return MV_OK. Failure, return error code @@ -13952,7 +13950,7 @@ 用户自定义名字 - + @@ -16175,7 +16173,7 @@ - 无效 + 无效 @@ -16345,7 +16343,7 @@ - [IN] 降噪强度(0-100) + [IN] 降噪强度(0-100) @@ -16785,7 +16783,6 @@ - @@ -16936,7 +16933,7 @@ Visible for experts or Gurus - + @@ -17361,7 +17358,7 @@ 最大值 - + @@ -17905,7 +17902,6 @@ - @@ -19038,4 +19034,4 @@ 输入的噪声特性内存大小错误 - + \ No newline at end of file diff --git a/PLCSharpWpf/Themes/Generic.xaml b/PLCSharpWpf/Themes/Generic.xaml index ee8264c..5bddabc 100644 --- a/PLCSharpWpf/Themes/Generic.xaml +++ b/PLCSharpWpf/Themes/Generic.xaml @@ -1 +1 @@ - + \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml b/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml index dbc1215..5c65ec6 100644 --- a/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml +++ b/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml @@ -39,6 +39,5 @@ - \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml.cs b/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml.cs index 2036269..0d6bc85 100644 --- a/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml.cs +++ b/PLCSharpWpf/VVMs/AlertDialog/AlertDialog.xaml.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using System.Windows.Controls; namespace PLCSharp.VVM.AlertDialog @@ -7,9 +7,6 @@ namespace PLCSharp.VVM.AlertDialog /// Alert对话框 /// [Dialog] - /// - /// AlertDialog.xaml 的交互逻辑 - /// public partial class AlertDialog : UserControl { /// @@ -20,4 +17,4 @@ namespace PLCSharp.VVM.AlertDialog InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/AlertDialog/AlertDialogViewModel.cs b/PLCSharpWpf/VVMs/AlertDialog/AlertDialogViewModel.cs index 0a9eda8..ba78575 100644 --- a/PLCSharpWpf/VVMs/AlertDialog/AlertDialogViewModel.cs +++ b/PLCSharpWpf/VVMs/AlertDialog/AlertDialogViewModel.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using PLCSharp.Core.Resources.Iconfont; using Prism.Commands; using Prism.Dialogs; @@ -33,7 +33,6 @@ namespace PLCSharp.VVM.AlertDialog RaiseRequestClose(new DialogResult(result)); } - private string _Ico = "\ueb65"; /// @@ -52,7 +51,6 @@ namespace PLCSharp.VVM.AlertDialog set { SetProperty(ref _Ico, value); } } - /// /// 打开对话框后要执行的 /// @@ -80,9 +78,7 @@ namespace PLCSharp.VVM.AlertDialog } else { - Message = msg[0]; - } Ico = Title switch { @@ -108,6 +104,5 @@ namespace PLCSharp.VVM.AlertDialog /// 按钮列表 /// public ObservableCollection @@ -26,6 +22,7 @@ /// 高级维护人员 /// SeniorMaintainer = 31, + /// /// 管理人员 /// diff --git a/PLCSharpWpf/VVMs/Authority/LoginModel.cs b/PLCSharpWpf/VVMs/Authority/LoginModel.cs index 2f99afd..a81c8df 100644 --- a/PLCSharpWpf/VVMs/Authority/LoginModel.cs +++ b/PLCSharpWpf/VVMs/Authority/LoginModel.cs @@ -39,20 +39,18 @@ namespace PLCSharp.VVMs.Authority _DatasContext.Users.Add(item); } _DatasContext.Save(); - } else { - foreach (var user in users) { UserList.Add(user); } } - } private ObservableCollection _UserList = []; + /// /// 用户列表 /// @@ -77,6 +75,7 @@ namespace PLCSharp.VVMs.Authority } private string _Password; + /// /// 密码 /// @@ -85,7 +84,9 @@ namespace PLCSharp.VVMs.Authority get { return _Password; } set { SetProperty(ref _Password, value); CheckPassword(); } } + private string _PasswordAct; + /// /// 密码Act /// @@ -96,6 +97,7 @@ namespace PLCSharp.VVMs.Authority } private User _CurrentUser; + /// /// 当前用户 /// @@ -109,13 +111,11 @@ namespace PLCSharp.VVMs.Authority { Target = "CurrentUser" }); - } } - - private User _RegisterUser = new(); + /// /// 注册用户 /// @@ -125,10 +125,8 @@ namespace PLCSharp.VVMs.Authority set { SetProperty(ref _RegisterUser, value); } } - - - private User _SelectUser; + /// /// 选择用户 /// @@ -137,14 +135,16 @@ namespace PLCSharp.VVMs.Authority get { return _SelectUser; } set { SetProperty(ref _SelectUser, value); } } + private DelegateCommand _Manage; + /// /// 管理 /// public DelegateCommand Manage => _Manage ??= new DelegateCommand(ExecuteManage); - void ExecuteManage(string cmd) + private void ExecuteManage(string cmd) { switch (cmd) { @@ -157,59 +157,49 @@ namespace PLCSharp.VVMs.Authority _dialogService.ShowDialog("PasswordChange", new DialogParameters($"name={SelectUser.Name}"), r => { }); break; - case "Delete": _dialogService.ShowDialog("AlertDialog", new DialogParameters($"message=choose:删除用户{SelectUser.Name}?"), r => { - switch (r.Result) { - case ButtonResult.Yes: if (SelectUser != null) { - if (SelectUser.Name == "admin" || SelectUser.Name == "guest") { MessageBox.Show($"无法删除{SelectUser.Name}用户"); } else { - _DatasContext.Remove(SelectUser); UserList.Remove(SelectUser); - } - } break; + default: break; } }); break; - - - } } private bool PasswordCheck { get; set; } private DelegateCommand _Register; + /// /// 注册 /// public DelegateCommand Register => _Register ??= new DelegateCommand(ExecuteRegister); - void ExecuteRegister() + private void ExecuteRegister() { - if (CheckPassword()) { - if (UserList.Where(u => u.Name == RegisterUser.Name).Any()) { MessageBox.Show($"用户{RegisterUser.Name}已存在!"); @@ -217,7 +207,6 @@ namespace PLCSharp.VVMs.Authority else if (RegisterUser.Authority == 0) { MessageBox.Show($"请选择权限!"); - } else { @@ -228,14 +217,12 @@ namespace PLCSharp.VVMs.Authority Password = ""; PasswordAct = ""; MessageBox.Show($"用户{RegisterUser.Name}注册成功!"); - } } - - } private string _PasswordMsg = ""; + /// /// 密码Msg /// @@ -245,7 +232,6 @@ namespace PLCSharp.VVMs.Authority set { SetProperty(ref _PasswordMsg, value); } } - private bool CheckPassword() { PasswordCheck = Password == PasswordAct && Password.Length > 0; @@ -262,39 +248,32 @@ namespace PLCSharp.VVMs.Authority return PasswordCheck; } - private DelegateCommand _ChangePassword; - /// /// Change密码 /// public DelegateCommand ChangePassword => _ChangePassword ??= new DelegateCommand(ExecuteChangePassword); - void ExecuteChangePassword() + private void ExecuteChangePassword() { if (CheckPassword() && SelectUser != null) { - SelectUser.Password = Encrypt(Password); var user = _DatasContext.Users.Where(u => u.Name == SelectUser.Name).FirstOrDefault(); if (user != null) { - user.Password = SelectUser.Password; Password = ""; PasswordAct = ""; PasswordMsg = $"用户{SelectUser.Name}密码修改完成!"; } - } - } - /// /// Encrypt /// diff --git a/PLCSharpWpf/VVMs/Authority/LoginViewModel.cs b/PLCSharpWpf/VVMs/Authority/LoginViewModel.cs index d1391fd..95641c8 100644 --- a/PLCSharpWpf/VVMs/Authority/LoginViewModel.cs +++ b/PLCSharpWpf/VVMs/Authority/LoginViewModel.cs @@ -16,6 +16,7 @@ namespace PLCSharp.VVMs.Authority /// 模型 /// public LoginModel Model { get; set; } + /// /// 登录视图模型 /// @@ -24,6 +25,7 @@ namespace PLCSharp.VVMs.Authority Model = container.Resolve(); Title = "登录"; } + private DelegateCommand _closeDialogCommand; /// @@ -34,7 +36,6 @@ namespace PLCSharp.VVMs.Authority private void ExecuteCloseDialogCommand(string parameter) { - switch (parameter) { case "Login": @@ -50,20 +51,19 @@ namespace PLCSharp.VVMs.Authority else { Model.CurrentUser = user; - - } break; + case "Logout": Model.CurrentUser = Model.UserList.Where(u => u.Name == "guest").FirstOrDefault(); PasswordMsg = "已注销,当前用户:游客guest"; break; + default: break; } - ButtonResult result = ButtonResult.None; if (parameter?.ToLower() == "manage") @@ -77,12 +77,12 @@ namespace PLCSharp.VVMs.Authority MessageBox.Show("管理用户需要管理员权限", "无权限"); return; } - } RaiseRequestClose(new DialogResult(result)); } private string _PasswordMsg; + /// /// 密码Msg /// @@ -91,8 +91,5 @@ namespace PLCSharp.VVMs.Authority get { return _PasswordMsg; } set { SetProperty(ref _PasswordMsg, value); } } - - - } } \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/PasswordChange.xaml b/PLCSharpWpf/VVMs/Authority/PasswordChange.xaml index 4c29944..4b8ef96 100644 --- a/PLCSharpWpf/VVMs/Authority/PasswordChange.xaml +++ b/PLCSharpWpf/VVMs/Authority/PasswordChange.xaml @@ -33,7 +33,6 @@ Orientation="Horizontal" Visibility="Collapsed"> - /// 密码Change /// public PasswordChange() { - InitializeComponent(); } - - - } } \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/PasswordChangeViewModel.cs b/PLCSharpWpf/VVMs/Authority/PasswordChangeViewModel.cs index d3987d8..231b1ac 100644 --- a/PLCSharpWpf/VVMs/Authority/PasswordChangeViewModel.cs +++ b/PLCSharpWpf/VVMs/Authority/PasswordChangeViewModel.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using Prism.Dialogs; using Prism.Events; using Prism.Ioc; @@ -29,8 +29,6 @@ namespace PLCSharp.VVMs.Authority set { SetProperty(ref _Name, value); } } - - /// /// 打开对话框后要执行的 /// @@ -45,9 +43,5 @@ namespace PLCSharp.VVMs.Authority /// 模型 /// public LoginModel Model { get; set; } - - - - } } \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/Register.xaml b/PLCSharpWpf/VVMs/Authority/Register.xaml index 78a775e..fe206a4 100644 --- a/PLCSharpWpf/VVMs/Authority/Register.xaml +++ b/PLCSharpWpf/VVMs/Authority/Register.xaml @@ -41,12 +41,10 @@ - - - + \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/Register.xaml.cs b/PLCSharpWpf/VVMs/Authority/Register.xaml.cs index 0ae30dc..101e099 100644 --- a/PLCSharpWpf/VVMs/Authority/Register.xaml.cs +++ b/PLCSharpWpf/VVMs/Authority/Register.xaml.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using System.Windows.Controls; namespace PLCSharp.VVMs.Authority @@ -7,9 +7,6 @@ namespace PLCSharp.VVMs.Authority /// 注册 /// [Dialog] - /// - /// Register.xaml 的交互逻辑 - /// public partial class Register : UserControl { /// @@ -20,4 +17,4 @@ namespace PLCSharp.VVMs.Authority InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/RegisterViewModel.cs b/PLCSharpWpf/VVMs/Authority/RegisterViewModel.cs index eb9ca10..d890f7d 100644 --- a/PLCSharpWpf/VVMs/Authority/RegisterViewModel.cs +++ b/PLCSharpWpf/VVMs/Authority/RegisterViewModel.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using Prism.Dialogs; using Prism.Events; using Prism.Ioc; @@ -23,7 +23,5 @@ namespace PLCSharp.VVMs.Authority /// 模型 /// public LoginModel Model { get; set; } - - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/User.cs b/PLCSharpWpf/VVMs/Authority/User.cs index 178aeb1..672b7e4 100644 --- a/PLCSharpWpf/VVMs/Authority/User.cs +++ b/PLCSharpWpf/VVMs/Authority/User.cs @@ -1,10 +1,8 @@ -using Prism.Mvvm; +using Prism.Mvvm; using System.ComponentModel.DataAnnotations; namespace PLCSharp.VVMs.Authority { - - /// /// 用户 /// @@ -13,20 +11,21 @@ namespace PLCSharp.VVMs.Authority /// /// 用户 /// - public User() { } + public User() + { } + /// /// 用户 /// public User(string name, string password, Authority authority) { - Name = name; Password = password; Authority = authority; } - private string _Name; + /// /// 名称 /// @@ -36,12 +35,14 @@ namespace PLCSharp.VVMs.Authority get { return _Name; } set { SetProperty(ref _Name, value); } } + /// /// 密码 /// public string Password { get; set; } private Authority _Authority; + /// /// 权限 /// diff --git a/PLCSharpWpf/VVMs/Authority/UserManage.xaml b/PLCSharpWpf/VVMs/Authority/UserManage.xaml index ea1af0c..8045bc2 100644 --- a/PLCSharpWpf/VVMs/Authority/UserManage.xaml +++ b/PLCSharpWpf/VVMs/Authority/UserManage.xaml @@ -43,6 +43,5 @@ Command="{Binding Model.Manage}" CommandParameter="Register" Content="注册" /> - \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Authority/UserManage.xaml.cs b/PLCSharpWpf/VVMs/Authority/UserManage.xaml.cs index fa21427..a99134a 100644 --- a/PLCSharpWpf/VVMs/Authority/UserManage.xaml.cs +++ b/PLCSharpWpf/VVMs/Authority/UserManage.xaml.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using System.Windows; using System.Windows.Controls; @@ -15,7 +15,6 @@ namespace PLCSharp.VVMs.Authority /// public UserManage() { - InitializeComponent(); } diff --git a/PLCSharpWpf/VVMs/Authority/UserManageViewModel.cs b/PLCSharpWpf/VVMs/Authority/UserManageViewModel.cs index de8bfff..9ba3082 100644 --- a/PLCSharpWpf/VVMs/Authority/UserManageViewModel.cs +++ b/PLCSharpWpf/VVMs/Authority/UserManageViewModel.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using Prism.Dialogs; using Prism.Events; using Prism.Ioc; @@ -23,7 +23,5 @@ namespace PLCSharp.VVMs.Authority Model = container.Resolve(); Title = "用户管理"; } - - } } \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/Connect.cs b/PLCSharpWpf/VVMs/Connects/Connect.cs index 56d4e87..984d266 100644 --- a/PLCSharpWpf/VVMs/Connects/Connect.cs +++ b/PLCSharpWpf/VVMs/Connects/Connect.cs @@ -1,6 +1,4 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; -using System.Text.Json; -using System.Text.Json.Serialization; using PLCSharp.Core.Tools; using PLCSharp.VVMs.Connects.ModbusTcp; using PLCSharp.VVMs.Connects.Socket; @@ -11,6 +9,8 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Globalization; using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Windows; @@ -18,10 +18,10 @@ namespace PLCSharp.VVMs.Connects { public enum CommunicationDataType { - String, Bytes, } + /// /// 连接 /// @@ -41,6 +41,7 @@ namespace PLCSharp.VVMs.Connects } private string _Name; + /// /// 连接配置 /// @@ -51,6 +52,7 @@ namespace PLCSharp.VVMs.Connects } private string _IP_SerialPort; + /// /// IP_串口端口 /// @@ -61,6 +63,7 @@ namespace PLCSharp.VVMs.Connects } private int _Port; + /// /// 端口 /// @@ -71,11 +74,11 @@ namespace PLCSharp.VVMs.Connects } private ProtocolType _Type; + /// /// 协议类型 /// [JsonIgnore] - public ProtocolType Type { get { return _Type; } @@ -86,18 +89,17 @@ namespace PLCSharp.VVMs.Connects if (value != ProtocolType.Undefined) { SetProperty(ref _Type, value); - } } else if (_Type != value) { MessageBox.Show("选定协议后不可改变!"); } - } } private string _Comment; + /// /// 备注 /// @@ -110,11 +112,11 @@ namespace PLCSharp.VVMs.Connects #region NotMapped private bool _LogSwitch; + /// /// 日志开关 /// [NotMapped] - public bool LogSwitch { get { return _LogSwitch; } @@ -122,11 +124,11 @@ namespace PLCSharp.VVMs.Connects } private bool _Connected; + /// /// 连接成功 /// [NotMapped] - public bool Connected { get { return _Connected; } @@ -134,24 +136,23 @@ namespace PLCSharp.VVMs.Connects } private bool _Successful; + /// /// 读写成功 /// [NotMapped] - public bool Successful { get { return _Successful; } set { SetProperty(ref _Successful, value); } } - private bool _Online; + /// /// 在线 /// [NotMapped] - public bool Online { get { return _Online; } @@ -167,7 +168,6 @@ namespace PLCSharp.VVMs.Connects set { SetProperty(ref _ReceiveInfo, value); } } - private byte[] _ReceiveData; [NotMapped] @@ -176,6 +176,7 @@ namespace PLCSharp.VVMs.Connects get { return _ReceiveData; } set { SetProperty(ref _ReceiveData, value); } } + private string _SendInfo; [NotMapped] @@ -184,6 +185,7 @@ namespace PLCSharp.VVMs.Connects get { return _SendInfo; } set { SetProperty(ref _SendInfo, value); } } + /// /// 告警信息 /// @@ -198,10 +200,10 @@ namespace PLCSharp.VVMs.Connects { get => JsonSerializer.Serialize(Params, JsonOptions.Default); // 自动序列化 set => Params = JsonSerializer.Deserialize(value, JsonOptions.Default); // 自动反序列化 - } private ObservableCollection _DataItems = []; + /// /// 数据Items /// @@ -211,6 +213,7 @@ namespace PLCSharp.VVMs.Connects get => _DataItems; set => SetProperty(ref _DataItems, value); } + /// /// 序列化数据Items /// @@ -219,10 +222,10 @@ namespace PLCSharp.VVMs.Connects { get => JsonSerializer.Serialize(DataItems, JsonOptions.Default); // 自动序列化 set => DataItems = value != null ? JsonSerializer.Deserialize>(value, JsonOptions.Default) : []; // 自动反序列化 - } private bool _PollEnabled = true; + /// 是否启用轮询 [NotMapped] public bool PollEnabled @@ -232,6 +235,7 @@ namespace PLCSharp.VVMs.Connects } private int _PollIntervalMs = 1000; + /// 轮询间隔(毫秒) [NotMapped] public int PollIntervalMs @@ -246,6 +250,7 @@ namespace PLCSharp.VVMs.Connects } private ConnectParams _Params; + /// /// 参数集合 /// @@ -265,6 +270,7 @@ namespace PLCSharp.VVMs.Connects } private ObservableCollection _Clients = []; + /// /// Clients /// @@ -283,22 +289,26 @@ namespace PLCSharp.VVMs.Connects { get => JsonSerializer.Serialize(Clients, JsonOptions.Default); // 自动序列化 set => Clients = JsonSerializer.Deserialize>(value, JsonOptions.Default); // 自动反序列化 - } + /// /// 打开 /// - public virtual void Open() { } + public virtual void Open() + { } /// /// 关闭 /// - public virtual void Close() { } + public virtual void Close() + { } + /// /// 日志Queue /// [NotMapped] public ConcurrentQueue LogQueue { get; set; } = []; + /// /// 日志 /// @@ -307,7 +317,6 @@ namespace PLCSharp.VVMs.Connects { if (LogSwitch) { - LogQueue.Enqueue(log); if (LogQueue.Count > 1000) @@ -315,7 +324,8 @@ namespace PLCSharp.VVMs.Connects RaisePropertyChanged(nameof(LogQueue)); } } - #endregion + + #endregion NotMapped /// /// HexStringToBytes @@ -338,7 +348,6 @@ namespace PLCSharp.VVMs.Connects bool isMatch = Regex.IsMatch(sendMsg, @"^[0-9A-Fa-f]+$"); if (isMatch) { - StringBuilder sb = new(); for (int i = 0; i < sendMsg.Length; i++) { @@ -349,21 +358,16 @@ namespace PLCSharp.VVMs.Connects format = sb.ToString(); var split = format.Split(" "); - for (int i = 0; i < split.Length; i++) { bytes.Add(byte.Parse(split[i], NumberStyles.HexNumber)); } return true; - - } else { - return false; } - } /// @@ -376,7 +380,6 @@ namespace PLCSharp.VVMs.Connects if (Params.DataType == CommunicationDataType.String) { return await SendMsgAsync(msg); - } else { @@ -390,10 +393,8 @@ namespace PLCSharp.VVMs.Connects ErrInfo = "请输入正确的十六进制字符串"; Log(ErrInfo); return false; - } } - } /// @@ -404,13 +405,11 @@ namespace PLCSharp.VVMs.Connects /// 返回结果 public virtual async Task SendAsync(string msg, string clientName) { - if (this is SocketServer server) { if (Params.DataType == CommunicationDataType.String) { return await server.SendMsgAsync(msg, clientName); - } else { @@ -419,7 +418,6 @@ namespace PLCSharp.VVMs.Connects { SendInfo = format; return await server.SendDataAsync([.. bytes], clientName); - } else { @@ -435,12 +433,9 @@ namespace PLCSharp.VVMs.Connects ErrInfo = "此连接不是服务器"; Log(ErrInfo); return false; - } - } - /// /// 发送HexMsgAsync /// @@ -457,6 +452,7 @@ namespace PLCSharp.VVMs.Connects byte[] bytes = Encoding.UTF8.GetBytes(msg); return await SendDataAsync(bytes); } + /// /// 发送MsgAsync /// @@ -474,6 +470,7 @@ namespace PLCSharp.VVMs.Connects byte[] bytes = Encoding.UTF8.GetBytes(msg); return await SendDataAsync(bytes); } + /// /// 发送数据Async /// @@ -484,14 +481,15 @@ namespace PLCSharp.VVMs.Connects { await Task.Delay(10); return false; - } + /// /// 连接Params /// public class ConnectParams : BindableBase { private CommunicationDataType _DataType; + /// /// 连接配置 /// @@ -506,11 +504,10 @@ namespace PLCSharp.VVMs.Connects } SetProperty(ref _DataType, value); } - } - private string _Prompt; + /// /// 提示 /// @@ -520,7 +517,9 @@ namespace PLCSharp.VVMs.Connects get { return _Prompt; } set { SetProperty(ref _Prompt, value); } } + private byte _UnitId = 1; + /// /// UnitId /// @@ -529,9 +528,11 @@ namespace PLCSharp.VVMs.Connects get => _UnitId; set => SetProperty(ref _UnitId, value); } + // ─── 串口参数 ─── private int _BaudRate = 9600; + /// /// BaudRate /// @@ -542,6 +543,7 @@ namespace PLCSharp.VVMs.Connects } private int _DataBits = 8; + /// /// 数据Bits /// @@ -552,6 +554,7 @@ namespace PLCSharp.VVMs.Connects } private System.IO.Ports.StopBits _StopBits = System.IO.Ports.StopBits.One; + /// /// 停止Bits值 /// @@ -562,6 +565,7 @@ namespace PLCSharp.VVMs.Connects } private System.IO.Ports.Parity _Parity = System.IO.Ports.Parity.None; + /// /// Parity值 /// @@ -570,8 +574,8 @@ namespace PLCSharp.VVMs.Connects get => _Parity; set => SetProperty(ref _Parity, value); } - } + public enum StateEnum { Init, @@ -579,5 +583,4 @@ namespace PLCSharp.VVMs.Connects Sleep } } - -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ConnectViewModel.cs b/PLCSharpWpf/VVMs/Connects/ConnectViewModel.cs index ec1d8e1..4655c9b 100644 --- a/PLCSharpWpf/VVMs/Connects/ConnectViewModel.cs +++ b/PLCSharpWpf/VVMs/Connects/ConnectViewModel.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using Prism.Dialogs; using Prism.Events; using Prism.Ioc; @@ -10,7 +10,6 @@ namespace PLCSharp.VVMs.Connects /// public class ConnectsViewModel : DialogAwareBase { - /// /// Connects视图模型 /// @@ -19,11 +18,10 @@ namespace PLCSharp.VVMs.Connects { ConnectsModel = container.Resolve(); } + /// /// Connects模型 /// public ConnectsModel ConnectsModel { get; set; } - - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/Connects.xaml b/PLCSharpWpf/VVMs/Connects/Connects.xaml index ff7a740..dc40699 100644 --- a/PLCSharpWpf/VVMs/Connects/Connects.xaml +++ b/PLCSharpWpf/VVMs/Connects/Connects.xaml @@ -28,7 +28,6 @@ - @@ -99,6 +98,5 @@ - \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/Connects.xaml.cs b/PLCSharpWpf/VVMs/Connects/Connects.xaml.cs index 5103397..84c23ce 100644 --- a/PLCSharpWpf/VVMs/Connects/Connects.xaml.cs +++ b/PLCSharpWpf/VVMs/Connects/Connects.xaml.cs @@ -19,6 +19,7 @@ namespace PLCSharp.VVMs.Connects { InitializeComponent(); } + private void DataGrid_Unloaded(object sender, RoutedEventArgs e) { var dataGrid = sender as DataGrid; diff --git a/PLCSharpWpf/VVMs/Connects/ConnectsModel.cs b/PLCSharpWpf/VVMs/Connects/ConnectsModel.cs index f8aa45e..574e980 100644 --- a/PLCSharpWpf/VVMs/Connects/ConnectsModel.cs +++ b/PLCSharpWpf/VVMs/Connects/ConnectsModel.cs @@ -47,12 +47,12 @@ namespace PLCSharp.VVMs.Connects Type = item.Type, Comment = item.Comment, Params = item.Params, - }; connect.Params.Prompt = ""; Connects.Add(connect); } break; + case ProtocolType.SocketSever: { var connect = new SocketServer @@ -69,9 +69,9 @@ namespace PLCSharp.VVMs.Connects connect.Params.Prompt = ""; connect.Clients.ToList().ForEach(c => c.Params.Prompt = ""); Connects.Add(connect); - } break; + case ProtocolType.ModbusTcpClient: { var connect = new ModbusTcp.ModbusTcpClient @@ -89,6 +89,7 @@ namespace PLCSharp.VVMs.Connects Connects.Add(connect); } break; + case ProtocolType.ModbusTcpServer: { var connect = new ModbusTcp.ModbusTcpServer @@ -110,6 +111,7 @@ namespace PLCSharp.VVMs.Connects ApplyAllDataToServer(connect); } break; + case ProtocolType.ModbusRtuClient: { var connect = new ModbusRtu.ModbusRtuClient @@ -127,6 +129,7 @@ namespace PLCSharp.VVMs.Connects Connects.Add(connect); } break; + case ProtocolType.FreeSerialProtocol: { var connect = new SerialPort.FreeSerialProtocol @@ -144,20 +147,21 @@ namespace PLCSharp.VVMs.Connects Connects.Add(connect); } break; + default: SendErr("未配置的协议"); break; } - } - - } + #region Connect + /// /// 全局模型 /// public GlobalModel GlobalModel { get; set; } + /// /// 初始化 /// @@ -166,6 +170,7 @@ namespace PLCSharp.VVMs.Connects { GlobalModel = globalModel; } + private ObservableCollection _Connects = []; /// @@ -205,7 +210,6 @@ namespace PLCSharp.VVMs.Connects { if (r.Result == ButtonResult.Yes) { - var type = r.Parameters.GetValue("Type"); switch (type) @@ -216,9 +220,9 @@ namespace PLCSharp.VVMs.Connects Name = r.Parameters.GetValue("Name"), IP_SerialPort = r.Parameters.GetValue("IP_SerialPort"), Type = type - }); break; + case ProtocolType.SocketSever: Connects.Add(new SocketServer() { @@ -227,6 +231,7 @@ namespace PLCSharp.VVMs.Connects Type = type }); break; + case ProtocolType.ModbusTcpClient: Connects.Add(new ModbusTcp.ModbusTcpClient() { @@ -235,6 +240,7 @@ namespace PLCSharp.VVMs.Connects Type = type }); break; + case ProtocolType.ModbusTcpServer: Connects.Add(new ModbusTcp.ModbusTcpServer() { @@ -243,6 +249,7 @@ namespace PLCSharp.VVMs.Connects Type = type }); break; + case ProtocolType.FreeSerialProtocol: Connects.Add(new SerialPort.FreeSerialProtocol() { @@ -251,6 +258,7 @@ namespace PLCSharp.VVMs.Connects Type = type }); break; + case ProtocolType.ModbusRtuClient: Connects.Add(new ModbusRtu.ModbusRtuClient() { @@ -259,11 +267,10 @@ namespace PLCSharp.VVMs.Connects Type = type }); break; + default: break; } - - } }); break; @@ -292,14 +299,12 @@ namespace PLCSharp.VVMs.Connects Connects.Add(client); } - _dialogService.Show("SocketClientConfig", new DialogParameters($"Name={SelectedConnect.Name}"), r => { - - }); } break; + case ProtocolType.SocketSever: { var server = Connects.Where(c => c.ID == SelectedConnect.ID).FirstOrDefault(); @@ -316,14 +321,12 @@ namespace PLCSharp.VVMs.Connects Connects.Add(server); } - _dialogService.Show("SocketServerConfig", new DialogParameters($"Name={SelectedConnect.Name}"), r => { - - }); } break; + case ProtocolType.ModbusTcpClient: { var client = Connects.Where(c => c.ID == SelectedConnect.ID).FirstOrDefault(); @@ -342,10 +345,10 @@ namespace PLCSharp.VVMs.Connects _dialogService.Show("ModbusClientConfig", new DialogParameters($"Name={SelectedConnect.Name}"), r => { - }); } break; + case ProtocolType.ModbusTcpServer: { var server = Connects.Where(c => c.ID == SelectedConnect.ID).FirstOrDefault(); @@ -364,10 +367,10 @@ namespace PLCSharp.VVMs.Connects _dialogService.Show("ModbusServerConfig", new DialogParameters($"Name={SelectedConnect.Name}"), r => { - }); } break; + case ProtocolType.ModbusRtuClient: { var client = Connects.Where(c => c.ID == SelectedConnect.ID).FirstOrDefault(); @@ -382,6 +385,7 @@ namespace PLCSharp.VVMs.Connects _dialogService.Show("ModbusRtuConfig", new DialogParameters($"Name={SelectedConnect.Name}"), r => { }); } break; + case ProtocolType.FreeSerialProtocol: { var client = Connects.Where(c => c.ID == SelectedConnect.ID).FirstOrDefault(); @@ -396,6 +400,7 @@ namespace PLCSharp.VVMs.Connects _dialogService.Show("FreeSerialProtocolConfig", new DialogParameters($"Name={SelectedConnect.Name}"), r => { }); } break; + default: break; } @@ -417,8 +422,6 @@ namespace PLCSharp.VVMs.Connects SendInfoDialog($"已删除:{name}"); _DatasContext.Save(); } - - } break; } @@ -435,7 +438,7 @@ namespace PLCSharp.VVMs.Connects { if (string.IsNullOrEmpty(item.Name)) { - SendInfoDialog($"保存失败,名称{item.Name}不合适!" ); + SendInfoDialog($"保存失败,名称{item.Name}不合适!"); return; } @@ -450,7 +453,6 @@ namespace PLCSharp.VVMs.Connects } } - foreach (var item in Connects) { if (!_DatasContext.Connects.Any(h => h.ID == item.ID)) @@ -468,15 +470,13 @@ namespace PLCSharp.VVMs.Connects connect.Clients = item.Clients; connect.DataItems = item.DataItems; } - } - SelectedConnect.Params.Prompt = ""; _DatasContext.Save(); } - #endregion ProtocolHost + #endregion Connect #region ModbusTcpClient 轮询 @@ -517,14 +517,17 @@ namespace PLCSharp.VVMs.Connects /// UnitId /// public byte UnitId { get; set; } + /// /// 启动Address /// public ushort StartAddress { get; set; } + /// /// 读取数量 /// public ushort ReadCount { get; set; } + /// /// Items /// @@ -608,11 +611,10 @@ namespace PLCSharp.VVMs.Connects private static void DispatchSetRawValues(DataItem item, ushort lo, ushort hi) { - item.SetRawValues(lo, hi); } - #endregion + #endregion ModbusTcpClient 轮询 /// 写入单个 DataItem 的值到服务器 /// @@ -710,6 +712,6 @@ namespace PLCSharp.VVMs.Connects else server.SetInputRegister(addr, val); } - #endregion + #endregion ModbusTcpServer 写入(本地内存) } } \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuClient.cs b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuClient.cs index 1577fa1..735a2fb 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuClient.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuClient.cs @@ -13,10 +13,12 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu /// FC_READ_HOLDING_REGISTERS /// public const byte FC_READ_HOLDING_REGISTERS = 0x03; + /// /// FC_WRITE_SINGLE_REGISTER /// public const byte FC_WRITE_SINGLE_REGISTER = 0x06; + /// /// FC_WRITE_MULTIPLE_REGISTERS /// @@ -26,8 +28,6 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu private System.IO.Ports.SerialPort _port; - - /// 打开串口 public override void Open() { @@ -42,13 +42,11 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu _port.Open(); Connected = true; Log($"串口 {IP_SerialPort} 已打开"); - } catch (Exception ex) { Log($"打开串口失败: {ex.Message}"); Connected = false; - } } @@ -307,4 +305,4 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu return Execute(uid, FC_WRITE_MULTIPLE_REGISTERS, data) != null; } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml index 9c1dd2e..e2b32ce 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml +++ b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml @@ -143,4 +143,4 @@ - + \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml.cs b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml.cs index f583935..72419b6 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfig.xaml.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using System.Windows; using System.Windows.Controls; @@ -24,4 +24,4 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu dataGrid.CommitEdit(DataGridEditingUnit.Row, true); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfigViewModel.cs b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfigViewModel.cs index 22ccfdd..ac9fae1 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfigViewModel.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusRtu/ModbusRtuConfigViewModel.cs @@ -17,6 +17,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu { private readonly ConnectsModel _ConnectsModel; private ModbusRtuClient _Client; + /// /// 客户端 /// @@ -61,7 +62,6 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu public void OnDialogClosed() { Client.LogSwitch = false; - } /// @@ -75,13 +75,11 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu if (Client == null) return; Client.LogSwitch = true; - } - - // ─── 串口操作 ─── private DelegateCommand _OpenPortCommand; + /// /// 打开端口Command /// @@ -89,6 +87,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu _OpenPortCommand ??= new DelegateCommand(() => Client?.Open()); private DelegateCommand _ClosePortCommand; + /// /// 关闭端口Command /// @@ -97,6 +96,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu // ─── DataItems 管理 ─── private DelegateCommand _ConnectsManage; + /// /// Connects管理 /// @@ -104,6 +104,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu _ConnectsManage ??= new DelegateCommand(ExecuteConnectsManage); private DataItem _SelectedDataItem; + /// /// Selected数据项 /// @@ -115,7 +116,6 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu private void ExecuteConnectsManage(string cmd) { - switch (cmd) { case "New": @@ -156,6 +156,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu // ─── 日志 ─── private ObservableCollection _Logs = []; + /// /// Logs /// @@ -164,6 +165,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu get => _Logs; set => SetProperty(ref _Logs, value); } + private readonly BackgroundWorker bkgWorker; private void BackgroundWork(object sender, DoWorkEventArgs e) @@ -188,6 +190,5 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu } } } - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/DataItem.cs b/PLCSharpWpf/VVMs/Connects/ModbusTcp/DataItem.cs index 57668ef..e52c564 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/DataItem.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/DataItem.cs @@ -1,6 +1,5 @@ -using System.Text.Json; +using Prism.Mvvm; using System.Text.Json.Serialization; -using Prism.Mvvm; namespace PLCSharp.VVMs.Connects.ModbusTcp { @@ -12,15 +11,19 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp public enum ValueInterpretationEnum { UInt16, + /// 两个连续寄存器组成 32 位有符号整数 (大端) Int32, + /// 两个连续寄存器组成 32 位 IEEE 754 浮点数 (大端) Float, + /// 每个寄存器存 2 个字符 (高字节在前) String, } private ushort _Address; + /// /// Address /// @@ -31,6 +34,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private ushort _Value; + /// /// 值 /// @@ -45,6 +49,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private ushort _HighValue; + /// /// High值 /// @@ -54,11 +59,11 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp set { SetProperty(ref _HighValue, value); - } } private ValueInterpretationEnum _ValueInterpretation = ValueInterpretationEnum.UInt16; + /// /// 值Interpretation /// @@ -74,6 +79,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp // ───────── 显示值(只读,由 RefreshDisplay 更新) ───────── private string _DisplayValue = "0"; + /// /// Display值 /// @@ -86,6 +92,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp // ───────── 本地设定值(服务端:输入即解析更新当前值) ───────── private string _InputValue; + /// /// Input值 /// @@ -98,7 +105,9 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp ParseInputValueAndRefresh(); } } + private byte _UnitId = 1; + /// /// UnitId /// @@ -107,14 +116,17 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp get { return _UnitId; } set { SetProperty(ref _UnitId, value); } } + // ───────── 远程发送值(客户端:输入不更新当前值,发送时解析) ───────── private string _SendValue = ""; + /// /// 发送值 /// public string SendValue { get => _SendValue; set => SetProperty(ref _SendValue, value); } private string _Description = ""; + /// /// Description /// @@ -222,4 +234,4 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp RefreshDisplay(); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfig.xaml b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfig.xaml index 76b5277..a600eeb 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfig.xaml +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfig.xaml @@ -109,4 +109,4 @@ - + \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfigViewModel.cs b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfigViewModel.cs index bacb372..9b996db 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfigViewModel.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusClientConfigViewModel.cs @@ -60,8 +60,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp Client.LogSwitch = false; bkgWorker.CancelAsync(); bkgWorker.Dispose(); - - } /// @@ -77,7 +75,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp IP = Client.IP_SerialPort; Port = Client.Port; Client.LogSwitch = true; - } private readonly BackgroundWorker bkgWorker; @@ -105,10 +102,10 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } } - #region Properties private Connect _Client; + /// /// 客户端 /// @@ -119,6 +116,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private ObservableCollection _Logs = []; + /// /// Logs /// @@ -129,6 +127,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private string _IP = "127.0.0.1"; + /// /// IP /// @@ -145,6 +144,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private int _Port = 502; + /// /// 端口 /// @@ -161,6 +161,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private DataItem _SelectedDataItem; + /// /// Selected数据项 /// @@ -170,11 +171,12 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp set => SetProperty(ref _SelectedDataItem, value); } - #endregion + #endregion Properties #region Commands private DelegateCommand _ConnectsManage; + /// /// Connects管理 /// @@ -222,6 +224,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } } - #endregion + #endregion Commands } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml index f4bf8de..941973f 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml @@ -106,4 +106,4 @@ - + \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml.cs b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml.cs index d797687..656ae10 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfig.xaml.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using System.Windows; using System.Windows.Controls; @@ -24,4 +24,4 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp dataGrid.CommitEdit(DataGridEditingUnit.Row, true); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfigViewModel.cs b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfigViewModel.cs index e880fd2..f879229 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfigViewModel.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusServerConfigViewModel.cs @@ -181,7 +181,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp if (Server is ModbusTcpServer modbusServer) { _ConnectsModel.ApplyAllDataToServer(modbusServer); - } } @@ -213,6 +212,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp #region Properties private Connect _Server; + /// /// 服务端 /// @@ -223,6 +223,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private ObservableCollection _Logs = []; + /// /// Logs /// @@ -267,6 +268,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } private DataItem _SelectedDataItem; + /// /// Selected数据项 /// @@ -276,11 +278,12 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp set => SetProperty(ref _SelectedDataItem, value); } - #endregion + #endregion Properties #region Commands private DelegateCommand _ConnectsManage; + /// /// Connects管理 /// @@ -324,7 +327,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp if (Server is not ModbusTcpServer modbusServer) return; if (sender is not DataItem item) return; _ConnectsModel.ApplyDataItemToServer(modbusServer, item); - } private void HookPropertyChangedOnAllItems() @@ -337,6 +339,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } } - #endregion + #endregion Commands } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpClient.cs b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpClient.cs index 9e14d7e..26b23ff 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpClient.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpClient.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Tools; +using PLCSharp.Core.Tools; using System.ComponentModel; using System.IO; using System.Net; @@ -17,14 +17,17 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp /// FC_READ_HOLDING_REGISTERS /// public const byte FC_READ_HOLDING_REGISTERS = 0x03; + /// /// FC_WRITE_SINGLE_COIL /// public const byte FC_WRITE_SINGLE_COIL = 0x05; + /// /// FC_WRITE_SINGLE_REGISTER /// public const byte FC_WRITE_SINGLE_REGISTER = 0x06; + /// /// FC_WRITE_MULTIPLE_REGISTERS /// @@ -288,4 +291,4 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp return Execute(uid, FC_WRITE_MULTIPLE_REGISTERS, data) != null; } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpServer.cs b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpServer.cs index fc5593d..4e845e6 100644 --- a/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpServer.cs +++ b/PLCSharpWpf/VVMs/Connects/ModbusTcp/ModbusTcpServer.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Tools; +using PLCSharp.Core.Tools; using System.Collections.Concurrent; using System.ComponentModel; using System.IO; @@ -20,30 +20,37 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp /// FC_READ_COILS /// public const byte FC_READ_COILS = 0x01; + /// /// FC_READ_DISCRETE_INPUTS /// public const byte FC_READ_DISCRETE_INPUTS = 0x02; + /// /// FC_READ_HOLDING_REGISTERS /// public const byte FC_READ_HOLDING_REGISTERS = 0x03; + /// /// FC_READ_INPUT_REGISTERS /// public const byte FC_READ_INPUT_REGISTERS = 0x04; + /// /// FC_WRITE_SINGLE_COIL /// public const byte FC_WRITE_SINGLE_COIL = 0x05; + /// /// FC_WRITE_SINGLE_REGISTER /// public const byte FC_WRITE_SINGLE_REGISTER = 0x06; + /// /// FC_WRITE_MULTIPLE_COILS /// public const byte FC_WRITE_MULTIPLE_COILS = 0x0F; + /// /// FC_WRITE_MULTIPLE_REGISTERS /// @@ -51,13 +58,14 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp // Modbus exception codes private const byte EX_ILLEGAL_FUNCTION = 0x01; + private const byte EX_ILLEGAL_DATA_ADDRESS = 0x02; private const byte EX_ILLEGAL_DATA_VALUE = 0x03; private const byte EX_SERVER_DEVICE_FAILURE = 0x04; private const int MAX_REGISTERS = 65536; - #endregion + #endregion Constants #region Fields @@ -68,16 +76,19 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp private readonly ConcurrentDictionary _clients = new(); private readonly List _badClients = []; - #endregion + #endregion Fields #region Modbus Data Store // 线圈 (Coils) — 可读写 private readonly byte[] _coils = new byte[MAX_REGISTERS / 8 + 1]; + // 离散输入 (Discrete Inputs) — 只读 private readonly byte[] _discreteInputs = new byte[MAX_REGISTERS / 8 + 1]; + // 保持寄存器 (Holding Registers) — 可读写 private readonly ushort[] _holdingRegisters = new ushort[MAX_REGISTERS]; + // 输入寄存器 (Input Registers) — 只读 private readonly ushort[] _inputRegisters = new ushort[MAX_REGISTERS]; @@ -90,6 +101,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp /// 接收事件 /// public event Action ReceiveEvent; + public event Action ReceiveDateEvent; /// @@ -98,7 +110,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp /// public event Action DataWritten; - #endregion + #endregion Modbus Data Store /// /// ModbusTcp服务端 @@ -179,7 +191,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp _inputRegisters[address] = value; } - #endregion + #endregion Public Data Access (for simulation / test) #region Connection @@ -308,7 +320,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp _clients.TryRemove(clientKey, out _); } - #endregion + #endregion Connection #region Modbus Protocol Processing @@ -579,7 +591,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp return [(byte)(functionCode | 0x80), exceptionCode]; } - #endregion + #endregion Modbus Protocol Processing #region Background Worker @@ -609,6 +621,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } } break; + case StateEnum.Sleep: { Thread.Sleep(1000); @@ -626,7 +639,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp } } - #endregion + #endregion Background Worker #region Send/Receive Override @@ -681,7 +694,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp return true; } - #endregion + #endregion Send/Receive Override #region Cleanup @@ -723,6 +736,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp _acceptThread?.Interrupt(); } - #endregion + #endregion Cleanup } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/NetVariable.cs b/PLCSharpWpf/VVMs/Connects/NetVariable.cs index 4fed921..5dc738d 100644 --- a/PLCSharpWpf/VVMs/Connects/NetVariable.cs +++ b/PLCSharpWpf/VVMs/Connects/NetVariable.cs @@ -1,4 +1,4 @@ -namespace PLCSharp.VVMs.Connects +namespace PLCSharp.VVMs.Connects { /// /// 网络变量 @@ -26,15 +26,16 @@ namespace PLCSharp.VVMs.Connects /// public string Address { get; set; } - /// /// 类型 /// public Type Type { get; set; } + /// /// 值 /// public dynamic Value { get; set; } + /// /// 请求报文 /// @@ -44,8 +45,5 @@ namespace PLCSharp.VVMs.Connects /// 响应报文 /// public string Response { get; set; } - - - } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/NewConnect.xaml b/PLCSharpWpf/VVMs/Connects/NewConnect.xaml index 0a1f894..870a280 100644 --- a/PLCSharpWpf/VVMs/Connects/NewConnect.xaml +++ b/PLCSharpWpf/VVMs/Connects/NewConnect.xaml @@ -23,7 +23,6 @@ - @@ -52,4 +51,4 @@ CommandParameter="No" Content="取消" Cursor="Hand" Foreground="White" /> - + \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/NewConnect.xaml.cs b/PLCSharpWpf/VVMs/Connects/NewConnect.xaml.cs index 19e7f64..be75d02 100644 --- a/PLCSharpWpf/VVMs/Connects/NewConnect.xaml.cs +++ b/PLCSharpWpf/VVMs/Connects/NewConnect.xaml.cs @@ -1,4 +1,4 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using System.Windows.Controls; namespace PLCSharp.VVMs.Connects @@ -7,9 +7,6 @@ namespace PLCSharp.VVMs.Connects /// 新建连接 /// [Dialog] - /// - /// NewConnect.xaml 的交互逻辑 - /// public partial class NewConnect : UserControl { /// @@ -20,4 +17,4 @@ namespace PLCSharp.VVMs.Connects InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/NewConnectViewModel.cs b/PLCSharpWpf/VVMs/Connects/NewConnectViewModel.cs index c59f1e7..c465caf 100644 --- a/PLCSharpWpf/VVMs/Connects/NewConnectViewModel.cs +++ b/PLCSharpWpf/VVMs/Connects/NewConnectViewModel.cs @@ -1,9 +1,8 @@ -using PLCSharp.Core.Prism; +using PLCSharp.Core.Prism; using Prism.Dialogs; using Prism.Events; using Prism.Ioc; - namespace PLCSharp.VVMs.Connects { /// @@ -11,8 +10,8 @@ namespace PLCSharp.VVMs.Connects /// public class NewConnectViewModel : DialogAwareBase { - private string _Name; + /// /// 名称 /// @@ -24,7 +23,9 @@ namespace PLCSharp.VVMs.Connects SetProperty(ref _Name, value); } } + private ProtocolType _Type; + /// /// 类型 /// @@ -40,21 +41,27 @@ namespace PLCSharp.VVMs.Connects case ProtocolType.SocketClient: IP_SerialPort = "192.168.0.1"; break; + case ProtocolType.SocketSever: IP_SerialPort = "192.168.0.1"; break; + case ProtocolType.ModbusTcpClient: IP_SerialPort = "192.168.0.1"; break; + case ProtocolType.ModbusTcpServer: IP_SerialPort = "192.168.0.1"; break; + case ProtocolType.FreeSerialProtocol: IP_SerialPort = "COM1"; break; + case ProtocolType.ModbusRtuClient: IP_SerialPort = "COM1"; break; + default: break; } @@ -69,6 +76,7 @@ namespace PLCSharp.VVMs.Connects } private string _IP_SerialPort; + /// /// IP_串口端口 /// @@ -77,6 +85,7 @@ namespace PLCSharp.VVMs.Connects get { return _IP_SerialPort; } set { SetProperty(ref _IP_SerialPort, value); } } + /// /// 打开对话框后要执行的 /// @@ -87,6 +96,7 @@ namespace PLCSharp.VVMs.Connects Type = ProtocolType.SocketClient; Title = "New Connect"; } + /// /// RaiseRequest关闭 /// @@ -99,4 +109,4 @@ namespace PLCSharp.VVMs.Connects base.RaiseRequestClose(dialogResult); } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocol.cs b/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocol.cs index 43ea6a7..72a3b34 100644 --- a/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocol.cs +++ b/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocol.cs @@ -1,4 +1,4 @@ -using System.IO.Ports; +using System.IO.Ports; using System.Text; namespace PLCSharp.VVMs.Connects.SerialPort @@ -6,7 +6,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort /// /// Free串口协议 /// - class FreeSerialProtocol : Connect + internal class FreeSerialProtocol : Connect { /// /// my串口 @@ -15,10 +15,10 @@ namespace PLCSharp.VVMs.Connects.SerialPort public event Action ReceiveBytes; - readonly byte[] readBuffer = new byte[1024]; + private readonly byte[] readBuffer = new byte[1024]; + private void DataReceivedHandlerScan(object sender, SerialDataReceivedEventArgs e) { - var spReceive = (System.IO.Ports.SerialPort)sender; var count = Math.Min(spReceive.BytesToRead, readBuffer.Length); spReceive.Read(readBuffer, 0, count); @@ -37,6 +37,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort Log("接收 <== " + Encoding.UTF8.GetString(receiveBuffer, 0, receiveBuffer.Length)); } } + /// /// 打开 /// @@ -77,7 +78,6 @@ namespace PLCSharp.VVMs.Connects.SerialPort /// 返回结果 public override async Task SendDataAsync(byte[] bytes, bool isLog = true) { - return await Task.Run(() => { if (bytes == null || bytes.Length == 0) return false; @@ -100,19 +100,12 @@ namespace PLCSharp.VVMs.Connects.SerialPort Successful = false; return false; } - } else { - return false; } - }); - - - - } } -} +} \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocolConfig.xaml b/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocolConfig.xaml index fdff2da..9195ccf 100644 --- a/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocolConfig.xaml +++ b/PLCSharpWpf/VVMs/Connects/SerialPort/FreeSerialProtocolConfig.xaml @@ -54,7 +54,6 @@ - - - @@ -102,7 +99,6 @@ -