diff --git a/BPASmart.ConfigurationSoftware/App.xaml.cs b/BPASmart.ConfigurationSoftware/App.xaml.cs index cc3e269a..bc6afab9 100644 --- a/BPASmart.ConfigurationSoftware/App.xaml.cs +++ b/BPASmart.ConfigurationSoftware/App.xaml.cs @@ -1,4 +1,5 @@ using BPA.Helper; +using BPASmart.Model; using System; using System.Collections.Generic; using System.Configuration; @@ -21,14 +22,7 @@ namespace BPASmart.ConfigurationSoftware { var res = e.Args[0]; Json.Read(res); - - var rrr = Json.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value); - rrr?.ToList()?.ForEach(item => - { - MessageBox.Show(item.Key); - }); - - + var pages = Json.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value); } MainWindow window = new MainWindow(); window.Show(); diff --git a/BPASmart.ConfigurationSoftware/FileHelper.cs b/BPASmart.ConfigurationSoftware/FileHelper.cs index bd851deb..8eb79792 100644 --- a/BPASmart.ConfigurationSoftware/FileHelper.cs +++ b/BPASmart.ConfigurationSoftware/FileHelper.cs @@ -1,4 +1,5 @@ using BPA.Helper; +using BPASmart.Model; using Microsoft.Win32; using System; using System.Collections.Generic; diff --git a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs index d4b24a38..23be174e 100644 --- a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs +++ b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs @@ -14,11 +14,51 @@ using BeDesignerSCADA; using BeDesignerSCADA.Controls; using System.Windows; using System.Reflection; +using System.Collections.Concurrent; namespace BPASmart.ConfigurationSoftware { public class MainWindowViewModel : NoticeBase { + + //public ushort CalcCRC(byte[] bytes) + //{ + // ushort uiCrcValue = 0xffff; + // ushort polynomial = 0x8408; + // for (int i = 0; i < bytes.Length; i++) + // { + // uiCrcValue = (ushort)(uiCrcValue ^ bytes[i]); + // for (int m = 0; m < 8; m++) + // { + // if ((uiCrcValue & 0x0001) == 1) + // { + // uiCrcValue = (ushort)((uiCrcValue >> 1) ^ polynomial); + // } + // else + // { + // uiCrcValue = (ushort)(uiCrcValue >> 1); + // } + // } + // } + // return uiCrcValue; + //} + + //public byte[] GetCrc(ushort value, bool IsReverse = true) + //{ + // byte[] bytes = new byte[2]; + // if (IsReverse) + // { + // bytes[0] = (byte)value; + // bytes[1] = (byte)(value >> 8); + // } + // else + // { + // bytes[1] = (byte)value; + // bytes[0] = (byte)(value >> 8); + // } + // return bytes; + //} + public MainWindowViewModel() { Init(); @@ -58,18 +98,16 @@ namespace BPASmart.ConfigurationSoftware OpenVarManagerCommand = new RelayCommand(() => { - //if (File.Exists(Global.VarManagerPath)) - //{ - // Process[] pro = Process.GetProcesses(); - // if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null) - // { - // Process.Start(Global.VarManagerPath); - // } - //} - - VariableManager.App.Start(Json.Data.ProjectPath); - - + Json.Data.ProjectPath = Json.Data.ProjectPath; + Json.Save(); + if (File.Exists(Global.VarManagerPath)) + { + Process[] pro = Process.GetProcesses(); + if (pro?.ToList().FirstOrDefault(p => p.ProcessName.Contains("BPASmart.VariableManager")) == null) + { + Process.Start(Global.VarManagerPath); + } + } }); SelectedPageCommand = new RelayCommand((o) => @@ -122,6 +160,8 @@ namespace BPASmart.ConfigurationSoftware { string path = Json.Data.ProjectPath; string name = Json.Data.ProjectName; + var pages = Json.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value); + if (pages != null) Json.Data.Pages = pages; Json.Save($"{path}\\{name}.project"); } diff --git a/BPASmart.ConfigurationSoftware/NewPageView.xaml.cs b/BPASmart.ConfigurationSoftware/NewPageView.xaml.cs index bcf9a791..015e588f 100644 --- a/BPASmart.ConfigurationSoftware/NewPageView.xaml.cs +++ b/BPASmart.ConfigurationSoftware/NewPageView.xaml.cs @@ -1,4 +1,5 @@ using BPA.Helper; +using BPASmart.Model; using System; using System.Collections.Generic; using System.Linq; diff --git a/BPASmart.ConfigurationSoftware/ProjectModel.cs b/BPASmart.ConfigurationSoftware/ProjectModel.cs index e9bc621f..3dfd6002 100644 --- a/BPASmart.ConfigurationSoftware/ProjectModel.cs +++ b/BPASmart.ConfigurationSoftware/ProjectModel.cs @@ -1,35 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Collections.Concurrent; -using System.Runtime.Serialization; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; +//using System.Collections.Concurrent; +//using System.Runtime.Serialization; -namespace BPASmart.ConfigurationSoftware -{ - public class ProjectModel - { - /// - /// 项目名称 - /// - public string ProjectName { get; set; } +//namespace BPASmart.ConfigurationSoftware +//{ +// public class ProjectModel +// { +// /// +// /// 项目名称 +// /// +// public string ProjectName { get; set; } - /// - /// 项目路径 - /// - public string ProjectPath { get; set; } +// /// +// /// 项目路径 +// /// +// public string ProjectPath { get; set; } - /// - /// 页面集合 - /// key 是页面名称 - /// value 是页面路径 - /// - public ConcurrentDictionary Pages { get; set; } = new ConcurrentDictionary(); +// /// +// /// 页面集合 +// /// key 是页面名称 +// /// value 是页面路径 +// /// +// public Dictionary Pages { get; set; } = new Dictionary(); - /// - /// 变量表配置路径 - /// - public string VariableTabPath { get; set; } - } -} +// /// +// /// 变量表配置路径 +// /// +// public string VariableTabPath { get; set; } +// } +//} diff --git a/BPASmart.Model/LocalPar.cs b/BPASmart.Model/LocalPar.cs new file mode 100644 index 00000000..8cf8afbb --- /dev/null +++ b/BPASmart.Model/LocalPar.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model +{ + public class LocalPar + { + /// + /// 项目路径 + /// + public string ProjectPath { get; set; } = string.Empty; + } +} diff --git a/BPASmart.Model/ProjectModel.cs b/BPASmart.Model/ProjectModel.cs new file mode 100644 index 00000000..3f517f18 --- /dev/null +++ b/BPASmart.Model/ProjectModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.Concurrent; +using System.Runtime.Serialization; + +namespace BPASmart.Model +{ + public class ProjectModel + { + /// + /// 项目名称 + /// + public string ProjectName { get; set; } + + /// + /// 项目路径 + /// + public string ProjectPath { get; set; } + + /// + /// 页面集合 + /// key 是页面名称 + /// value 是页面路径 + /// + public Dictionary Pages { get; set; } = new Dictionary(); + + /// + /// 变量表配置路径 + /// + public string VariableTabPath { get; set; } + } +} diff --git a/BPASmart.VariableManager/App.xaml.cs b/BPASmart.VariableManager/App.xaml.cs index 7cfe6936..5bf67fbd 100644 --- a/BPASmart.VariableManager/App.xaml.cs +++ b/BPASmart.VariableManager/App.xaml.cs @@ -20,11 +20,13 @@ namespace BPASmart.VariableManager /// public partial class App : Application { - public static string ConstPath = string.Empty; + //public static string ConstPath = string.Empty; public static Window MainWindow; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); + Json.Read(); + FileConfigModel.ConstPath = Json.Data.ProjectPath; DataRead(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; MenuInit(); @@ -35,19 +37,7 @@ namespace BPASmart.VariableManager } - public static void Start(string path) - { - ConstPath = path; - DataRead(); - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - MenuInit(); - MainView mv = new MainView(); - mv.WindowState = WindowState.Normal; - MainWindow = mv; - mv.Show(); - } - - private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { DataSave(); } @@ -58,7 +48,7 @@ namespace BPASmart.VariableManager DataSave(); } - private static void MenuInit() + private void MenuInit() { #region 设备管理 ObservableCollection DeviceMonitor = new ObservableCollection(); @@ -113,7 +103,7 @@ namespace BPASmart.VariableManager } - private static SubMenumodel AddSubMenuModel(string s) + private SubMenumodel AddSubMenuModel(string s) { return new SubMenumodel() { @@ -124,24 +114,29 @@ namespace BPASmart.VariableManager }; } - static string path - { - get - { - string path = $"{ConstPath}\\AccessFile\\JSON"; - Directory.CreateDirectory(path); - return $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json"; - } - } - - private static void DataSave() + //static string path + //{ + // get + // { + // string ReturnValue = null; + // if (Directory.Exists(ConstPath)) + // { + // string path = $"{ConstPath}\\AccessFile\\JSON"; + // Directory.CreateDirectory(path); + // ReturnValue = $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json"; + // } + // return ReturnValue; + // } + //} + + private void DataSave() { - Json.Save(path); + Json.Save(FileConfigModel.GetPath); } - private static void DataRead() + private void DataRead() { - Json.Read(path); + Json.Read(FileConfigModel.GetPath); } } diff --git a/BPASmart.VariableManager/FileConfigModel.cs b/BPASmart.VariableManager/FileConfigModel.cs new file mode 100644 index 00000000..8491d794 --- /dev/null +++ b/BPASmart.VariableManager/FileConfigModel.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.VariableManager +{ + public class FileConfigModel + { + public static string ConstPath = string.Empty; + + public static string GetPath + { + get + { + string ReturnValue = null; + if (Directory.Exists(ConstPath)) + { + string path = $"{ConstPath}\\AccessFile\\JSON"; + Directory.CreateDirectory(path); + ReturnValue = $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json"; + } + return ReturnValue; + } + } + } +} diff --git a/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs b/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs index c2e40530..0c2034d2 100644 --- a/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs +++ b/BPASmart.VariableManager/ViewModels/CommunicationSetViewModel.cs @@ -8,9 +8,8 @@ using System.Collections.ObjectModel; using Microsoft.Toolkit.Mvvm.Input; using BPASmart.VariableManager.Views; using System.Windows; -using BPASmartClient.Helper; +using BPA.Helper; using BPASmart.Model; -//using BPASmartClient.Model; using System.IO.Ports; using System.IO; using System.Reflection; @@ -21,12 +20,12 @@ namespace BPASmart.VariableManager.ViewModels { public CommunicationSetViewModel() { - Json.Read(); + Json.Read(FileConfigModel.GetPath); communicationDevices = Json.Data.CommunicationDevices; DataListInit(); NewConnectCommand = new RelayCommand(() => { NewConnect(); }); RemoveDeviceCommand = new RelayCommand(RemoveDevice); - SaveConnectSetCommand = new RelayCommand(() => { Json.Save(); }); + SaveConnectSetCommand = new RelayCommand(() => { Json.Save(FileConfigModel.GetPath); }); DelegationNotifi.GetInstance.AddDeviceVerify = new Func((p) => { diff --git a/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs b/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs index 6d35a3a0..a54112e3 100644 --- a/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs +++ b/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs @@ -9,7 +9,7 @@ using Microsoft.Toolkit.Mvvm.Input; using BPASmart.Model; using System.Diagnostics; using Microsoft.EntityFrameworkCore; -using BPASmartClient.Helper; +using BPA.Helper; using System.Text.Json.Serialization; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Ubiety.Dns.Core.Records; @@ -275,19 +275,6 @@ namespace BPASmart.VariableManager.ViewModels public RelayCommand RemoveCommand { get; set; } #endregion - //private void SetValue(TArray[] arrays, ReadDataModel readDataModel, ushort by) - //{ - // for (int i = 0; i < arrays.Length; i++) - // { - // int varIndex = Array.FindIndex(varialeInfos.ToArray(), p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString()); - // if (varIndex >= 0 && varIndex < varialeInfos.Count) - // { - // varialeInfos.ElementAt(varIndex).CurrentValue = arrays[i].ToString(); - // } - // } - - //} - private void SetValue(Array arrays, ReadDataModel readDataModel, EDataType eDataType) { if (arrays != null) @@ -301,107 +288,9 @@ namespace BPASmart.VariableManager.ViewModels varialeInfos.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString(); } } - - - - - //int index = Array.FindIndex(Json.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置 - //if (index >= 0 && index < Json.Data.CommunicationDevices.Count) - //{ - // var tempArray = Json.Data.CommunicationDevices.ElementAt(index).VarTableModels.ToArray(); - // for (int i = 0; i < arrays.Length; i++) - // { - // int varIndex = Array.FindIndex(tempArray, p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString()); - // if (varIndex >= 0 && varIndex < tempArray.Length) - // { - // Json.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString(); - // } - // } - // var Devicename = Json.Data.CommunicationDevices[index].DeviceName; - // List reeisDataModels = new List(); - // Json.Data.CommunicationDevices[index].VarTableModels.ToList().ForEach(tempVar => - // { - // if (tempVar.VarName.Length > 0) - // { - // reeisDataModels.Add(new ReeisDataModel() - // { - // VarName = tempVar.VarName, - // VarVaule = tempVar.CurrentValue, - // DataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.DataType) - // }); - // } - // }); - // RedisHelper.GetInstance.SetValue($"{Devicename}", reeisDataModels); - //} } } - //private Dictionary> GetReadDataModels() - //{ - // Dictionary> readDataModels = new Dictionary>(); - // varialeInfos.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar => - // { - // if (tempVar.Key != null && tempVar.Key.Length > 0) - // { - // EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key); - // switch (dataType) - // { - // case EDataType.Bool: - // case EDataType.Byte: - // case EDataType.Int: - // case EDataType.Word: - // if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar)); - // break; - // case EDataType.Dint: - // case EDataType.Dword: - // case EDataType.Float: - // if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar, 2)); - // break; - // default: - // break; - // } - // } - // }); - // return readDataModels; - //} - - //private List GetDataGroup(IGrouping variableInfos, int by = 1) - //{ - // List ReturnValue = new List(); - // var res = variableInfos?.OrderBy(p => p.RealAddress).ToList(); - // List RealAddresss = new List(); - // variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); }); - // int count = 0; - // if (res != null) - // { - // int address = RealAddresss.Min(); - // int startAddress = address; - // for (int i = 0; i < res.Count; i++) - // { - // if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress)) - // { - // if (TempAddress == address) - // { - // count++; - // address += by; - // } - // else - // { - // ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count }); - // count = 1; - // address = TempAddress + by; - // startAddress = TempAddress; - // } - // } - - // } - // ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count }); - // } - // return ReturnValue; - //} - - - /// /// 下拉列表初始化 /// diff --git a/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs b/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs index e0f03cfb..1627c692 100644 --- a/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs +++ b/BPASmart.VariableManager/Views/CommunicationSetView.xaml.cs @@ -1,5 +1,5 @@ using BPASmart.Model; -using BPASmartClient.Helper; +using BPA.Helper; using System; using System.Collections.Generic; using System.Linq; @@ -30,7 +30,7 @@ namespace BPASmart.VariableManager.Views private void CommunicationSetView_Unloaded(object sender, RoutedEventArgs e) { - Json.Save(); + Json.Save(FileConfigModel.GetPath); } } } diff --git a/BPASmart.VariableManager/Views/VariableConfig.xaml.cs b/BPASmart.VariableManager/Views/VariableConfig.xaml.cs index 8d7a207b..db6f920d 100644 --- a/BPASmart.VariableManager/Views/VariableConfig.xaml.cs +++ b/BPASmart.VariableManager/Views/VariableConfig.xaml.cs @@ -1,6 +1,6 @@ using BPASmart.Model; using BPASmart.VariableManager.ViewModels; -using BPASmartClient.Helper; +using BPA.Helper; using System; using System.Collections.Generic; using System.Diagnostics; @@ -33,7 +33,7 @@ namespace BPASmart.VariableManager.Views private void VariableConfig_Unloaded(object sender, RoutedEventArgs e) { - Json.Save(); + Json.Save(FileConfigModel.GetPath); } private void VariableConfig_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)