自动整理代码格式
This commit is contained in:
parent
1d2df8e3cf
commit
7eaa2edacc
@ -1,9 +1,7 @@
|
||||
<prism:PrismApplication x:Class="PLCSharp.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cvt="clr-namespace:PLCSharp.Core.Tools"
|
||||
xmlns:local="clr-namespace:PLCSharp"
|
||||
xmlns:prism="http://prismlibrary.com/">
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<prism:PrismApplication.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
@ -59,7 +57,6 @@ namespace PLCSharp
|
||||
_ = containerRegistry.RegisterSingleton(model);
|
||||
}
|
||||
|
||||
|
||||
//注册导航特性的类到导航
|
||||
var views = from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.GetCustomAttribute<NavigationPageAttribute>() 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<DialogMenuAttribute>();
|
||||
var navigteItem = Container.Resolve<NavigateItem>();
|
||||
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<MainWindow>();
|
||||
@ -166,6 +156,7 @@ namespace PLCSharp
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动寻找ViewModel并绑定到View,要求ViewModel命名为View的全名加上ViewModel,比如MainWindow的ViewModel命名为MainWindowViewModel
|
||||
/// </summary>
|
||||
@ -181,12 +172,12 @@ namespace PLCSharp
|
||||
return Type.GetType(viewModelName);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载环境变量
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
@ -235,50 +220,42 @@ namespace PLCSharp
|
||||
/// </summary>
|
||||
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());
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录日志
|
||||
/// </summary>
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace PLCSharp.Core.Common
|
||||
{
|
||||
|
||||
public enum CellState
|
||||
{
|
||||
无料 = 0,
|
||||
@ -20,8 +19,8 @@ namespace PLCSharp.Core.Common
|
||||
/// </summary>
|
||||
public class CellInfo : BindableBase
|
||||
{
|
||||
|
||||
private int _Index;
|
||||
|
||||
/// <summary>
|
||||
/// 单元格索引
|
||||
/// </summary>
|
||||
@ -32,6 +31,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private int _Row;
|
||||
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
@ -42,6 +42,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private int _Column;
|
||||
|
||||
/// <summary>
|
||||
/// 列号
|
||||
/// </summary>
|
||||
@ -52,6 +53,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private CellState _State;
|
||||
|
||||
/// <summary>
|
||||
/// 状态标志
|
||||
/// </summary>
|
||||
@ -67,6 +69,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private string _Info;
|
||||
|
||||
/// <summary>
|
||||
/// 附加信息
|
||||
/// </summary>
|
||||
@ -77,6 +80,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private string _Tag;
|
||||
|
||||
/// <summary>
|
||||
/// 标签
|
||||
/// </summary>
|
||||
@ -87,7 +91,5 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
public event EventHandler<CellState> _CellChanged;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public class ErrorLog : BindableBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
/// </summary>
|
||||
@ -22,10 +21,10 @@ namespace PLCSharp.Core.Common
|
||||
{
|
||||
Message = message;
|
||||
Time = DateTime.Now;
|
||||
|
||||
}
|
||||
|
||||
private string _Message;
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
@ -36,6 +35,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private DateTime _Time;
|
||||
|
||||
/// <summary>
|
||||
/// Time
|
||||
/// </summary>
|
||||
@ -46,6 +46,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private bool _IsConfirm;
|
||||
|
||||
/// <summary>
|
||||
/// IsConfirm
|
||||
/// </summary>
|
||||
@ -55,4 +56,4 @@ namespace PLCSharp.Core.Common
|
||||
set { SetProperty(ref _IsConfirm, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,9 +5,8 @@
|
||||
/// </summary>
|
||||
public class FlowModel
|
||||
{
|
||||
|
||||
|
||||
private int _Step;
|
||||
|
||||
/// <summary>
|
||||
/// 当前执行的步骤序号
|
||||
/// </summary>
|
||||
@ -22,7 +21,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前步骤的开始时间
|
||||
/// </summary>
|
||||
@ -32,28 +30,32 @@
|
||||
/// 整个流程的开始时间
|
||||
/// </summary>
|
||||
public DateTime FlowStarTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 是否完成
|
||||
/// </summary>
|
||||
public bool Done { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流程是否正常结束(默认 false,正常结束时置 true)
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 失败原因(非空表示异常结束)
|
||||
/// </summary>
|
||||
public string? FailMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单个步骤超时时间(秒),默认 5 秒
|
||||
/// </summary>
|
||||
public double TimeoutSeconds { get; set; } = 5;
|
||||
|
||||
/// <summary>
|
||||
/// 默认构造函数,自动调用 Reset 初始化
|
||||
/// </summary>
|
||||
public FlowModel()
|
||||
{
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@ -69,6 +71,7 @@
|
||||
StepTime = DateTime.Now;
|
||||
FlowStarTime = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查当前步骤是否已超时
|
||||
/// </summary>
|
||||
@ -89,7 +92,6 @@
|
||||
return FlowStarTime.AddSeconds(second) < DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
public Task<bool> TaskBool { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 = "";
|
||||
|
||||
/// <summary>
|
||||
/// Info
|
||||
/// </summary>
|
||||
@ -19,6 +20,7 @@ namespace PLCSharp.Core.Common
|
||||
}
|
||||
|
||||
private Brush _Background = Brushes.White;
|
||||
|
||||
/// <summary>
|
||||
/// Background
|
||||
/// </summary>
|
||||
@ -28,4 +30,4 @@ namespace PLCSharp.Core.Common
|
||||
set { SetProperty(ref _Background, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,27 +1,19 @@
|
||||
namespace PLCSharp.Core.Prism
|
||||
namespace PLCSharp.Core.Prism
|
||||
{
|
||||
/// <summary>
|
||||
/// 标志此特性的类会被注册为单例
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
|
||||
public class ModelAttribute : Attribute
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 标志此特性的类会被注册为弹出窗口
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class DialogAttribute : Attribute
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -30,7 +22,6 @@ namespace PLCSharp.Core.Prism
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class DialogMenuAttribute : Attribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 视图名称
|
||||
/// </summary>
|
||||
@ -60,7 +51,6 @@ namespace PLCSharp.Core.Prism
|
||||
/// 当前索引
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -98,6 +88,5 @@ namespace PLCSharp.Core.Prism
|
||||
/// 当前索引
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public class DataGridScrollToBottomBehavior : Behavior<DataGrid>
|
||||
{
|
||||
@ -46,5 +46,4 @@ namespace PLCSharp.Core.Prism
|
||||
AssociatedObject.ScrollIntoView(AssociatedObject.Items[^1]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -17,11 +17,10 @@ namespace PLCSharp.Core.Prism
|
||||
public DialogAwareBase(IContainerExtension container, IEventAggregator ea, IDialogService dialogService)
|
||||
{
|
||||
_EventAggregator = ea;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private string _Title = "";
|
||||
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
@ -30,7 +29,9 @@ namespace PLCSharp.Core.Prism
|
||||
get { return _Title; }
|
||||
set { SetProperty(ref _Title, value); }
|
||||
}
|
||||
|
||||
private DelegateCommand<string> _closeDialogCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 关闭对话框命令
|
||||
/// </summary>
|
||||
@ -114,16 +115,18 @@ namespace PLCSharp.Core.Prism
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件聚合器,用于发送消息和通知
|
||||
/// </summary>
|
||||
protected readonly IEventAggregator _EventAggregator;
|
||||
|
||||
/// <summary>
|
||||
/// 发送错误消息到日志和界面
|
||||
/// </summary>
|
||||
/// <param name="msg">错误消息内容</param>
|
||||
/// <param name="type">消息类型(记录、对话框提示等)</param>
|
||||
public void SendErr(string msg, ShowType type,ErrType errType)
|
||||
public void SendErr(string msg, ShowType type, ErrType errType)
|
||||
{
|
||||
_EventAggregator.GetEvent<MessageEvent>().Publish(new()
|
||||
{
|
||||
@ -142,6 +145,7 @@ namespace PLCSharp.Core.Prism
|
||||
{
|
||||
SendErr(msg, ShowType.Record, ErrType.Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送弹出故障消息
|
||||
/// </summary>
|
||||
|
||||
@ -29,8 +29,7 @@ namespace PLCSharp.Core.Prism
|
||||
/// </summary>
|
||||
public ShowType Type { get; set; }
|
||||
|
||||
|
||||
public ErrType ErrType { get; set; }
|
||||
public ErrType ErrType { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -63,16 +62,16 @@ namespace PLCSharp.Core.Prism
|
||||
|
||||
public enum ShowType
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 记录
|
||||
/// </summary>
|
||||
Record = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 弹出
|
||||
/// </summary>
|
||||
ShowDialog = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 弹出并记录
|
||||
/// </summary>
|
||||
@ -81,16 +80,14 @@ namespace PLCSharp.Core.Prism
|
||||
|
||||
public enum ErrType
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 普通信息
|
||||
/// </summary>
|
||||
Info = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 故障
|
||||
/// </summary>
|
||||
Error = 2,
|
||||
|
||||
}
|
||||
}
|
||||
@ -16,21 +16,25 @@ namespace PLCSharp.Core.Prism
|
||||
/// _EventAggregator
|
||||
/// </summary>
|
||||
protected readonly IEventAggregator _EventAggregator;
|
||||
|
||||
/// <summary>
|
||||
/// 对话框服务
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public readonly IDialogService _dialogService;
|
||||
|
||||
/// <summary>
|
||||
/// _container
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public readonly IContainerExtension _container;
|
||||
|
||||
/// <summary>
|
||||
/// _DatasContext
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public DatasContext _DatasContext { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型Base
|
||||
/// </summary>
|
||||
@ -41,10 +45,8 @@ namespace PLCSharp.Core.Prism
|
||||
_EventAggregator = ea;
|
||||
_dialogService = dialogService;
|
||||
AppDomain.CurrentDomain.ProcessExit += OnExit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// OnExit
|
||||
/// </summary>
|
||||
@ -52,8 +54,8 @@ namespace PLCSharp.Core.Prism
|
||||
/// <param name="e">e</param>
|
||||
protected virtual void OnExit(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息到事件总线
|
||||
/// </summary>
|
||||
@ -69,14 +71,16 @@ namespace PLCSharp.Core.Prism
|
||||
Content = msg
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送故障信息
|
||||
/// </summary>
|
||||
/// <param name="msg">msg</param>
|
||||
public void SendErr(string msg )
|
||||
public void SendErr(string msg)
|
||||
{
|
||||
SendErr(msg, ShowType.Record, ErrType.Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送弹出故障消息
|
||||
/// </summary>
|
||||
@ -103,6 +107,5 @@ namespace PLCSharp.Core.Prism
|
||||
{
|
||||
SendErr(msg, ShowType.ShowDialogAndRecord, ErrType.Info);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
@ -89,42 +89,37 @@ namespace PLCSharp.Core.Prism
|
||||
return Index.CompareTo(other.Index);
|
||||
}
|
||||
|
||||
|
||||
private DelegateCommand _Open;
|
||||
|
||||
/// <summary>
|
||||
/// 打开
|
||||
/// </summary>
|
||||
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<string> ShowList = [];
|
||||
IDialogService _dialogService { get; set; }
|
||||
private IDialogService _dialogService { get; set; }
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public new KeyCollection Keys => base.Keys;
|
||||
|
||||
/// <summary>
|
||||
/// Values
|
||||
/// </summary>
|
||||
public new ValueCollection Values => base.Values;
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
@ -123,7 +127,7 @@ namespace PLCSharp.Core.Prism
|
||||
/// <returns>返回布尔值</returns>
|
||||
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 辅助方法
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
namespace PLCSharp.Core.Resources.Iconfont
|
||||
namespace PLCSharp.Core.Resources.Iconfont
|
||||
{
|
||||
/// <summary>
|
||||
/// Icon
|
||||
@ -9,262 +9,325 @@ namespace PLCSharp.Core.Resources.Iconfont
|
||||
/// 方向圆_向上
|
||||
/// </summary>
|
||||
public static string 方向圆_向上 = "\ue61a";
|
||||
|
||||
/// <summary>
|
||||
/// 方向圆_向下
|
||||
/// </summary>
|
||||
public static string 方向圆_向下 = "\ue61d";
|
||||
|
||||
/// <summary>
|
||||
/// 方向圆_向右
|
||||
/// </summary>
|
||||
public static string 方向圆_向右 = "\ue61e";
|
||||
|
||||
/// <summary>
|
||||
/// 方向圆_向左
|
||||
/// </summary>
|
||||
public static string 方向圆_向左 = "\ue620";
|
||||
|
||||
/// <summary>
|
||||
/// 方向_向下
|
||||
/// </summary>
|
||||
public static string 方向_向下 = "\ue615";
|
||||
|
||||
/// <summary>
|
||||
/// 方向_向上
|
||||
/// </summary>
|
||||
public static string 方向_向上 = "\ue617";
|
||||
|
||||
/// <summary>
|
||||
/// 方向_向左
|
||||
/// </summary>
|
||||
public static string 方向_向左 = "\ue618";
|
||||
|
||||
/// <summary>
|
||||
/// 方向_向右
|
||||
/// </summary>
|
||||
public static string 方向_向右 = "\ue619";
|
||||
|
||||
/// <summary>
|
||||
/// 操作_温度
|
||||
/// </summary>
|
||||
public static string 操作_温度 = "\ue626";
|
||||
|
||||
/// <summary>
|
||||
/// 拍照_线性
|
||||
/// </summary>
|
||||
public static string 拍照_线性 = "\ue8d1";
|
||||
|
||||
/// <summary>
|
||||
/// 停止
|
||||
/// </summary>
|
||||
public static string 停止 = "\ue611";
|
||||
|
||||
/// <summary>
|
||||
/// 功能
|
||||
/// </summary>
|
||||
public static string 功能 = "\ue612";
|
||||
|
||||
/// <summary>
|
||||
/// 操作_打印
|
||||
/// </summary>
|
||||
public static string 操作_打印 = "\ue738";
|
||||
|
||||
/// <summary>
|
||||
/// 操作日志
|
||||
/// </summary>
|
||||
public static string 操作日志 = "\ue664";
|
||||
|
||||
/// <summary>
|
||||
/// 气缸
|
||||
/// </summary>
|
||||
public static string 气缸 = "\ue616";
|
||||
|
||||
/// <summary>
|
||||
/// 伺服电机
|
||||
/// </summary>
|
||||
public static string 伺服电机 = "\ue609";
|
||||
|
||||
/// <summary>
|
||||
/// 拆线简
|
||||
/// </summary>
|
||||
public static string 拆线简 = "\ue64a";
|
||||
|
||||
/// <summary>
|
||||
/// 折线
|
||||
/// </summary>
|
||||
public static string 折线 = "\ue878";
|
||||
|
||||
/// <summary>
|
||||
/// 饼图
|
||||
/// </summary>
|
||||
public static string 饼图 = "\ue66b";
|
||||
|
||||
/// <summary>
|
||||
/// 仪表盘
|
||||
/// </summary>
|
||||
public static string 仪表盘 = "\ueab4";
|
||||
|
||||
/// <summary>
|
||||
/// 服务
|
||||
/// </summary>
|
||||
public static string 服务 = "\ue6d8";
|
||||
|
||||
/// <summary>
|
||||
/// 工具
|
||||
/// </summary>
|
||||
public static string 工具 = "\ue614";
|
||||
|
||||
/// <summary>
|
||||
/// 网络系统
|
||||
/// </summary>
|
||||
public static string 网络系统 = "\ue62e";
|
||||
|
||||
/// <summary>
|
||||
/// 管理员
|
||||
/// </summary>
|
||||
public static string 管理员 = "\ue62a";
|
||||
|
||||
/// <summary>
|
||||
/// 紧急告警
|
||||
/// </summary>
|
||||
public static string 紧急告警 = "\ue678";
|
||||
|
||||
/// <summary>
|
||||
/// 记录
|
||||
/// </summary>
|
||||
public static string 记录 = "\ue604";
|
||||
|
||||
/// <summary>
|
||||
/// 告警
|
||||
/// </summary>
|
||||
public static string 告警 = "\uec35";
|
||||
|
||||
/// <summary>
|
||||
/// 历史记录
|
||||
/// </summary>
|
||||
public static string 历史记录 = "\ue605";
|
||||
|
||||
/// <summary>
|
||||
/// 咨询记录
|
||||
/// </summary>
|
||||
public static string 咨询记录 = "\ue68c";
|
||||
|
||||
/// <summary>
|
||||
/// 时钟
|
||||
/// </summary>
|
||||
public static string 时钟 = "\ue75b";
|
||||
|
||||
/// <summary>
|
||||
/// 告警记录
|
||||
/// </summary>
|
||||
public static string 告警记录 = "\ue66a";
|
||||
|
||||
/// <summary>
|
||||
/// 告警灯
|
||||
/// </summary>
|
||||
public static string 告警灯 = "\ue61f";
|
||||
|
||||
/// <summary>
|
||||
/// 权限
|
||||
/// </summary>
|
||||
public static string 权限 = "\ue610";
|
||||
|
||||
/// <summary>
|
||||
/// 权限管理
|
||||
/// </summary>
|
||||
public static string 权限管理 = "\ue64c";
|
||||
|
||||
/// <summary>
|
||||
/// 转换
|
||||
/// </summary>
|
||||
public static string 转换 = "\ue61b";
|
||||
|
||||
/// <summary>
|
||||
/// 服务器
|
||||
/// </summary>
|
||||
public static string 服务器 = "\ue687";
|
||||
|
||||
/// <summary>
|
||||
/// 配方方案
|
||||
/// </summary>
|
||||
public static string 配方方案 = "\ue681";
|
||||
|
||||
/// <summary>
|
||||
/// 人和钥匙
|
||||
/// </summary>
|
||||
public static string 人和钥匙 = "\ue61c";
|
||||
|
||||
/// <summary>
|
||||
/// 安全密钥
|
||||
/// </summary>
|
||||
public static string 安全密钥 = "\ue665";
|
||||
|
||||
/// <summary>
|
||||
/// 配置
|
||||
/// </summary>
|
||||
public static string 配置 = "\ue659";
|
||||
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
public static string 查询 = "\ue660";
|
||||
|
||||
/// <summary>
|
||||
/// 主页
|
||||
/// </summary>
|
||||
public static string 主页 = "\ue622";
|
||||
|
||||
/// <summary>
|
||||
/// 关闭
|
||||
/// </summary>
|
||||
public static string 关闭 = "\ueca0";
|
||||
|
||||
/// <summary>
|
||||
/// 最小化
|
||||
/// </summary>
|
||||
public static string 最小化 = "\ue650";
|
||||
|
||||
/// <summary>
|
||||
/// 菜单
|
||||
/// </summary>
|
||||
public static string 菜单 = "\ue790";
|
||||
|
||||
/// <summary>
|
||||
/// 最大化2
|
||||
/// </summary>
|
||||
public static string 最大化2 = "\ue623";
|
||||
|
||||
/// <summary>
|
||||
/// 设置
|
||||
/// </summary>
|
||||
public static string 设置 = "\ue8b8";
|
||||
|
||||
/// <summary>
|
||||
/// 调试
|
||||
/// </summary>
|
||||
public static string 调试 = "\ueb61";
|
||||
|
||||
/// <summary>
|
||||
/// 编辑
|
||||
/// </summary>
|
||||
public static string 编辑 = "\ueb62";
|
||||
|
||||
/// <summary>
|
||||
/// 警告
|
||||
/// </summary>
|
||||
public static string 警告 = "\ueb65";
|
||||
|
||||
/// <summary>
|
||||
/// 人机交互
|
||||
/// </summary>
|
||||
public static string 人机交互 = "\ueb67";
|
||||
|
||||
/// <summary>
|
||||
/// 使用文档
|
||||
/// </summary>
|
||||
public static string 使用文档 = "\ueb68";
|
||||
|
||||
/// <summary>
|
||||
/// 数据看板
|
||||
/// </summary>
|
||||
public static string 数据看板 = "\ueb6b";
|
||||
|
||||
/// <summary>
|
||||
/// 账号权限管理
|
||||
/// </summary>
|
||||
public static string 账号权限管理 = "\ueb6e";
|
||||
|
||||
/// <summary>
|
||||
/// 园区运维
|
||||
/// </summary>
|
||||
public static string 园区运维 = "\ueb6f";
|
||||
|
||||
/// <summary>
|
||||
/// 自定义
|
||||
/// </summary>
|
||||
public static string 自定义 = "\ueb71";
|
||||
|
||||
/// <summary>
|
||||
/// 载入中
|
||||
/// </summary>
|
||||
public static string 载入中 = "\ueb80";
|
||||
|
||||
/// <summary>
|
||||
/// 图表_柱状图
|
||||
/// </summary>
|
||||
public static string 图表_柱状图 = "\ueb96";
|
||||
|
||||
/// <summary>
|
||||
/// 形状_图片
|
||||
/// </summary>
|
||||
public static string 形状_图片 = "\ueb98";
|
||||
|
||||
/// <summary>
|
||||
/// 组织群组
|
||||
/// </summary>
|
||||
public static string 组织群组 = "\uebd8";
|
||||
|
||||
/// <summary>
|
||||
/// 打开
|
||||
/// </summary>
|
||||
public static string 打开 = "\uebdf";
|
||||
|
||||
/// <summary>
|
||||
/// 控件已选
|
||||
/// </summary>
|
||||
public static string 控件已选 = "\uebf0";
|
||||
|
||||
/// <summary>
|
||||
/// 刷新
|
||||
/// </summary>
|
||||
public static string 刷新 = "\uec08";
|
||||
|
||||
/// <summary>
|
||||
/// 搜索放大
|
||||
/// </summary>
|
||||
public static string 搜索放大 = "\uec32";
|
||||
|
||||
/// <summary>
|
||||
/// 最大化
|
||||
/// </summary>
|
||||
public static string 最大化 = "\ue673";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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');
|
||||
|
||||
@ -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');
|
||||
}
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
namespace PLCSharp.Core.Tools
|
||||
namespace PLCSharp.Core.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Bit工具
|
||||
/// </summary>
|
||||
public static class BitTool
|
||||
{
|
||||
|
||||
#region uint
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 转换
|
||||
/// </summary>
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 转换Back
|
||||
/// </summary>
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<Type, Delegate> _cache = [];
|
||||
|
||||
/// <summary>
|
||||
/// DeepCopy
|
||||
/// </summary>
|
||||
@ -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<T, T>)func)(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public class FileTools
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取图像
|
||||
/// </summary>
|
||||
@ -24,6 +21,5 @@ namespace PLCSharp.Core.Tools
|
||||
bmp.Freeze();
|
||||
return bmp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
|
||||
/// <summary>
|
||||
/// PingIPAsync
|
||||
/// </summary>
|
||||
@ -34,12 +35,10 @@ namespace PLCSharp.Core.Tools
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// PingIP
|
||||
/// </summary>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,8 @@ namespace PLCSharp.Core.Tools
|
||||
public class WpfTool
|
||||
{
|
||||
private readonly ConcurrentQueue<PointF> PointsQueue = new();
|
||||
readonly List<PointF> Points = [];
|
||||
private readonly List<PointF> Points = [];
|
||||
|
||||
/// <summary>
|
||||
/// 执行绘制Async
|
||||
/// </summary>
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -134,4 +131,4 @@ namespace PLCSharp.Core.Tools
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ namespace PLCSharp.Core.Tools
|
||||
public class XPoint : BindableBase, IEquatable<XPoint>
|
||||
{
|
||||
private double _X;
|
||||
|
||||
/// <summary>
|
||||
/// X坐标
|
||||
/// </summary>
|
||||
@ -20,6 +21,7 @@ namespace PLCSharp.Core.Tools
|
||||
}
|
||||
|
||||
private double _Y;
|
||||
|
||||
/// <summary>
|
||||
/// Y
|
||||
/// </summary>
|
||||
@ -30,6 +32,7 @@ namespace PLCSharp.Core.Tools
|
||||
}
|
||||
|
||||
private double _Z;
|
||||
|
||||
/// <summary>
|
||||
/// Z
|
||||
/// </summary>
|
||||
@ -40,6 +43,7 @@ namespace PLCSharp.Core.Tools
|
||||
}
|
||||
|
||||
private double _Angle;
|
||||
|
||||
/// <summary>
|
||||
/// U
|
||||
/// </summary>
|
||||
@ -49,8 +53,6 @@ namespace PLCSharp.Core.Tools
|
||||
set { SetProperty(ref _Angle, Math.Round(value, 6)); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取Offs点位
|
||||
/// </summary>
|
||||
@ -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}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,6 @@
|
||||
Text="100%"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="Wheat" />
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<TextBlock Name="mousey"
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
|
||||
using PLCSharp.Core.UserControls.ROI;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@ -54,7 +55,7 @@ namespace PLCSharp.Core.UserControls
|
||||
rate.Text = zoom.ToString("P2");
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion 缩放
|
||||
|
||||
#region 图片
|
||||
|
||||
@ -100,7 +101,7 @@ namespace PLCSharp.Core.UserControls
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion 图片
|
||||
|
||||
#region 拖动和画
|
||||
|
||||
@ -114,6 +115,7 @@ namespace PLCSharp.Core.UserControls
|
||||
|
||||
// --- ROI 绘制会话状态 ---
|
||||
private bool drawing;
|
||||
|
||||
private ROIType _roiMode; // 当前绘制模式
|
||||
private RectROI? _tempRoi; // 矩形/旋转矩形橡皮筋预览
|
||||
private RectROI? _pendingRoi; // 左键松开后创建、等待右键确认的矩形ROI
|
||||
@ -126,8 +128,10 @@ namespace PLCSharp.Core.UserControls
|
||||
private TaskCompletionSource<RectROI>? _roiTcs;
|
||||
private TaskCompletionSource<RotateRectROI>? _rotateRoiTcs;
|
||||
private TaskCompletionSource<LineROI>? _lineTcs;
|
||||
|
||||
// --- 圆形状态 ---
|
||||
private System.Windows.Shapes.Ellipse? _tempCircle; // 橡皮筋圆形预览
|
||||
|
||||
private CircleROI? _pendingCircle; // 左键松开后创建、等待右键确认的圆形
|
||||
private string? _circleAdjustMode; // null/"move"/"radius"
|
||||
private TaskCompletionSource<CircleROI>? _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 圆形辅助方法
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1018,18 +1033,22 @@ namespace PLCSharp.Core.UserControls
|
||||
/// 启动X
|
||||
/// </summary>
|
||||
public double StartX { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 启动Y
|
||||
/// </summary>
|
||||
public double StartY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// EndX
|
||||
/// </summary>
|
||||
public double EndX { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// EndY
|
||||
/// </summary>
|
||||
public double EndY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tag
|
||||
/// </summary>
|
||||
@ -1045,17 +1064,20 @@ namespace PLCSharp.Core.UserControls
|
||||
/// 圆心X
|
||||
/// </summary>
|
||||
public double CenterX { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 圆心Y
|
||||
/// </summary>
|
||||
public double CenterY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 半径
|
||||
/// </summary>
|
||||
public double Radius { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tag
|
||||
/// </summary>
|
||||
public string? Tag { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,5 +7,4 @@
|
||||
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
||||
<PasswordBox x:Name="passwordBox" PasswordChanged="PasswordBox_PasswordChanged" />
|
||||
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Text
|
||||
/// </summary>
|
||||
@ -45,7 +43,6 @@ namespace PLCSharp.Core.UserControls
|
||||
|
||||
if (obj.Text == "")
|
||||
obj.passwordBox.Password = obj.Text;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,6 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
<ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
|
||||
<Rectangle Fill="Transparent" />
|
||||
</ControlTemplate>
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty RectAngleProperty =
|
||||
DependencyProperty.Register("RectAngle", typeof(double), typeof(RotateRectROI), new PropertyMetadata(0d));
|
||||
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,6 @@
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
|
||||
</UserControl.ContextMenu>
|
||||
<Border BorderBrush="Black" BorderThickness="1">
|
||||
<Grid>
|
||||
@ -37,7 +36,6 @@
|
||||
<RowDefinition Height="2*" />
|
||||
<RowDefinition Height="2*" />
|
||||
<RowDefinition Height="2*" />
|
||||
|
||||
</Grid.RowDefinitions>
|
||||
<Viewbox HorizontalAlignment="Left" VerticalAlignment="Bottom">
|
||||
<TextBlock>
|
||||
@ -66,4 +64,4 @@
|
||||
</Viewbox>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace PLCSharp.Core.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
@ -9,18 +10,17 @@ namespace PLCSharp.Core.UserControls
|
||||
/// </summary>
|
||||
public class SimpleCellViewModel : BindableBase
|
||||
{
|
||||
|
||||
private DelegateCommand<object> _MenuItemCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项Command
|
||||
/// </summary>
|
||||
public DelegateCommand<object> MenuItemCommand =>
|
||||
_MenuItemCommand ??= new DelegateCommand<object>(ExecuteMenuItemCommand);
|
||||
|
||||
void ExecuteMenuItemCommand(object state)
|
||||
private void ExecuteMenuItemCommand(object state)
|
||||
{
|
||||
CellInfo.State = (CellState)state;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -45,6 +45,7 @@ namespace PLCSharp.Core.UserControls
|
||||
}
|
||||
|
||||
private Brush _Background;
|
||||
|
||||
/// <summary>
|
||||
/// 背景画刷
|
||||
/// </summary>
|
||||
@ -53,7 +54,9 @@ namespace PLCSharp.Core.UserControls
|
||||
get { return _Background; }
|
||||
set { SetProperty(ref _Background, value); }
|
||||
}
|
||||
|
||||
private CellInfo _CellInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 单元格信息
|
||||
/// </summary>
|
||||
@ -62,7 +65,5 @@ namespace PLCSharp.Core.UserControls
|
||||
get { return _CellInfo; }
|
||||
set { SetProperty(ref _CellInfo, value); }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cvt="clr-namespace:PLCSharp.Core.Tools">
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cvt="clr-namespace:PLCSharp.Core.Tools">
|
||||
|
||||
<FontFamily x:Key="iconfont">
|
||||
Core/Resources/Iconfont/#iconfont
|
||||
@ -116,6 +118,4 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
@ -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")]
|
||||
@ -26,33 +26,38 @@ namespace PLCSharp.Models
|
||||
{
|
||||
this.Database.EnsureCreated();
|
||||
this.EnsureCreatingMissingTables();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Users
|
||||
/// </summary>
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Recipes
|
||||
/// </summary>
|
||||
public DbSet<Recipe> Recipes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统全局变量集合
|
||||
/// </summary>
|
||||
public DbSet<SystemVariable> SystemVariables { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户全局变量集合
|
||||
/// <summary>
|
||||
public DbSet<Variable> Variables { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Workflows
|
||||
/// </summary>
|
||||
public DbSet<Workflow> Workflows { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// VisionFunctions
|
||||
/// </summary>
|
||||
public DbSet<VisionFunction> VisionFunctions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 全局图像列表
|
||||
/// </summary>
|
||||
@ -62,22 +67,27 @@ namespace PLCSharp.Models
|
||||
/// 局部图像列表
|
||||
/// </summary>
|
||||
public DbSet<LocalImageData> LocalImageDatas { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接模型·
|
||||
/// </summary>
|
||||
public DbSet<Connect> Connects { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cameras
|
||||
/// </summary>
|
||||
public DbSet<CameraBase> Cameras { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controllers
|
||||
/// </summary>
|
||||
public DbSet<Controller> Controllers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Axes
|
||||
/// </summary>
|
||||
public DbSet<Axis> Axes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轴Points
|
||||
/// </summary>
|
||||
@ -92,10 +102,12 @@ namespace PLCSharp.Models
|
||||
/// 插补Groups
|
||||
/// </summary>
|
||||
public DbSet<InterpolationGroup> InterpolationGroups { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DI
|
||||
/// </summary>
|
||||
public DbSet<DI> DI { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DQ
|
||||
/// </summary>
|
||||
@ -105,32 +117,37 @@ namespace PLCSharp.Models
|
||||
/// Robots
|
||||
/// </summary>
|
||||
public DbSet<Robot> Robots { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 机器人Points
|
||||
/// </summary>
|
||||
public DbSet<RobotPoint> RobotPoints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 机器人矩阵
|
||||
/// </summary>
|
||||
public DbSet<RobotMatrix> RobotMatrices { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误Logs
|
||||
/// </summary>
|
||||
public DbSet<ErrorLog> ErrorLogs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CustomControls
|
||||
/// </summary>
|
||||
public DbSet<CustomControl> CustomControls { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CanvasConfigs
|
||||
/// </summary>
|
||||
public DbSet<CanvasConfig> CanvasConfigs { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// CurrentRecipe
|
||||
/// </summary>
|
||||
public Recipe CurrentRecipe { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OnConfiguring
|
||||
/// </summary>
|
||||
@ -139,6 +156,7 @@ namespace PLCSharp.Models
|
||||
=> options.UseSqlite(@"Data Source=./Config/Datas.db");
|
||||
|
||||
private object _dbLock = new();
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
@ -148,11 +166,9 @@ namespace PLCSharp.Models
|
||||
{
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// DbContextExtensions
|
||||
/// </summary>
|
||||
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<CustomControl> _CustomControls = [];
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -81,6 +81,7 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
private CanvasConfig _CurrentCanvasConfig;
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -91,15 +92,15 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
private DelegateCommand _Apply;
|
||||
|
||||
/// <summary>
|
||||
/// Apply
|
||||
/// </summary>
|
||||
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<MessageEvent>().Publish(new()
|
||||
@ -118,6 +118,7 @@ namespace PLCSharp.Models
|
||||
});
|
||||
_DatasContext.Save();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion 主页面
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<ErrorLog> _ErrorLogs = [];
|
||||
|
||||
/// <summary>
|
||||
@ -22,7 +23,9 @@ namespace PLCSharp.Models
|
||||
get { return _ErrorLogs; }
|
||||
set { SetProperty(ref _ErrorLogs, value); }
|
||||
}
|
||||
|
||||
private TitleState _CurrentState = new();
|
||||
|
||||
/// <summary>
|
||||
/// TitleState
|
||||
/// </summary>
|
||||
@ -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 日志
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 当前配方
|
||||
/// </summary>
|
||||
@ -36,7 +36,9 @@ namespace PLCSharp.Models
|
||||
_DatasContext.CurrentRecipe = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Recipe _RecipeSelected;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的配方
|
||||
/// </summary>
|
||||
@ -47,6 +49,7 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
private ObservableCollection<Recipe> _Recipes = [];
|
||||
|
||||
/// <summary>
|
||||
/// 配方集合
|
||||
/// </summary>
|
||||
@ -57,18 +60,19 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
#region 配方管理
|
||||
|
||||
private DelegateCommand<string> _RecipeManage;
|
||||
|
||||
/// <summary>
|
||||
/// Recipe管理
|
||||
/// </summary>
|
||||
public DelegateCommand<string> RecipeManage =>
|
||||
_RecipeManage ??= new DelegateCommand<string>(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<MessageEvent>().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 配方
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,9 @@ namespace PLCSharp.Models
|
||||
public partial class GlobalModel
|
||||
{
|
||||
#region 模式与状态
|
||||
|
||||
private ModeState _ModeState = new();
|
||||
|
||||
/// <summary>
|
||||
/// ModeState
|
||||
/// </summary>
|
||||
@ -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 模式与状态
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 全局变量
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取变量
|
||||
/// </summary>
|
||||
@ -159,13 +145,15 @@ namespace PLCSharp.Models
|
||||
return variable;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion 全局变量
|
||||
|
||||
#region 硬件
|
||||
|
||||
/// <summary>
|
||||
/// 连接模型
|
||||
/// </summary>
|
||||
public ConnectsModel Connects { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controllers模型
|
||||
/// </summary>
|
||||
@ -181,7 +169,6 @@ namespace PLCSharp.Models
|
||||
/// </summary>
|
||||
public VariablesModel VariablesModel { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取连接
|
||||
/// </summary>
|
||||
@ -194,6 +181,7 @@ namespace PLCSharp.Models
|
||||
|
||||
return connect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Robot
|
||||
/// </summary>
|
||||
@ -206,6 +194,7 @@ namespace PLCSharp.Models
|
||||
|
||||
return robot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取VisionFunction
|
||||
/// </summary>
|
||||
@ -216,6 +205,7 @@ namespace PLCSharp.Models
|
||||
return VisionsModel.VisionFunctions.FirstOrDefault(v => v.Name == name)
|
||||
?? throw new Exception("视觉功能未配置!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取图像数据
|
||||
/// </summary>
|
||||
@ -229,14 +219,15 @@ namespace PLCSharp.Models
|
||||
return imageData;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#endregion 硬件
|
||||
|
||||
#region 任务
|
||||
|
||||
/// <summary>
|
||||
/// Workflows模型
|
||||
/// </summary>
|
||||
public WorkflowsModel WorkflowsModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 视觉模型
|
||||
/// </summary>
|
||||
@ -251,7 +242,7 @@ namespace PLCSharp.Models
|
||||
{
|
||||
return WorkflowsModel.Workflows.FirstOrDefault(t => t.Name == name);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion 任务
|
||||
}
|
||||
}
|
||||
@ -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<NavigateItem> _NavigateListShow = [];
|
||||
|
||||
/// <summary>
|
||||
/// Navigate列表显示
|
||||
/// </summary>
|
||||
@ -67,7 +64,6 @@ namespace PLCSharp.Models
|
||||
set { SetProperty(ref _NavigateListShow, value); }
|
||||
}
|
||||
|
||||
|
||||
private ObservableCollection<NavigateItem> _NavigateList = [];
|
||||
/// <summary>
|
||||
/// 导航页列表
|
||||
@ -80,6 +76,7 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
private ObservableCollection<NavigateItem> _DialogList = [];
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -90,6 +87,7 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
private ObservableCollection<NavigateItem> _DialogListShow = [];
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -99,8 +97,8 @@ namespace PLCSharp.Models
|
||||
set { SetProperty(ref _DialogListShow, value); }
|
||||
}
|
||||
|
||||
|
||||
private NavigateItem _DialogTarget;
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NavigateToAsync
|
||||
/// </summary>
|
||||
@ -199,8 +196,5 @@ namespace PLCSharp.Models
|
||||
/// 登录
|
||||
/// </summary>
|
||||
public LoginModel Login { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -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")]
|
||||
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PLCSharp" xmlns:roi="clr-namespace:PLCSharp.Core.UserControls.ROI" />
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PLCSharp" xmlns:roi="clr-namespace:PLCSharp.Core.UserControls.ROI" />
|
||||
@ -39,6 +39,5 @@
|
||||
</ListBox.ItemsPanel>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -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对话框
|
||||
/// </summary>
|
||||
[Dialog]
|
||||
/// <summary>
|
||||
/// AlertDialog.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class AlertDialog : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
@ -20,4 +17,4 @@ namespace PLCSharp.VVM.AlertDialog
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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";
|
||||
|
||||
/// <summary>
|
||||
@ -52,7 +51,6 @@ namespace PLCSharp.VVM.AlertDialog
|
||||
set { SetProperty(ref _Ico, value); }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开对话框后要执行的
|
||||
/// </summary>
|
||||
@ -80,9 +78,7 @@ namespace PLCSharp.VVM.AlertDialog
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Message = msg[0];
|
||||
|
||||
}
|
||||
Ico = Title switch
|
||||
{
|
||||
@ -108,6 +104,5 @@ namespace PLCSharp.VVM.AlertDialog
|
||||
/// 按钮列表
|
||||
/// </summary>
|
||||
public ObservableCollection<Button> Source { get; set; } = [];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,8 @@
|
||||
namespace PLCSharp.VVMs.Authority
|
||||
{
|
||||
[Flags]
|
||||
/// <summary>
|
||||
/// 权限
|
||||
/// </summary
|
||||
public enum Authority
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 仅查看
|
||||
/// </summary>
|
||||
@ -26,6 +22,7 @@
|
||||
/// 高级维护人员
|
||||
/// </summary>
|
||||
SeniorMaintainer = 31,
|
||||
|
||||
/// <summary>
|
||||
/// 管理人员
|
||||
/// </summary>
|
||||
|
||||
@ -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<User> _UserList = [];
|
||||
|
||||
/// <summary>
|
||||
/// 用户列表
|
||||
/// </summary>
|
||||
@ -77,6 +75,7 @@ namespace PLCSharp.VVMs.Authority
|
||||
}
|
||||
|
||||
private string _Password;
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
@ -85,7 +84,9 @@ namespace PLCSharp.VVMs.Authority
|
||||
get { return _Password; }
|
||||
set { SetProperty(ref _Password, value); CheckPassword(); }
|
||||
}
|
||||
|
||||
private string _PasswordAct;
|
||||
|
||||
/// <summary>
|
||||
/// 密码Act
|
||||
/// </summary>
|
||||
@ -96,6 +97,7 @@ namespace PLCSharp.VVMs.Authority
|
||||
}
|
||||
|
||||
private User _CurrentUser;
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户
|
||||
/// </summary>
|
||||
@ -109,13 +111,11 @@ namespace PLCSharp.VVMs.Authority
|
||||
{
|
||||
Target = "CurrentUser"
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private User _RegisterUser = new();
|
||||
|
||||
/// <summary>
|
||||
/// 注册用户
|
||||
/// </summary>
|
||||
@ -125,10 +125,8 @@ namespace PLCSharp.VVMs.Authority
|
||||
set { SetProperty(ref _RegisterUser, value); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private User _SelectUser;
|
||||
|
||||
/// <summary>
|
||||
/// 选择用户
|
||||
/// </summary>
|
||||
@ -137,14 +135,16 @@ namespace PLCSharp.VVMs.Authority
|
||||
get { return _SelectUser; }
|
||||
set { SetProperty(ref _SelectUser, value); }
|
||||
}
|
||||
|
||||
private DelegateCommand<string> _Manage;
|
||||
|
||||
/// <summary>
|
||||
/// 管理
|
||||
/// </summary>
|
||||
public DelegateCommand<string> Manage =>
|
||||
_Manage ??= new DelegateCommand<string>(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;
|
||||
|
||||
/// <summary>
|
||||
/// 注册
|
||||
/// </summary>
|
||||
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 = "";
|
||||
|
||||
/// <summary>
|
||||
/// 密码Msg
|
||||
/// </summary>
|
||||
@ -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;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Change密码
|
||||
/// </summary>
|
||||
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}密码修改完成!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt
|
||||
/// </summary>
|
||||
|
||||
@ -16,6 +16,7 @@ namespace PLCSharp.VVMs.Authority
|
||||
/// 模型
|
||||
/// </summary>
|
||||
public LoginModel Model { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录视图模型
|
||||
/// </summary>
|
||||
@ -24,6 +25,7 @@ namespace PLCSharp.VVMs.Authority
|
||||
Model = container.Resolve<LoginModel>();
|
||||
Title = "登录";
|
||||
}
|
||||
|
||||
private DelegateCommand<string> _closeDialogCommand;
|
||||
|
||||
/// <summary>
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 密码Msg
|
||||
/// </summary>
|
||||
@ -91,8 +91,5 @@ namespace PLCSharp.VVMs.Authority
|
||||
get { return _PasswordMsg; }
|
||||
set { SetProperty(ref _PasswordMsg, value); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,6 @@
|
||||
Orientation="Horizontal" Visibility="Collapsed">
|
||||
<TextBlock Text="确认:" />
|
||||
<myControl:PasswordBoxNew Width="200" Text="{Binding Model.PasswordAct}" />
|
||||
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Row="3"
|
||||
d:Text="两次输入不一致"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using PLCSharp.Core.Prism;
|
||||
using PLCSharp.Core.Prism;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PLCSharp.VVMs.Authority
|
||||
@ -9,17 +9,12 @@ namespace PLCSharp.VVMs.Authority
|
||||
[Dialog]
|
||||
public partial class PasswordChange : UserControl
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 密码Change
|
||||
/// </summary>
|
||||
public PasswordChange()
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -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); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开对话框后要执行的
|
||||
/// </summary>
|
||||
@ -45,9 +43,5 @@ namespace PLCSharp.VVMs.Authority
|
||||
/// 模型
|
||||
/// </summary>
|
||||
public LoginModel Model { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -41,12 +41,10 @@
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
<TextBlock Text="密码:" HorizontalAlignment="Left" VerticalAlignment="Center" />
|
||||
<myControl:PasswordBoxNew Width="250" Text="{Binding Model.Password}" />
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
<TextBlock Text="确认:" HorizontalAlignment="Left" VerticalAlignment="Center" />
|
||||
<myControl:PasswordBoxNew Width="250" Text="{Binding Model.PasswordAct}" />
|
||||
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Row="3"
|
||||
d:Text="两次输入不一致"
|
||||
@ -59,4 +57,4 @@
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -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
|
||||
/// 注册
|
||||
/// </summary>
|
||||
[Dialog]
|
||||
/// <summary>
|
||||
/// Register.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class Register : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
@ -20,4 +17,4 @@ namespace PLCSharp.VVMs.Authority
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// 模型
|
||||
/// </summary>
|
||||
public LoginModel Model { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
using Prism.Mvvm;
|
||||
using Prism.Mvvm;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PLCSharp.VVMs.Authority
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
@ -13,20 +11,21 @@ namespace PLCSharp.VVMs.Authority
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
public User() { }
|
||||
public User()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
public User(string name, string password, Authority authority)
|
||||
{
|
||||
|
||||
Name = name;
|
||||
Password = password;
|
||||
Authority = authority;
|
||||
}
|
||||
|
||||
|
||||
private string _Name;
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
@ -36,12 +35,14 @@ namespace PLCSharp.VVMs.Authority
|
||||
get { return _Name; }
|
||||
set { SetProperty(ref _Name, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
private Authority _Authority;
|
||||
|
||||
/// <summary>
|
||||
/// 权限
|
||||
/// </summary>
|
||||
|
||||
@ -43,6 +43,5 @@
|
||||
Command="{Binding Model.Manage}"
|
||||
CommandParameter="Register" Content="注册" />
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -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
|
||||
/// </summary>
|
||||
public UserManage()
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
@ -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<LoginModel>();
|
||||
Title = "用户管理";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接
|
||||
/// </summary>
|
||||
@ -41,6 +41,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private string _Name;
|
||||
|
||||
/// <summary>
|
||||
/// 连接配置
|
||||
/// </summary>
|
||||
@ -51,6 +52,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private string _IP_SerialPort;
|
||||
|
||||
/// <summary>
|
||||
/// IP_串口端口
|
||||
/// </summary>
|
||||
@ -61,6 +63,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private int _Port;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
@ -71,11 +74,11 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private ProtocolType _Type;
|
||||
|
||||
/// <summary>
|
||||
/// 协议类型
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
@ -110,11 +112,11 @@ namespace PLCSharp.VVMs.Connects
|
||||
#region NotMapped
|
||||
|
||||
private bool _LogSwitch;
|
||||
|
||||
/// <summary>
|
||||
/// 日志开关
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
|
||||
public bool LogSwitch
|
||||
{
|
||||
get { return _LogSwitch; }
|
||||
@ -122,11 +124,11 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private bool _Connected;
|
||||
|
||||
/// <summary>
|
||||
/// 连接成功
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
|
||||
public bool Connected
|
||||
{
|
||||
get { return _Connected; }
|
||||
@ -134,24 +136,23 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private bool _Successful;
|
||||
|
||||
/// <summary>
|
||||
/// 读写成功
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
|
||||
public bool Successful
|
||||
{
|
||||
get { return _Successful; }
|
||||
set { SetProperty(ref _Successful, value); }
|
||||
}
|
||||
|
||||
|
||||
private bool _Online;
|
||||
|
||||
/// <summary>
|
||||
/// 在线
|
||||
/// </summary>
|
||||
[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); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 告警信息
|
||||
/// </summary>
|
||||
@ -198,10 +200,10 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
get => JsonSerializer.Serialize(Params, JsonOptions.Default); // 自动序列化
|
||||
set => Params = JsonSerializer.Deserialize<ConnectParams>(value, JsonOptions.Default); // 自动反序列化
|
||||
|
||||
}
|
||||
|
||||
private ObservableCollection<DataItem> _DataItems = [];
|
||||
|
||||
/// <summary>
|
||||
/// 数据Items
|
||||
/// </summary>
|
||||
@ -211,6 +213,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
get => _DataItems;
|
||||
set => SetProperty(ref _DataItems, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化数据Items
|
||||
/// </summary>
|
||||
@ -219,10 +222,10 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
get => JsonSerializer.Serialize(DataItems, JsonOptions.Default); // 自动序列化
|
||||
set => DataItems = value != null ? JsonSerializer.Deserialize<ObservableCollection<DataItem>>(value, JsonOptions.Default) : []; // 自动反序列化
|
||||
|
||||
}
|
||||
|
||||
private bool _PollEnabled = true;
|
||||
|
||||
/// <summary>是否启用轮询</summary>
|
||||
[NotMapped]
|
||||
public bool PollEnabled
|
||||
@ -232,6 +235,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private int _PollIntervalMs = 1000;
|
||||
|
||||
/// <summary>轮询间隔(毫秒)</summary>
|
||||
[NotMapped]
|
||||
public int PollIntervalMs
|
||||
@ -246,6 +250,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private ConnectParams _Params;
|
||||
|
||||
/// <summary>
|
||||
/// 参数集合
|
||||
/// </summary>
|
||||
@ -265,6 +270,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private ObservableCollection<Connect> _Clients = [];
|
||||
|
||||
/// <summary>
|
||||
/// Clients
|
||||
/// </summary>
|
||||
@ -283,22 +289,26 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
get => JsonSerializer.Serialize(Clients, JsonOptions.Default); // 自动序列化
|
||||
set => Clients = JsonSerializer.Deserialize<ObservableCollection<Connect>>(value, JsonOptions.Default); // 自动反序列化
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开
|
||||
/// </summary>
|
||||
public virtual void Open() { }
|
||||
public virtual void Open()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// 关闭
|
||||
/// </summary>
|
||||
public virtual void Close() { }
|
||||
public virtual void Close()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// 日志Queue
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public ConcurrentQueue<string> LogQueue { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 日志
|
||||
/// </summary>
|
||||
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -404,13 +405,11 @@ namespace PLCSharp.VVMs.Connects
|
||||
/// <returns>返回结果</returns>
|
||||
public virtual async Task<bool> 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送HexMsgAsync
|
||||
/// </summary>
|
||||
@ -457,6 +452,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(msg);
|
||||
return await SendDataAsync(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送MsgAsync
|
||||
/// </summary>
|
||||
@ -474,6 +470,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(msg);
|
||||
return await SendDataAsync(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据Async
|
||||
/// </summary>
|
||||
@ -484,14 +481,15 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
await Task.Delay(10);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接Params
|
||||
/// </summary>
|
||||
public class ConnectParams : BindableBase
|
||||
{
|
||||
private CommunicationDataType _DataType;
|
||||
|
||||
/// <summary>
|
||||
/// 连接配置
|
||||
/// </summary>
|
||||
@ -506,11 +504,10 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
SetProperty(ref _DataType, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private string _Prompt;
|
||||
|
||||
/// <summary>
|
||||
/// 提示
|
||||
/// </summary>
|
||||
@ -520,7 +517,9 @@ namespace PLCSharp.VVMs.Connects
|
||||
get { return _Prompt; }
|
||||
set { SetProperty(ref _Prompt, value); }
|
||||
}
|
||||
|
||||
private byte _UnitId = 1;
|
||||
|
||||
/// <summary>
|
||||
/// UnitId
|
||||
/// </summary>
|
||||
@ -529,9 +528,11 @@ namespace PLCSharp.VVMs.Connects
|
||||
get => _UnitId;
|
||||
set => SetProperty(ref _UnitId, value);
|
||||
}
|
||||
|
||||
// ─── 串口参数 ───
|
||||
|
||||
private int _BaudRate = 9600;
|
||||
|
||||
/// <summary>
|
||||
/// BaudRate
|
||||
/// </summary>
|
||||
@ -542,6 +543,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private int _DataBits = 8;
|
||||
|
||||
/// <summary>
|
||||
/// 数据Bits
|
||||
/// </summary>
|
||||
@ -552,6 +554,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private System.IO.Ports.StopBits _StopBits = System.IO.Ports.StopBits.One;
|
||||
|
||||
/// <summary>
|
||||
/// 停止Bits值
|
||||
/// </summary>
|
||||
@ -562,6 +565,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
}
|
||||
|
||||
private System.IO.Ports.Parity _Parity = System.IO.Ports.Parity.None;
|
||||
|
||||
/// <summary>
|
||||
/// Parity值
|
||||
/// </summary>
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public class ConnectsViewModel : DialogAwareBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Connects视图模型
|
||||
/// </summary>
|
||||
@ -19,11 +18,10 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
ConnectsModel = container.Resolve<ConnectsModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connects模型
|
||||
/// </summary>
|
||||
public ConnectsModel ConnectsModel { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -28,7 +28,6 @@
|
||||
<cvt:BoolToValueConverter x:Key="BoolToValueConverter" />
|
||||
</UserControl.Resources>
|
||||
|
||||
|
||||
<UniformGrid>
|
||||
<GroupBox Header="连接">
|
||||
<Grid>
|
||||
@ -99,6 +98,5 @@
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
</UniformGrid>
|
||||
</UserControl>
|
||||
@ -19,6 +19,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void DataGrid_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataGrid = sender as DataGrid;
|
||||
|
||||
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// 全局模型
|
||||
/// </summary>
|
||||
public GlobalModel GlobalModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
@ -166,6 +170,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
GlobalModel = globalModel;
|
||||
}
|
||||
|
||||
private ObservableCollection<Connect> _Connects = [];
|
||||
|
||||
/// <summary>
|
||||
@ -205,7 +210,6 @@ namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
if (r.Result == ButtonResult.Yes)
|
||||
{
|
||||
|
||||
var type = r.Parameters.GetValue<ProtocolType>("Type");
|
||||
|
||||
switch (type)
|
||||
@ -216,9 +220,9 @@ namespace PLCSharp.VVMs.Connects
|
||||
Name = r.Parameters.GetValue<string>("Name"),
|
||||
IP_SerialPort = r.Parameters.GetValue<string>("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
|
||||
/// </summary>
|
||||
public byte UnitId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 启动Address
|
||||
/// </summary>
|
||||
public ushort StartAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 读取数量
|
||||
/// </summary>
|
||||
public ushort ReadCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Items
|
||||
/// </summary>
|
||||
@ -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 轮询
|
||||
|
||||
/// <summary>写入单个 DataItem 的值到服务器</summary>
|
||||
/// <summary>
|
||||
@ -710,6 +712,6 @@ namespace PLCSharp.VVMs.Connects
|
||||
else server.SetInputRegister(addr, val);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion ModbusTcpServer 写入(本地内存)
|
||||
}
|
||||
}
|
||||
@ -13,10 +13,12 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
/// FC_READ_HOLDING_REGISTERS
|
||||
/// </summary>
|
||||
public const byte FC_READ_HOLDING_REGISTERS = 0x03;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_SINGLE_REGISTER
|
||||
/// </summary>
|
||||
public const byte FC_WRITE_SINGLE_REGISTER = 0x06;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_MULTIPLE_REGISTERS
|
||||
/// </summary>
|
||||
@ -26,8 +28,6 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
|
||||
private System.IO.Ports.SerialPort _port;
|
||||
|
||||
|
||||
|
||||
/// <summary>打开串口</summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,4 +143,4 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
{
|
||||
private readonly ConnectsModel _ConnectsModel;
|
||||
private ModbusRtuClient _Client;
|
||||
|
||||
/// <summary>
|
||||
/// 客户端
|
||||
/// </summary>
|
||||
@ -61,7 +62,6 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
Client.LogSwitch = false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -75,13 +75,11 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
if (Client == null) return;
|
||||
|
||||
Client.LogSwitch = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ─── 串口操作 ───
|
||||
private DelegateCommand _OpenPortCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 打开端口Command
|
||||
/// </summary>
|
||||
@ -89,6 +87,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
_OpenPortCommand ??= new DelegateCommand(() => Client?.Open());
|
||||
|
||||
private DelegateCommand _ClosePortCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 关闭端口Command
|
||||
/// </summary>
|
||||
@ -97,6 +96,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
|
||||
// ─── DataItems 管理 ───
|
||||
private DelegateCommand<string> _ConnectsManage;
|
||||
|
||||
/// <summary>
|
||||
/// Connects管理
|
||||
/// </summary>
|
||||
@ -104,6 +104,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
|
||||
_ConnectsManage ??= new DelegateCommand<string>(ExecuteConnectsManage);
|
||||
|
||||
private DataItem _SelectedDataItem;
|
||||
|
||||
/// <summary>
|
||||
/// Selected数据项
|
||||
/// </summary>
|
||||
@ -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<ErrorLog> _Logs = [];
|
||||
|
||||
/// <summary>
|
||||
/// Logs
|
||||
/// </summary>
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
|
||||
/// <summary>两个连续寄存器组成 32 位有符号整数 (大端)</summary>
|
||||
Int32,
|
||||
|
||||
/// <summary>两个连续寄存器组成 32 位 IEEE 754 浮点数 (大端)</summary>
|
||||
Float,
|
||||
|
||||
/// <summary>每个寄存器存 2 个字符 (高字节在前)</summary>
|
||||
String,
|
||||
}
|
||||
|
||||
private ushort _Address;
|
||||
|
||||
/// <summary>
|
||||
/// Address
|
||||
/// </summary>
|
||||
@ -31,6 +34,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private ushort _Value;
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
@ -45,6 +49,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private ushort _HighValue;
|
||||
|
||||
/// <summary>
|
||||
/// High值
|
||||
/// </summary>
|
||||
@ -54,11 +59,11 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
set
|
||||
{
|
||||
SetProperty(ref _HighValue, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private ValueInterpretationEnum _ValueInterpretation = ValueInterpretationEnum.UInt16;
|
||||
|
||||
/// <summary>
|
||||
/// 值Interpretation
|
||||
/// </summary>
|
||||
@ -74,6 +79,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
|
||||
// ───────── 显示值(只读,由 RefreshDisplay 更新) ─────────
|
||||
private string _DisplayValue = "0";
|
||||
|
||||
/// <summary>
|
||||
/// Display值
|
||||
/// </summary>
|
||||
@ -86,6 +92,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
|
||||
// ───────── 本地设定值(服务端:输入即解析更新当前值) ─────────
|
||||
private string _InputValue;
|
||||
|
||||
/// <summary>
|
||||
/// Input值
|
||||
/// </summary>
|
||||
@ -98,7 +105,9 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
ParseInputValueAndRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
private byte _UnitId = 1;
|
||||
|
||||
/// <summary>
|
||||
/// UnitId
|
||||
/// </summary>
|
||||
@ -107,14 +116,17 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
get { return _UnitId; }
|
||||
set { SetProperty(ref _UnitId, value); }
|
||||
}
|
||||
|
||||
// ───────── 远程发送值(客户端:输入不更新当前值,发送时解析) ─────────
|
||||
private string _SendValue = "";
|
||||
|
||||
/// <summary>
|
||||
/// 发送值
|
||||
/// </summary>
|
||||
public string SendValue { get => _SendValue; set => SetProperty(ref _SendValue, value); }
|
||||
|
||||
private string _Description = "";
|
||||
|
||||
/// <summary>
|
||||
/// Description
|
||||
/// </summary>
|
||||
@ -222,4 +234,4 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
RefreshDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,4 +109,4 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -60,8 +60,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
Client.LogSwitch = false;
|
||||
bkgWorker.CancelAsync();
|
||||
bkgWorker.Dispose();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 客户端
|
||||
/// </summary>
|
||||
@ -119,6 +116,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private ObservableCollection<ErrorLog> _Logs = [];
|
||||
|
||||
/// <summary>
|
||||
/// Logs
|
||||
/// </summary>
|
||||
@ -129,6 +127,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private string _IP = "127.0.0.1";
|
||||
|
||||
/// <summary>
|
||||
/// IP
|
||||
/// </summary>
|
||||
@ -145,6 +144,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private int _Port = 502;
|
||||
|
||||
/// <summary>
|
||||
/// 端口
|
||||
/// </summary>
|
||||
@ -161,6 +161,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private DataItem _SelectedDataItem;
|
||||
|
||||
/// <summary>
|
||||
/// Selected数据项
|
||||
/// </summary>
|
||||
@ -170,11 +171,12 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
set => SetProperty(ref _SelectedDataItem, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Properties
|
||||
|
||||
#region Commands
|
||||
|
||||
private DelegateCommand<string> _ConnectsManage;
|
||||
|
||||
/// <summary>
|
||||
/// Connects管理
|
||||
/// </summary>
|
||||
@ -222,6 +224,6 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,4 +106,4 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 服务端
|
||||
/// </summary>
|
||||
@ -223,6 +223,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private ObservableCollection<ErrorLog> _Logs = [];
|
||||
|
||||
/// <summary>
|
||||
/// Logs
|
||||
/// </summary>
|
||||
@ -267,6 +268,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
}
|
||||
|
||||
private DataItem _SelectedDataItem;
|
||||
|
||||
/// <summary>
|
||||
/// Selected数据项
|
||||
/// </summary>
|
||||
@ -276,11 +278,12 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
set => SetProperty(ref _SelectedDataItem, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Properties
|
||||
|
||||
#region Commands
|
||||
|
||||
private DelegateCommand<string> _ConnectsManage;
|
||||
|
||||
/// <summary>
|
||||
/// Connects管理
|
||||
/// </summary>
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public const byte FC_READ_HOLDING_REGISTERS = 0x03;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_SINGLE_COIL
|
||||
/// </summary>
|
||||
public const byte FC_WRITE_SINGLE_COIL = 0x05;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_SINGLE_REGISTER
|
||||
/// </summary>
|
||||
public const byte FC_WRITE_SINGLE_REGISTER = 0x06;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_MULTIPLE_REGISTERS
|
||||
/// </summary>
|
||||
@ -288,4 +291,4 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
return Execute(uid, FC_WRITE_MULTIPLE_REGISTERS, data) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// </summary>
|
||||
public const byte FC_READ_COILS = 0x01;
|
||||
|
||||
/// <summary>
|
||||
/// FC_READ_DISCRETE_INPUTS
|
||||
/// </summary>
|
||||
public const byte FC_READ_DISCRETE_INPUTS = 0x02;
|
||||
|
||||
/// <summary>
|
||||
/// FC_READ_HOLDING_REGISTERS
|
||||
/// </summary>
|
||||
public const byte FC_READ_HOLDING_REGISTERS = 0x03;
|
||||
|
||||
/// <summary>
|
||||
/// FC_READ_INPUT_REGISTERS
|
||||
/// </summary>
|
||||
public const byte FC_READ_INPUT_REGISTERS = 0x04;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_SINGLE_COIL
|
||||
/// </summary>
|
||||
public const byte FC_WRITE_SINGLE_COIL = 0x05;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_SINGLE_REGISTER
|
||||
/// </summary>
|
||||
public const byte FC_WRITE_SINGLE_REGISTER = 0x06;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_MULTIPLE_COILS
|
||||
/// </summary>
|
||||
public const byte FC_WRITE_MULTIPLE_COILS = 0x0F;
|
||||
|
||||
/// <summary>
|
||||
/// FC_WRITE_MULTIPLE_REGISTERS
|
||||
/// </summary>
|
||||
@ -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<string, System.Net.Sockets.Socket> _clients = new();
|
||||
private readonly List<System.Net.Sockets.Socket> _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
|
||||
/// 接收事件
|
||||
/// </summary>
|
||||
public event Action<string> ReceiveEvent;
|
||||
|
||||
public event Action<byte[]> ReceiveDateEvent;
|
||||
|
||||
/// <summary>
|
||||
@ -98,7 +110,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
|
||||
/// </summary>
|
||||
public event Action<ushort, ushort> DataWritten;
|
||||
|
||||
#endregion
|
||||
#endregion Modbus Data Store
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
namespace PLCSharp.VVMs.Connects
|
||||
namespace PLCSharp.VVMs.Connects
|
||||
{
|
||||
/// <summary>
|
||||
/// 网络变量
|
||||
@ -26,15 +26,16 @@ namespace PLCSharp.VVMs.Connects
|
||||
/// </summary>
|
||||
public string Address { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 类型
|
||||
/// </summary>
|
||||
public Type Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public dynamic Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求报文
|
||||
/// </summary>
|
||||
@ -44,8 +45,5 @@ namespace PLCSharp.VVMs.Connects
|
||||
/// 响应报文
|
||||
/// </summary>
|
||||
public string Response { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,6 @@
|
||||
<x:Type TypeName="connect:ProtocolType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
|
||||
</UserControl.Resources>
|
||||
<StackPanel Width="300" Margin="20">
|
||||
<UniformGrid>
|
||||
@ -52,4 +51,4 @@
|
||||
CommandParameter="No" Content="取消" Cursor="Hand" Foreground="White" />
|
||||
</UniformGrid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@ -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
|
||||
/// 新建连接
|
||||
/// </summary>
|
||||
[Dialog]
|
||||
/// <summary>
|
||||
/// NewConnect.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class NewConnect : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
@ -20,4 +17,4 @@ namespace PLCSharp.VVMs.Connects
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
@ -11,8 +10,8 @@ namespace PLCSharp.VVMs.Connects
|
||||
/// </summary>
|
||||
public class NewConnectViewModel : DialogAwareBase
|
||||
{
|
||||
|
||||
private string _Name;
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
@ -24,7 +23,9 @@ namespace PLCSharp.VVMs.Connects
|
||||
SetProperty(ref _Name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private ProtocolType _Type;
|
||||
|
||||
/// <summary>
|
||||
/// 类型
|
||||
/// </summary>
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// IP_串口端口
|
||||
/// </summary>
|
||||
@ -77,6 +85,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
get { return _IP_SerialPort; }
|
||||
set { SetProperty(ref _IP_SerialPort, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开对话框后要执行的
|
||||
/// </summary>
|
||||
@ -87,6 +96,7 @@ namespace PLCSharp.VVMs.Connects
|
||||
Type = ProtocolType.SocketClient;
|
||||
Title = "New Connect";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RaiseRequest关闭
|
||||
/// </summary>
|
||||
@ -99,4 +109,4 @@ namespace PLCSharp.VVMs.Connects
|
||||
base.RaiseRequestClose(dialogResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
/// <summary>
|
||||
/// Free串口协议
|
||||
/// </summary>
|
||||
class FreeSerialProtocol : Connect
|
||||
internal class FreeSerialProtocol : Connect
|
||||
{
|
||||
/// <summary>
|
||||
/// my串口
|
||||
@ -15,10 +15,10 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
|
||||
public event Action<byte[]> 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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开
|
||||
/// </summary>
|
||||
@ -77,7 +78,6 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
/// <returns>返回结果</returns>
|
||||
public override async Task<bool> SendDataAsync(byte[] bytes, bool isLog = true)
|
||||
{
|
||||
|
||||
return await Task<bool>.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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,7 +54,6 @@
|
||||
<DataGridTextColumn Width="5*" Binding="{Binding Message, UpdateSourceTrigger=LostFocus}" Header="消息" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
</GroupBox>
|
||||
|
||||
<StackPanel Grid.Column="1"
|
||||
@ -64,10 +63,8 @@
|
||||
|
||||
<CheckBox Content="记录日志" IsChecked="{Binding Client.LogSwitch}" />
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<!-- 串口参数 -->
|
||||
<GroupBox Grid.Row="1" Header="串口设置">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@ -102,7 +99,6 @@
|
||||
<TextBlock Margin="10,0,0,0" Text="消息类型:" VerticalAlignment="Center" />
|
||||
<ComboBox Width="150" ItemsSource="{Binding Source={StaticResource DataType}}" SelectedValue="{Binding Client.Params.DataType, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
|
||||
<Button Width="40" Margin="5,0"
|
||||
Content="保存"
|
||||
Command="{Binding ConnectsManage}"
|
||||
@ -110,7 +106,6 @@
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
|
||||
<!-- 发送 -->
|
||||
<Grid Grid.Row="2" Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -131,7 +126,6 @@
|
||||
HorizontalAlignment="Right" VerticalAlignment="Bottom"
|
||||
Command="{Binding Send}"
|
||||
CommandParameter="String" Content="发送" Cursor="Hand" />
|
||||
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
@ -150,7 +144,6 @@
|
||||
HorizontalAlignment="Right" VerticalAlignment="Bottom"
|
||||
Command="{Binding Send}"
|
||||
CommandParameter="Hex" Content="发送" />
|
||||
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using PLCSharp.Core.Prism;
|
||||
using PLCSharp.Core.Prism;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@ -17,6 +17,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void DataGrid_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataGrid = sender as DataGrid;
|
||||
|
||||
@ -13,7 +13,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
/// <summary>
|
||||
/// Free串口协议配置视图模型
|
||||
/// </summary>
|
||||
class FreeSerialProtocolConfigViewModel : ValidateBase, IDialogAware
|
||||
internal class FreeSerialProtocolConfigViewModel : ValidateBase, IDialogAware
|
||||
{
|
||||
/// <summary>
|
||||
/// Free串口协议配置视图模型
|
||||
@ -27,8 +27,10 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
if (!bkgWorker.IsBusy)
|
||||
bkgWorker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private readonly ConnectsModel _ConnectsModel;
|
||||
private FreeSerialProtocol _Client;
|
||||
|
||||
/// <summary>
|
||||
/// 客户端
|
||||
/// </summary>
|
||||
@ -60,8 +62,8 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
Client.LogSwitch = false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开对话框后要执行的
|
||||
/// </summary>
|
||||
@ -73,11 +75,11 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
if (Client == null) return;
|
||||
|
||||
Client.LogSwitch = true;
|
||||
|
||||
}
|
||||
|
||||
// ─── 日志 ───
|
||||
private ObservableCollection<ErrorLog> _Logs = [];
|
||||
|
||||
/// <summary>
|
||||
/// Logs
|
||||
/// </summary>
|
||||
@ -86,6 +88,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
get => _Logs;
|
||||
set => SetProperty(ref _Logs, value);
|
||||
}
|
||||
|
||||
private readonly BackgroundWorker bkgWorker;
|
||||
|
||||
private void BackgroundWork(object sender, DoWorkEventArgs e)
|
||||
@ -111,7 +114,6 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string[] _Ports;
|
||||
|
||||
/// <summary>
|
||||
@ -125,6 +127,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
|
||||
// ─── 串口操作 ───
|
||||
private DelegateCommand _OpenPortCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 打开端口Command
|
||||
/// </summary>
|
||||
@ -132,6 +135,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
_OpenPortCommand ??= new DelegateCommand(() => Client?.Open());
|
||||
|
||||
private DelegateCommand _ClosePortCommand;
|
||||
|
||||
/// <summary>
|
||||
/// 关闭端口Command
|
||||
/// </summary>
|
||||
@ -139,6 +143,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
_ClosePortCommand ??= new DelegateCommand(() => Client?.Close());
|
||||
|
||||
private string _SendString;
|
||||
|
||||
/// <summary>
|
||||
/// 发送String
|
||||
/// </summary>
|
||||
@ -147,7 +152,9 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
get { return _SendString; }
|
||||
set { SetProperty(ref _SendString, value); }
|
||||
}
|
||||
|
||||
private string _SendHex;
|
||||
|
||||
/// <summary>
|
||||
/// 发送Hex
|
||||
/// </summary>
|
||||
@ -225,32 +232,32 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
}
|
||||
|
||||
private DelegateCommand<string> _ConnectsManage;
|
||||
|
||||
/// <summary>
|
||||
/// Connects管理
|
||||
/// </summary>
|
||||
public DelegateCommand<string> ConnectsManage =>
|
||||
_ConnectsManage ??= new DelegateCommand<string>(ExecuteConnectsManage);
|
||||
|
||||
|
||||
private void ExecuteConnectsManage(string cmd)
|
||||
{
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
|
||||
case "Save":
|
||||
_ConnectsModel.SaveConnects();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private DelegateCommand<object> _Send;
|
||||
|
||||
/// <summary>
|
||||
/// 发送
|
||||
/// </summary>
|
||||
public DelegateCommand<object> Send =>
|
||||
_Send ??= new DelegateCommand<object>(ExecuteSend);
|
||||
|
||||
void ExecuteSend(object param)
|
||||
private void ExecuteSend(object param)
|
||||
{
|
||||
var cmd = (string)param;
|
||||
|
||||
@ -259,17 +266,16 @@ namespace PLCSharp.VVMs.Connects.SerialPort
|
||||
case "String":
|
||||
_ = Client.SendMsgAsync(SendString);
|
||||
break;
|
||||
|
||||
case "Hex":
|
||||
if (Connect.HexStringToBytes(SendHex, out List<byte> byes, out string format))
|
||||
{
|
||||
SendHex = format;
|
||||
|
||||
_ = Client.SendDataAsync([.. byes]);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,10 @@
|
||||
using PLCSharp.Core.Tools;
|
||||
using PLCSharp.Core.Tools;
|
||||
using System.ComponentModel;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
/// <summary>
|
||||
@ -13,17 +12,16 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
/// </summary>
|
||||
public class SocketClient : Connect
|
||||
{
|
||||
|
||||
private TcpClient _client;
|
||||
|
||||
private readonly BackgroundWorker bkgWorker;
|
||||
|
||||
/// <summary>
|
||||
/// Socket客户端
|
||||
/// </summary>
|
||||
public SocketClient()
|
||||
|
||||
{
|
||||
|
||||
bkgWorker = new BackgroundWorker { WorkerSupportsCancellation = true };
|
||||
bkgWorker.DoWork += BackgroundWork;
|
||||
|
||||
@ -31,8 +29,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
bkgWorker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public event Action<string> ReceiveEvent;
|
||||
|
||||
public event Action<byte[]> ReceiveDateEvent;
|
||||
@ -52,13 +48,11 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
_client?.Close();
|
||||
_client = new TcpClient();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
_client.Connect(IP_SerialPort, Port);
|
||||
success = _client.Connected;
|
||||
Log($"{DateTime.Now} ;{IP_SerialPort}:{Port}连接成功");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -89,6 +83,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = done;
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据Async
|
||||
/// </summary>
|
||||
@ -118,7 +113,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -151,6 +145,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = done;
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据
|
||||
/// </summary>
|
||||
@ -185,7 +180,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -194,14 +188,11 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 接收Bytes
|
||||
/// </summary>
|
||||
public byte[] ReceiveBytes { get; private set; } = [];
|
||||
|
||||
|
||||
|
||||
private readonly byte[] _buff = new byte[1024];
|
||||
|
||||
private bool ReceiveMsg()
|
||||
@ -231,7 +222,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
var bytesStr = BitConverter.ToString(ReceiveBytes);
|
||||
|
||||
Log($"{DateTime.Now:HH:mm:ss:fff} 接收{IP_SerialPort}信息 <=={bytesStr}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -240,7 +230,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
ReceiveEvent?.Invoke(msg);
|
||||
|
||||
Log($"{DateTime.Now:HH:mm:ss:fff} 接收{IP_SerialPort}信息 <== {msg}");
|
||||
|
||||
}
|
||||
|
||||
//以上两个指令必须一起执行,中间不能有异步操作,否则_buff里的数据会丢失!!!
|
||||
@ -262,6 +251,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BackgroundWork
|
||||
/// </summary>
|
||||
@ -292,6 +282,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case StateEnum.Receive:
|
||||
{
|
||||
if (ReceiveMsg())
|
||||
@ -314,19 +305,15 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Error: {ex.Message}");
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取Stream
|
||||
/// </summary>
|
||||
@ -335,6 +322,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
return _client?.GetStream();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///关闭连接
|
||||
/// </summary>
|
||||
@ -344,11 +332,5 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
bkgWorker.Dispose();
|
||||
_client?.Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -23,13 +23,11 @@
|
||||
<x:Type TypeName="connects:CommunicationDataType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<GroupBox Header="客户端">
|
||||
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
@ -64,12 +62,9 @@
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top"
|
||||
Orientation="Horizontal">
|
||||
|
||||
|
||||
<TextBlock Margin="10,0" Text="服务器IP: " VerticalAlignment="Center" />
|
||||
<TextBox Width="150" Text="{Binding IP, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" VerticalAlignment="Center" />
|
||||
|
||||
|
||||
|
||||
<TextBlock Margin="10,0" Text="服务端口:" VerticalAlignment="Center" />
|
||||
<TextBox Width="150" Text="{Binding Port, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" VerticalAlignment="Center" />
|
||||
|
||||
@ -83,8 +78,6 @@
|
||||
<ComboBox Width="150" VerticalAlignment="Center" ItemsSource="{Binding Source={StaticResource DataType}}" SelectedValue="{Binding Client.Params.DataType, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -11,7 +11,6 @@ using System.Threading;
|
||||
|
||||
namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Socket客户端配置视图模型
|
||||
/// </summary>
|
||||
@ -44,6 +43,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
SetProperty(ref _Title, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request关闭
|
||||
/// </summary>
|
||||
@ -57,6 +57,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭对话框后要执行的
|
||||
/// </summary>
|
||||
@ -80,8 +81,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
IP = Client.IP_SerialPort;
|
||||
Port = Client.Port;
|
||||
Client.LogSwitch = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private readonly BackgroundWorker bkgWorker;
|
||||
@ -95,7 +94,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Thread.Sleep(100);
|
||||
if (Client != null)
|
||||
{
|
||||
|
||||
if (Client.LogSwitch)
|
||||
{
|
||||
if (!(Client as SocketClient).LogQueue.IsEmpty)
|
||||
@ -109,14 +107,11 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Connect _Client;
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -125,6 +120,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
get { return _Client; }
|
||||
set { SetProperty(ref _Client, value); }
|
||||
}
|
||||
|
||||
//日志
|
||||
private ObservableCollection<ErrorLog> _Logs = [];
|
||||
|
||||
@ -174,7 +170,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string _SendString = "hello";
|
||||
|
||||
/// <summary>
|
||||
@ -199,16 +194,12 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
public AsyncDelegateCommand Send =>
|
||||
_Send ??= new AsyncDelegateCommand(ExecuteSendAsync);
|
||||
|
||||
|
||||
private async Task ExecuteSendAsync()
|
||||
|
||||
{
|
||||
await Client.SendAsync(SendString);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion Command
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
using PLCSharp.Core.Tools;
|
||||
using PLCSharp.Core.Tools;
|
||||
using System.ComponentModel;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
@ -19,13 +19,13 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
private readonly BackgroundWorker bkgWorker;
|
||||
|
||||
private StateEnum State;
|
||||
|
||||
/// <summary>
|
||||
/// Socket服务端
|
||||
/// </summary>
|
||||
public SocketServer()
|
||||
|
||||
{
|
||||
|
||||
bkgWorker = new BackgroundWorker { WorkerSupportsCancellation = true };
|
||||
bkgWorker.DoWork += BackgroundWork;
|
||||
|
||||
@ -56,29 +56,24 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
State = StateEnum.Sleep;
|
||||
Connected = false;
|
||||
Successful = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case StateEnum.Sleep:
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
Online = NetTool.PingIP(IP_SerialPort);
|
||||
State = StateEnum.Init;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Error: {ex.Message}");
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +85,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
IPEndPoint iPEndPoint = new(IPAddress.Parse(IP_SerialPort), Port);
|
||||
|
||||
if (socketServer != null && socketServer.LocalEndPoint.ToString() == $"{IP_SerialPort}:{Port}")
|
||||
@ -128,7 +122,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
thread.Start();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -137,9 +130,9 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
socketServer.Dispose();
|
||||
socketServer = null;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///关闭连接
|
||||
/// </summary>
|
||||
@ -158,6 +151,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
ClearBad();
|
||||
thread?.Interrupt();
|
||||
}
|
||||
|
||||
private void AcceptClientConnect()
|
||||
{
|
||||
//转换Socket
|
||||
@ -191,15 +185,11 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Log($"SendMsg:{ex.Message}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ReceiveClientMsg(System.Net.Sockets.Socket proxSocket)
|
||||
{
|
||||
var clientIP = proxSocket.RemoteEndPoint.ToString();
|
||||
@ -236,8 +226,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return;//让方法结束,终结当前客户端数据的异步线程,方法退出,即线程结束
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Params.DataType == CommunicationDataType.Bytes)
|
||||
{
|
||||
var bytesStr = BitConverter.ToString(data, 0, len);
|
||||
@ -260,11 +248,9 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
if (client != null)
|
||||
{
|
||||
client.ReceiveInfo = msgStr;
|
||||
|
||||
}
|
||||
Log($"{DateTime.Now:HH:mm:ss:fff} 接收到[{clientIP}]的消息<==:{msgStr.Replace("\r\n", "\\r\\n")}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,6 +270,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据
|
||||
/// </summary>
|
||||
@ -298,10 +285,8 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (ClientList.Count > 0)
|
||||
{
|
||||
|
||||
foreach (var proxSocket in ClientList)
|
||||
{
|
||||
if (proxSocket.Connected)//判断客户端是否还在连接
|
||||
@ -310,27 +295,20 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
if (isLog)
|
||||
{
|
||||
|
||||
var bytesStr = BitConverter.ToString(bytes).Replace("-", " ");
|
||||
Log($"{DateTime.Now:HH:mm:ss:fff}向{proxSocket.RemoteEndPoint}发送信息 ==>{bytesStr}");
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var str = Encoding.UTF8.GetString(bytes);
|
||||
Log($"{DateTime.Now:HH:mm:ss:fff}向{proxSocket.RemoteEndPoint}发送信息 ==>{str}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
BadClientList.Add(proxSocket);
|
||||
Log("SendMsg:客户端未连接");
|
||||
ClearBad();
|
||||
|
||||
}
|
||||
}
|
||||
Successful = true;
|
||||
@ -342,8 +320,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -363,6 +339,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据Async
|
||||
/// </summary>
|
||||
@ -377,10 +354,8 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (ClientList.Count > 0)
|
||||
{
|
||||
|
||||
foreach (var proxSocket in ClientList)
|
||||
{
|
||||
if (proxSocket.Connected)//判断客户端是否还在连接
|
||||
@ -413,8 +388,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -451,6 +424,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据Async
|
||||
/// </summary>
|
||||
@ -468,7 +442,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (ClientList.Count > 0)
|
||||
{
|
||||
var client = Clients.FirstOrDefault(c => c.Name == clientName);
|
||||
@ -516,9 +489,8 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
Successful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ClearBad()
|
||||
{
|
||||
foreach (var proxSocket in BadClientList)
|
||||
@ -566,6 +538,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向指定客户端发送消息
|
||||
/// </summary>
|
||||
@ -582,7 +555,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
var proxSocket = ClientList.FirstOrDefault(x => x.RemoteEndPoint.ToString().Split(":")[0] == client.IP_SerialPort);
|
||||
|
||||
|
||||
if (proxSocket.Connected)//判断客户端是否还在连接
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes(str);
|
||||
@ -600,12 +572,12 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClientExit(string msg, System.Net.Sockets.Socket proxSocket)
|
||||
{
|
||||
Log(msg);
|
||||
BadClientList.Add(proxSocket);//移除集合中的连接Socket
|
||||
ClearBad();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,164 +1,156 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.Connects.Socket.SocketServerConfig"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:beavior="clr-namespace:PLCSharp.Core.Prism"
|
||||
xmlns:cvt="clr-namespace:PLCSharp.Core.Tools"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:local="clr-namespace:PLCSharp.VVMs.Connects.Socket"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:viewmodels="clr-namespace:PLCSharp.VVMs.Connects.Socket"
|
||||
xmlns:connects="clr-namespace:PLCSharp.VVMs.Connects"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
mc:Ignorable="d" d:Background="White"
|
||||
d:DataContext="{d:DesignInstance Type=local:SocketServerConfigViewModel}"
|
||||
Width="900" Height="400">
|
||||
<UserControl.Resources>
|
||||
<cvt:BoolToValueConverter x:Key="BoolToValueConverter" />
|
||||
|
||||
<ObjectDataProvider x:Key="DataType" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="connects:CommunicationDataType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<GroupBox Header="客户端">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="30" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="3*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid>
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding Server.Clients}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
SelectedItem="{Binding SelectedClient}"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<DataGrid.ItemContainerStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Params.Prompt}" Value="已修改,请保存">
|
||||
<Setter Property="Foreground" Value="Red" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Params.Prompt}" Value="">
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.ItemContainerStyle>
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu IsEnabled="True" StaysOpen="False">
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="New" Header="新增" />
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="Remove" Header="删除" />
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="Save" Header="保存" />
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="Config" Header="配置" />
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn MinWidth="60" Binding="{Binding Name, UpdateSourceTrigger=LostFocus}" Header="连接名" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding IP, UpdateSourceTrigger=LostFocus}" Header="IP" />
|
||||
<DataGridComboBoxColumn Width="150" Header="消息类型" ItemsSource="{Binding Source={StaticResource DataType}}" SelectedValueBinding="{Binding Params.DataType, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Comment, UpdateSourceTrigger=LostFocus}" Header="备注" />
|
||||
<DataGridTemplateColumn Header="在线">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Viewbox>
|
||||
<Ellipse Width="10" Height="10" Fill="{Binding Online, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
</Viewbox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="连接">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Viewbox>
|
||||
<Ellipse Width="10" Height="10" Fill="{Binding Connected, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
</Viewbox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="读写">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Viewbox>
|
||||
<Ellipse Width="10" Height="10" Fill="{Binding Successful, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
</Viewbox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Params.Prompt}" Header="提示" IsReadOnly="True" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
<Grid Grid.Row="1">
|
||||
|
||||
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding Logs}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<i:Interaction.Behaviors>
|
||||
<beavior:DataGridScrollToBottomBehavior />
|
||||
</i:Interaction.Behaviors>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="1*" Binding="{Binding Time, UpdateSourceTrigger=LostFocus}" Header="时间" />
|
||||
<DataGridTextColumn Width="5*" Binding="{Binding Message, UpdateSourceTrigger=LostFocus}" Header="消息" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal">
|
||||
<TextBox Width="600" Text="{Binding SendString, Mode=TwoWay}" TextWrapping="Wrap" AcceptsReturn="True" />
|
||||
<Button Width="80" Command="{Binding Send}" Content="发送" />
|
||||
<Button Width="80" Margin="10,0" Command="{Binding SendToAll}" Content="广播" />
|
||||
<CheckBox Content="显示日志" IsChecked="{Binding Server.LogSwitch}" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
|
||||
|
||||
<TextBlock Margin="10,0" Text="服务器IP: " VerticalAlignment="Center" />
|
||||
<TextBox Width="150" Text="{Binding IP, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" VerticalAlignment="Center" />
|
||||
|
||||
|
||||
|
||||
<TextBlock Margin="10,0" Text="服务端口:" VerticalAlignment="Center" />
|
||||
<TextBox Width="150" Text="{Binding Port, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" VerticalAlignment="Center" />
|
||||
|
||||
<TextBlock Margin="10,0" Text="在线:" VerticalAlignment="Center" />
|
||||
|
||||
<Ellipse Width="20" Height="20" Fill="{Binding Server.Online, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
<TextBlock Margin="10,0" Text="连接:" VerticalAlignment="Center" />
|
||||
|
||||
<Ellipse Width="20" Height="20" Fill="{Binding Server.Connected, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
<TextBlock Margin="10,0" Text="消息类型:" VerticalAlignment="Center" />
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="PLCSharp.VVMs.Connects.Socket.SocketServerConfig"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:beavior="clr-namespace:PLCSharp.Core.Prism"
|
||||
xmlns:cvt="clr-namespace:PLCSharp.Core.Tools"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:local="clr-namespace:PLCSharp.VVMs.Connects.Socket"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:viewmodels="clr-namespace:PLCSharp.VVMs.Connects.Socket"
|
||||
xmlns:connects="clr-namespace:PLCSharp.VVMs.Connects"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
mc:Ignorable="d" d:Background="White"
|
||||
d:DataContext="{d:DesignInstance Type=local:SocketServerConfigViewModel}"
|
||||
Width="900" Height="400">
|
||||
<UserControl.Resources>
|
||||
<cvt:BoolToValueConverter x:Key="BoolToValueConverter" />
|
||||
|
||||
<ObjectDataProvider x:Key="DataType" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="connects:CommunicationDataType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<GroupBox Header="客户端">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="30" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="3*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid>
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding Server.Clients}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
SelectedItem="{Binding SelectedClient}"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<DataGrid.ItemContainerStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Params.Prompt}" Value="已修改,请保存">
|
||||
<Setter Property="Foreground" Value="Red" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Params.Prompt}" Value="">
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.ItemContainerStyle>
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu IsEnabled="True" StaysOpen="False">
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="New" Header="新增" />
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="Remove" Header="删除" />
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="Save" Header="保存" />
|
||||
<MenuItem Command="{Binding ConnectsManage}" CommandParameter="Config" Header="配置" />
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn MinWidth="60" Binding="{Binding Name, UpdateSourceTrigger=LostFocus}" Header="连接名" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding IP, UpdateSourceTrigger=LostFocus}" Header="IP" />
|
||||
<DataGridComboBoxColumn Width="150" Header="消息类型" ItemsSource="{Binding Source={StaticResource DataType}}" SelectedValueBinding="{Binding Params.DataType, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Comment, UpdateSourceTrigger=LostFocus}" Header="备注" />
|
||||
<DataGridTemplateColumn Header="在线">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Viewbox>
|
||||
<Ellipse Width="10" Height="10" Fill="{Binding Online, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
</Viewbox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="连接">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Viewbox>
|
||||
<Ellipse Width="10" Height="10" Fill="{Binding Connected, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
</Viewbox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn Header="读写">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Viewbox>
|
||||
<Ellipse Width="10" Height="10" Fill="{Binding Successful, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
</Viewbox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Params.Prompt}" Header="提示" IsReadOnly="True" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
<Grid Grid.Row="1">
|
||||
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding Logs}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<i:Interaction.Behaviors>
|
||||
<beavior:DataGridScrollToBottomBehavior />
|
||||
</i:Interaction.Behaviors>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="1*" Binding="{Binding Time, UpdateSourceTrigger=LostFocus}" Header="时间" />
|
||||
<DataGridTextColumn Width="5*" Binding="{Binding Message, UpdateSourceTrigger=LostFocus}" Header="消息" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal">
|
||||
<TextBox Width="600" Text="{Binding SendString, Mode=TwoWay}" TextWrapping="Wrap" AcceptsReturn="True" />
|
||||
<Button Width="80" Command="{Binding Send}" Content="发送" />
|
||||
<Button Width="80" Margin="10,0" Command="{Binding SendToAll}" Content="广播" />
|
||||
<CheckBox Content="显示日志" IsChecked="{Binding Server.LogSwitch}" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
|
||||
<TextBlock Margin="10,0" Text="服务器IP: " VerticalAlignment="Center" />
|
||||
<TextBox Width="150" Text="{Binding IP, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" VerticalAlignment="Center" />
|
||||
|
||||
<TextBlock Margin="10,0" Text="服务端口:" VerticalAlignment="Center" />
|
||||
<TextBox Width="150" Text="{Binding Port, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" VerticalAlignment="Center" />
|
||||
|
||||
<TextBlock Margin="10,0" Text="在线:" VerticalAlignment="Center" />
|
||||
|
||||
<Ellipse Width="20" Height="20" Fill="{Binding Server.Online, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
<TextBlock Margin="10,0" Text="连接:" VerticalAlignment="Center" />
|
||||
|
||||
<Ellipse Width="20" Height="20" Fill="{Binding Server.Connected, Converter={StaticResource BoolToValueConverter}, Mode=TwoWay, ConverterParameter=Lime, FallbackValue=Gray}" />
|
||||
<TextBlock Margin="10,0" Text="消息类型:" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -20,8 +20,8 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
private void DataGrid_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataGrid = sender as DataGrid;
|
||||
dataGrid.CommitEdit(DataGridEditingUnit.Row, true);
|
||||
var dataGrid = sender as DataGrid;
|
||||
dataGrid.CommitEdit(DataGridEditingUnit.Row, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,6 @@ using System.Threading;
|
||||
|
||||
namespace PLCSharp.VVMs.Connects.Socket
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Socket服务端配置视图模型
|
||||
/// </summary>
|
||||
@ -83,8 +82,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
IP = Server.IP_SerialPort;
|
||||
Port = Server.Port;
|
||||
Server.LogSwitch = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private readonly BackgroundWorker bkgWorker;
|
||||
@ -114,12 +111,11 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Connect _Server;
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -130,6 +126,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
|
||||
private Connect _SelectedClient;
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
@ -142,11 +139,10 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
if (value != null)
|
||||
{
|
||||
Server.Params.DataType = value.Params.DataType;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//日志
|
||||
private ObservableCollection<ErrorLog> _Logs = [];
|
||||
|
||||
@ -196,7 +192,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string _SendString = "hello";
|
||||
|
||||
/// <summary>
|
||||
@ -221,27 +216,23 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
public AsyncDelegateCommand Send =>
|
||||
_Send ??= new AsyncDelegateCommand(ExecuteSendAsync);
|
||||
|
||||
|
||||
private async Task ExecuteSendAsync()
|
||||
|
||||
{
|
||||
if (SelectedClient == null)
|
||||
{
|
||||
|
||||
Server.Log("请选择客户端"); return;
|
||||
|
||||
}
|
||||
|
||||
await Server.SendAsync(SendString, SelectedClient.Name);
|
||||
if (Server.Params.DataType == CommunicationDataType.Bytes)
|
||||
{
|
||||
|
||||
SendString = Server.SendInfo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AsyncDelegateCommand _SendToAll;
|
||||
|
||||
/// <summary>
|
||||
/// 发送ToAll
|
||||
/// </summary>
|
||||
@ -256,6 +247,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
SendString = Server.SendInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private DelegateCommand<string> _ConnectsManage;
|
||||
|
||||
/// <summary>
|
||||
@ -294,8 +286,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void SaveConnects()
|
||||
{
|
||||
var names = new List<string>();
|
||||
@ -310,7 +300,7 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
|
||||
if (names.Contains(item.Name))
|
||||
{
|
||||
_ConnectsModel.SendInfoDialog($"保存失败,重复的名称{item.Name}!" );
|
||||
_ConnectsModel.SendInfoDialog($"保存失败,重复的名称{item.Name}!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -319,7 +309,6 @@ namespace PLCSharp.VVMs.Connects.Socket
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SelectedClient.Params.Prompt = "";
|
||||
_ConnectsModel.SaveConnects();
|
||||
}
|
||||
|
||||
@ -1,68 +1,68 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.GlobalVariables.GlobalVariables"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:PLCSharp.VVMs.GlobalVariables"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=local:GlobalVariablesViewModel}"
|
||||
d:Height="300" d:Width="1000"
|
||||
Background="AliceBlue">
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style TargetType="Window">
|
||||
|
||||
<Setter Property="SizeToContent" Value="Manual" />
|
||||
</Style>
|
||||
</prism:Dialog.WindowStyle>
|
||||
<UserControl.Resources>
|
||||
<ObjectDataProvider x:Key="DataFromEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="local:VariableDataType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="1">
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding Model.Variables}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
SelectedItem="{Binding Model.SelectedVariable}"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu IsEnabled="True" StaysOpen="False">
|
||||
<MenuItem Command="{Binding Model.VariablesManage}" CommandParameter="Save" Header="保存" />
|
||||
<MenuItem Command="{Binding Model.VariablesManage}" CommandParameter="New" Header="新增" />
|
||||
<MenuItem Command="{Binding Model.VariablesManage}" CommandParameter="Delete" Header="删除" />
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Name, UpdateSourceTrigger=LostFocus}" Header="变量名" />
|
||||
<DataGridComboBoxColumn MinWidth="100" Header="数据类型" ItemsSource="{Binding Source={StaticResource DataFromEnum}}" SelectedValueBinding="{Binding Type}" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Value, UpdateSourceTrigger=LostFocus}" Header="当前值" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding DefaultValue, UpdateSourceTrigger=LostFocus}" Header="初始值" />
|
||||
<DataGridTemplateColumn Header="保持">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox IsChecked="{Binding RetainPersistent, UpdateSourceTrigger=LostFocus}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn MinWidth="200" Binding="{Binding Comment}" Header="备注" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
<UserControl x:Class="PLCSharp.VVMs.GlobalVariables.GlobalVariables"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:PLCSharp.VVMs.GlobalVariables"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=local:GlobalVariablesViewModel}"
|
||||
d:Height="300" d:Width="1000"
|
||||
Background="AliceBlue">
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style TargetType="Window">
|
||||
|
||||
<Setter Property="SizeToContent" Value="Manual" />
|
||||
</Style>
|
||||
</prism:Dialog.WindowStyle>
|
||||
<UserControl.Resources>
|
||||
<ObjectDataProvider x:Key="DataFromEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="local:VariableDataType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="1">
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding Model.Variables}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
SelectedItem="{Binding Model.SelectedVariable}"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu IsEnabled="True" StaysOpen="False">
|
||||
<MenuItem Command="{Binding Model.VariablesManage}" CommandParameter="Save" Header="保存" />
|
||||
<MenuItem Command="{Binding Model.VariablesManage}" CommandParameter="New" Header="新增" />
|
||||
<MenuItem Command="{Binding Model.VariablesManage}" CommandParameter="Delete" Header="删除" />
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Name, UpdateSourceTrigger=LostFocus}" Header="变量名" />
|
||||
<DataGridComboBoxColumn MinWidth="100" Header="数据类型" ItemsSource="{Binding Source={StaticResource DataFromEnum}}" SelectedValueBinding="{Binding Type}" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding Value, UpdateSourceTrigger=LostFocus}" Header="当前值" />
|
||||
<DataGridTextColumn MinWidth="100" Binding="{Binding DefaultValue, UpdateSourceTrigger=LostFocus}" Header="初始值" />
|
||||
<DataGridTemplateColumn Header="保持">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox IsChecked="{Binding RetainPersistent, UpdateSourceTrigger=LostFocus}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn MinWidth="200" Binding="{Binding Comment}" Header="备注" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user