From eaf9d14a343b0a16f5d01c78882c84dec4840d01 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: Mon, 12 Sep 2022 16:15:48 +0800
Subject: [PATCH] =?UTF-8?q?redis=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BPASmart.Server/BPASmart.Server.csproj | 3 +-
BPASmart.Server/CommunicationServer.cs | 21 +-
.../BPASmart.VariableManager.csproj | 4 +
.../ViewModels/VariableConfigViewModel.cs | 218 +++++++++++++++---
.../Views/VariableConfig.xaml | 3 +-
.../RecDictionarys/RecComboBox.xaml | 4 +-
Communication/Communication.csproj | 17 ++
Communication/RedisHelper.cs | 60 +++++
SmartClient.sln | 29 ++-
9 files changed, 313 insertions(+), 46 deletions(-)
create mode 100644 Communication/Communication.csproj
create mode 100644 Communication/RedisHelper.cs
diff --git a/BPASmart.Server/BPASmart.Server.csproj b/BPASmart.Server/BPASmart.Server.csproj
index 46e749d2..3a6a8072 100644
--- a/BPASmart.Server/BPASmart.Server.csproj
+++ b/BPASmart.Server/BPASmart.Server.csproj
@@ -7,13 +7,14 @@
-
+
+
diff --git a/BPASmart.Server/CommunicationServer.cs b/BPASmart.Server/CommunicationServer.cs
index 2c3e80f3..0fb7173e 100644
--- a/BPASmart.Server/CommunicationServer.cs
+++ b/BPASmart.Server/CommunicationServer.cs
@@ -2,6 +2,7 @@
using BPA.Helper;
using BPA.Communication;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
+using Communication;
namespace BPASmart.Server
{
@@ -10,21 +11,17 @@ namespace BPASmart.Server
public void Init()
{
BPASmartClient.Message.MessageLog.GetInstance.ShowDebugLog("通讯模块初始化");
-
+ RedisHelper.GetInstance.Connect();
Json.Data.CommunicationDevices.ToList()?.ForEach(item =>
{
- #region 数据加载测试
-
- #endregion
-
ThreadManage.GetInstance().Start(new Action(() =>
{
switch (item.CommDevice)
{
- case ModbusRtu _modbusRtu:
+ case BPASmart.Model.ModbusRtu _modbusRtu:
break;
- case ModbusTcp _modbusTcp:
- ModbusTcpMaster modbusTcpMaster = new ModbusTcpMaster();
+ case BPASmart.Model.ModbusTcp _modbusTcp:
+ BPA.Communication.ModbusTcp modbusTcpMaster = new BPA.Communication.ModbusTcp();
modbusTcpMaster.ConnectOk = new Action(() =>
{
ThreadManage.GetInstance().StartLong(new Action(() =>
@@ -77,9 +74,9 @@ namespace BPASmart.Server
var DeviceModel = item;
});
modbusTcpMaster.IsReconnect = true;
- modbusTcpMaster.ModbusTcpConnect(DeviceType.kinco_PLC, _modbusTcp.IP, _modbusTcp.PortNum);
+ modbusTcpMaster.ModbusTcpConnect(_modbusTcp.IP, _modbusTcp.PortNum);
break;
- case Siemens _siemens:
+ case BPASmart.Model.Siemens _siemens:
break;
default:
break;
@@ -104,6 +101,10 @@ namespace BPASmart.Server
int varIndex = Array.FindIndex(tempArray, p => p.RealAddress == readDataModel.StartAddress + (i * by));
if (varIndex >= 0 && varIndex < tempArray.Length)
{
+ var Devicename = Json.Data.CommunicationDevices[index].DeviceName;
+ var varname = Json.Data.CommunicationDevices[index].VarTableModels[varIndex].VarName;
+ RedisHelper.GetInstance.SetValue($"{Devicename}.{varname}", arrays[i]);
+
Json.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays[i].ToString();
}
}
diff --git a/BPASmart.VariableManager/BPASmart.VariableManager.csproj b/BPASmart.VariableManager/BPASmart.VariableManager.csproj
index 159b08a7..222669ea 100644
--- a/BPASmart.VariableManager/BPASmart.VariableManager.csproj
+++ b/BPASmart.VariableManager/BPASmart.VariableManager.csproj
@@ -28,6 +28,10 @@
+
+
+
+
diff --git a/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs b/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
index c6aea29c..8c923cd0 100644
--- a/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
+++ b/BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
@@ -14,6 +14,8 @@ using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Ubiety.Dns.Core.Records;
using System.Windows;
+using BPA.Communication;
+using System.Threading;
namespace BPASmart.VariableManager.ViewModels
{
@@ -22,6 +24,50 @@ namespace BPASmart.VariableManager.ViewModels
private int varialeInfosIndex = -1;
ICommunicationDevice DeviceType;
public VariableConfigViewModel(string o)
+ {
+ DataInit(o);
+ VarNameChanged();
+ StartMotionCommand = new RelayCommand(() =>
+ {
+ switch (ButtonContext)
+ {
+ case "开始监控":
+ TabName = "当前值";
+ CurrentVisibility = Visibility.Visible;
+ RemoveButVisiblity = Visibility.Collapsed;
+ ButtonContext = "停止监控";
+ IsEnable = false;
+ Motion();
+ break;
+ case "停止监控":
+ TabName = "操作";
+ CurrentVisibility = Visibility.Collapsed;
+ RemoveButVisiblity = Visibility.Visible;
+ ButtonContext = "开始监控";
+ IsEnable = true;
+ ThreadManage.GetInstance().StopTask($"{DeviceType} 初始化连接");
+ ThreadManage.GetInstance().StopTask($"{DeviceType} 设备数据采集");
+ break;
+ default:
+ break;
+ }
+
+ });
+
+ RemoveCommand = new RelayCommand