diff --git a/BPASmartClient.Helper/Json.cs b/BPASmartClient.Helper/Json.cs index 4f909f55..e20bdb75 100644 --- a/BPASmartClient.Helper/Json.cs +++ b/BPASmartClient.Helper/Json.cs @@ -11,24 +11,12 @@ namespace BPASmartClient.Helper /// public class Json where T : class, new() { - - //private static string DeviceType = ActionManage.GetInstance.SendResult("GetDeviceType").ToString(); - - //static string path - //{ - // get - // { - // Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\{DeviceType}\\JSON")); - // return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\{DeviceType}\\JSON\\{typeof(T).Name}.json"; - // } - //} - static string path { get { - Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"JSON")); - return $"{AppDomain.CurrentDomain.BaseDirectory}JSON\\{typeof(T).Name}.json"; + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\JSON")); + return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\{typeof(T).Name}.json"; } } @@ -43,8 +31,6 @@ namespace BPASmartClient.Helper File.WriteAllText(path, outjson); } - - /// /// 获取保存的数据 /// diff --git a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs index 04994172..b7b11c7f 100644 --- a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs +++ b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs @@ -12,16 +12,8 @@ namespace BPASmartClient.PLC public class PLCMachine : BasePeripheral { ModbusTcp modbusTcp = new ModbusTcp(); - //public string IpAddress { get; set; } - //public int Port { get; set; } - //public string PLCReadAddress { get; set; } - - //private List plcReadParameters; - public override void Init() { - //plcReadParameters = PLCReadParameter.DeSerialize(PLCReadAddress); - Task.Run(new Action(() => { modbusTcp.ModbusTcpConnect(communicationPar.IPAddress, communicationPar.IPPort); })); //PLC 设备连接 ThreadManage.GetInstance().StartLong(new Action(() => @@ -45,61 +37,12 @@ namespace BPASmartClient.PLC status.TryAdd(par.Address, res); } } - - //ushort address = (ushort)modbusTcp.GetAddress(par?.Address); - //object readData = new object(); - //switch (par.CmdType) - //{ - // case CommandType.Coils: - // modbusTcp.Readbool(address, par.Length, new Action((s) => { readData = s; })); - // break; - // case CommandType.HoldingRegisters: - // readData = modbusTcp.Read(address, CommandType.HoldingRegisters, par.Length); - // break; - //} - //status[par.Address] = readData; } - - - //foreach (var par in plcReadParameters) - //{ - // ushort address = (ushort)modbusTcp.GetAddress(par?.Address); - // object readData = new object(); - // switch (par.CmdType) - // { - // case CommandType.Coils: - // modbusTcp.Readbool(address, par.Length, new Action((s) => { readData = s; })); - // break; - // case CommandType.HoldingRegisters: - // readData = modbusTcp.Read(address, CommandType.HoldingRegisters, par.Length); - // break; - // } - // status[par.Address] = readData; - //} - Thread.Sleep(500); } Thread.Sleep(1000); }), $"设备[{DeviceId}]PLC读取线程", true); - //读取数据 - // EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) - //{ - // if (@event == null) return; - // var par = @event as ReadModel; - // ushort address = (ushort)modbusTcp.GetAddress(par?.Address); - // object readData = new object(); - // if (par.Address.ToUpper().Contains("M")) - // { - // modbusTcp.Readbool(address, par.Length, new Action((s) => { readData = s; })); - // } - // else if (par.Address.ToUpper().Contains("VW")) - // { - // readData = modbusTcp.Read(address, CommandType.HoldingRegisters, par.Length); - // } - // callBack?.Invoke(readData); - //}); - //写入数据 EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { @@ -107,15 +50,6 @@ namespace BPASmartClient.PLC var par = @event as WriteModel; modbusTcp.Write(par?.Address, par?.Value); - //ushort address = (ushort)modbusTcp.GetAddress(par?.Address); - //if (par.Address.ToUpper().Contains("M")) - //{ - // modbusTcp.Write(address, CommandType.Coils, par.Value); - //} - //else if (par.Address.ToUpper().Contains("VW")) - //{ - // modbusTcp.Write(address, CommandType.HoldingRegisters, par.Value); - //} }); } diff --git a/BPASmartClient.Model/KeepDataBase.cs b/BPASmartClient.Model/KeepDataBase.cs index 839db8bb..410020ab 100644 --- a/BPASmartClient.Model/KeepDataBase.cs +++ b/BPASmartClient.Model/KeepDataBase.cs @@ -26,7 +26,7 @@ namespace BPASmartClient.Model /// /// 参数设置 /// - public ObservableCollection parSets { get; set; } = new ObservableCollection(); + //public ObservableCollection parSets { get; set; } = new ObservableCollection(); } } diff --git a/BPASmartClient.Model/ParSet.cs b/BPASmartClient.Model/ParSet.cs index 03261db1..8fb4611b 100644 --- a/BPASmartClient.Model/ParSet.cs +++ b/BPASmartClient.Model/ParSet.cs @@ -1,29 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; -namespace BPASmartClient.Model -{ - public class ParSet - { - public ushort Minute { get { return _mMinute; } set { _mMinute = value; } } - private ushort _mMinute; +//namespace BPASmartClient.Model +//{ +// public class ParSet +// { +// public ushort Minute { get { return _mMinute; } set { _mMinute = value; } } +// private ushort _mMinute; - public ushort Second { get { return _mSecond; } set { _mSecond = value; } } - private ushort _mSecond; +// public ushort Second { get { return _mSecond; } set { _mSecond = value; } } +// private ushort _mSecond; - public bool IsShield { get { return _mIsShield; } set { _mIsShield = value; } } - private bool _mIsShield; +// public bool IsShield { get { return _mIsShield; } set { _mIsShield = value; } } +// private bool _mIsShield; - public string TextBlockContext { get { return _mTextBlockContext; } set { _mTextBlockContext = value; } } - private string _mTextBlockContext; +// public string TextBlockContext { get { return _mTextBlockContext; } set { _mTextBlockContext = value; } } +// private string _mTextBlockContext; - public string CheckBoxContext { get { return _mCheckBoxContext; } set { _mCheckBoxContext = value; } } - private string _mCheckBoxContext; +// public string CheckBoxContext { get { return _mCheckBoxContext; } set { _mCheckBoxContext = value; } } +// private string _mCheckBoxContext; - } -} +// } +//} diff --git a/BPASmartClient.MorkS/Control_Morks.cs b/BPASmartClient.MorkS/Control_Morks.cs index 986ed962..7825f92b 100644 --- a/BPASmartClient.MorkS/Control_Morks.cs +++ b/BPASmartClient.MorkS/Control_Morks.cs @@ -14,6 +14,8 @@ using System.Linq; using BPASmartClient.Model.PLC; using System.Threading.Tasks; using System.Reflection; +using BPASmartClient.MorkS.Model; +using System.Collections.ObjectModel; namespace BPASmartClient.MorkS { @@ -27,6 +29,33 @@ namespace BPASmartClient.MorkS { ServerInit(); DataParse(); + + Json.Read(); + if (Json.Data.parSets == null) Json.Data.parSets = new ObservableCollection(); + if (Json.Data.parSets.Count < 6) + { + Json.Data.parSets.Clear(); + for (int i = 0; i < 6; i++) + { + Json.Data.parSets.Add(new ParSet() + { + CheckBoxContext = $"煮面口{i + 1}屏蔽", + Minute = 1, + Second = 0, + IsShield = false, + TextBlockContext = $"煮面口{i + 1}时间设定" + }); + } + } + + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); + }), "WriteVW"); + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); + }), "WriteBools"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice"); } diff --git a/BPASmartClient.MorkS/Model/MorksPar.cs b/BPASmartClient.MorkS/Model/MorksPar.cs new file mode 100644 index 00000000..ed3c049c --- /dev/null +++ b/BPASmartClient.MorkS/Model/MorksPar.cs @@ -0,0 +1,15 @@ +using BPASmartClient.Model; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkS.Model +{ + internal class MorksPar + { + public ObservableCollection parSets { get; set; } = new ObservableCollection(); + } +} diff --git a/BPASmartClient.MorkS/Model/ParSet.cs b/BPASmartClient.MorkS/Model/ParSet.cs new file mode 100644 index 00000000..03261db1 --- /dev/null +++ b/BPASmartClient.MorkS/Model/ParSet.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class ParSet + { + public ushort Minute { get { return _mMinute; } set { _mMinute = value; } } + private ushort _mMinute; + + public ushort Second { get { return _mSecond; } set { _mSecond = value; } } + private ushort _mSecond; + + + public bool IsShield { get { return _mIsShield; } set { _mIsShield = value; } } + private bool _mIsShield; + + + public string TextBlockContext { get { return _mTextBlockContext; } set { _mTextBlockContext = value; } } + private string _mTextBlockContext; + + public string CheckBoxContext { get { return _mCheckBoxContext; } set { _mCheckBoxContext = value; } } + private string _mCheckBoxContext; + + } +} diff --git a/BPASmartClient.MorkS/Model/WritePar.cs b/BPASmartClient.MorkS/Model/WritePar.cs new file mode 100644 index 00000000..2b7f1bdd --- /dev/null +++ b/BPASmartClient.MorkS/Model/WritePar.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.MorkS.Model +{ + public class WritePar + { + public string Address { get; set; } + public object Value { get; set; } + } +} diff --git a/BPASmartClient.MorkS/View/ParSet.xaml b/BPASmartClient.MorkS/View/ParSet.xaml index 9222bf3f..123c8b08 100644 --- a/BPASmartClient.MorkS/View/ParSet.xaml +++ b/BPASmartClient.MorkS/View/ParSet.xaml @@ -46,28 +46,11 @@ - - - - + diff --git a/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs b/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs index e132e782..f45648f2 100644 --- a/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs +++ b/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs @@ -1,8 +1,12 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using BPASmartClient.Helper; +using BPASmartClient.Model; +using BPASmartClient.MorkS.Model; using Microsoft.Toolkit.Mvvm.ComponentModel; namespace BPASmartClient.MorkS.ViewModel @@ -11,7 +15,29 @@ namespace BPASmartClient.MorkS.ViewModel { public ParSetViewModel() { + SaveInfoCommand = new Action(() => + { + List values = new List(); + values.Clear(); + List bools = new List(); + bools.Clear(); + + for (int i = 0; i < Json.Data.parSets.Count; i++) + { + values.Clear(); + values.Add(Json.Data.parSets[i].Minute); + values.Add(Json.Data.parSets[i].Second); + bools.Add(Json.Data.parSets[i].IsShield); + ActionManage.GetInstance.Send("WriteVW", new WritePar() { Address = $"VW{116 + (i * 6)}", Value = values.ToArray() }); + } + ActionManage.GetInstance.Send("WriteBools", new WritePar() { Address = "M260.0", Value = bools.ToArray() }); + Json.Save(); + }); } + + public Action SaveInfoCommand { get; set; } + + public ObservableCollection parSets { get; set; } = Json.Data.parSets; } } diff --git a/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs b/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs index f26722a7..97765523 100644 --- a/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs +++ b/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs @@ -68,6 +68,24 @@ namespace BPASmartClient.ViewModel } } } + if (Devices.Count > 0) + { + Devices.ElementAt(0).IsChecked = true; + DeviceMonitors.Clear(); + Assembly.Load(Devices.ElementAt(0).Namespace.Substring(0, Devices.ElementAt(0).Namespace.LastIndexOf("."))).GetTypes().ToList().ForEach((type) => + { + if (type?.BaseType?.Name == "UserControl") + { + var fe = type.GetConstructor(Type.EmptyTypes).Invoke(null) as FrameworkElement; + DeviceMonitors.Add(new Device() { Name = fe.Name, Namespace = type?.FullName, fe = fe }); + } + }); + if (DeviceMonitors.Count > 0) + { + DeviceMonitors.ElementAt(0).IsChecked = true; + if (DeviceMonitors.ElementAt(0).fe != null) MainContent = DeviceMonitors.ElementAt(0).fe; + } + } } public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } } @@ -93,7 +111,13 @@ namespace BPASmartClient.ViewModel public string Namespace { get { return _mNamespace; } set { _mNamespace = value; OnPropertyChanged(); } } private string _mNamespace; + + public bool IsChecked { get { return _mIsChecked; } set { _mIsChecked = value; OnPropertyChanged(); } } + private bool _mIsChecked; + + public FrameworkElement fe { get; set; } + } diff --git a/BPASmartClient.ViewModel/SystemSetViewModel.cs b/BPASmartClient.ViewModel/SystemSetViewModel.cs index 7d9817cb..4226b414 100644 --- a/BPASmartClient.ViewModel/SystemSetViewModel.cs +++ b/BPASmartClient.ViewModel/SystemSetViewModel.cs @@ -17,29 +17,29 @@ namespace BPASmartClient.ViewModel { if (SaveInfoCommand == null) { - SaveInfoCommand = new Action(() => - { - List values = new List(); - values.Clear(); + //SaveInfoCommand = new Action(() => + //{ + // List values = new List(); + // values.Clear(); - List bools = new List(); - bools.Clear(); + // List bools = new List(); + // bools.Clear(); - for (int i = 0; i < Json.Data.parSets.Count; i++) - { - values.Clear(); - values.Add(Json.Data.parSets[i].Minute); - values.Add(Json.Data.parSets[i].Second); - bools.Add(Json.Data.parSets[i].IsShield); - //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (i * 6)}"), WriteType.HoldingRegisters, values.ToArray()); - } - //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetBoolAddress("M260.0"), WriteType.Coils, bools.ToArray()); + // for (int i = 0; i < Json.Data.parSets.Count; i++) + // { + // values.Clear(); + // values.Add(Json.Data.parSets[i].Minute); + // values.Add(Json.Data.parSets[i].Second); + // bools.Add(Json.Data.parSets[i].IsShield); + // //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (i * 6)}"), WriteType.HoldingRegisters, values.ToArray()); + // } + // //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetBoolAddress("M260.0"), WriteType.Coils, bools.ToArray()); - }); + //}); } } - public ObservableCollection parSets { get; set; } = Json.Data.parSets; + //public ObservableCollection parSets { get; set; } = Json.Data.parSets; public Action SaveInfoCommand { get; set; } } diff --git a/BPASmartClient/Control/DeviceMonitorView.xaml b/BPASmartClient/Control/DeviceMonitorView.xaml index e95c947c..4496a69a 100644 --- a/BPASmartClient/Control/DeviceMonitorView.xaml +++ b/BPASmartClient/Control/DeviceMonitorView.xaml @@ -81,6 +81,7 @@ CommandParameter="{Binding Namespace}" Content="{Binding Name}" GroupName="Devices" + IsChecked="{Binding IsChecked}" Style="{StaticResource RectangleRadioButtonStyle}" /> @@ -108,6 +109,7 @@ Content="{Binding Name}" FontSize="16" GroupName="DeviceMotion" + IsChecked="{Binding IsChecked}" Style="{StaticResource RectangleLeftRadioButtonStyle}" />