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 6d7b1136..6cff81ff 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 @@ -205,16 +207,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") { @@ -289,8 +291,11 @@ namespace BPASmartClient.Device { ThreadManage.GetInstance().StopTask($"ReadData:{DeviceId}", new Action(() => { - ResetProgram(); - InitTask(); + ThreadManage.GetInstance().StopTask($"GvlStatusMonitor:{DeviceId}", new Action(() => + { + ResetProgram(); + InitTask(); + })); })); })); } @@ -317,6 +322,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.Helper/Json.cs b/BPASmartClient.Helper/Json.cs index 4f909f55..e20bdb75 100644 --- a/BPASmartClient.Helper/Json.cs +++ b/BPASmartClient.Helper/Json.cs @@ -11,24 +11,12 @@ namespace BPASmartClient.Helper /// public class Json 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); } - - /// /// 获取保存的数据 /// diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs index f2bf1c2a..a2354915 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 dataVNode = new List(); Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device => { @@ -299,7 +301,7 @@ namespace BPASmartClient.IoT string FileName = result.data?.fileName; string uploadId = result.data?.uploadId; FileUpload.FileSend(DeviceDataV, uploadId, result.data.offset); - MessageLog.GetInstance.Show($"[阿里云上传]:请求上传云回执成功."); + //MessageLog.GetInstance.Show($"[阿里云上传]:请求上传云回执成功."); } else MessageLog.GetInstance.Show($"[阿里云上传]:请求上传云回执失败.原因:{result.message}"); @@ -314,7 +316,7 @@ namespace BPASmartClient.IoT { FileUploadModelResult result = Tools.JsonToObjectTools(message); } - + } /// diff --git a/BPASmartClient.IoT/Model/FileUpload.cs b/BPASmartClient.IoT/Model/FileUpload.cs index ff5fbe5b..f07818bd 100644 --- a/BPASmartClient.IoT/Model/FileUpload.cs +++ b/BPASmartClient.IoT/Model/FileUpload.cs @@ -84,7 +84,7 @@ namespace BPASmartClient.IoT.Model //fileUpload.@params.extraParams.fileTag = new Dictionary { {"Time", DateTime.Now.ToString("yyyy_M_d") },{"Name", "HBL.LogDir" } }; dataV.IOT_Publish(dataV.FileUpLoadTopic, Tools.JsonConvertTools(fileUpload)); - MessageLog.GetInstance.Show($"[阿里云上传]:第[{i+1}]包数据,请求上传."); + //MessageLog.GetInstance.Show($"[阿里云上传]:第[{i+1}]包数据,请求上传."); int count = 0; while (modelResult == null)//等待上传完成 @@ -100,8 +100,13 @@ namespace BPASmartClient.IoT.Model ; - if(modelResult.code==200) - MessageLog.GetInstance.Show($"[阿里云上传]:第[{i + 1}]包,上传成功."); + if (modelResult.code == 200) + { + if (modelResult.data.complete) + { + MessageLog.GetInstance.Show($"[阿里云上传]:文件上传完成,总长度[{modelResult.data.bSize}]字节."); + } + } else MessageLog.GetInstance.Show($"[阿里云上传]:第[{i + 1}]包,上传失败.原因:{modelResult.message}"); ; diff --git a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs index 04994172..b7b11c7f 100644 --- a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs +++ b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs @@ -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 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((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((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(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((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(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); - //} }); } diff --git a/BPASmartClient.MQTT/MQTTProxy.cs b/BPASmartClient.MQTT/MQTTProxy.cs index 9398ec46..bdad1d69 100644 --- a/BPASmartClient.MQTT/MQTTProxy.cs +++ b/BPASmartClient.MQTT/MQTTProxy.cs @@ -22,15 +22,17 @@ namespace BPASmartClient.MQTT private IMqttClient client; - public void Connect(string ip, int port, string clientId) + public void Connect(string userName, string Password, string ip, int port, string clientId) { IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddMqttClientHostedService(p => { p.Server = ip; p.Port = port; - p.UserName = "rafiul"; - p.Password = "12345678"; + //p.UserName = "rafiul"; + //p.Password = "12345678"; + p.UserName = userName; + p.Password = Password; p.mqttClientConnectedHandlerDelegate = new MQTTnet.Client.Connecting.MqttClientConnectedHandlerDelegate(e => { IsConnected = true; diff --git a/BPASmartClient.Model/KeepDataBase.cs b/BPASmartClient.Model/KeepDataBase.cs index 839db8bb..9fa752a5 100644 --- a/BPASmartClient.Model/KeepDataBase.cs +++ b/BPASmartClient.Model/KeepDataBase.cs @@ -22,11 +22,5 @@ namespace BPASmartClient.Model /// public ObservableCollection orderLists { get; set; } = new ObservableCollection(); - - /// - /// 参数设置 - /// - public ObservableCollection parSets { get; set; } = new ObservableCollection(); - } } diff --git a/BPASmartClient.Model/ParSet.cs b/BPASmartClient.Model/ParSet.cs index 03261db1..8fb4611b 100644 --- a/BPASmartClient.Model/ParSet.cs +++ b/BPASmartClient.Model/ParSet.cs @@ -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; - } -} +// } +//} diff --git a/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj b/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj index 4e56b6db..f5f6ce16 100644 --- a/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj +++ b/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj @@ -14,6 +14,7 @@ + diff --git a/BPASmartClient.MorkS/Control_Morks.cs b/BPASmartClient.MorkS/Control_Morks.cs index 986ed962..04cbf7e3 100644 --- a/BPASmartClient.MorkS/Control_Morks.cs +++ b/BPASmartClient.MorkS/Control_Morks.cs @@ -14,6 +14,9 @@ using System.Linq; using BPASmartClient.Model.PLC; using System.Threading.Tasks; using System.Reflection; +using BPASmartClient.MorkS.Model; +using System.Collections.ObjectModel; +using BPASmartClient.MorkS.ViewModel; namespace BPASmartClient.MorkS { @@ -25,8 +28,36 @@ namespace BPASmartClient.MorkS public override void DoMain() { + MonitorViewModel.DeviceId = DeviceId; ServerInit(); DataParse(); + + Json.Read(); + if (Json.Data.parSets == null) Json.Data.parSets = new ObservableCollection(); + if (Json.Data.parSets.Count < 6) + { + Json.Data.parSets.Clear(); + for (int i = 0; i < 6; i++) + { + Json.Data.parSets.Add(new ParSet() + { + CheckBoxContext = $"煮面口{i + 1}屏蔽", + Minute = 1, + Second = 0, + IsShield = false, + TextBlockContext = $"煮面口{i + 1}时间设定" + }); + } + } + + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); + }), "WriteVW"); + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is WritePar writePar) WriteData(writePar.Address, writePar.Value); + }), "WriteBools"); ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitDevice"); } @@ -189,14 +220,6 @@ namespace BPASmartClient.MorkS if (obj is ushort[] UshortValue && UshortValue.Length > 0 && UshortValue.Length <= 1) mORKS.TurntableFeedbackloc = UshortValue[0]; })); - - //EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = "VW372", Length = 1 }, (o) => - //{ - // if (o != null && o.Length > 0 && o[0] is ushort value) - // { - // mORKS.TurntableFeedbackloc = value; - // } - //}); } /// @@ -455,11 +478,10 @@ namespace BPASmartClient.MorkS OrderChange(orderLocInfo.SuborderId, ORDER_STATUS.COOKING); DeviceProcessLogShow($"订单【{orderLocInfo.SuborderId}】,机器人倒面至【{loc + 1}】号煮面栏"); //写入煮面时间 - //List values = new List(); - //values.Add(Json.Data.parSets.ElementAt(loc).Minute); - //values.Add(Json.Data.parSets.ElementAt(loc).Second); - //ModbusTcpHelper.GetInstance.Write((ushort)ModbusTcpHelper.GetInstance.GetWordAddress($"VW{116 + (loc * 6)}"), WriteType.HoldingRegisters, values.ToArray()); - + List values = new List(); + values.Add(Json.Data.parSets.ElementAt(loc).Minute); + values.Add(Json.Data.parSets.ElementAt(loc).Second); + WriteData($"VW{116 + (loc * 6)}", values.ToArray()); mORKS.TakeNoodleInterlock = true; } } diff --git a/BPASmartClient.MorkS/Model/MorksPar.cs b/BPASmartClient.MorkS/Model/MorksPar.cs new file mode 100644 index 00000000..ed3c049c --- /dev/null +++ b/BPASmartClient.MorkS/Model/MorksPar.cs @@ -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 parSets { get; set; } = new ObservableCollection(); + } +} diff --git a/BPASmartClient.MorkS/Model/ParSet.cs b/BPASmartClient.MorkS/Model/ParSet.cs new file mode 100644 index 00000000..03261db1 --- /dev/null +++ b/BPASmartClient.MorkS/Model/ParSet.cs @@ -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; + + } +} diff --git a/BPASmartClient.MorkS/Model/WritePar.cs b/BPASmartClient.MorkS/Model/WritePar.cs new file mode 100644 index 00000000..2b7f1bdd --- /dev/null +++ b/BPASmartClient.MorkS/Model/WritePar.cs @@ -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; } + } +} diff --git a/BPASmartClient.MorkS/View/Monitor.xaml b/BPASmartClient.MorkS/View/Monitor.xaml index fe5ada3d..d3491af6 100644 --- a/BPASmartClient.MorkS/View/Monitor.xaml +++ b/BPASmartClient.MorkS/View/Monitor.xaml @@ -15,11 +15,228 @@ - - diff --git a/BPASmartClient/MainWindow.xaml.cs b/BPASmartClient/MainWindow.xaml.cs index a9197d34..f6b9fca9 100644 --- a/BPASmartClient/MainWindow.xaml.cs +++ b/BPASmartClient/MainWindow.xaml.cs @@ -48,7 +48,7 @@ namespace BPASmartClient ActionManage.GetInstance.Register(new Action(() => { myMenu.Visibility = Visibility.Visible; - MenuItem_Click(new MenuItem() { Tag = "LogView", Header = "日志监视" },null); + MenuItem_Click(new MenuItem() { Tag = "LogView", Header = "日志监视" }, null); }), "LoginSuccess"); Initialize(); } @@ -80,18 +80,21 @@ namespace BPASmartClient mainConsole.Start(); }), "启动主控制台", false); - ThreadManage.GetInstance().Start(new Action(() => + ActionManage.GetInstance.Register(new Action(() => { - try + ThreadManage.GetInstance().Start(new Action(() => { - DataVClient.GetInstance().Initialize(); - DataVClient.GetInstance().Start(); - } - catch (Exception ex) - { - MessageLog.GetInstance.ShowEx(ex.ToString()); - } - }), "启动主IoT", false); + try + { + DataVClient.GetInstance().Initialize(); + DataVClient.GetInstance().Start(); + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + } + }), "启动主IoT", false); + }), "配置初始化完成Iot启动"); ActionManage.GetInstance.Register(new Action((o) => { @@ -102,14 +105,14 @@ namespace BPASmartClient switch (iot.CommandName) { case 0://控制类 - if (iot.CommandValue != null && iot.CommandValue.Count>0) + if (iot.CommandValue != null && iot.CommandValue.Count > 0) { switch (iot.CommandValue.Keys.ToList()[0]) { case "程序启动": //mainConsole.Start(); break; - //mainConsole.Stop(); + //mainConsole.Stop(); case "程序停止": break; case "程序复位":