From 5ecd3171621191041cd55c0a4048b1efd3367d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Fri, 16 Sep 2022 15:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9D=80=E6=95=B0=E6=8D=AE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommDeviceModel/AddressConvert.cs | 32 +++++++++++++------ BPASmart.Model/Enums/EDataType.cs | 4 ++- BPASmart.Model/GlobalVar.cs | 13 ++++++++ BPASmart.Model/PlcConvertModel.cs | 14 ++++++++ BPASmart.Model/VariableInfo.cs | 10 ++---- BPASmart.VariableManager/App.xaml.cs | 20 ++++++------ .../ViewModels/VariableConfigViewModel.cs | 1 + .../Views/VariableConfig.xaml | 5 ++- .../Views/VariableConfig.xaml.cs | 14 ++++++++ BPASmartClient/App.config | 12 +++---- ComputerTestDemo/Form1.cs | 13 +++++++- 11 files changed, 102 insertions(+), 36 deletions(-) create mode 100644 BPASmart.Model/GlobalVar.cs create mode 100644 BPASmart.Model/PlcConvertModel.cs diff --git a/BPASmart.Model/CommDeviceModel/AddressConvert.cs b/BPASmart.Model/CommDeviceModel/AddressConvert.cs index 6341bd09..f410fa7a 100644 --- a/BPASmart.Model/CommDeviceModel/AddressConvert.cs +++ b/BPASmart.Model/CommDeviceModel/AddressConvert.cs @@ -12,19 +12,22 @@ namespace BPASmart.Model public static AddressConvert GetInstance => _Instance ?? (_Instance = new AddressConvert()); private AddressConvert() { } - public string PlcConverter(ICommunicationDevice device, string Address) + public PlcConvertModel PlcConverter(ICommunicationDevice device, string Address) { - string address = string.Empty; - //if (Address != null && int.TryParse(Address, out int result)) return result; + PlcConvertModel plcConvertModel = new PlcConvertModel(); if (device != null && Address != null && Address.Length > 0) { switch (device) { case Invoance _tempInvoance: - if (Address.ToUpper().Contains("LW") && Address.Length >= 3) + if (Address.ToUpper().Contains("D") && Address.Length >= 3) { var res = Address.Substring(2); - if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress.ToString(); + if (res != null && int.TryParse(res, out int LwAddress)) + { + plcConvertModel.Address = LwAddress.ToString(); + plcConvertModel.DataType = EDataType.Word.ToString(); + } } break; case kinco _tempKinco: @@ -37,7 +40,8 @@ namespace BPASmart.Model { if (ExitAddress >= 0 && ExitAddress <= 7) { - return ((firstAddress * 8) + 320 + ExitAddress).ToString(); + plcConvertModel.Address = ((firstAddress * 8) + 320 + ExitAddress).ToString(); + plcConvertModel.DataType = EDataType.Bool.ToString(); } } } @@ -45,21 +49,29 @@ namespace BPASmart.Model else if ((Address.ToUpper().Contains("VW") || Address.ToUpper().Contains("VD")) && Address.Length >= 3) { var res = Address.Substring(2); - if (res != null && int.TryParse(res, out int tempAddress)) return ((tempAddress / 2) + 100).ToString(); + if (res != null && int.TryParse(res, out int tempAddress)) + { + plcConvertModel.Address = ((tempAddress / 2) + 100).ToString(); + plcConvertModel.DataType = Address.ToUpper().Contains("VW") ? EDataType.Word.ToString() : EDataType.Dword.ToString(); + } } break; case KincoOneMachine _tempKincoOneMachine: - if (Address.ToUpper().Contains("D") && Address.Length >= 2) + if (Address.ToUpper().Contains("LW") && Address.Length >= 2) { var res = Address.Substring(1); - if (res != null && int.TryParse(res, out int LwAddress)) return LwAddress.ToString(); + if (res != null && int.TryParse(res, out int LwAddress)) + { + plcConvertModel.Address = LwAddress.ToString(); + plcConvertModel.DataType = EDataType.Word.ToString(); + } } break; default: break; } } - return address; + return plcConvertModel; } } diff --git a/BPASmart.Model/Enums/EDataType.cs b/BPASmart.Model/Enums/EDataType.cs index 463447a4..ff7c2aab 100644 --- a/BPASmart.Model/Enums/EDataType.cs +++ b/BPASmart.Model/Enums/EDataType.cs @@ -17,6 +17,8 @@ namespace BPASmart.Model Word = 4, Dint = 5, Dword = 6, - Float = 7 + Float = 7, + Double = 8, + String = 9, } } diff --git a/BPASmart.Model/GlobalVar.cs b/BPASmart.Model/GlobalVar.cs new file mode 100644 index 00000000..3b1f1532 --- /dev/null +++ b/BPASmart.Model/GlobalVar.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model +{ + public class GlobalVar + { + public static ICommunicationDevice DeviceType { get; set; } + } +} diff --git a/BPASmart.Model/PlcConvertModel.cs b/BPASmart.Model/PlcConvertModel.cs new file mode 100644 index 00000000..696595e8 --- /dev/null +++ b/BPASmart.Model/PlcConvertModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmart.Model +{ + public class PlcConvertModel + { + public string Address { get; set; } = string.Empty; + public string DataType { get; set; } = string.Empty; + } +} diff --git a/BPASmart.Model/VariableInfo.cs b/BPASmart.Model/VariableInfo.cs index c28faa26..c1f99811 100644 --- a/BPASmart.Model/VariableInfo.cs +++ b/BPASmart.Model/VariableInfo.cs @@ -17,13 +17,8 @@ namespace BPASmart.Model { public class VariableInfo : AlarmSet { - private ICommunicationDevice DeviceType = new kinco(); public VariableInfo(params object[] s) { - if (s != null && s.Length >= 0) - { - DeviceType = s[0] as ICommunicationDevice; - } CancelCommand = new RelayCommand(() => { IsOpen = false; }); ConfirmCommand = new RelayCommand(() => { IsOpen = false; }); } @@ -56,8 +51,9 @@ namespace BPASmart.Model { _mAddress = value; OnPropertyChanged(); - string address = AddressConvert.GetInstance.PlcConverter(DeviceType, value); - if (address.Length > 0) RealAddress = address; + var address = AddressConvert.GetInstance.PlcConverter(GlobalVar.DeviceType, value); + if (address.Address.Length > 0) RealAddress = address.Address; + if (DataType.Length <= 0) DataType = address.DataType; } } private string _mAddress = string.Empty; diff --git a/BPASmart.VariableManager/App.xaml.cs b/BPASmart.VariableManager/App.xaml.cs index a27ae676..1d08a174 100644 --- a/BPASmart.VariableManager/App.xaml.cs +++ b/BPASmart.VariableManager/App.xaml.cs @@ -112,16 +112,16 @@ namespace BPASmart.VariableManager private void DataSave() { - for (int i = 0; i < Json.Data.CommunicationDevices.Count; i++) - { - for (int m = 0; m < Json.Data.CommunicationDevices.ElementAt(i).VarTableModels.Count; m++) - { - var deviceType = Json.Data.CommunicationDevices.ElementAt(i).CommDevice; - var deviceValue = Json.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).Address; - string RealAddress = AddressConvert.GetInstance.PlcConverter(deviceType, deviceValue); - Json.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).RealAddress = RealAddress; - } - } + //for (int i = 0; i < Json.Data.CommunicationDevices.Count; i++) + //{ + // for (int m = 0; m < Json.Data.CommunicationDevices.ElementAt(i).VarTableModels.Count; m++) + // { + // var deviceType = Json.Data.CommunicationDevices.ElementAt(i).CommDevice; + // var deviceValue = Json.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).Address; + // string RealAddress = AddressConvert.GetInstance.PlcConverter(deviceType, deviceValue); + // Json.Data.CommunicationDevices.ElementAt(i).VarTableModels.ElementAt(m).RealAddress = RealAddress; + // } + //} Json.Save(); } diff --git a/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs b/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs index 1c5ba606..780f30a5 100644 --- a/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs +++ b/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs @@ -73,6 +73,7 @@ namespace BPASmart.VariableManager.ViewModels if (varialeInfosIndex >= 0 && varialeInfosIndex < Json.Data.CommunicationDevices.Count) { DeviceType = Json.Data.CommunicationDevices.ElementAt(varialeInfosIndex).CommDevice; + GlobalVar.DeviceType = DeviceType; varialeInfos = Json.Data.CommunicationDevices.ElementAt(varialeInfosIndex).VarTableModels; if (varialeInfos.Count <= 0) AddRow(); } diff --git a/BPASmart.VariableManager/Views/VariableConfig.xaml b/BPASmart.VariableManager/Views/VariableConfig.xaml index 5954c15d..bf1ddc19 100644 --- a/BPASmart.VariableManager/Views/VariableConfig.xaml +++ b/BPASmart.VariableManager/Views/VariableConfig.xaml @@ -272,11 +272,12 @@ Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}" Text="{Binding ID}" /> - + diff --git a/BPASmart.VariableManager/Views/VariableConfig.xaml.cs b/BPASmart.VariableManager/Views/VariableConfig.xaml.cs index 6c9b2b45..8d7a207b 100644 --- a/BPASmart.VariableManager/Views/VariableConfig.xaml.cs +++ b/BPASmart.VariableManager/Views/VariableConfig.xaml.cs @@ -63,5 +63,19 @@ namespace BPASmart.VariableManager.Views } } + + private void TextBox_KeyDown(object sender, KeyEventArgs e) + { + var uie = e.OriginalSource as TextBox; + if (uie != null) + { + if (e.Key == Key.Enter) + { + uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); + e.Handled = true; + } + } + + } } } diff --git a/BPASmartClient/App.config b/BPASmartClient/App.config index 76a86418..d4a266c7 100644 --- a/BPASmartClient/App.config +++ b/BPASmartClient/App.config @@ -7,19 +7,19 @@ - + - - - + + diff --git a/ComputerTestDemo/Form1.cs b/ComputerTestDemo/Form1.cs index e0d01b2b..993cf669 100644 --- a/ComputerTestDemo/Form1.cs +++ b/ComputerTestDemo/Form1.cs @@ -12,6 +12,8 @@ namespace ComputerTestDemo public Form1() { InitializeComponent(); + bool[] cct = new bool[120]; + GetData(cct); textBox1.Enabled = false; button1.Enabled = false; Json.Read(); @@ -23,8 +25,17 @@ namespace ComputerTestDemo })); } - private TResult GetData() + private TResult GetData(TResult tc) { + + if (tc is Array tt) + { + var len = tt.Length; + var va = tt.GetValue(0); + } + + + Type type = typeof(TResult); var name = type.Name; Debug.WriteLine(name);