diff --git a/BPASmartClient.Business/InternetInfo.cs b/BPASmartClient.Business/InternetInfo.cs
index 8e35a266..8f007d09 100644
--- a/BPASmartClient.Business/InternetInfo.cs
+++ b/BPASmartClient.Business/InternetInfo.cs
@@ -59,6 +59,21 @@ namespace BPASmartClient.Business
/// 是否启用测试模式
///
public static bool IsEnableTest { get; set; }
+
+ ///
+ /// 大屏地址
+ ///
+ public static string DataVApiAddress { get; set; }
+
+ ///
+ /// 大屏主题
+ ///
+ public static string BroadcastPubTopic { get; set; }
+
+ ///
+ /// 物料管理地址
+ ///
+ public static string WebServiceUri { get; set; }
#endregion
}
diff --git a/BPASmartClient.Business/Plugin/ConfigMgr.cs b/BPASmartClient.Business/Plugin/ConfigMgr.cs
index a877e591..dd49de63 100644
--- a/BPASmartClient.Business/Plugin/ConfigMgr.cs
+++ b/BPASmartClient.Business/Plugin/ConfigMgr.cs
@@ -26,6 +26,10 @@ namespace BPASmartClient.Business
///
public MQTT_Entity MQTT_Config { get; set; }
+ public MQTT_Account Mqtt_Account { get; set; }
+
+ public UriConfig uriConfig { get; set; }
+
//Apollo地址
private string apolloUri;
private string apoid;
@@ -42,11 +46,11 @@ namespace BPASmartClient.Business
apolloUri = System.Configuration.ConfigurationManager.AppSettings["ApolloUri"].ToString();
apoid = System.Configuration.ConfigurationManager.AppSettings["AppId"].ToString();
namespa = System.Configuration.ConfigurationManager.AppSettings["Namespaces"].ToString();
- InternetInfo.OrderServer = System.Configuration.ConfigurationManager.AppSettings["OrderServiceUri"].ToString();
- InternetInfo.StockServer = System.Configuration.ConfigurationManager.AppSettings["StockServiceUri"].ToString();
+ //InternetInfo.OrderServer = System.Configuration.ConfigurationManager.AppSettings["OrderServiceUri"].ToString();
+ //InternetInfo.StockServer = System.Configuration.ConfigurationManager.AppSettings["StockServiceUri"].ToString();
InternetInfo.IsEnableTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["IsEnableTest"].ToString());
InitDeviceModel();
- InitMQTT();
+ InitConfig();
}
public List GetDeviceConfigs()
@@ -132,30 +136,45 @@ namespace BPASmartClient.Business
///
/// 加载MQTT配置
///
- private void InitMQTT()
+ //private void InitMQTT()
+ //{
+ // IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());
+ // configurationBuilder.AddApolloConfiguration(p =>
+ // {
+ // p.AppId = apoid;
+ // p.MetaServer = apolloUri;
+ // p.Namespaces = new List() { namespa };
+ // });
+
+ // IConfiguration config = configurationBuilder.Build();
+ // var mqttBroker = config.GetSection("BrokerHostSettings");
+ // MQTT_Config = mqttBroker.Value.FromJSON();
+ // if (MQTT_Config == null) MessageLog.GetInstance.Show("获取配置数据为空!");
+ //}
+
+ public void InitConfig()
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());
-
- //测试版本
- //configurationBuilder.AddApolloConfiguration(p =>
- // {
- // p.AppId = "dev1_order";
- // p.MetaServer = apolloUri;
- // p.Namespaces = new List() { "DEV.Config" };
- // });
-
- //正式版本
configurationBuilder.AddApolloConfiguration(p =>
{
- p.AppId = apoid;
+ p.AppId = "HostComputer";
p.MetaServer = apolloUri;
- p.Namespaces = new List() { namespa };
+ p.Namespaces = new List() { "application", namespa };
});
IConfiguration config = configurationBuilder.Build();
- var mqttBroker = config.GetSection("BrokerHostSettings");
- MQTT_Config = mqttBroker.Value.FromJSON();
- if (MQTT_Config == null) MessageLog.GetInstance.Show("获取配置数据为空!");
+ MQTT_Config = config.GetSection("BrokerHostSettings").Value.FromJSON();
+ Mqtt_Account = config.GetSection("MqttAccount").Value.FromJSON();
+ uriConfig = config.GetSection("URL").Value.FromJSON();
+ if (uriConfig != null)
+ {
+ InternetInfo.OrderServer = uriConfig.OrderServiceUrl;
+ InternetInfo.StockServer = uriConfig.StockServiceUrl;
+ InternetInfo.BroadcastPubTopic = uriConfig.BroadcastPubTopic;
+ InternetInfo.DataVApiAddress = uriConfig.DataVServiceUrl;
+ InternetInfo.WebServiceUri = uriConfig.WebServiceUrl;
+ ActionManage.GetInstance.Send("配置初始化完成Iot启动");
+ }
}
public void Start()
@@ -167,5 +186,20 @@ namespace BPASmartClient.Business
public string Host { get; set; }
public int Port { get; set; }
}
+
+ public class MQTT_Account
+ {
+ public string UserName { get; set; }
+ public string Password { get; set; }
+ }
+
+ public class UriConfig
+ {
+ public string OrderServiceUrl { get; set; }
+ public string StockServiceUrl { get; set; }
+ public string DataVServiceUrl { get; set; }
+ public string WebServiceUrl { get; set; }
+ public string BroadcastPubTopic { get; set; }
+ }
}
}
\ No newline at end of file
diff --git a/BPASmartClient.Business/Plugin/MQTTMgr.cs b/BPASmartClient.Business/Plugin/MQTTMgr.cs
index 1585d54a..9dbb18f7 100644
--- a/BPASmartClient.Business/Plugin/MQTTMgr.cs
+++ b/BPASmartClient.Business/Plugin/MQTTMgr.cs
@@ -46,6 +46,7 @@ namespace BPASmartClient.Business
mqttProxy.Connected = new Action(() =>
{
mqttProxy.Subscrib(TopicDefine.GetInstance().SubscribTopics.ToArray());
+ MessageLog.GetInstance.Show("MQTT 连接成功");
});
//MQTT 连接成功
mqttProxy.LostConnect = new Action(() =>
@@ -57,10 +58,10 @@ namespace BPASmartClient.Business
{
msg.Enqueue(message);
});
- MessageLog.GetInstance.Show("准备连接MQTT");
+ var MqttServerConfig = Plugin.GetInstance().GetPlugin().MQTT_Config;
+ var MqttServerAccount = Plugin.GetInstance().GetPlugin().Mqtt_Account;
//MQTT 初始化
- mqttProxy.Connect(Plugin.GetInstance().GetPlugin().MQTT_Config.Host, Plugin.GetInstance().GetPlugin().MQTT_Config.Port,
- Guid.NewGuid().ToString());
+ mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, Guid.NewGuid().ToString());
ThreadManage.GetInstance().Start(() =>
{
diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs
index 5bad77e9..6cbd9d5f 100644
--- a/BPASmartClient.Device/BaseDevice.cs
+++ b/BPASmartClient.Device/BaseDevice.cs
@@ -12,6 +12,7 @@ using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using System.Collections.ObjectModel;
namespace BPASmartClient.Device
{
@@ -88,7 +89,7 @@ namespace BPASmartClient.Device
///
/// 设备变量监控
///
- public List variableMonitors { get; set; } = new List();
+ public ObservableCollection variableMonitors { get; set; } = new ObservableCollection();
///
/// 外设状态,硬件设备数据
@@ -105,6 +106,7 @@ namespace BPASmartClient.Device
public List alarms { get; set; } = new List();
public IAlarm InterfaceAlarm { get; set; }
public AlarmHelper alarmHelper { get; set; } = new AlarmHelper();
+ public IStatus InterfaceStatus { get; set; }
#endregion
@@ -204,16 +206,16 @@ namespace BPASmartClient.Device
{
if (faces.Name == "IStatus")
{
- IStatus status = item.GetValue(this) as IStatus;
- GetMonitorData(status);
- ThreadManage.GetInstance().StopTask($"{item.Name}:{DeviceId}", new Action(() =>
- {
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- UpdateValue(status);
- Thread.Sleep(1000);
- }), $"{item.Name}:{DeviceId}");
- }));
+ InterfaceStatus = item.GetValue(this) as IStatus;
+ GetMonitorData(InterfaceStatus);
+ //ThreadManage.GetInstance().StopTask($"{item.Name}:{DeviceId}", new Action(() =>
+ // {
+ //ThreadManage.GetInstance().StartLong(new Action(() =>
+ //{
+ // UpdateValue(InterfaceStatus);
+ // Thread.Sleep(1000);
+ //}), $"GvlStatusMonitor:{DeviceId}");
+ //}));
}
else if (faces.Name == "IAlarm")
{
@@ -288,8 +290,11 @@ namespace BPASmartClient.Device
{
ThreadManage.GetInstance().StopTask($"ReadData:{DeviceId}", new Action(() =>
{
- ResetProgram();
- InitTask();
+ ThreadManage.GetInstance().StopTask($"GvlStatusMonitor:{DeviceId}", new Action(() =>
+ {
+ ResetProgram();
+ InitTask();
+ }));
}));
}));
}
@@ -316,6 +321,13 @@ namespace BPASmartClient.Device
}), $"MainTask:{DeviceId}");
#endregion
+ #region 设备状态监控
+ ThreadManage.GetInstance().StartLong(new Action(() =>
+ {
+ UpdateValue(InterfaceStatus);
+ Thread.Sleep(1000);
+ }), $"GvlStatusMonitor:{DeviceId}");
+ #endregion
}
///
diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs
index 565073cb..ccafbe3a 100644
--- a/BPASmartClient.Device/IDevice.cs
+++ b/BPASmartClient.Device/IDevice.cs
@@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Collections.ObjectModel;
namespace BPASmartClient.Device
{
@@ -54,7 +55,7 @@ namespace BPASmartClient.Device
///
/// 设备变量信息
///
- List variableMonitors { get; set; }
+ ObservableCollection variableMonitors { get; set; }
///
/// 设备报警信息集合
@@ -66,6 +67,11 @@ namespace BPASmartClient.Device
///
IAlarm InterfaceAlarm { get; set; }
+ ///
+ /// 接口设备状态
+ ///
+ IStatus InterfaceStatus { get; set; }
+
///
/// 报警实体
///
diff --git a/BPASmartClient.Device/VariableMonitor.cs b/BPASmartClient.Device/VariableMonitor.cs
index fea90df9..5e8373f9 100644
--- a/BPASmartClient.Device/VariableMonitor.cs
+++ b/BPASmartClient.Device/VariableMonitor.cs
@@ -3,46 +3,49 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Microsoft.Toolkit.Mvvm.ComponentModel;
namespace BPASmartClient.Device
{
- public class VariableMonitor
+ public class VariableMonitor : ObservableObject
{
- public int Id { get { return _mId; } set { _mId = value; } }
+ public int Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } }
private int _mId;
- public string VarName { get { return _mVarName; } set { _mVarName = value; } }
+ public string VarName { get { return _mVarName; } set { _mVarName = value; OnPropertyChanged(); } }
private string _mVarName;
- public string PLCAddress { get { return _mPLCAddress; } set { _mPLCAddress = value; } }
+ public string PLCAddress { get { return _mPLCAddress; } set { _mPLCAddress = value; OnPropertyChanged(); } }
private string _mPLCAddress;
- public string Notes { get { return _mNotes; } set { _mNotes = value; } }
+ public string Notes { get { return _mNotes; } set { _mNotes = value; OnPropertyChanged(); } }
private string _mNotes;
- public string ModbusTcpAddress { get { return _mModbusTcpAddress; } set { _mModbusTcpAddress = value; } }
+ public string ModbusTcpAddress { get { return _mModbusTcpAddress; } set { _mModbusTcpAddress = value; OnPropertyChanged(); } }
private string _mModbusTcpAddress;
- public string CurrentValue
- {
- get { return _mCurrentValue; }
- set
- {
+ public string CurrentValue
+ {
+ get { return _mCurrentValue; }
+ set
+ {
_mCurrentValue = value;
+ OnPropertyChanged();
if (_mCurrentValue == "False" || _mCurrentValue == "True")
{
if (_mCurrentValue == "True")
StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
else
StatusColor = new { r = 255, g = 0, b = 0, a = 1 };
- }else
+ }
+ else
StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
- }
+ }
}
private string _mCurrentValue;
diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs
index f2bf1c2a..65794f28 100644
--- a/BPASmartClient.IoT/DataVClient.cs
+++ b/BPASmartClient.IoT/DataVClient.cs
@@ -34,13 +34,15 @@ namespace BPASmartClient.IoT
///
public DataVClient()
{
- DataVApiAddress = System.Configuration.ConfigurationManager.AppSettings["DataVServiceUri"].ToString();
+ DataVApiAddress = InternetInfo.DataVApiAddress;
+ //DataVApiAddress = System.Configuration.ConfigurationManager.AppSettings["DataVServiceUri"].ToString();
ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
DeviceName = System.Configuration.ConfigurationManager.AppSettings["DeviceName"].ToString();
ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"].ToString();
DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"].ToString();
StartupMode = System.Configuration.ConfigurationManager.AppSettings["StartupMode"].ToString();
- BroadcastPubTopic = System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString();
+ BroadcastPubTopic = InternetInfo.BroadcastPubTopic;
+ //BroadcastPubTopic = System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString();
}
#endregion
@@ -178,7 +180,7 @@ namespace BPASmartClient.IoT
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
- iOTDevSXModel.Device1=String.Empty;iOTDevSXModel.Device2=String.Empty;iOTDevSXModel.Device3 = String.Empty;
+ iOTDevSXModel.Device1 = String.Empty; iOTDevSXModel.Device2 = String.Empty; iOTDevSXModel.Device3 = String.Empty;
List