|
@@ -1,5 +1,6 @@
|
|
|
using AutoMapper;
|
|
|
using BizService;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
using Model.Dto;
|
|
|
using Model.Entities;
|
|
|
using PLCTool.Common;
|
|
@@ -18,14 +19,15 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
|
|
|
public class PLCWriteViewModel:BindableBase
|
|
|
{
|
|
|
private readonly IBasicPlcItemConfigService _iBasPlcItemConfigService;
|
|
|
-
|
|
|
+ private readonly ILogger _logger;
|
|
|
private readonly IMapper _mapper;
|
|
|
private List<BasPlcItemConfigDto> plcConfigs = new List<BasPlcItemConfigDto>();
|
|
|
- public PLCWriteViewModel(IBasicPlcItemConfigService iBasPlcItemConfigService, IMapper mapper)
|
|
|
+ public PLCWriteViewModel(IBasicPlcItemConfigService iBasPlcItemConfigService, IMapper mapper,ILogger logger)
|
|
|
{
|
|
|
|
|
|
_iBasPlcItemConfigService = iBasPlcItemConfigService;
|
|
|
_mapper = mapper;
|
|
|
+ _logger= logger;
|
|
|
WriteCommand = new DelegateCommand<object>(WriteToPlc);
|
|
|
GetPLCConfig();
|
|
|
}
|
|
@@ -59,6 +61,7 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
|
|
|
bool isResult = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.Bit, plcValue);
|
|
|
if(isResult)
|
|
|
{
|
|
|
+ _logger.LogInformation($"向PLC写入值。plc地址{plcAddr},数据值{plcValue}");
|
|
|
MessageBox.Show("写入成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
break;
|
|
@@ -66,6 +69,7 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
|
|
|
bool isResult2 = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.Word, plcValue);
|
|
|
if (isResult2)
|
|
|
{
|
|
|
+ _logger.LogInformation($"向PLC写入值。plc地址{plcAddr},数据值{plcValue}");
|
|
|
MessageBox.Show("写入成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
break;
|
|
@@ -73,6 +77,7 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
|
|
|
bool isResult3 = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.DWord, plcValue);
|
|
|
if (isResult3)
|
|
|
{
|
|
|
+ _logger.LogInformation($"向PLC写入值。plc地址{plcAddr},数据值{plcValue}");
|
|
|
MessageBox.Show("写入成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
break;
|
|
@@ -81,6 +86,7 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
|
|
|
bool isResult4 = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.Real, plcValue);
|
|
|
if (isResult4)
|
|
|
{
|
|
|
+ _logger.LogInformation($"向PLC写入值。plc地址{plcAddr},数据值{plcValue}");
|
|
|
MessageBox.Show("写入成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
break;
|