Просмотр исходного кода

Merge branch 'master' of http://49.235.130.76/XXF_1122/DaisyNPILine

KWD 5 месяцев назад
Родитель
Сommit
a563764b87

+ 94 - 44
TeamAAS-VM/Core/Management.cs

@@ -977,7 +977,7 @@ namespace TeamAAS_VP.Core
                 try
                 {
                     await WriteSystemParameterToPlcAsync(_configService.GetSystemConfiguration());
-                    await WritePositionToPlcAsync();
+                    await WriteParameterToPlcExAsync();
                 }
                 catch (Exception ex)
                 {
@@ -1187,6 +1187,17 @@ namespace TeamAAS_VP.Core
             plc.SubscribeNodes("AutoSensor", monitorNodeIds, PlcCommandTrigger);
         }
 
+        /// <summary>
+        /// 将产品的参数统一写入PLC
+        /// </summary>
+        /// <returns></returns>
+        public async Task WriteParameterToPlcExAsync()
+        {
+            await WritePositionToPlcAsync();// 写入点位信息给PLC
+            //await WriteParameterToPlcAsync();// 写入组装上下限给PLC
+            await WriteProductLoadModeToPLC();//把当前产品型号,写入PLC
+        }
+
         /// <summary>
         /// 写入点位信息给PLC
         /// </summary>
@@ -1267,6 +1278,38 @@ namespace TeamAAS_VP.Core
             }
         }
 
+        /// <summary>
+        /// 将当前产品类型写入PLC
+        /// </summary>
+        /// <param name="mode"></param>
+        public async Task WriteProductLoadModeToPLC(int modeIndex)
+        {
+            var addressConfig = _configService.GetPlcAddresses();
+            var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null || !plc.IsConnected) return;
+
+            await plc.WriteNodeAsync(addressConfig.Out_ProductLoadMode.Address, (Int16)modeIndex);
+        }
+
+        /// <summary>
+        /// 将当前产品类型写入PLC
+        /// </summary>
+        /// <param name="mode"></param>
+        public async Task WriteProductLoadModeToPLC()
+        {
+            var addressConfig = _configService.GetPlcAddresses();
+            var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
+            if (plc == null || !plc.IsConnected) return;
+
+            var current = _productService.GetCurrentProduct();
+            if (current == null) return;
+
+            var qMes = await _systemDatabaseService.QueryProductFromMesAsync(current.Name);
+            if (qMes == null) return;
+
+            await plc.WriteNodeAsync(addressConfig.Out_ProductLoadMode.Address, (Int16)qMes.ProductLoadMode);
+        }
+
         PointF[] DowmCameraResults = new PointF[10];
         PointF[] UpCameraPutResults = new PointF[10];
 
@@ -2216,7 +2259,7 @@ namespace TeamAAS_VP.Core
                                     code = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, i));
                                 }
                                 productSn = code;
-                                           
+
 
                                 //询问mes
                                 if (state == 1)
@@ -2245,12 +2288,13 @@ namespace TeamAAS_VP.Core
                                                 string ProductMainSN_Temp = "";
                                                 LogHelper.WriteLogMes($"询问mes成功");
                                                 SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
-
                                                 string[] item = response.Split('\n');
-                                                if (item[2].Contains("sn="))
+                                                //获取过度件sn
+                                                string snItem = item.FirstOrDefault(f => f.Contains("sn="));
+                                                if (snItem != null)
                                                 {
-                                                    ProductMainSN_Temp = item[2].Replace("sn=", "");
-                                                    SendTaskMessage($"流程sn:{ProductMainSN_Temp}", MessageLevel.Info);
+                                                    ProductMainSN_Temp = snItem.Replace("sn=", "").Trim();
+                                                    SendTaskMessage($"过度件sn:{ProductMainSN_Temp}", MessageLevel.Info);
                                                 }
 
                                                 LogHelper.WriteLogMes($"询问mes成功");
@@ -2264,28 +2308,31 @@ namespace TeamAAS_VP.Core
                                                     SendTaskMessage($"询问mes成功:{response2}", MessageLevel.Debug);
 
                                                     item = response2.Split('\n');
