@@ -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<ProjectModel>.Read(res); | |||
var rrr = Json<ProjectModel>.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value); | |||
rrr?.ToList()?.ForEach(item => | |||
{ | |||
MessageBox.Show(item.Key); | |||
}); | |||
var pages = Json<ProjectModel>.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value); | |||
} | |||
MainWindow window = new MainWindow(); | |||
window.Show(); | |||
@@ -1,4 +1,5 @@ | |||
using BPA.Helper; | |||
using BPASmart.Model; | |||
using Microsoft.Win32; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -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<ProjectModel>.Data.ProjectPath); | |||
Json<LocalPar>.Data.ProjectPath = Json<ProjectModel>.Data.ProjectPath; | |||
Json<LocalPar>.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<object>((o) => | |||
@@ -122,6 +160,8 @@ namespace BPASmart.ConfigurationSoftware | |||
{ | |||
string path = Json<ProjectModel>.Data.ProjectPath; | |||
string name = Json<ProjectModel>.Data.ProjectName; | |||
var pages = Json<ProjectModel>.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value); | |||
if (pages != null) Json<ProjectModel>.Data.Pages = pages; | |||
Json<ProjectModel>.Save($"{path}\\{name}.project"); | |||
} | |||
@@ -1,4 +1,5 @@ | |||
using BPA.Helper; | |||
using BPASmart.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 项目名称 | |||
/// </summary> | |||
public string ProjectName { get; set; } | |||
//namespace BPASmart.ConfigurationSoftware | |||
//{ | |||
// public class ProjectModel | |||
// { | |||
// /// <summary> | |||
// /// 项目名称 | |||
// /// </summary> | |||
// public string ProjectName { get; set; } | |||
/// <summary> | |||
/// 项目路径 | |||
/// </summary> | |||
public string ProjectPath { get; set; } | |||
// /// <summary> | |||
// /// 项目路径 | |||
// /// </summary> | |||
// public string ProjectPath { get; set; } | |||
/// <summary> | |||
/// 页面集合 | |||
/// key 是页面名称 | |||
/// value 是页面路径 | |||
/// </summary> | |||
public ConcurrentDictionary<string, string> Pages { get; set; } = new ConcurrentDictionary<string, string>(); | |||
// /// <summary> | |||
// /// 页面集合 | |||
// /// key 是页面名称 | |||
// /// value 是页面路径 | |||
// /// </summary> | |||
// public Dictionary<string, string> Pages { get; set; } = new Dictionary<string, string>(); | |||
/// <summary> | |||
/// 变量表配置路径 | |||
/// </summary> | |||
public string VariableTabPath { get; set; } | |||
} | |||
} | |||
// /// <summary> | |||
// /// 变量表配置路径 | |||
// /// </summary> | |||
// public string VariableTabPath { get; set; } | |||
// } | |||
//} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 项目路径 | |||
/// </summary> | |||
public string ProjectPath { get; set; } = string.Empty; | |||
} | |||
} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 项目名称 | |||
/// </summary> | |||
public string ProjectName { get; set; } | |||
/// <summary> | |||
/// 项目路径 | |||
/// </summary> | |||
public string ProjectPath { get; set; } | |||
/// <summary> | |||
/// 页面集合 | |||
/// key 是页面名称 | |||
/// value 是页面路径 | |||
/// </summary> | |||
public Dictionary<string, string> Pages { get; set; } = new Dictionary<string, string>(); | |||
/// <summary> | |||
/// 变量表配置路径 | |||
/// </summary> | |||
public string VariableTabPath { get; set; } | |||
} | |||
} |
@@ -20,11 +20,13 @@ namespace BPASmart.VariableManager | |||
/// </summary> | |||
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<LocalPar>.Read(); | |||
FileConfigModel.ConstPath = Json<LocalPar>.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<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>(); | |||
@@ -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<CommunicationPar>.Save(path); | |||
Json<CommunicationPar>.Save(FileConfigModel.GetPath); | |||
} | |||
private static void DataRead() | |||
private void DataRead() | |||
{ | |||
Json<CommunicationPar>.Read(path); | |||
Json<CommunicationPar>.Read(FileConfigModel.GetPath); | |||
} | |||
} | |||
@@ -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; | |||
} | |||
} | |||
} | |||
} |
@@ -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<CommunicationPar>.Read(); | |||
Json<CommunicationPar>.Read(FileConfigModel.GetPath); | |||
communicationDevices = Json<CommunicationPar>.Data.CommunicationDevices; | |||
DataListInit(); | |||
NewConnectCommand = new RelayCommand(() => { NewConnect(); }); | |||
RemoveDeviceCommand = new RelayCommand<object>(RemoveDevice); | |||
SaveConnectSetCommand = new RelayCommand(() => { Json<CommunicationPar>.Save(); }); | |||
SaveConnectSetCommand = new RelayCommand(() => { Json<CommunicationPar>.Save(FileConfigModel.GetPath); }); | |||
DelegationNotifi.GetInstance.AddDeviceVerify = new Func<DeviceManagermentResult, bool>((p) => | |||
{ | |||
@@ -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<object> RemoveCommand { get; set; } | |||
#endregion | |||
//private void SetValue<TArray>(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<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置 | |||
//if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count) | |||
//{ | |||
// var tempArray = Json<CommunicationPar>.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<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString(); | |||
// } | |||
// } | |||
// var Devicename = Json<CommunicationPar>.Data.CommunicationDevices[index].DeviceName; | |||
// List<ReeisDataModel> reeisDataModels = new List<ReeisDataModel>(); | |||
// Json<CommunicationPar>.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<EDataType, List<ReadDataModel>> GetReadDataModels() | |||
//{ | |||
// Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>(); | |||
// 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<ReadDataModel> GetDataGroup(IGrouping<string, VariableInfo> variableInfos, int by = 1) | |||
//{ | |||
// List<ReadDataModel> ReturnValue = new List<ReadDataModel>(); | |||
// var res = variableInfos?.OrderBy(p => p.RealAddress).ToList(); | |||
// List<int> RealAddresss = new List<int>(); | |||
// 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; | |||
//} | |||
/// <summary> | |||
/// 下拉列表初始化 | |||
/// </summary> | |||
@@ -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<CommunicationPar>.Save(); | |||
Json<CommunicationPar>.Save(FileConfigModel.GetPath); | |||
} | |||
} | |||
} |
@@ -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<CommunicationPar>.Save(); | |||
Json<CommunicationPar>.Save(FileConfigModel.GetPath); | |||
} | |||
private void VariableConfig_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) | |||