@@ -11,24 +11,12 @@ namespace BPASmartClient.Helper | |||
/// </summary> | |||
public class Json<T> 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); | |||
} | |||
/// <summary> | |||
/// 获取保存的数据 | |||
/// </summary> | |||
@@ -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<PLCReadParameter> 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<bool[]>((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<bool[]>((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<ReadModel>(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<bool[]>((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<WriteModel>(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); | |||
//} | |||
}); | |||
} | |||
@@ -26,7 +26,7 @@ namespace BPASmartClient.Model | |||
/// <summary> | |||
/// 参数设置 | |||
/// </summary> | |||
public ObservableCollection<ParSet> parSets { get; set; } = new ObservableCollection<ParSet>(); | |||
//public ObservableCollection<ParSet> parSets { get; set; } = new ObservableCollection<ParSet>(); | |||
} | |||
} |
@@ -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; | |||
} | |||
} | |||
// } | |||
//} |
@@ -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<MorksPar>.Read(); | |||
if (Json<MorksPar>.Data.parSets == null) Json<MorksPar>.Data.parSets = new ObservableCollection<ParSet>(); | |||
if (Json<MorksPar>.Data.parSets.Count < 6) | |||
{ | |||
Json<MorksPar>.Data.parSets.Clear(); | |||
for (int i = 0; i < 6; i++) | |||
{ | |||
Json<MorksPar>.Data.parSets.Add(new ParSet() | |||
{ | |||
CheckBoxContext = $"煮面口{i + 1}屏蔽", | |||
Minute = 1, | |||
Second = 0, | |||
IsShield = false, | |||
TextBlockContext = $"煮面口{i + 1}时间设定" | |||
}); | |||
} | |||
} | |||
ActionManage.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); | |||
}), "WriteVW"); | |||
ActionManage.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); | |||
}), "WriteBools"); | |||
ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice"); | |||
} | |||
@@ -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<ParSet> parSets { get; set; } = new ObservableCollection<ParSet>(); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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; } | |||
} | |||
} |
@@ -46,28 +46,11 @@ | |||
<Grid Margin="10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="40" /> | |||
<RowDefinition Height="35" /> | |||
<RowDefinition Height="Auto" /> | |||
</Grid.RowDefinitions> | |||
<CheckBox | |||
Grid.Row="0" | |||
Grid.Column="2" | |||
Height="20" | |||
Margin="10" | |||
VerticalAlignment="Top" | |||
Background="#FF2AB2E7" | |||
Content="开机启动" | |||
FontSize="14" | |||
Foreground="#00c2f4" | |||
IsChecked="{Binding IsSelected}" | |||
Template="{StaticResource CbTemplate}" /> | |||
<StackPanel | |||
Grid.Row="1" | |||
HorizontalAlignment="Right" | |||
Orientation="Horizontal"> | |||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal"> | |||
<TextBlock Style="{StaticResource TextBlockStyle}" Text="请点击按钮保存参数:" /> | |||
@@ -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<ushort> values = new List<ushort>(); | |||
values.Clear(); | |||
List<bool> bools = new List<bool>(); | |||
bools.Clear(); | |||
for (int i = 0; i < Json<MorksPar>.Data.parSets.Count; i++) | |||
{ | |||
values.Clear(); | |||
values.Add(Json<MorksPar>.Data.parSets[i].Minute); | |||
values.Add(Json<MorksPar>.Data.parSets[i].Second); | |||
bools.Add(Json<MorksPar>.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<MorksPar>.Save(); | |||
}); | |||
} | |||
public Action SaveInfoCommand { get; set; } | |||
public ObservableCollection<ParSet> parSets { get; set; } = Json<MorksPar>.Data.parSets; | |||
} | |||
} |
@@ -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; } | |||
} | |||
@@ -17,29 +17,29 @@ namespace BPASmartClient.ViewModel | |||
{ | |||
if (SaveInfoCommand == null) | |||
{ | |||
SaveInfoCommand = new Action(() => | |||
{ | |||
List<ushort> values = new List<ushort>(); | |||
values.Clear(); | |||
//SaveInfoCommand = new Action(() => | |||
//{ | |||
// List<ushort> values = new List<ushort>(); | |||
// values.Clear(); | |||
List<bool> bools = new List<bool>(); | |||
bools.Clear(); | |||
// List<bool> bools = new List<bool>(); | |||
// bools.Clear(); | |||
for (int i = 0; i < Json<KeepDataBase>.Data.parSets.Count; i++) | |||
{ | |||
values.Clear(); | |||
values.Add(Json<KeepDataBase>.Data.parSets[i].Minute); | |||
values.Add(Json<KeepDataBase>.Data.parSets[i].Second); | |||
bools.Add(Json<KeepDataBase>.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<KeepDataBase>.Data.parSets.Count; i++) | |||
// { | |||
// values.Clear(); | |||
// values.Add(Json<KeepDataBase>.Data.parSets[i].Minute); | |||
// values.Add(Json<KeepDataBase>.Data.parSets[i].Second); | |||
// bools.Add(Json<KeepDataBase>.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<ParSet> parSets { get; set; } = Json<KeepDataBase>.Data.parSets; | |||
//public ObservableCollection<ParSet> parSets { get; set; } = Json<KeepDataBase>.Data.parSets; | |||
public Action SaveInfoCommand { get; set; } | |||
} | |||
@@ -81,6 +81,7 @@ | |||
CommandParameter="{Binding Namespace}" | |||
Content="{Binding Name}" | |||
GroupName="Devices" | |||
IsChecked="{Binding IsChecked}" | |||
Style="{StaticResource RectangleRadioButtonStyle}" /> | |||
</Grid> | |||
</DataTemplate> | |||
@@ -108,6 +109,7 @@ | |||
Content="{Binding Name}" | |||
FontSize="16" | |||
GroupName="DeviceMotion" | |||
IsChecked="{Binding IsChecked}" | |||
Style="{StaticResource RectangleLeftRadioButtonStyle}" /> | |||
</Grid> | |||
</DataTemplate> | |||