diff --git a/BPASmartClient.Business/Plugin/DeviceMgr.cs b/BPASmartClient.Business/Plugin/DeviceMgr.cs index 22e7a926..3373ed91 100644 --- a/BPASmartClient.Business/Plugin/DeviceMgr.cs +++ b/BPASmartClient.Business/Plugin/DeviceMgr.cs @@ -65,7 +65,6 @@ namespace BPASmartClient.Business { string Namespace = device.DeviceNamespace.Substring(0, device.DeviceNamespace.LastIndexOf('.')); - //string startModel = device.DeviceNamespace.Substring(device.DeviceNamespace.LastIndexOf('.') + 1); var deviceTemp = Assembly.Load(Namespace).CreateInstance(device.DeviceNamespace) as IDevice; deviceTemp.Name = device?.DeviceName; deviceTemp.DeviceId = int.Parse(device.DeviceId); @@ -75,7 +74,6 @@ namespace BPASmartClient.Business foreach (var comms in device.communicationDevcies)//通讯集合 { string IPeripheralNamespace = comms.CommunicationNamespace.Substring(0, comms.CommunicationNamespace.LastIndexOf('.')); - //string IPeripheralStartModel = comms.CommunicationNamespace.Substring(comms.CommunicationNamespace.LastIndexOf('.')); var peripheralTemp = Assembly.Load(IPeripheralNamespace).CreateInstance(comms.CommunicationNamespace) as IPeripheral; peripheralTemp.variables = comms.variables; peripheralTemp.communicationPar = comms.communicationPar; @@ -141,24 +139,22 @@ namespace BPASmartClient.Business if (PushType == 1) { - device.recipeBoms = JsonConvert.DeserializeObject(result); - //EventBus.EventBus.GetInstance().Publish(new RecipeBomEvent() - //{ - // DeviceId = device.DeviceId, - // recipeBoms = JsonConvert.DeserializeObject(result) - //}); - MessageLog.GetInstance.Show("接收到辅料信息"); + new RecipeBomEvent() + { + DeviceId = device.DeviceId, + recipeBoms = JsonConvert.DeserializeObject(result) + }.Publish(); + MessageLog.GetInstance.Show("接收到【 API 】获取的辅料信息"); } else if (PushType == 0) { var apiData = JsonConvert.DeserializeObject(result); - device.orderMaterialDelivery = apiData; - //EventBus.EventBus.GetInstance().Publish(new MaterialDeliveryEvent() - //{ - // DeviceId = device.DeviceId, - // orderMaterialDelivery = apiData - //}); - MessageLog.GetInstance.Show("接收到物料信息"); + new MaterialDeliveryEvent() + { + DeviceId = device.DeviceId, + orderMaterialDelivery = apiData + }.Publish(); + MessageLog.GetInstance.Show("接收到【 API 】获取的物料信息"); apiData?.BatchingInfo?.ForEach(x => { MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}"); diff --git a/BPASmartClient.Business/Plugin/OrderProxy.cs b/BPASmartClient.Business/Plugin/OrderProxy.cs index f6a5130c..3622772c 100644 --- a/BPASmartClient.Business/Plugin/OrderProxy.cs +++ b/BPASmartClient.Business/Plugin/OrderProxy.cs @@ -78,12 +78,26 @@ namespace BPASmartClient.Business //辅料信息 else if (message is RecipeBoms recipe) { - + new RecipeBomEvent() + { + DeviceId = recipe.DeviceId, + recipeBoms = recipe + }.Publish(); + MessageLog.GetInstance.Show("接收到 【 MQTT 】 的辅料信息"); } //物料消息 else if (message is OrderMaterialDelivery delivery) { - + new MaterialDeliveryEvent() + { + DeviceId = delivery.DeviceId, + orderMaterialDelivery = delivery + }.Publish(); + MessageLog.GetInstance.Show("接收到 【 MQTT 】 的物料信息"); + delivery?.BatchingInfo?.ForEach(x => + { + MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}"); + }); } }); diff --git a/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml b/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml index c56bc286..131aec66 100644 --- a/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml +++ b/BPASmartClient.CustomResource/RecDictionarys/BeveledRadioButtonStyle.xaml @@ -86,4 +86,95 @@ + + + + + + + + \ No newline at end of file diff --git a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml index 1ca4af46..c033fdb0 100644 --- a/BPASmartClient.CustomResource/Themes/GenricStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/GenricStyle.xaml @@ -1273,7 +1273,7 @@ - + diff --git a/BPASmartClient.DRCoffee/CoffeeMachine.cs b/BPASmartClient.DRCoffee/CoffeeMachine.cs index ef5f74f4..d1d8ebfd 100644 --- a/BPASmartClient.DRCoffee/CoffeeMachine.cs +++ b/BPASmartClient.DRCoffee/CoffeeMachine.cs @@ -103,7 +103,7 @@ namespace BPASmartClient.DRCoffee //一系列解包 while (dataStorage.GetSize() > 0) { - + IsConnected = true; byte item = dataStorage.GetData(); if (DrCoffee.HEADER == item) { @@ -147,6 +147,7 @@ namespace BPASmartClient.DRCoffee status["Status"] = package.Status; lastRefreshTime = DateTime.Now; + IsConnected = OnLine; new DRCoffee_CoffeEndCookEvent() { DeviceId = DeviceId }.Publish(); } else status["Status"] = package.Status; @@ -160,8 +161,7 @@ namespace BPASmartClient.DRCoffee || (DrCoffeeFault)status["Fault"] != DrCoffeeFault.无故障 ) { - IsWork = false; - + IsWork = false; } else IsWork = true; diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs index ce0e7fe4..565073cb 100644 --- a/BPASmartClient.Device/IDevice.cs +++ b/BPASmartClient.Device/IDevice.cs @@ -32,12 +32,12 @@ namespace BPASmartClient.Device /// /// 订单物料信息 /// - OrderMaterialDelivery orderMaterialDelivery { get; set; } + //OrderMaterialDelivery orderMaterialDelivery { get; set; } /// /// 配方数据信息 /// - RecipeBoms recipeBoms { get; set; } + //RecipeBoms recipeBoms { get; set; } /// /// 设备所有状态 diff --git a/BPASmartClient.GSIceCream/IceCreamMachine.cs b/BPASmartClient.GSIceCream/IceCreamMachine.cs index 38371140..b7baa092 100644 --- a/BPASmartClient.GSIceCream/IceCreamMachine.cs +++ b/BPASmartClient.GSIceCream/IceCreamMachine.cs @@ -48,7 +48,6 @@ namespace BPASmartClient.GSIceCream try { commProxy.Start(); - IsConnected = true; free = false; MainLoop(); } @@ -177,6 +176,7 @@ namespace BPASmartClient.GSIceCream private void ProcessHeart(ICMSG_Heart_UP heartUpMsg) { + IsConnected = OnLine; status["CurrentMode"] = heartUpMsg.MS; status["YLWD"] = BitConverter.ToInt16(new byte[] { heartUpMsg.YLWD_L,heartUpMsg.YLWD_H },0); status["HQWD"] = BitConverter.ToInt16(new byte[] { heartUpMsg.HQWD_L,heartUpMsg.HQWD_H },0); @@ -195,6 +195,7 @@ namespace BPASmartClient.GSIceCream { MessageLog.GetInstance.Show("打料中"); } + Thread.Sleep(1000); } private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg) diff --git a/BPASmartClient.IoT/BPASmartClient.IoT.csproj b/BPASmartClient.IoT/BPASmartClient.IoT.csproj index 0f2a2042..ac372833 100644 --- a/BPASmartClient.IoT/BPASmartClient.IoT.csproj +++ b/BPASmartClient.IoT/BPASmartClient.IoT.csproj @@ -5,10 +5,15 @@ + + + + + diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs index 4a120b24..f2bf1c2a 100644 --- a/BPASmartClient.IoT/DataVClient.cs +++ b/BPASmartClient.IoT/DataVClient.cs @@ -298,25 +298,17 @@ namespace BPASmartClient.IoT { string FileName = result.data?.fileName; string uploadId = result.data?.uploadId; - FileUpload.SetUploadData(result.id,uploadId); - FileUpload.FileSend(DeviceDataV, uploadId); - MessageLog.GetInstance.Show($"请求上传【阿里云】成功,准备上传日志文件【HBL.LogDir{DateTime.Now.ToString("yyyy_M_d")}.log】"); + FileUpload.FileSend(DeviceDataV, uploadId, result.data.offset); + MessageLog.GetInstance.Show($"[阿里云上传]:请求上传云回执成功."); } else - MessageLog.GetInstance.Show($"【HBL.LogDir{DateTime.Now.ToString("yyyy_M_d")}.log】请求上传【阿里云】失败,{result.message}"); + MessageLog.GetInstance.Show($"[阿里云上传]:请求上传云回执失败.原因:{result.message}"); } else if (DeviceDataV.FileUpLoadSendReplyTopic == topic)//文件上传Topic { FileUploadModelResult result = Tools.JsonToObjectTools(message); - if (result.code == 200) - { - MessageLog.GetInstance.Show($"今日日志文件“HBL.LogDir{DateTime.Now.ToString("yyyy_M_d")}.log”更新上传【阿里云】成功"); - bool complete = result.data.complete; - string uploadId = result.data?.uploadId; - }else - MessageLog.GetInstance.Show($"今日日志文件“HBL.LogDir{DateTime.Now.ToString("yyyy_M_d")}.log”更新上传【阿里云】失败,{result.message}"); - + FileUpload.modelResult = result; } else if (DeviceDataV.CancelFileUpLoadSendReplyTopic == topic)//取消文件上传Topic { diff --git a/BPASmartClient.IoT/Model/FileUpload.cs b/BPASmartClient.IoT/Model/FileUpload.cs index 45021c59..ff5fbe5b 100644 --- a/BPASmartClient.IoT/Model/FileUpload.cs +++ b/BPASmartClient.IoT/Model/FileUpload.cs @@ -1,4 +1,5 @@ using BPASmartClient.Helper; +using BPASmartClient.Message; using BPASmartDatavDeviceClient.IoT; using DataVAPI.Tool.IOT; using System; @@ -6,7 +7,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; +using static AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileResponseBody; namespace BPASmartClient.IoT.Model { @@ -15,55 +18,112 @@ namespace BPASmartClient.IoT.Model /// public class FileUpload { - public static Dictionary UploadData = new Dictionary(); public static string FileName = $"HBL.LogDir{DateTime.Now.ToString("yyyy_M_d")}"; public static string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}LogDir\\{FileName}.log"; - public static void SetUploadData(string key, string value) - { - UploadData[key] = value; - } - public static string GetUploadData(string key) - { - return UploadData.ContainsKey(key) ? UploadData[key] : string.Empty; - } - public static long length = 0; + /// + /// 一次性上传的包 + /// public static byte[] FileBlock; /// + /// 请求反馈信息 + /// + public static FileUploadModelResult modelResult=null; + /// /// 文件请求上传 /// public static void FileRequest(DataVReport dataV) { - FileBlock = FileContent(path); - length = FileBlock.Count(); - FileUploadModel fileUpload = new FileUploadModel(); - fileUpload.@params.fileName = FileName; - fileUpload.@params.fileSize = length; - fileUpload.@params.conflictStrategy = "overwrite";//覆盖模式 - //fileUpload.@params.ficMode = "crc64"; - //fileUpload.@params.ficValue = CRC.ToCRC16(FileBlock); - fileUpload.@params.initUid = $"ab{RandomHelper.GenerateRandomCode()}"; + ThreadManage.GetInstance().Start(new Action(() => + { + try + { + List queryDeviceFiles= Sample.FileQueryALL(DataVClient.GetInstance().DeviceName); + QueryDeviceFileResponseBodyData _data= queryDeviceFiles?.Find(par => par.Name == FileName); + if (_data != null)//删除文件 + { + MessageLog.GetInstance.Show("阿里云设备下文件已存在,准备删除续传..."); + Sample.DeleteFile(DataVClient.GetInstance().DeviceName, _data.FileId); + MessageLog.GetInstance.Show("删除成功.准备上传.."); + } + byte[] FileBlockALL = FileContent(path); + //分包上传 + int length = FileBlockALL.Count(); + int bfb = (FileBlockALL.Count() / 130000) + 1; + MessageLog.GetInstance.Show($"[阿里云上传]:文件整理中总长度[{length}]字节,分包数[{bfb}]包."); + //分包上传 + for (int i = 0; i < bfb; i++) + { + modelResult = null; + byte[] data; + if (i == bfb - 1) data = new byte[FileBlockALL.Count() - i * 130000];//最后一包 + else data = new byte[130000];//前面的包 - //上传到阿里云物联网平台的OSS存储空间中 - fileUpload.@params.extraParams.ossOwnerType = "iot-platform"; + for (int k = 0; k < data.Length; k++) + { + data[k] = FileBlockALL[k + i * 130000]; + } + FileBlock = data; - //表示上传到设备所属用户自己的OSS存储空间中 - //{ossbucket}/aliyun-iot-device-file/${instanceId}/${productKey}/${serviceId}/${deviceName}/${fileName} - //fileUpload.@params.extraParams.ossOwnerType = "device-user"; - //fileUpload.@params.extraParams.serviceId = "black"; - //fileUpload.@params.extraParams.fileTag = new Dictionary { {"Time", DateTime.Now.ToString("yyyy_M_d") },{"Name", "HBL.LogDir" } }; + FileUploadModel fileUpload = new FileUploadModel(); + fileUpload.@params.fileName = FileName; + fileUpload.@params.fileSize =-1; - dataV.IOT_Publish(dataV.FileUpLoadTopic, Tools.JsonConvertTools(fileUpload)); + fileUpload.@params.conflictStrategy = length>130000 ? "append":"overwrite"; + //fileUpload.@params.conflictStrategy = "append";// "overwrite";//覆盖模式 + //fileUpload.@params.ficMode = "crc64"; + //fileUpload.@params.ficValue = CRC.ToCRC16(FileBlock); + fileUpload.@params.initUid = $"ab{RandomHelper.GenerateRandomCode()}"; + + //上传到阿里云物联网平台的OSS存储空间中 + fileUpload.@params.extraParams.ossOwnerType = "iot-platform"; + + //表示上传到设备所属用户自己的OSS存储空间中 + //{ossbucket}/aliyun-iot-device-file/${instanceId}/${productKey}/${serviceId}/${deviceName}/${fileName} + //fileUpload.@params.extraParams.ossOwnerType = "device-user"; + //fileUpload.@params.extraParams.serviceId = "black"; + //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}]包数据,请求上传."); + + int count = 0; + while (modelResult == null)//等待上传完成 + { + if (count > 5) + { + MessageLog.GetInstance.Show($"[阿里云上传]:超时上传、未知原因、退出线程."); + + return; + } + Thread.Sleep(3000); count++; + } + + ; + + if(modelResult.code==200) + MessageLog.GetInstance.Show($"[阿里云上传]:第[{i + 1}]包,上传成功."); + else + MessageLog.GetInstance.Show($"[阿里云上传]:第[{i + 1}]包,上传失败.原因:{modelResult.message}"); + ; + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx(ex.ToString()); + } + }), "文件请求上传", false); } /// /// 文件上传 /// - public static void FileSend(DataVReport dataV, string uploadId) + public static void FileSend(DataVReport dataV, string uploadId,long offset) { FileSendModel fileSend = new FileSendModel(); fileSend.@params.uploadId = uploadId; - fileSend.@params.offset = 0; - fileSend.@params.bSize = length; + fileSend.@params.offset = offset; + fileSend.@params.bSize = FileBlock.Count(); + fileSend.@params.isComplete = FileBlock.Count()==130000?false:true; //结构如下图 //Header.length(高 低) + Header(字节数组UTF-8) + 文件分片的字节数组 + "分片校验值CrC16 低 高" byte[] Header = Encoding.UTF8.GetBytes(Tools.JsonConvertTools(fileSend)); diff --git a/BPASmartClient.IoT/Model/Sample.cs b/BPASmartClient.IoT/Model/Sample.cs new file mode 100644 index 00000000..2c06ca98 --- /dev/null +++ b/BPASmartClient.IoT/Model/Sample.cs @@ -0,0 +1,152 @@ +using DataVAPI.Tool.IOT; +using System; +using System.Collections.Generic; +using Tea; +using static AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileResponseBody; + + +namespace BPASmartClient.IoT.Model +{ + public class Sample + { + + /** + * 使用AK&SK初始化账号Client + * @param accessKeyId + * @param accessKeySecret + * @return Client + * @throws Exception + */ + public static AlibabaCloud.SDK.Iot20180120.Client CreateClient(string accessKeyId, string accessKeySecret) + { + AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config + { + // 您的AccessKey ID + AccessKeyId = accessKeyId, + // 您的AccessKey Secret + AccessKeySecret = accessKeySecret, + }; + // 访问的域名 + config.Endpoint = "iot.cn-shanghai.aliyuncs.com"; + return new AlibabaCloud.SDK.Iot20180120.Client(config); + } + + public static List FileQueryALL(string DeviceName) + { + List retdata = new List(); + AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi"); + AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListRequest queryDeviceFileListRequest = new AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListRequest + { + IotInstanceId = "iot-06z00g9pf3kwtxp", + DeviceName = DataVClient.GetInstance().DeviceName, + ProductKey = DataVClient.GetInstance().ProductKey, + }; + AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions(); + AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListResponse resp = client.QueryDeviceFileListWithOptions(queryDeviceFileListRequest, runtime); + + AlibabaCloudRes cloudRes = Tools.JsonToObjectTools(AlibabaCloud.TeaUtil.Common.ToJSONString(resp.ToMap())); + cloudRes?.body?.Data?.FileSummary?.ForEach(fileSummary => + { + QueryDeviceFileResponseBodyData _data = FileQuery(DeviceName, fileSummary.FileId); + if (_data != null) + { + _data.UtcCreatedOn = DateTime.Parse(_data.UtcCreatedOn).AddHours(8).ToString("yyyy-MM-dd HH:mm:ss"); + _data.DownloadUrl = _data.DownloadUrl.Replace("http://", "https://"); + retdata.Add(_data); + } + }); + return retdata; + } + /// + /// 替换字符串起始位置(开头)中指定的字符串 + /// + /// 源串 + /// 查找的串 + /// 替换的目标串 + /// + public static string CutStarStr(string s, string searchStr, string replaceStr) + { + var result = s; + try + { + if (string.IsNullOrEmpty(result)) + { + return result; + } + if (s.Length < searchStr.Length) + { + return result; + } + if (s.IndexOf(searchStr, 0, searchStr.Length, StringComparison.Ordinal) > -1) + { + result = s.Substring(searchStr.Length); + } + return result; + } + catch (Exception e) + { + return result; + } + } + public static QueryDeviceFileResponseBodyData FileQuery(string DeviceName, string FileId) + { + AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi"); + AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileRequest queryDeviceFileRequest = new AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileRequest + { + IotInstanceId = "iot-06z00g9pf3kwtxp", + DeviceName = DataVClient.GetInstance().DeviceName, + ProductKey = DataVClient.GetInstance().ProductKey, + FileId = FileId, + }; + AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions(); + // 复制代码运行请自行打印 API 的返回值 + QueryDeviceFileResponseBodyData queryDeviceFile = client.QueryDeviceFileWithOptions(queryDeviceFileRequest, runtime).Body.Data; + return queryDeviceFile; + } + + public static bool? DeleteFile(string DeviceName, string FileId) + { + AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi"); + AlibabaCloud.SDK.Iot20180120.Models.DeleteDeviceFileRequest deleteDeviceFileRequest = new AlibabaCloud.SDK.Iot20180120.Models.DeleteDeviceFileRequest + { + IotInstanceId = "iot-06z00g9pf3kwtxp", + DeviceName = DataVClient.GetInstance().DeviceName, + ProductKey = DataVClient.GetInstance().ProductKey, + FileId = FileId, + }; + AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions(); + // 复制代码运行请自行打印 API 的返回值 + return client.DeleteDeviceFileWithOptions(deleteDeviceFileRequest, runtime).Body.Success; + } + + } + + public class AlibabaCloudRes + { + public object headers { get; set; } + public StrRes body { get; set; } + } + public class StrRes + { + public string code { get; set; } + public string CurrentPage { get; set; } + public ResData Data { get; set; } + public string ErrorMessage { get; set; } + public int PageCount { get; set; } + public int PageSize { get; set; } + public string RequestId { get; set; } + public bool Success { get; set; } + public int Total { get; set; } + } + public class ResData + { + public List FileSummary { get; set; } + } + public class summary + { + public string UtcCreatedOn { get; set; } + public string Size { get; set; } + public string FileId { get; set; } + public string Name { get; set; } + } +} diff --git a/BPASmartClient.LebaiRobot/LebaiHelper.cs b/BPASmartClient.LebaiRobot/LebaiHelper.cs index 4432b1da..48d7d45b 100644 --- a/BPASmartClient.LebaiRobot/LebaiHelper.cs +++ b/BPASmartClient.LebaiRobot/LebaiHelper.cs @@ -15,11 +15,7 @@ namespace BPASmartClient.LebaiRobot public class LebaiHelper:Singleton { - - - - - + private LebaiRobotClient client; public RobotData robotData; public bool IsIdle { get; set; } = false; diff --git a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs index 472d4092..04994172 100644 --- a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs +++ b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs @@ -35,7 +35,7 @@ namespace BPASmartClient.PLC { if (par?.Address.Length > 0) { - var res = modbusTcp.READD(par.Address, (ushort)par.ReadLeng); + var res = modbusTcp.Read(par.Address, (ushort)par.ReadLeng); if (status.ContainsKey(par.Address)) { status[par.Address] = res; @@ -106,7 +106,7 @@ namespace BPASmartClient.PLC if (@event == null) return; var par = @event as WriteModel; - modbusTcp.WRITEE(par?.Address, par?.Value); + modbusTcp.Write(par?.Address, par?.Value); //ushort address = (ushort)modbusTcp.GetAddress(par?.Address); //if (par.Address.ToUpper().Contains("M")) //{ diff --git a/BPASmartClient.Modbus/ModbusTcp.cs b/BPASmartClient.Modbus/ModbusTcp.cs index 1b3e905a..e01ec0c1 100644 --- a/BPASmartClient.Modbus/ModbusTcp.cs +++ b/BPASmartClient.Modbus/ModbusTcp.cs @@ -129,7 +129,7 @@ namespace BPASmartClient.Modbus // } //} - public object READD(string address, ushort len = 1, byte slaveAddress = 1) + public object Read(string address, ushort len = 1, byte slaveAddress = 1) { if (address == null || tcpClient == null) return default(object); ushort startAddress = (ushort)GetAddress(address); @@ -164,7 +164,7 @@ namespace BPASmartClient.Modbus return default(object); } - public void WRITEE(string address, T value, byte slaveAddress = 1) + public void Write(string address, T value, byte slaveAddress = 1) { if (address == null || tcpClient == null) return; ushort startAddress = (ushort)GetAddress(address); diff --git a/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj b/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj index b4b46ffa..9a6ccc24 100644 --- a/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj +++ b/BPASmartClient.MorkD/BPASmartClient.MorkD.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0-windows + enable + true bin\ portable diff --git a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj index 09946d55..feae8a16 100644 --- a/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj +++ b/BPASmartClient.MorkF/BPASmartClient.MorkF.csproj @@ -1,7 +1,8 @@ - net6.0 + net6.0-windows + true enable enable bin\ diff --git a/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj b/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj index 11f083b1..4e56b6db 100644 --- a/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj +++ b/BPASmartClient.MorkS/BPASmartClient.MorkS.csproj @@ -1,16 +1,20 @@ - + - net6.0 + net6.0-windows + enable + true bin\ portable + + diff --git a/BPASmartClient.MorkS/Control_Morks.cs b/BPASmartClient.MorkS/Control_Morks.cs index 18acf596..986ed962 100644 --- a/BPASmartClient.MorkS/Control_Morks.cs +++ b/BPASmartClient.MorkS/Control_Morks.cs @@ -73,116 +73,130 @@ namespace BPASmartClient.MorkS EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType }); } - private void ReadData(string address, ushort len = 1, Action action = null) - { - EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = address, Length = len }, (o) => - { - if (o != null && o.Length > 0 && o[0] is bool[] bools) - { - action(bools); - } - }); - } - - private void GetStatus(string key, Action action) + private void GetStatus(string key, Action action) { if (peripheralStatus.ContainsKey(key)) { - if (peripheralStatus[key] is bool[] bools) + if (peripheralStatus[key] != null) { - action?.Invoke(bools); + action?.Invoke(peripheralStatus[key]); } - //action((bool[])peripheralStatus[key]); } } public override void ReadData() { - GetStatus("M230.0", new Action((bools) => + GetStatus("M230.0", new Action((obj) => { - alarm.MachineLeftLowTemperature = bools[0]; - alarm.MachineRightLowTemperature = bools[1]; - alarm.Supply1_LossBowl = bools[2]; - alarm.Supply2_LossBowl = bools[3]; - alarm.Supply1_ErrorOutBowl = bools[4]; - alarm.Supply2_ErrorOutBowl = bools[5]; - alarm.PushBowlCylinderError = bools[6]; - alarm.NoodleMacCommunicateError = bools[7]; - alarm.DosingMacCommunicateError = bools[8]; - alarm.RobotMacCommunicateError = bools[9]; - alarm.DeviceEstop = bools[10]; - alarm.RobotInitError = bools[11]; - alarm.RobotUrgentStop = bools[12]; - alarm.RobotNotInRemoteMode = bools[13]; - alarm.RobotNotInReady = bools[14]; - alarm.RobotSelfInException = bools[15]; - alarm.LeftLackWater = bools[16]; - alarm.RightLackWater = bools[17]; - alarm.SvrewInitFail = bools[18]; - alarm.TurntableInitFail = bools[19]; - alarm.RobotInitFail = bools[20]; - alarm.NoodleCookerInitFail = bools[21]; - alarm.PushBowlInitFail1 = bools[22]; - alarm.PushBowlInitFail2 = bools[23]; + if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24) + { + alarm.MachineLeftLowTemperature = bools[0]; + alarm.MachineRightLowTemperature = bools[1]; + alarm.Supply1_LossBowl = bools[2]; + alarm.Supply2_LossBowl = bools[3]; + alarm.Supply1_ErrorOutBowl = bools[4]; + alarm.Supply2_ErrorOutBowl = bools[5]; + alarm.PushBowlCylinderError = bools[6]; + alarm.NoodleMacCommunicateError = bools[7]; + alarm.DosingMacCommunicateError = bools[8]; + alarm.RobotMacCommunicateError = bools[9]; + alarm.DeviceEstop = bools[10]; + alarm.RobotInitError = bools[11]; + alarm.RobotUrgentStop = bools[12]; + alarm.RobotNotInRemoteMode = bools[13]; + alarm.RobotNotInReady = bools[14]; + alarm.RobotSelfInException = bools[15]; + alarm.LeftLackWater = bools[16]; + alarm.RightLackWater = bools[17]; + alarm.SvrewInitFail = bools[18]; + alarm.TurntableInitFail = bools[19]; + alarm.RobotInitFail = bools[20]; + alarm.NoodleCookerInitFail = bools[21]; + alarm.PushBowlInitFail1 = bools[22]; + alarm.PushBowlInitFail2 = bools[23]; + } })); - GetStatus("M0.3", new Action((bools) => + GetStatus("M0.3", new Action((obj) => { - mORKS.RobotTakeNoodle = bools[0]; - mORKS.RobotOutMeal = bools[1]; - mORKS.MoveTurntable = bools[2]; + if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 3) + { + mORKS.RobotTakeNoodle = bools[0]; + mORKS.RobotOutMeal = bools[1]; + mORKS.MoveTurntable = bools[2]; + } })); - GetStatus("M100.0", new Action((bools) => + GetStatus("M100.0", new Action((obj) => { - mORKS.InitComplete = bools[0]; - mORKS.TakeBowlIdle = bools[1]; - mORKS.TemperatureReached = bools[2]; - mORKS.AllowFallNoodle = bools[3]; - mORKS.RbTakeNoodleComplete = bools[4]; - mORKS.RbFallNoodleComplete = bools[5]; - mORKS.RbOutMealComplete = bools[6]; - mORKS.RobotIdle = bools[7]; - mORKS.TakeMealDetect = bools[8]; - mORKS.MissingBowl = bools[9]; - Initing = bools[10]; - mORKS.TurntableLowerLimit = bools[11]; - mORKS.MissingBowlSignal2 = bools[12]; - mORKS.TurntableUpLimit = bools[13]; - mORKS.FeedComplete = bools[14]; - mORKS.TurntableMoveInPlace = bools[15]; + if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 16) + { + mORKS.InitComplete = bools[0]; + mORKS.TakeBowlIdle = bools[1]; + mORKS.TemperatureReached = bools[2]; + mORKS.AllowFallNoodle = bools[3]; + mORKS.RbTakeNoodleComplete = bools[4]; + mORKS.RbFallNoodleComplete = bools[5]; + mORKS.RbOutMealComplete = bools[6]; + mORKS.RobotIdle = bools[7]; + mORKS.TakeMealDetect = bools[8]; + mORKS.MissingBowl = bools[9]; + Initing = bools[10]; + mORKS.TurntableLowerLimit = bools[11]; + mORKS.MissingBowlSignal2 = bools[12]; + mORKS.TurntableUpLimit = bools[13]; + mORKS.FeedComplete = bools[14]; + mORKS.TurntableMoveInPlace = bools[15]; + } + })); - GetStatus("M235.0", new Action((bools) => + GetStatus("M235.0", new Action((obj) => { - mORKS.Error = bools[0]; + if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1) + { + mORKS.Error = bools[0]; + } })); - GetStatus("M102.0", new Action((bools) => + GetStatus("M102.0", new Action((obj) => { - for (int i = 0; i < 6; i++) + if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7) { - mORKS.NoodleCookerStatus[i] = bools[i]; + for (int i = 0; i < 6; i++) + { + mORKS.NoodleCookerStatus[i] = bools[i]; + } + mORKS.Feeding = bools[6]; } - mORKS.Feeding = bools[6]; })); - GetStatus("M103.0", new Action((bools) => + GetStatus("M103.0", new Action((obj) => { - for (int i = 0; i < 6; i++) + if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6) { - mORKS.CookNoodlesComplete[i] = bools[i]; + for (int i = 0; i < 6; i++) + { + mORKS.CookNoodlesComplete[i] = bools[i]; + } } + })); - EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = "VW372", Length = 1 }, (o) => + GetStatus("VW372", new Action((obj) => { - if (o != null && o.Length > 0 && o[0] is ushort value) - { - mORKS.TurntableFeedbackloc = value; - } - }); + 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; + // } + //}); } /// diff --git a/BPASmartClient.MorkS/View/Debug.xaml b/BPASmartClient.MorkS/View/Debug.xaml new file mode 100644 index 00000000..b625652e --- /dev/null +++ b/BPASmartClient.MorkS/View/Debug.xaml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/BPASmartClient.MorkS/View/Debug.xaml.cs b/BPASmartClient.MorkS/View/Debug.xaml.cs new file mode 100644 index 00000000..0f3e4cbc --- /dev/null +++ b/BPASmartClient.MorkS/View/Debug.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.MorkS.View +{ + /// + /// Debug.xaml 的交互逻辑 + /// + public partial class Debug : UserControl + { + public Debug() + { + InitializeComponent(); + } + } +} diff --git a/BPASmartClient.MorkS/View/Monitor.xaml b/BPASmartClient.MorkS/View/Monitor.xaml new file mode 100644 index 00000000..fe5ada3d --- /dev/null +++ b/BPASmartClient.MorkS/View/Monitor.xaml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/BPASmartClient.MorkS/View/Monitor.xaml.cs b/BPASmartClient.MorkS/View/Monitor.xaml.cs new file mode 100644 index 00000000..dd046012 --- /dev/null +++ b/BPASmartClient.MorkS/View/Monitor.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.MorkS.View +{ + /// + /// Monitor.xaml 的交互逻辑 + /// + public partial class Monitor : UserControl + { + public Monitor() + { + InitializeComponent(); + } + } +} diff --git a/BPASmartClient.MorkS/View/ParSet.xaml b/BPASmartClient.MorkS/View/ParSet.xaml new file mode 100644 index 00000000..9222bf3f --- /dev/null +++ b/BPASmartClient.MorkS/View/ParSet.xaml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.MorkS/View/ParSet.xaml.cs b/BPASmartClient.MorkS/View/ParSet.xaml.cs new file mode 100644 index 00000000..1eada46b --- /dev/null +++ b/BPASmartClient.MorkS/View/ParSet.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.MorkS.View +{ + /// + /// ParSet.xaml 的交互逻辑 + /// + public partial class ParSet : UserControl + { + public ParSet() + { + InitializeComponent(); + } + } +} diff --git a/BPASmartClient.MorkS/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkS/ViewModel/DebugViewModel.cs new file mode 100644 index 00000000..fb5afe6c --- /dev/null +++ b/BPASmartClient.MorkS/ViewModel/DebugViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; + + +namespace BPASmartClient.MorkS.ViewModel +{ + public class DebugViewModel : ObservableObject + { + public DebugViewModel() + { + + } + } +} diff --git a/BPASmartClient.MorkS/ViewModel/MonitorViewModel.cs b/BPASmartClient.MorkS/ViewModel/MonitorViewModel.cs new file mode 100644 index 00000000..9b417b57 --- /dev/null +++ b/BPASmartClient.MorkS/ViewModel/MonitorViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; + +namespace BPASmartClient.MorkS.ViewModel +{ + public class MonitorViewModel : ObservableObject + { + public MonitorViewModel() + { + + } + } +} diff --git a/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs b/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs new file mode 100644 index 00000000..e132e782 --- /dev/null +++ b/BPASmartClient.MorkS/ViewModel/ParSetViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; + +namespace BPASmartClient.MorkS.ViewModel +{ + public class ParSetViewModel : ObservableObject + { + public ParSetViewModel() + { + + } + } +} diff --git a/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj b/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj index 256ad966..08d23ce9 100644 --- a/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj +++ b/BPASmartClient.MorkT/BPASmartClient.MorkT.csproj @@ -1,15 +1,32 @@ - net6.0 + net6.0-windows + enable + true D:\HBL\Porgram\BPASmartClient\BPASmartClient\bin\Debug\net6.0-windows\Devices + + + + + Code + + + + + + $(DefaultXamlRuntime) + Designer + + + diff --git a/BPASmartClient/Control/MorkT_DebugView.xaml b/BPASmartClient.MorkT/View/DebugView.xaml similarity index 97% rename from BPASmartClient/Control/MorkT_DebugView.xaml rename to BPASmartClient.MorkT/View/DebugView.xaml index dbc19a31..5a23087b 100644 --- a/BPASmartClient/Control/MorkT_DebugView.xaml +++ b/BPASmartClient.MorkT/View/DebugView.xaml @@ -1,14 +1,14 @@ - - + diff --git a/BPASmartClient/Control/MorkT_DebugView.xaml.cs b/BPASmartClient.MorkT/View/DebugView.xaml.cs similarity index 81% rename from BPASmartClient/Control/MorkT_DebugView.xaml.cs rename to BPASmartClient.MorkT/View/DebugView.xaml.cs index b96ec05d..c482d29d 100644 --- a/BPASmartClient/Control/MorkT_DebugView.xaml.cs +++ b/BPASmartClient.MorkT/View/DebugView.xaml.cs @@ -13,14 +13,14 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; -namespace BPASmartClient.Control +namespace BPASmartClient.MorkT.View { /// /// MorkT_DebugView.xaml 的交互逻辑 /// - public partial class MorkT_DebugView : UserControl + public partial class DebugView : UserControl { - public MorkT_DebugView() + public DebugView() { InitializeComponent(); } diff --git a/BPASmartClient.ViewModel/MorkT_DebugViewModel.cs b/BPASmartClient.MorkT/ViewModel/DebugViewModel.cs similarity index 69% rename from BPASmartClient.ViewModel/MorkT_DebugViewModel.cs rename to BPASmartClient.MorkT/ViewModel/DebugViewModel.cs index ef20fd36..11e10381 100644 --- a/BPASmartClient.ViewModel/MorkT_DebugViewModel.cs +++ b/BPASmartClient.MorkT/ViewModel/DebugViewModel.cs @@ -1,29 +1,23 @@ using BPASmartClient.Business; -using BPASmartClient.Device; using BPASmartClient.DRCoffee; using BPASmartClient.EventBus; using BPASmartClient.GSIceCream; using BPASmartClient.Helper; -using BPASmartClient.Lebai; using BPASmartClient.LebaiRobot; +using BPASmartClient.Message; using BPASmartClient.Model; using BPASmartClient.Model.乐白机器人; using BPASmartClient.Model.冰淇淋.Enum; using BPASmartClient.Model.咖啡机.Enum; -using BPASmartClient.SCChip; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; -using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; -namespace BPASmartClient.ViewModel +namespace BPASmartClient.MorkT.ViewModel { - public class MorkT_DebugViewModel : ObservableObject + public class DebugViewModel : ObservableObject { /// /// 设备ID @@ -33,11 +27,13 @@ namespace BPASmartClient.ViewModel /// /// 乐白机器人连接状态 /// - public string RobotConnected { get; set; } + public string RobotConnected { get { return _robotConnected; } set { _robotConnected = value; OnPropertyChanged(); } } + private string _robotConnected { get; set; } /// /// 乐白机器人的模式状态 /// - public ELebaiRModel RobotMode { get; set; } + public ELebaiRModel RobotMode { get { return _robotMode; } set { _robotMode = value; OnPropertyChanged(); } } + private ELebaiRModel _robotMode { get; set; } /// /// 机器人控制指令 /// @@ -66,43 +62,53 @@ namespace BPASmartClient.ViewModel /// /// 冰淇淋连接状态 /// - public string IceCreamConnected { get; set; } + public string IceCreamConnected { get { return _iceCreamConnected; } set { _iceCreamConnected = value; OnPropertyChanged(); } } + private string _iceCreamConnected { get; set; } /// /// 预冷温度 /// - public short YLWD { get; set; } + public short YLWD { get { return _yLWD; } set { _yLWD = value; OnPropertyChanged(); } } + private short _yLWD { get; set; } /// /// 回气温度 /// - public short HQWD { get; set; } + public short HQWD { get { return _hQWD; } set { _hQWD = value; OnPropertyChanged(); } } + private short _hQWD { get; set; } /// /// 环境温度 /// - public short HJWD { get; set; } + public short HJWD { get { return _hJWD; } set { _hJWD = value; OnPropertyChanged(); } } + private short _hJWD { get; set; } /// /// 电流 /// - public short DL { get; set; } + public short DL { get { return _DL; } set { _DL = value; OnPropertyChanged(); } } + private short _DL { get; set; } /// /// 电压 /// - public short DY { get; set; } + public short DY { get { return _dy; } set { _dy = value; OnPropertyChanged(); } } + private short _dy { get; set; } /// /// 当前模式 /// - public MORKI_MODE CurrentMode { get; set; } + public MORKI_MODE CurrentMode { get { return _CurrentMode; } set { _CurrentMode = value; OnPropertyChanged(); } } + private MORKI_MODE _CurrentMode; /// /// 故障 /// - public MORKI_FAULT IceCreamFault { get; set; } + public MORKI_FAULT IceCreamFault { get { return _IceCreamFault; } set { _IceCreamFault = value; OnPropertyChanged(); } } + private MORKI_FAULT _IceCreamFault { get; set; } /// /// 成型比 /// - public byte CXB { get; set; } + public byte CXB { get { return _cXB; } set { _cXB = value; OnPropertyChanged(); } } + private byte _cXB { get; set; } /// /// 打料完成状态 /// - public string DLCompleted { get; set; } + public string DLCompleted { get { return _dLCompleted; } set { _dLCompleted = value; OnPropertyChanged(); } } + private string _dLCompleted { get; set; } public List IceCreamModes { get; set; } = new List(); public string SelecteIceCreamdMode { get; set; } @@ -114,8 +120,6 @@ namespace BPASmartClient.ViewModel private void Button_SetIceCreamModel() { MORKI_MODE mORKI_MODE = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode); - //ActionManage.GetInstance.Send("测试", mORKI_MODE); - new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = mORKI_MODE }.Publish(); } #endregion @@ -124,23 +128,28 @@ namespace BPASmartClient.ViewModel /// /// 咖啡机连接状态 /// - public string CoffeeConnected { get; set; } + public string CoffeeConnected { get { return _coffeeConnected; } set { _coffeeConnected = value; OnPropertyChanged(); } } + private string _coffeeConnected { get; set; } /// /// 咖啡机状态 /// - public DrCoffeeStatus CoffeeStatus { get; set; } + public DrCoffeeStatus CoffeeStatus { get { return _coffeeStatus; } set { _coffeeStatus = value; OnPropertyChanged(); } } + private DrCoffeeStatus _coffeeStatus { get; set; } /// /// 应用状态 /// - public DrCoffeeAppStatus AppStatus { get; set; } + public DrCoffeeAppStatus AppStatus { get { return _appStatus; } set { _appStatus = value; OnPropertyChanged(); } } + private DrCoffeeAppStatus _appStatus { get; set; } /// /// 告警 /// - public DrCoffeeWarning Warning { get; set; } + public DrCoffeeWarning Warning { get { return _warning; } set { _warning = value; OnPropertyChanged(); } } + public DrCoffeeWarning _warning { get; set; } /// /// 故障信息 /// - public DrCoffeeFault CaffeeFault { get; set; } + public DrCoffeeFault CaffeeFault { get { return _caffeeFault; } set { _caffeeFault = value; OnPropertyChanged(); } } + public DrCoffeeFault _caffeeFault { get; set; } public List Coffees { get; set; } = new List(); public string SelectedCoffee { get; set; } @@ -152,7 +161,7 @@ namespace BPASmartClient.ViewModel Dictionary CurrentData { get; set; } - public MorkT_DebugViewModel() + public DebugViewModel() { Button_RobotControlCommand = new RelayCommand(Button_RobotControl); Button_MakeIceCreamCommand = new RelayCommand(Button_MakeIceCream); @@ -181,6 +190,7 @@ namespace BPASmartClient.ViewModel { Plugin.GetInstance()?.GetPlugin()?.GetDevices().ForEach(device => { + CurrentData?.Clear(); if (device.Name == "MorkT") CurrentData = device.Status.GetStatus(); DeviceId = device.DeviceId; }); diff --git a/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs b/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs new file mode 100644 index 00000000..f26722a7 --- /dev/null +++ b/BPASmartClient.ViewModel/DeviceMonitorViewModel.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System.Collections.ObjectModel; +using BPASmartClient.Helper; +using System.IO; +using Newtonsoft.Json; +using BPASmartClient.Model; +using System.Reflection; +using Microsoft.Toolkit.Mvvm.Input; +using System.Windows; + +namespace BPASmartClient.ViewModel +{ + public class DeviceMonitorViewModel : ObservableObject + { + public DeviceMonitorViewModel() + { + DeviceSwitch = new RelayCommand((o) => + { + if (o is string nameSpace) + { + DeviceMonitors.Clear(); + Assembly.Load(nameSpace.Substring(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 }); + } + }); + } + }); + + DeviceWindowSwitch = new RelayCommand((o) => + { + if (o != null && o is string nameSpace) + { + var fe = DeviceMonitors.FirstOrDefault(p => p.Namespace == nameSpace); + if (fe != null) MainContent = fe.fe; + } + }); + + GetData(); + } + + + + private void GetData() + { + var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig"); + string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json"; + if (File.Exists(path)) + { + string JsonString = File.ReadAllText(path); + var result = JsonConvert.DeserializeObject>(JsonString); + if (result != null) + { + foreach (var shop in result)//店铺集合 + { + foreach (var device in shop.deviceModels)//设备集合 + { + Devices.Add(new Device() { Name = device.DeviceName, Namespace = device.DeviceNamespace }); + } + } + } + } + } + + public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } } + private FrameworkElement _mMainContent; + + public RelayCommand DeviceSwitch { get; set; } + + public RelayCommand DeviceWindowSwitch { get; set; } + + public ObservableCollection Devices { get; set; } = new ObservableCollection(); + + public ObservableCollection DeviceMonitors { get; set; } = new ObservableCollection(); + + } + + public class Device : ObservableObject + { + + public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } } + private string _mName; + + + public string Namespace { get { return _mNamespace; } set { _mNamespace = value; OnPropertyChanged(); } } + private string _mNamespace; + + public FrameworkElement fe { get; set; } + } + + + + + + +} diff --git a/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs b/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs deleted file mode 100644 index 4dceab30..00000000 --- a/BPASmartClient.ViewModel/Model/DeviceConfigModel.cs +++ /dev/null @@ -1,181 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; -//using Microsoft.Toolkit.Mvvm.ComponentModel; -//using System.Collections.ObjectModel; -//using Microsoft.Toolkit.Mvvm.Input; -//using System.Windows; - -//namespace BPASmartClient.ViewModel.Model -//{ -// /// -// /// 店铺设备 -// /// -// public class DeviceConfigModel : ObservableObject -// { -// /// -// /// 店铺名称 -// /// -// public string ShopName { get { return _mShopName; } set { _mShopName = value; OnPropertyChanged(); } } -// private string _mShopName = string.Empty; - -// /// -// /// 店铺ID -// /// -// public string ShopId { get { return _mShopId; } set { _mShopId = value; OnPropertyChanged(); } } -// private string _mShopId = string.Empty; - -// /// -// /// 设备集合 -// /// -// public ObservableCollection deviceModels { get; set; } = new ObservableCollection(); -// } - -// /// -// /// 启动模块 -// /// -// public class DeviceModel : ObservableObject -// { -// /// -// /// 设备名称 -// /// -// public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } -// private string _mDeviceName = string.Empty; - -// /// -// /// 启动设备模块 -// /// -// public string DeviceModule { get { return _mDeviceModule; } set { _mDeviceModule = value; OnPropertyChanged(); } } -// private string _mDeviceModule = string.Empty; - -// public string DeviceNamespace { get; set; } - - -// public string Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } } -// private string _mId = string.Empty; - - -// /// -// /// 设备ID -// /// -// public string DeviceId { get { return _mDeviceId; } set { _mDeviceId = value; OnPropertyChanged(); } } -// private string _mDeviceId = string.Empty; - -// /// -// /// 通讯模块 -// /// -// public ObservableCollection communicationDevcies { get; set; } = new ObservableCollection(); - -// } - -// /// -// /// 通讯模块 -// /// -// public class CommunicationModel : ObservableObject -// { -// /// -// /// 通讯启动模块 -// /// -// public string CommunicationModule { get { return _mCommunicationModule; } set { _mCommunicationModule = value; OnPropertyChanged(); } } -// private string _mCommunicationModule = string.Empty; - -// public string CommunicationNamespace { get; set; } - -// public string CommunicationName { get { return _mCommunicationName; } set { _mCommunicationName = value; OnPropertyChanged(); } } -// private string _mCommunicationName = string.Empty; - -// public string DeviceModelId { get { return _mDeviceModelId; } set { _mDeviceModelId = value; OnPropertyChanged(); } } -// private string _mDeviceModelId = string.Empty; - -// public CommunicationPar communicationPar { get { return _mcommunicationPar; } set { _mcommunicationPar = value; OnPropertyChanged(); } } -// private CommunicationPar _mcommunicationPar = new CommunicationPar(); - -// } - -// /// -// /// 通讯参数 -// /// -// public class CommunicationPar : ObservableObject -// { -// /// -// /// 选择网口通讯 -// /// -// public bool IsNetworkPort { get { return _mIsNetworkPort; } set { _mIsNetworkPort = value; OnPropertyChanged(); } } -// private bool _mIsNetworkPort = false; - -// /// -// /// 选择串口通讯 -// /// -// public bool IsSerialPort { get { return _mIsSerialPort; } set { _mIsSerialPort = value; OnPropertyChanged(); } } -// private bool _mIsSerialPort = true; - -// /// -// /// IP地址 -// /// -// public string IPAddress { get { return _mIPAddress; } set { _mIPAddress = value; OnPropertyChanged(); } } -// private string _mIPAddress; - -// /// -// /// IP 端口号 -// /// -// public int IPPort { get { return _mIPPort; } set { _mIPPort = value; OnPropertyChanged(); } } -// private int _mIPPort; - -// /// -// /// ip 串口 站号 -// /// -// public int StationNo { get { return _mStationNo; } set { _mStationNo = value; OnPropertyChanged(); } } -// private int _mStationNo; - - -// /// -// /// 串口单口号 -// /// -// public string SerialPort { get { return _mSerialPort; } set { _mSerialPort = value; OnPropertyChanged(); } } -// private string _mSerialPort; - -// /// -// /// 波特率 -// /// -// public int BaudRate { get { return _mBaudRate; } set { _mBaudRate = value; OnPropertyChanged(); } } -// private int _mBaudRate; - -// /// -// /// 数据位 -// /// -// public int DataBits { get { return _mDataBits; } set { _mDataBits = value; OnPropertyChanged(); } } -// private int _mDataBits = 8; - -// /// -// /// 停止位 -// /// -// public string StopBits { get { return _mStopBits; } set { _mStopBits = value; OnPropertyChanged(); } } -// private string _mStopBits = "1"; - -// /// -// /// 校验位 -// /// -// public string Parity { get { return _mParity; } set { _mParity = value; OnPropertyChanged(); } } -// private string _mParity; - -// public ObservableCollection variables { get; set; } = new ObservableCollection(); -// } - -// public class Variable : ObservableObject -// { -// public int Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } } -// private int _mId; - - -// public string Address { get { return _mAddress; } set { _mAddress = value; OnPropertyChanged(); } } -// private string _mAddress; - - -// public int ReadLeng { get { return _mReadLeng; } set { _mReadLeng = value; OnPropertyChanged(); } } -// private int _mReadLeng; - - -// } -//} diff --git a/BPASmartClient/App.xaml b/BPASmartClient/App.xaml index a8c1adef..28a2b7fc 100644 --- a/BPASmartClient/App.xaml +++ b/BPASmartClient/App.xaml @@ -26,7 +26,8 @@ - + + diff --git a/BPASmartClient/BPASmartClient.csproj b/BPASmartClient/BPASmartClient.csproj index b855cb67..3dea524b 100644 --- a/BPASmartClient/BPASmartClient.csproj +++ b/BPASmartClient/BPASmartClient.csproj @@ -7,8 +7,13 @@ true true BPASmartClient.App + hbl.ico + + + + @@ -30,7 +35,6 @@ - diff --git a/BPASmartClient/Control/DeviceMonitorView.xaml b/BPASmartClient/Control/DeviceMonitorView.xaml index 6f2c38dd..e95c947c 100644 --- a/BPASmartClient/Control/DeviceMonitorView.xaml +++ b/BPASmartClient/Control/DeviceMonitorView.xaml @@ -1,13 +1,123 @@ - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index c94b5647..7515e122 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -82,11 +82,13 @@ Header="阿里连接维护" Tag="DataVView" /> - + Tag="DebugView" /> + + >(JsonString); + // if (result != null) + // { + // foreach (var shop in result)//店铺集合 + // { + // foreach (var device in shop.deviceModels)//设备集合 + // { + + // dv.Items.Add(new MenuItem { Header = device.DeviceModule }); + // } + // } + // } + //} } /// /// 获取设备集合 @@ -197,10 +217,9 @@ namespace BPASmartClient }); }); - } - #endregion - #region Click + } + /// /// 菜单切换栏 /// @@ -222,6 +241,24 @@ namespace BPASmartClient MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]"); } } + + private void Debug_Click(object sender,RoutedEventArgs e) + { + try + { + if (sender is MenuItem) + { + Type type = Assembly.Load("BPASmartClient.MorkT").GetType("BPASmartClient.MorkT.View.DebugView"); + ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes); + contentRegion.Content = (FrameworkElement)cti.Invoke(null); + Title.Text = (sender as MenuItem).Header?.ToString() + "界面"; + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx($"BPASmartClient 中引发错误,MainWindow.xaml.cs 类MenuItem_Click(),描述:[{ex.Message}]"); + } + } #endregion #region 公用 diff --git a/BPASmartClient/hbl.ico b/BPASmartClient/hbl.ico new file mode 100644 index 00000000..cf89051a Binary files /dev/null and b/BPASmartClient/hbl.ico differ diff --git a/SmartClient.sln b/SmartClient.sln index 9870235b..7727b312 100644 --- a/SmartClient.sln +++ b/SmartClient.sln @@ -76,9 +76,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.PLC", "BPASm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MorkF", "BPASmartClient.MorkF\BPASmartClient.MorkF.csproj", "{15FD3FF1-80F1-4274-945A-BA5EBA35999E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MORKIC", "HBLConsole.MORKIC\BPASmartClient.MORKIC.csproj", "{31A3B51C-A4BB-4FEB-B712-38482F6D1667}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPASmartClient.LebaiRobot", "BPASmartClient.LebaiRobot\BPASmartClient.LebaiRobot.csproj", "{D40C3CC7-C07C-4882-93D3-7F9ABCD3B5F0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.LebaiRobot", "BPASmartClient.LebaiRobot\BPASmartClient.LebaiRobot.csproj", "{D40C3CC7-C07C-4882-93D3-7F9ABCD3B5F0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -654,18 +652,6 @@ Global {15FD3FF1-80F1-4274-945A-BA5EBA35999E}.Release|x64.Build.0 = Release|Any CPU {15FD3FF1-80F1-4274-945A-BA5EBA35999E}.Release|x86.ActiveCfg = Release|Any CPU {15FD3FF1-80F1-4274-945A-BA5EBA35999E}.Release|x86.Build.0 = Release|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Debug|Any CPU.Build.0 = Debug|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Debug|ARM.ActiveCfg = Debug|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Debug|x64.ActiveCfg = Debug|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Debug|x86.ActiveCfg = Debug|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Release|Any CPU.ActiveCfg = Release|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Release|Any CPU.Build.0 = Release|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Release|ARM.ActiveCfg = Release|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Release|ARM64.ActiveCfg = Release|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Release|x64.ActiveCfg = Release|Any CPU - {31A3B51C-A4BB-4FEB-B712-38482F6D1667}.Release|x86.ActiveCfg = Release|Any CPU {D40C3CC7-C07C-4882-93D3-7F9ABCD3B5F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D40C3CC7-C07C-4882-93D3-7F9ABCD3B5F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {D40C3CC7-C07C-4882-93D3-7F9ABCD3B5F0}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -719,7 +705,6 @@ Global {3A55F68A-D526-4CFC-A5A6-B69FB76716C2} = {666CB1A9-562E-453A-A2C7-FD9D77CFDFDD} {7F04A788-38B5-42CB-B601-70C657C953B8} = {666CB1A9-562E-453A-A2C7-FD9D77CFDFDD} {15FD3FF1-80F1-4274-945A-BA5EBA35999E} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F} - {31A3B51C-A4BB-4FEB-B712-38482F6D1667} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F} {D40C3CC7-C07C-4882-93D3-7F9ABCD3B5F0} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/WpfLibrary1/Class1.cs b/WpfLibrary1/Class1.cs new file mode 100644 index 00000000..ee7f48bf --- /dev/null +++ b/WpfLibrary1/Class1.cs @@ -0,0 +1,8 @@ +using System; + +namespace WpfLibrary1 +{ + public class Class1 + { + } +} diff --git a/WpfLibrary1/WpfLibrary1.csproj b/WpfLibrary1/WpfLibrary1.csproj new file mode 100644 index 00000000..9a7c06f1 --- /dev/null +++ b/WpfLibrary1/WpfLibrary1.csproj @@ -0,0 +1,9 @@ + + + + net6.0-windows + enable + true + + +