-
-                                                    if (item[1].Contains("color="))
+                                                    snItem = item.FirstOrDefault(f => f.Contains("sn="));
+                                                    if (snItem != null)
                                                     {
-                                                        color[i] = item[1].Replace("color=", "");
-                                                        SendTaskMessage($"产品color:{color[i]}", MessageLevel.Info);
+                                                        ProductMainSN[i] = snItem.Replace("sn=", "").Trim();
+                                                        _productService.CurrentProductCode = ProductMainSN[i];
+                                                        _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                                        SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                     }
-                                                    if (item[3].Contains("model_num="))
+                                                    string woItem = item.FirstOrDefault(f => f.Contains("wo="));
+                                                    if (woItem != null)
                                                     {
-                                                        model_num[i] = item[3].Replace("model_num=", "");
-                                                        SendTaskMessage($"产品model_num:{model_num[i]}", MessageLevel.Info);
+                                                        wo[i] = woItem.Replace("wo=", "").Trim();
+                                                        SendTaskMessage($"工单信息:{wo[i]}", MessageLevel.Info);
                                                     }
-                                                    if (item[4].Contains("sn="))
+                                                    string modelItem = item.FirstOrDefault(f => f.Contains("model_num="));
+                                                    if (modelItem != null)
                                                     {
-                                                        ProductMainSN[i] = item[4].Replace("sn=", "");
-                                                        SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
-                                                        _productService.CurrentProductCode = ProductMainSN[i];
-                                                        _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                                        model_num[i] = modelItem.Replace("model_num=", "").Trim();
+                                                        SendTaskMessage($"model_num:{model_num[i]}", MessageLevel.Info);
                                                     }
-                                                    if (item[5].Contains("wo="))
+                                                    string colorItem = item.FirstOrDefault(f => f.Contains("color="));
+                                                    if (colorItem != null)
                                                     {
-                                                        wo[i] = item[5].Replace("wo=", "");
-                                                        SendTaskMessage($"产品主wo:{wo[i]}", MessageLevel.Info);
+                                                        color[i] = colorItem.Replace("color=", "").Trim();
+                                                        SendTaskMessage($"color:{color[i]}", MessageLevel.Info);
                                                     }
 
                                                     LogHelper.WriteLogMes($"第二次询问mes成功");
@@ -2295,13 +2342,13 @@ namespace TeamAAS_VP.Core
                                                     if (i == 0)//i=0时才会切换产品
                                                     {
                                                         var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num[i], color[i]);
