From 08850a2f157ad334da7c2f7a25107c8c69dfaf65 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Tue, 28 May 2024 20:09:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=A7=BB=E6=A4=8D=E6=9F=A5=E8=AF=A2=E7=94=B5?= =?UTF-8?q?=E5=8E=8B=E5=80=BC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WCS.BLL/HardWare/SmartShelf.cs | 83 +++++++++++++++++++ WCS.BLL/HardWare/SmartShelfModule.cs | 29 ++++++- .../Services/IService/IStoreInfoService.cs | 7 ++ WCS.BLL/Services/Service/OutstoreService.cs | 8 ++ WCS.BLL/Services/Service/StoreInfoService.cs | 48 +++++++++++ .../StoreInfo/QueryModuleVoltageRequest.cs | 11 +++ WCS.WebApi/Controllers/StoreInfoController.cs | 7 ++ 货架标准上位机/Views/ModuleInfoView.xaml.cs | 36 +++++++- 货架标准上位机/data/jsconfig.json | 4 +- 9 files changed, 227 insertions(+), 6 deletions(-) create mode 100644 WCS.Model/ApiModel/StoreInfo/QueryModuleVoltageRequest.cs diff --git a/WCS.BLL/HardWare/SmartShelf.cs b/WCS.BLL/HardWare/SmartShelf.cs index a0c519a..1f392d6 100644 --- a/WCS.BLL/HardWare/SmartShelf.cs +++ b/WCS.BLL/HardWare/SmartShelf.cs @@ -626,6 +626,15 @@ namespace WCS.BLL.HardWare this.CurrentMode = Mode.待机模式; } + public void QueryVoltage(int moduleId) + { + var moudle = Modules.Where(t => t.ModuleId == moduleId).First(); + if (moudle != null) + { + moudle.QueryVoltage(TcpCleint); + } + } + void IShelfBase.SetCurrentMode() { throw new NotImplementedException(); @@ -684,6 +693,15 @@ namespace WCS.BLL.HardWare case 0x13://复位的返回信号 ResetReturnProcess(data, boardId, lightNumber); break; + case 0x17://电压值1 + QueryVoltageProcess(data, boardId, lightNumber); + break; + case 0x18://电压值2 + QueryVoltageProcess(data, boardId, lightNumber); + break; + case 0x19://电压值3 + QueryVoltageProcess(data, boardId, lightNumber); + break; default: ; break; @@ -1789,6 +1807,71 @@ namespace WCS.BLL.HardWare module.CurrentMode = Mode.待机模式; } } + + public void QueryVoltageProcess(byte[] data, int boardId, int lightNumber) + { + //第n帧 + var n = (int)data[TcpCleint.PreFixLength + 3]; + + var voltage1 = (data[TcpCleint.PreFixLength + 4] << 8) + data[TcpCleint.PreFixLength + 5]; + var voltage2 = (data[TcpCleint.PreFixLength + 6] << 8) + data[TcpCleint.PreFixLength + 7]; + var voltage3 = (data[TcpCleint.PreFixLength + 8] << 8) + data[TcpCleint.PreFixLength + 9]; + + var number1 = (n - 1) * 3 + 1; + var number2 = (n - 1) * 3 + 2; + var number3 = (n - 1) * 3 + 3; + + if (number1 <= 16) + { + var storeInfo1 = DbHelp.db.Queryable() + .Where(t => t.BoardId == boardId && t.LightNumber == number1 && t.ShelfId == ShelfId) + .First(); + if (storeInfo1 != null) + { + if (data[TcpCleint.PreFixLength + 2] == 0x17) + storeInfo1.CurrentVoltage = voltage1; + else if (data[TcpCleint.PreFixLength + 2] == 0x18) + storeInfo1.OffsetVoltage = voltage1; + else + storeInfo1.StandardVoltage = voltage1; + DbHelp.db.Updateable(storeInfo1).ExecuteCommand(); + } + } + + if (number2 <= 16) + { + var storeInfo2 = DbHelp.db.Queryable() + .Where(t => t.BoardId == boardId && t.LightNumber == number2 && t.ShelfId == ShelfId) + .First(); + if (storeInfo2 != null) + { + if (data[TcpCleint.PreFixLength + 2] == 0x17) + storeInfo2.CurrentVoltage = voltage2; + else if (data[TcpCleint.PreFixLength + 2] == 0x18) + storeInfo2.OffsetVoltage = voltage2; + else + storeInfo2.StandardVoltage = voltage2; + DbHelp.db.Updateable(storeInfo2).ExecuteCommand(); + } + } + + if (number1 <= 16) + { + var storeInfo3 = DbHelp.db.Queryable() + .Where(t => t.BoardId == boardId && t.LightNumber == number3 && t.ShelfId == ShelfId) + .First(); + if (storeInfo3 != null) + { + if (data[TcpCleint.PreFixLength + 2] == 0x17) + storeInfo3.CurrentVoltage = voltage3; + else if (data[TcpCleint.PreFixLength + 2] == 0x18) + storeInfo3.OffsetVoltage = voltage3; + else + storeInfo3.StandardVoltage = voltage3; + DbHelp.db.Updateable(storeInfo3).ExecuteCommand(); + } + } + } #endregion } diff --git a/WCS.BLL/HardWare/SmartShelfModule.cs b/WCS.BLL/HardWare/SmartShelfModule.cs index ab59ceb..3c3dd81 100644 --- a/WCS.BLL/HardWare/SmartShelfModule.cs +++ b/WCS.BLL/HardWare/SmartShelfModule.cs @@ -65,11 +65,22 @@ namespace WCS.BLL.HardWare /// public byte[] GoOutStockTakingModeData = { 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - /// /// 复位命令 /// public byte[] ResetData = { 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + /// + /// 查询当前电压值 + /// + public byte[] VoltageSingleData = { 0x17, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + /// + /// 电压偏移值 + /// + public byte[] OffsetSingleData = { 0x18, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + /// + /// 电压标准值 + /// + public byte[] StandardSingleData = { 0x19, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; #endregion public int ModuleId { get; set; } public string ModuleCode { get; set; } @@ -370,5 +381,21 @@ namespace WCS.BLL.HardWare tcpClient.Send(tcpClient.GenerateMessage(BoardId, ComfirmOutstoreData)); } + /// + /// 查询电压值 + /// + /// + public void QueryVoltage(TCPClient tcpClient) + { + Thread.Sleep(10); + Task.Run(() => + { + tcpClient.Send(tcpClient.GenerateMessage(BoardId, VoltageSingleData)); + Thread.Sleep(50); + tcpClient.Send(tcpClient.GenerateMessage(BoardId, StandardSingleData)); + Thread.Sleep(50); + tcpClient.Send(tcpClient.GenerateMessage(BoardId, OffsetSingleData)); + }); + } } } diff --git a/WCS.BLL/Services/IService/IStoreInfoService.cs b/WCS.BLL/Services/IService/IStoreInfoService.cs index e4ac645..73e869b 100644 --- a/WCS.BLL/Services/IService/IStoreInfoService.cs +++ b/WCS.BLL/Services/IService/IStoreInfoService.cs @@ -45,6 +45,13 @@ namespace WCS.BLL.Services.IService /// public Task disableOrEnableModule(DisableOrEnableModuleRequest request); + /// + /// 查询模组电压值 + /// + /// + /// + public Task queryModuleVoltage(QueryModuleVoltageRequest request); + /// /// 查询库位列表 diff --git a/WCS.BLL/Services/Service/OutstoreService.cs b/WCS.BLL/Services/Service/OutstoreService.cs index e57e316..eb4a440 100644 --- a/WCS.BLL/Services/Service/OutstoreService.cs +++ b/WCS.BLL/Services/Service/OutstoreService.cs @@ -691,6 +691,12 @@ namespace WCS.BLL.Services.Service outOrderMatDetails = outOrderMatDetails.Where(t => t.MatCode == matCode) .ToList(); Logs.Write($"出库单{order.OrderNumber},本次亮灯物料{matCode}!",LogsType.Outstore); + + //分批次亮灯再计算一次出哪些货架 以免亮大灯不亮小灯 + shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId) + .Distinct() + .ToList(); + shelfs = ShelfManager.Shelves.Where(t => shelfIds.Contains(t.ShelfId)).ToList(); } //相同物料不存在盘数超过n的情况,剩余物料全部亮灯 else @@ -698,6 +704,8 @@ namespace WCS.BLL.Services.Service //剩余物料全出 Logs.Write($"出库单{order.OrderNumber},剩余物料灯全亮!", LogsType.Outstore); } + + } //对应的货架对应位置 进入出库模式 亮灯 diff --git a/WCS.BLL/Services/Service/StoreInfoService.cs b/WCS.BLL/Services/Service/StoreInfoService.cs index 8ae2c07..5dde99b 100644 --- a/WCS.BLL/Services/Service/StoreInfoService.cs +++ b/WCS.BLL/Services/Service/StoreInfoService.cs @@ -397,6 +397,53 @@ namespace WCS.BLL.Services.Service }; } } + + + /// + /// 发送指令获取模组的电压值 + /// + /// + /// + /// + public async Task queryModuleVoltage(QueryModuleVoltageRequest request) + { + try + { + var modules = await DbHelp.db.Queryable().Where(t => request.MouduleIds.Contains(t.Id)).ToListAsync(); + var isSend = false; + foreach (var module in modules) + { + var shelf = ShelfManager.Shelves.Where(t => t.ShelfId == module.ShelfId).FirstOrDefault(); + if (shelf != null && shelf is SmartShelf) + { + var smartShelf = (SmartShelf)shelf; + smartShelf.QueryVoltage(module.Id); + isSend = true; + } + } + if (isSend) + return new ResponseCommon() + { + Code = 200, + Message = "Success" + }; + else + return new ResponseCommon() + { + Code = 201, + Message = "操作失败:未找到对应模组" + }; + } + catch (Exception ex) + { + return new ResponseCommon() + { + Code = 300, + Message = "操作失败:" + ex.Message + }; + } + } + #endregion #region 库位管理 @@ -534,6 +581,7 @@ namespace WCS.BLL.Services.Service } } + #endregion } } diff --git a/WCS.Model/ApiModel/StoreInfo/QueryModuleVoltageRequest.cs b/WCS.Model/ApiModel/StoreInfo/QueryModuleVoltageRequest.cs new file mode 100644 index 0000000..67ff5be --- /dev/null +++ b/WCS.Model/ApiModel/StoreInfo/QueryModuleVoltageRequest.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.StoreInfo +{ + public class QueryModuleVoltageRequest : RequestBase + { + public List MouduleIds { get; set; } + } +} diff --git a/WCS.WebApi/Controllers/StoreInfoController.cs b/WCS.WebApi/Controllers/StoreInfoController.cs index d0ac534..92dc1a4 100644 --- a/WCS.WebApi/Controllers/StoreInfoController.cs +++ b/WCS.WebApi/Controllers/StoreInfoController.cs @@ -59,6 +59,13 @@ namespace WCS.WebApi.Controllers { return await _storeInfoService.disableOrEnableModule(request); } + + [Route("queryModuleVoltage")] + [HttpPost(Name = "queryModuleVoltage")] + public async Task queryModuleVoltage(QueryModuleVoltageRequest request) + { + return await _storeInfoService.queryModuleVoltage(request); + } #endregion #region 库位管理 diff --git a/货架标准上位机/Views/ModuleInfoView.xaml.cs b/货架标准上位机/Views/ModuleInfoView.xaml.cs index 566de9b..7b3fe2a 100644 --- a/货架标准上位机/Views/ModuleInfoView.xaml.cs +++ b/货架标准上位机/Views/ModuleInfoView.xaml.cs @@ -1,4 +1,5 @@ -using Ping9719.WpfEx; +using HandyControl.Controls; +using Ping9719.WpfEx; using System; using System.Collections.Generic; using System.Diagnostics; @@ -14,7 +15,11 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using WCS.Model; +using WCS.Model.ApiModel.StoreInfo; +using 货架标准上位机.Api; using 货架标准上位机.ViewModel; +using 货架标准上位机.Views.Controls; namespace 货架标准上位机 { @@ -66,7 +71,7 @@ namespace 货架标准上位机 //dataGrid.UnselectAllCells(); // 取消选中所有单元格 } } - catch(Exception ex) + catch (Exception ex) { Debug.WriteLine("SelectionChanged event handler failed: " + ex.Message); } @@ -91,8 +96,33 @@ namespace 货架标准上位机 { //先获取选中的模组 var module = viewModel.SelectedataGridItem; - #region 调用接口 发送指令获取 + #region 调用接口 发送指令进行查询 + try + { + var body = new QueryModuleVoltageRequest() + { + MouduleIds = new List() { module.Id }, + UserName = LocalStatic.CurrentUser, + DeviceType = LocalFile.Config.DeviceType, + }; + var Result = ApiHelp.GetDataFromHttp(LocalFile.Config.ApiIpHost + "storeInfo/queryModuleVoltage", body, "POST"); + if (Result != null && Result.Code == 200) + { + Growl.Success("操作成功:可以进行查询!"); + } + else if (Result != null) + { + Growl.Success(Result.Message); + } + } + catch (Exception ex) + { + Growl.Error("操作失败:" + ex.Message); + } + finally + { + } #endregion } } diff --git a/货架标准上位机/data/jsconfig.json b/货架标准上位机/data/jsconfig.json index de00b3b..1aa3976 100644 --- a/货架标准上位机/data/jsconfig.json +++ b/货架标准上位机/data/jsconfig.json @@ -2,9 +2,9 @@ //连接不上加:SslMode=none; "MySql": "server=localhost;Database=db1;Uid=root;Pwd=123456;Convert Zero Datetime=True", //货架服务器的IP和端口号 - "ApiIpHost": "http://192.168.9.183:8888/", + "ApiIpHost": "http://127.0.0.1:8888/", //WebSocket的地址 - "WebSocketUrl": "ws://192.168.9.183:7789/ws", + "WebSocketUrl": "ws://127.0.0.1:7789/ws", //货架分区 "GroupName": [ "C0"], //设备类型 可以配置为每个电脑不一样