Sfoglia il codice sorgente

参数配置界面优化

样式分支
pry 2 anni fa
parent
commit
ed1a5f3fe8
13 ha cambiato i file con 181 aggiunte e 139 eliminazioni
  1. +2
    -16
      BPASmartClient.Helper/Json.cs
  2. +0
    -66
      BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs
  3. +1
    -1
      BPASmartClient.Model/KeepDataBase.cs
  4. +21
    -21
      BPASmartClient.Model/ParSet.cs
  5. +29
    -0
      BPASmartClient.MorkS/Control_Morks.cs
  6. +15
    -0
      BPASmartClient.MorkS/Model/MorksPar.cs
  7. +29
    -0
      BPASmartClient.MorkS/Model/ParSet.cs
  8. +14
    -0
      BPASmartClient.MorkS/Model/WritePar.cs
  9. +1
    -18
      BPASmartClient.MorkS/View/ParSet.xaml
  10. +26
    -0
      BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs
  11. +24
    -0
      BPASmartClient.ViewModel/DeviceMonitorViewModel.cs
  12. +17
    -17
      BPASmartClient.ViewModel/SystemSetViewModel.cs
  13. +2
    -0
      BPASmartClient/Control/DeviceMonitorView.xaml

+ 2
- 16
BPASmartClient.Helper/Json.cs Vedi File

@@ -11,24 +11,12 @@ namespace BPASmartClient.Helper
/// </summary> /// </summary>
public class Json<T> where T : class, new() 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 static string path
{ {
get 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); File.WriteAllText(path, outjson);
} }




/// <summary> /// <summary>
/// 获取保存的数据 /// 获取保存的数据
/// </summary> /// </summary>


+ 0
- 66
BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs Vedi File

@@ -12,16 +12,8 @@ namespace BPASmartClient.PLC
public class PLCMachine : BasePeripheral public class PLCMachine : BasePeripheral
{ {
ModbusTcp modbusTcp = new ModbusTcp(); 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() public override void Init()
{ {
//plcReadParameters = PLCReadParameter.DeSerialize(PLCReadAddress);

Task.Run(new Action(() => { modbusTcp.ModbusTcpConnect(communicationPar.IPAddress, communicationPar.IPPort); })); //PLC 设备连接 Task.Run(new Action(() => { modbusTcp.ModbusTcpConnect(communicationPar.IPAddress, communicationPar.IPPort); })); //PLC 设备连接


ThreadManage.GetInstance().StartLong(new Action(() => ThreadManage.GetInstance().StartLong(new Action(() =>
@@ -45,61 +37,12 @@ namespace BPASmartClient.PLC
status.TryAdd(par.Address, res); 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(500);
} }
Thread.Sleep(1000); Thread.Sleep(1000);
}), $"设备[{DeviceId}]PLC读取线程", true); }), $"设备[{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) EventBus.EventBus.GetInstance().Subscribe<WriteModel>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
{ {
@@ -107,15 +50,6 @@ namespace BPASmartClient.PLC
var par = @event as WriteModel; var par = @event as WriteModel;


modbusTcp.Write(par?.Address, par?.Value); 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);
//}
}); });
} }




+ 1
- 1
BPASmartClient.Model/KeepDataBase.cs Vedi File

@@ -26,7 +26,7 @@ namespace BPASmartClient.Model
/// <summary> /// <summary>
/// 参数设置 /// 参数设置
/// </summary> /// </summary>
public ObservableCollection<ParSet> parSets { get; set; } = new ObservableCollection<ParSet>();
//public ObservableCollection<ParSet> parSets { get; set; } = new ObservableCollection<ParSet>();


} }
} }

+ 21
- 21
BPASmartClient.Model/ParSet.cs Vedi File

@@ -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;


}
}
// }
//}

+ 29
- 0
BPASmartClient.MorkS/Control_Morks.cs Vedi File

@@ -14,6 +14,8 @@ using System.Linq;
using BPASmartClient.Model.PLC; using BPASmartClient.Model.PLC;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Reflection; using System.Reflection;
using BPASmartClient.MorkS.Model;
using System.Collections.ObjectModel;


namespace BPASmartClient.MorkS namespace BPASmartClient.MorkS
{ {
@@ -27,6 +29,33 @@ namespace BPASmartClient.MorkS
{ {
ServerInit(); ServerInit();
DataParse(); 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"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice");
} }




+ 15
- 0
BPASmartClient.MorkS/Model/MorksPar.cs Vedi File

@@ -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>();
}
}

+ 29
- 0
BPASmartClient.MorkS/Model/ParSet.cs Vedi File

@@ -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;

}
}

+ 14
- 0
BPASmartClient.MorkS/Model/WritePar.cs Vedi File

@@ -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; }
}
}

+ 1
- 18
BPASmartClient.MorkS/View/ParSet.xaml Vedi File

@@ -46,28 +46,11 @@


<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="35" /> <RowDefinition Height="35" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </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="请点击按钮保存参数:" /> <TextBlock Style="{StaticResource TextBlockStyle}" Text="请点击按钮保存参数:" />




+ 26
- 0
BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs Vedi File

@@ -1,8 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using BPASmartClient.MorkS.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.ComponentModel;


namespace BPASmartClient.MorkS.ViewModel namespace BPASmartClient.MorkS.ViewModel
@@ -11,7 +15,29 @@ namespace BPASmartClient.MorkS.ViewModel
{ {
public ParSetViewModel() 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;
} }
} }

+ 24
- 0
BPASmartClient.ViewModel/DeviceMonitorViewModel.cs Vedi File

@@ -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(); } } 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(); } } public string Namespace { get { return _mNamespace; } set { _mNamespace = value; OnPropertyChanged(); } }
private string _mNamespace; private string _mNamespace;



public bool IsChecked { get { return _mIsChecked; } set { _mIsChecked = value; OnPropertyChanged(); } }
private bool _mIsChecked;


public FrameworkElement fe { get; set; } public FrameworkElement fe { get; set; }

} }






+ 17
- 17
BPASmartClient.ViewModel/SystemSetViewModel.cs Vedi File

@@ -17,29 +17,29 @@ namespace BPASmartClient.ViewModel
{ {
if (SaveInfoCommand == null) 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; } public Action SaveInfoCommand { get; set; }


} }


+ 2
- 0
BPASmartClient/Control/DeviceMonitorView.xaml Vedi File

@@ -81,6 +81,7 @@
CommandParameter="{Binding Namespace}" CommandParameter="{Binding Namespace}"
Content="{Binding Name}" Content="{Binding Name}"
GroupName="Devices" GroupName="Devices"
IsChecked="{Binding IsChecked}"
Style="{StaticResource RectangleRadioButtonStyle}" /> Style="{StaticResource RectangleRadioButtonStyle}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
@@ -108,6 +109,7 @@
Content="{Binding Name}" Content="{Binding Name}"
FontSize="16" FontSize="16"
GroupName="DeviceMotion" GroupName="DeviceMotion"
IsChecked="{Binding IsChecked}"
Style="{StaticResource RectangleLeftRadioButtonStyle}" /> Style="{StaticResource RectangleLeftRadioButtonStyle}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>


Caricamento…
Annulla
Salva