-                                                        if (!string.IsNullOrEmpty(q))
+                                                        if (q != null && !string.IsNullOrEmpty(q.ProductName))
                                                         {
                                                             ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
                                                             Guid productId = Guid.Empty;
                                                             foreach (var itt in ProductList)
                                                             {
-                                                                if (itt.Name == q)
+                                                                if (itt.Name == q.ProductName)
                                                                 {
                                                                     productId = itt.ID;
                                                                     break;
@@ -2310,9 +2357,9 @@ namespace TeamAAS_VP.Core
                                                             if (currentProduct.ID != productId)
                                                             {
                                                                 //切换产品
-                                                                _productService.LoadProduct(productId);
+                                                                await _productService.LoadProductAsync(productId);
                                                                 _productService.SetCurrentProduct(productId);
-                                                                await WritePositionToPlcAsync();
+                                                                await WriteParameterToPlcExAsync();
                                                                 SendTaskMessage($"切换产品成功", MessageLevel.Debug);
                                                             }
                                                         }
@@ -2353,41 +2400,44 @@ namespace TeamAAS_VP.Core
                                                 SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
 
                                                 var item = response.Split('\n');
-
-                                                if (item[1].Contains("color="))
+                                                string snItem = item.FirstOrDefault(f => f.Contains("sn="));
+                                                if (snItem != null)
                                                 {
-                                                    color[i] = item[1].Replace("color=", "");
-                                                    SendTaskMessage($"产品color:{color[i]}", MessageLevel.Info);
+                                                    ProductMainSN[i] = snItem.Replace("sn=", "").Trim();
+                                                    _productService.CurrentProductCode = ProductMainSN[i];
+                                                    _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                                    SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                 }
-                                                if (item[3].Contains("model_num="))
+                                                string woItem = item.FirstOrDefault(f => f.Contains("wo="));
+                                                if (woItem != null)
                                                 {
-                                                    model_num[i] = item[3].Replace("model_num=", "");
-                                                    SendTaskMessage($"产品model_num:{model_num[i]}", MessageLevel.Info);
+                                                    wo[i] = woItem.Replace("wo=", "").Trim();
+                                                    SendTaskMessage($"工单信息:{wo[i]}", MessageLevel.Info);
                                                 }
-                                                if (item[4].Contains("sn="))
+                                                string modelItem = item.FirstOrDefault(f => f.Contains("model_num="));
+                                                if (modelItem != null)
                                                 {
-                                                    ProductMainSN[i] = item[4].Replace("sn=", "");
-                                                    SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
-                                                    _productService.CurrentProductCode = ProductMainSN[i];
-                                                    _eventAggregator.GetEvent<DelaySaveImageNotification>().Publish(true);//通知界面延迟保存图片,等待MES查询结果返回,避免图片和数据不同步
+                                                    model_num[i] = modelItem.Replace("model_num=", "").Trim();
+                                                    SendTaskMessage($"model_num:{model_num[i]}", MessageLevel.Info);
                                                 }
-                                                if (item[5].Contains("wo="))
+                                                string colorItem = item.FirstOrDefault(f => f.Contains("color="));
+                                                if (colorItem != null)
                                                 {
-                                                    wo[i] = item[5].Replace("wo=", "");
-                                                    SendTaskMessage($"产品主wo:{wo[i]}", MessageLevel.Info);
+                                                    color[i] = colorItem.Replace("color=", "").Trim();
+                                                    SendTaskMessage($"color:{color[i]}", MessageLevel.Info);
                                                 }
 
                                                 //切换产品
                                                 if (i == 0)//i=0时才会切换产品
                                                 {
                                                     var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num[i], color[i]);
-                                                    if (!string.IsNullOrEmpty(q))
+                                                    if (q != null && !string.IsNullOrEmpty(q.ProductName))
                                                     {
                                                         ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
                                                         Guid productId = Guid.Empty;
                                                         foreach (var itt in ProductList)
                                                         {
-                                                            if (itt.Name == q)
+                                                            if (itt.Name == q.ProductName)
                                                             {
                                                                 productId = itt.ID;
                                                                 break;
@@ -2396,9 +2446,9 @@ namespace TeamAAS_VP.Core
                                                         if (currentProduct.ID != productId)
                                                         {
                                                             //切换产品
-                                                            _productService.LoadProduct(productId);
+                                                            await _productService.LoadProductAsync(productId);
                                                             _productService.SetCurrentProduct(productId);
-                                                            await WritePositionToPlcAsync();
+                                                            await WriteParameterToPlcExAsync();
                                                             SendTaskMessage($"切换产品成功", MessageLevel.Debug);
                                                         }
                                                     }

+ 46 - 39
TeamAAS-VM/Data/SystemDatabaseService.cs

@@ -130,7 +130,7 @@ namespace TeamAAS_VP.Data
             {
                 UserId = userId,
                 Success = true,
-                Time = DateTime.Now,
+                Time = DateTime.UtcNow,
                 Message = "Set as current user"
             };
 
@@ -150,7 +150,7 @@ namespace TeamAAS_VP.Data
             {
                 UserId = user.Id,
                 Success = true,
-                Time = DateTime.Now,
+                Time = DateTime.UtcNow,
                 Message = user.UserName
             };
             await RecordUserLoginAsync(rec);
@@ -194,7 +194,7 @@ namespace TeamAAS_VP.Data
         public async Task RecordUserLoginAsync(UserLoginRecord record)
         {
             if (record == null) throw new ArgumentNullException(nameof(record));
-            if (record.Time == default(DateTime)) record.Time = DateTime.Now;
+            if (record.Time == default(DateTime)) record.Time = DateTime.UtcNow;
             await _db.Insertable(record).ExecuteCommandAsync();
         }
 
@@ -401,9 +401,9 @@ namespace TeamAAS_VP.Data
         public async Task<int> GetTodayProductionAsync(string productName)
         {
             //今天的起始时间
-            var todayStart = DateTime.Now.Date;
+            var todayStart = DateTime.UtcNow.Date;
             //今天的结束时间
-            var todayEnd = DateTime.Now.Date;
+            var todayEnd = DateTime.UtcNow.Date;
             todayEnd = todayEnd.AddDays(1);
             //按照产品名称和时间范围查询生产记录的总数
             var total = await _db.Queryable<ProductionRecord>()
@@ -419,8 +419,8 @@ namespace TeamAAS_VP.Data
         /// <returns></returns>
         public async Task<int> GetLastHourProductionAsync(string productName)
         {
-            var lastHourStart = DateTime.Now.AddHours(-1);
-            var lastHourEnd = DateTime.Now;
+            var lastHourStart = DateTime.UtcNow.AddHours(-1);
+            var lastHourEnd = DateTime.UtcNow;
             //按照产品名称和时间范围查询生产记录的总数
             var total = await _db.Queryable<ProductionRecord>()
                 .Where(r => r.ProductName == productName && r.Timestamp >= lastHourStart && r.Timestamp < lastHourEnd)
@@ -436,9 +436,9 @@ namespace TeamAAS_VP.Data
         public async Task<int> GetNGProductionAsync(string productName)
         {
             //今天的起始时间
-            var todayStart = DateTime.Now.Date;
+            var todayStart = DateTime.UtcNow.Date;
             //今天的结束时间
-            var todayEnd = DateTime.Now.Date;
+            var todayEnd = DateTime.UtcNow.Date;
             todayEnd = todayEnd.AddDays(1);
             //按照产品名称和时间范围查询生产记录的总数
             var total = await _db.Queryable<ProductionRecord>()
@@ -455,7 +455,7 @@ namespace TeamAAS_VP.Data
         public Task<int> GetCurrentMonthProductionAsync(string productName)
         {
 
-            var now = DateTime.Now;
+            var now = DateTime.UtcNow;
             var monthStart = new DateTime(now.Year, now.Month, 1);
             var monthEnd = monthStart.AddMonths(1);
             //按照产品名称和时间范围查询生产记录的总数
@@ -472,7 +472,7 @@ namespace TeamAAS_VP.Data
         /// <returns></returns>
         public Task<int> GetCurrentWeekProductionAsync(string productName)
         {
-            var now = DateTime.Now;
+            var now = DateTime.UtcNow;
             var weekStart = FirstDayOfWeek(now);
             var weekEnd = weekStart.AddDays(7);
             //按照产品名称和时间范围查询生产记录的总数
@@ -545,7 +545,7 @@ namespace TeamAAS_VP.Data
         /// <returns></returns>
         public async Task<Dictionary<DateTime, Dictionary<string, int>>> GetMonthlyProductionByDayAndCategoryAsync(string productName)
         {
-            var now = DateTime.Now;
+            var now = DateTime.UtcNow;
             var monthStart = new DateTime(now.Year, now.Month, 1);
             var monthEnd = monthStart.AddMonths(1);
             var list = await _db.Queryable<ProductionRecord>()
@@ -570,7 +570,7 @@ namespace TeamAAS_VP.Data
         /// <returns></returns>
         public async Task<Dictionary<int, Dictionary<string, int>>> GetWeeklyProductionByDayAndCategoryAsync(string productName)
         {
-            var now = DateTime.Now;
+            var now = DateTime.UtcNow;
             var weekStart = FirstDayOfWeek(now);
             var weekEnd = weekStart.AddDays(7);
             var list = await _db.Queryable<ProductionRecord>()
@@ -594,7 +594,7 @@ namespace TeamAAS_VP.Data
         /// <returns></returns>
         public async Task<Dictionary<int, Dictionary<string, int>>> GetDailyProductionByHourAndCategoryAsync(string productName)
         {
-            var now = DateTime.Now;
+            var now = DateTime.UtcNow;
             var dayStart = now.Date;
             var dayEnd = dayStart.AddDays(1);
             var list = await _db.Queryable<ProductionRecord>()
@@ -637,7 +637,7 @@ namespace TeamAAS_VP.Data
         public async Task RecordAlarmAsync(AlarmRecord alarm)
         {
             if (alarm == null) throw new ArgumentNullException(nameof(alarm));
-            if (alarm.Time == default(DateTime)) alarm.Time = DateTime.Now;
+            if (alarm.Time == default(DateTime)) alarm.Time = DateTime.UtcNow;
             await _db.Insertable(alarm).ExecuteCommandAsync();
         }
 
@@ -670,7 +670,7 @@ namespace TeamAAS_VP.Data
             try
             {
                 if (result == null) throw new ArgumentNullException(nameof(result));
-                if (result.Timestamp == default(DateTime)) result.Timestamp = DateTime.Now;
+                if (result.Timestamp == default(DateTime)) result.Timestamp = DateTime.UtcNow;
                 await _db.Insertable(result).ExecuteCommandAsync();
             }
             catch (Exception)
@@ -724,7 +724,7 @@ namespace TeamAAS_VP.Data
         public async Task RecordScrewFeederBatchAsync(ScrewFeederBatchRecord record)
         {
             if (record == null) throw new ArgumentNullException(nameof(record));
-            if (record.ChangeTime == default(DateTime)) record.ChangeTime = DateTime.Now;
+            if (record.ChangeTime == default(DateTime)) record.ChangeTime = DateTime.UtcNow;
             record.Id = record.Id == Guid.Empty ? Guid.NewGuid() : record.Id;
             await _db.Insertable(record).ExecuteCommandAsync();
         }
@@ -798,7 +798,7 @@ namespace TeamAAS_VP.Data
         public async Task RecordPhotoCaptureAsync(PhotoCaptureRecord record)
         {
             if (record == null) throw new ArgumentNullException(nameof(record));
-            if (record.CaptureTime == default(DateTime)) record.CaptureTime = DateTime.Now;
+            if (record.CaptureTime == default(DateTime)) record.CaptureTime = DateTime.UtcNow;
             record.Id = record.Id == Guid.Empty ? Guid.NewGuid() : record.Id;
             await _db.Insertable(record).ExecuteCommandAsync();
         }
@@ -852,7 +852,7 @@ namespace TeamAAS_VP.Data
         public async Task RecordHeadChangeAsync(HeadChangeRecord record)
         {
             if (record == null) throw new ArgumentNullException(nameof(record));
-            if (record.ChangeTime == default(DateTime)) record.ChangeTime = DateTime.Now;
+            if (record.ChangeTime == default(DateTime)) record.ChangeTime = DateTime.UtcNow;
             record.Id = record.Id == Guid.Empty ? Guid.NewGuid() : record.Id;
             await _db.Insertable(record).ExecuteCommandAsync();
         }
@@ -916,7 +916,7 @@ namespace TeamAAS_VP.Data
                 {
                     var newRec = new HeadChangeRecord
                     {
-                        ChangeTime = DateTime.Now,
+                        ChangeTime = DateTime.UtcNow,
                         HeadBatchNumber = string.Empty,
                         CurrentLockCount = 1,
                         OperatorName = operatorName
@@ -949,7 +949,7 @@ namespace TeamAAS_VP.Data
         public async Task RecordNozzleChangeAsync(NozzleChangeRecord record)
         {
             if (record == null) throw new ArgumentNullException(nameof(record));
-            if (record.ChangeTime == default(DateTime)) record.ChangeTime = DateTime.Now;
+            if (record.ChangeTime == default(DateTime)) record.ChangeTime = DateTime.UtcNow;
             record.Id = record.Id == Guid.Empty ? Guid.NewGuid() : record.Id;
             await _db.Insertable(record).ExecuteCommandAsync();
         }
@@ -996,7 +996,7 @@ namespace TeamAAS_VP.Data
                 {
                     var newRec = new NozzleChangeRecord
                     {
-                        ChangeTime = DateTime.Now,
+                        ChangeTime = DateTime.UtcNow,
                         NozzleBatchNumber = string.Empty,
                         CurrentLockCount = 1,
                         OperatorName = operatorName
@@ -1046,7 +1046,7 @@ namespace TeamAAS_VP.Data
             {
                 var record = new NozzleChangeRecord
                 {
-                    ChangeTime = DateTime.Now.AddMinutes(-i * 10),
+                    ChangeTime = DateTime.UtcNow.AddMinutes(-i * 10),
                     NozzleBatchNumber = $"Batch-{i}",
                     CurrentLockCount = i,
                     OperatorName = $"Operator-{i}"
@@ -1059,7 +1059,7 @@ namespace TeamAAS_VP.Data
             {
                 var record = new HeadChangeRecord
                 {
-                    ChangeTime = DateTime.Now.AddMinutes(-i * 15),
+                    ChangeTime = DateTime.UtcNow.AddMinutes(-i * 15),
                     HeadBatchNumber = $"HeadBatch-{i}",
                     CurrentLockCount = i,
                     OperatorName = $"HeadOperator-{i}"
@@ -1072,7 +1072,7 @@ namespace TeamAAS_VP.Data
             {
                 var record = new ScrewFeederBatchRecord
                 {
-                    ChangeTime = DateTime.Now.AddMinutes(-i * 20),
+                    ChangeTime = DateTime.UtcNow.AddMinutes(-i * 20),
                     BatchNumber = $"ScrewBatch-{i}",
                     FeederNumber = i + 1
                 };
@@ -1088,7 +1088,7 @@ namespace TeamAAS_VP.Data
                     ProductName = "产品1",
                     Category = (i % 2 == 0) ? "OK" : "NG",
                     Quantity = 1,
-                    Timestamp = DateTime.Now.AddMinutes(-i * 5),
+                    Timestamp = DateTime.UtcNow.AddMinutes(-i * 5),
                     UserName = "TestUser",
                     Remark = $"TotalSeconds:1.10"
                 };
@@ -1101,7 +1101,7 @@ namespace TeamAAS_VP.Data
                 var result = new LockResult(i % 4, $"PN-{i % 5}", 10.5f, 0.3f, (i % 3 != 0))
                 {
                     ProductName = "产品1",
-                    Timestamp = DateTime.Now.AddMinutes(-i * 3),
+                    Timestamp = DateTime.UtcNow.AddMinutes(-i * 3),
                 };
                 await RecordLockResultAsync(result);
             }
@@ -1118,7 +1118,7 @@ namespace TeamAAS_VP.Data
                         CameraName = $"下相机",
                         ProductSN = $"SN-{i}",
                         IsSuccess = (i % 2 == 0),
-                        CaptureTime = DateTime.Now.AddMinutes(-i * 7),
+                        CaptureTime = DateTime.UtcNow.AddMinutes(-i * 7),
                         ImagePath = $"/images/photo_{i}.jpg"
                     };
                     await RecordPhotoCaptureAsync(record);
@@ -1155,9 +1155,9 @@ namespace TeamAAS_VP.Data
         public async Task<int> GetThrowNumberAsync()
         {
             //今天的起始时间
-            var todayStart = DateTime.Now.Date;
+            var todayStart = DateTime.UtcNow.Date;
             //今天的结束时间
-            var todayEnd = DateTime.Now.Date;
+            var todayEnd = DateTime.UtcNow.Date;
             todayEnd = todayEnd.AddDays(1);
             //按照时间范围查询抛料的总数
             var total = await _db.Queryable<ThrowRecord>()
@@ -1173,9 +1173,9 @@ namespace TeamAAS_VP.Data
         public async Task ResetThrowNumberAsync()
         {
             //今天的起始时间
-            var todayStart = DateTime.Now.Date;
+            var todayStart = DateTime.UtcNow.Date;
             //今天的结束时间
-            var todayEnd = DateTime.Now.Date;
+            var todayEnd = DateTime.UtcNow.Date;
             todayEnd = todayEnd.AddDays(1);
             await _db.Deleteable<ThrowRecord>().Where(r => r.DayTime >= todayStart && r.DayTime < todayEnd).ExecuteCommandAsync();
         }
@@ -1245,18 +1245,25 @@ namespace TeamAAS_VP.Data
         }
 
         /// <summary>
-        /// 通过产品的编码和颜色查询产品的名称
+        /// 通过产品的编码和颜色查询产品
         /// </summary>
         /// <param name="code"></param>
         /// <returns></returns>
-        public async Task<string> QueryProductFromMesAsync(string code, string color)
+        public async Task<ProductWithMes> QueryProductFromMesAsync(string code, string color)
         {
             var v = await _db.Queryable<ProductWithMes>().Where(r => r.ProductCode == code && r.ProductColor == color).FirstAsync();
-            if (v == null || v.ProductName == null)
-            {
-                return "";
-            }
-            return v.ProductName;
+            return v;
+        }
+
+        /// <summary>
+        /// 通过产品名称的查询产品
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public async Task<ProductWithMes> QueryProductFromMesAsync(string name)
+        {
+            var v = await _db.Queryable<ProductWithMes>().Where(r => r.ProductName == name).FirstAsync();
+            return v;
         }
         #endregion
     }

+ 9 - 2
TeamAAS-VM/Interfaces/ISystemDatabaseService.cs

@@ -554,11 +554,18 @@ namespace TeamAAS_VP.Interfaces
         Task<List<ProductWithMes>> QueryProductWithMesALLAsync();
 
         /// <summary>
-        /// 通过产品的编码和颜色查询产品的id
+        /// 通过产品的编码和颜色查询产品
         /// </summary>
         /// <param name="code"></param>
         /// <returns></returns>
-        Task<string> QueryProductFromMesAsync(string code, string color);
+        Task<ProductWithMes> QueryProductFromMesAsync(string code, string color);
+
+        /// <summary>
+        /// 通过产品名称的查询产品
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        Task<ProductWithMes> QueryProductFromMesAsync(string name);
         #endregion
     }
 }

+ 18 - 3
TeamAAS-VM/Models/PLC/PlcAddressConfig.cs

@@ -19,14 +19,24 @@ namespace TeamAAS_VP.Models.PLC
             set { SetProperty(ref _PlcNo, value); }
         }
 
-        private PlcAddress _WorkMode = new PlcAddress();
+        private PlcAddress _Out_ProductLoadMode;
+        /// <summary>
+        /// 产品切换类型
+        /// </summary>
+        public PlcAddress Out_ProductLoadMode
+        {
+            get { return _Out_ProductLoadMode; }
+            set { SetProperty(ref _Out_ProductLoadMode, value); }
+        }
+
+        private PlcAddress _Out_WorkMode = new PlcAddress();
         /// <summary>
         /// 工作模式 =1 拍1打1 =2 拍1打所有
         /// </summary>
         public PlcAddress Out_WorkMode
         {
-            get { return _WorkMode; }
-            set { SetProperty(ref _WorkMode, value); }
+            get { return _Out_WorkMode; }
+            set { SetProperty(ref _Out_WorkMode, value); }
         }
 
         private PlcAddress _PickPointNum = new PlcAddress();
@@ -742,6 +752,11 @@ namespace TeamAAS_VP.Models.PLC
             }
 
             // 2. 按 JSON 提供的数据设置默认值(以当前属性名为准)
+            Out_ProductLoadMode = Ensure(Out_ProductLoadMode);
+            Out_ProductLoadMode.Address = "ns=4;s=DB_Communication|FromPC.ProductLoadMode";
+            Out_ProductLoadMode.DataType = "int16";
+            Out_ProductLoadMode.Description = "产品切换类型";
+
             Out_WorkMode = Ensure(Out_WorkMode);
             Out_WorkMode.Address = "ns=4;s=DB_Communication|FromPC.WorkMode";
             Out_WorkMode.DataType = "int16";

+ 12 - 3
TeamAAS-VM/Models/ProductWithMes.cs

@@ -14,7 +14,7 @@ namespace TeamAAS_VP.Models
         //[SugarColumn(IsPrimaryKey = true)]
         //public Guid Id { get; set; } = Guid.NewGuid();
 
-        
+
         private string _ProductName;
         [SugarColumn(IsPrimaryKey = true)]
         /// <summary>
@@ -37,7 +37,7 @@ namespace TeamAAS_VP.Models
             set { SetProperty(ref _ProductCode, value); }
         }
 
-       
+
         private string _ProductColor = "";
         /// <summary>
         /// 产品颜色
@@ -47,6 +47,15 @@ namespace TeamAAS_VP.Models
             get { return _ProductColor; }
             set { SetProperty(ref _ProductColor, value); }
         }
-    }
 
+        private int _ProductLoadMode;
+        /// <summary>
+        /// 产品加载编号
+        /// </summary>
+        public int ProductLoadMode
+        {
+            get { return _ProductLoadMode; }
+            set { SetProperty(ref _ProductLoadMode, value); }
+        }
+    }
 }

+ 2 - 2
TeamAAS-VM/ViewModels/HomeViewModel.cs

@@ -280,9 +280,9 @@ namespace TeamAAS_VP.ViewModels
                     var waiting = new WaitingControl();
                     //show the dialog
                     var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
-                    _productService.LoadProduct(product.ID);
+                    await _productService.LoadProductAsync(product.ID);
                     _productService.SetCurrentProduct(product.ID);
-                    await management.WritePositionToPlcAsync();
+                    await management.WriteParameterToPlcExAsync();
                     if (DialogHost.IsDialogOpen("RootDialog"))
                     {
                         DialogHost.Close("RootDialog");

+ 1 - 1
TeamAAS-VM/ViewModels/MainWindowViewModel.cs

@@ -384,7 +384,7 @@ namespace TeamAAS_VP.ViewModels
                     }
                 }
                 _container.Resolve<ShowVisionRenderViewModel>().Renders = management.Renders;
-                await management.WritePositionToPlcAsync();
+                await management.WriteParameterToPlcExAsync();
 
             }
             var homeviewmodel = _container.Resolve<HomeViewModel>();

+ 1 - 1
TeamAAS-VM/ViewModels/Product/ProductParamsViewModel.cs

@@ -208,7 +208,7 @@ namespace TeamAAS_VP.ViewModels.Product
                 var current = _productService.GetCurrentProduct();
                 if (current != null && current.IsLoad)
                 {
-                    await management.WritePositionToPlcAsync();
+                    await management.WriteParameterToPlcExAsync();
                 }
                 if (DialogHost.IsDialogOpen("RootDialog"))
                 {

+ 3 - 0
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -1926,11 +1926,13 @@ namespace TeamAAS_VP.ViewModels
             {
                 ProMesInfo.ProductCode = "";
                 ProMesInfo.ProductColor = "";
+                ProMesInfo.ProductLoadMode = 0;
             }
             else
             {
                 ProMesInfo.ProductCode = v.ProductCode;
                 ProMesInfo.ProductColor = v.ProductColor;
+                ProMesInfo.ProductLoadMode = v.ProductLoadMode;
             }
         }
 
@@ -1945,6 +1947,7 @@ namespace TeamAAS_VP.ViewModels
                 {
                     ProMesInfo.ProductCode = "";
                     ProMesInfo.ProductColor = "";
+                    ProMesInfo.ProductLoadMode = 0;
                 }
             }
         }

+ 24 - 2
TeamAAS-VM/Views/SettingView.xaml

@@ -2913,7 +2913,8 @@
                                 <ColumnDefinition Width="auto" />
                             </Grid.ColumnDefinitions>
                             <Grid.RowDefinitions>
-                                <RowDefinition Height="auto" />
+                                <RowDefinition Height=" auto" />
+                                <RowDefinition Height=" auto" />
                                 <RowDefinition Height=" auto" />
                                 <RowDefinition Height=" auto" />
                                 <RowDefinition Height=" auto" />
@@ -2993,7 +2994,28 @@
                                 </TextBox.Text>
                             </TextBox>
 
-                            <StackPanel Grid.Row="5"
+                            <TextBlock Margin="0,0,0,8"
+                                       Grid.Row="3"
+                                       VerticalAlignment="Center"
+                                       Text="产品类型:"
+                                       FontSize="{DynamicResource Font.Size.Body3}"
+                                       HorizontalAlignment="Right" />
+                            <TextBox Grid.Row="3"
+                                     Grid.Column="1"
+                                     Margin="10,4"
+                                     MinWidth="100"
+                                     FontSize="{DynamicResource Font.Size.Body3}"
+                                     TextAlignment="Center"
+                                     HorizontalAlignment="Left"
+                                     VerticalAlignment="Center">
+                                <TextBox.Text>
+                                    <Binding Path="ProMesInfo.ProductLoadMode"
+                                             Mode="TwoWay">
+                                    </Binding>
+                                </TextBox.Text>
+                            </TextBox>
+
+                            <StackPanel Grid.Row="6"
                                         Grid.ColumnSpan="2"
                                         Margin="0,6"
                                         Orientation="Horizontal"