现场更改2
This commit is contained in:
@@ -9,7 +9,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.Services
|
||||
@@ -22,12 +21,6 @@ namespace CapMachine.Wpf.Services
|
||||
|
||||
public HighSpeedDataService HighSpeedDataService { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 读写锁,用于保护 ListCanDbcModel 的并发访问
|
||||
/// 支持多个读取操作同时进行,写入操作独占
|
||||
/// </summary>
|
||||
private readonly ReaderWriterLockSlim _dbcModelLock = new ReaderWriterLockSlim();
|
||||
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// </summary>
|
||||
@@ -63,25 +56,17 @@ namespace CapMachine.Wpf.Services
|
||||
/// </summary>
|
||||
public void InitCanConfig(CanLinConfigPro selectedCanLinConfigPro)
|
||||
{
|
||||
_dbcModelLock.EnterWriteLock();
|
||||
try
|
||||
//赋值配置数据
|
||||
SelectedCanLinConfigPro = selectedCanLinConfigPro;
|
||||
//为DBC实时数据关联配置的名称
|
||||
foreach (var item in SelectedCanLinConfigPro.CanLinConfigContents)
|
||||
{
|
||||
//赋值配置数据
|
||||
SelectedCanLinConfigPro = selectedCanLinConfigPro;
|
||||
//为DBC实时数据关联配置的名称
|
||||
foreach (var item in SelectedCanLinConfigPro.CanLinConfigContents)
|
||||
var FindData = ListCanDbcModel.FindFirst(a => a.SignalName == item.SignalName);
|
||||
if (FindData != null)
|
||||
{
|
||||
var FindData = ListCanDbcModel.FindFirst(a => a.SignalName == item.SignalName);
|
||||
if (FindData != null)
|
||||
{
|
||||
FindData.Name = item.Name;
|
||||
}
|
||||
FindData.Name = item.Name;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbcModelLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,22 +227,14 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
if (ToomossCanDrive.IsCycleRevice == false)
|
||||
{
|
||||
_dbcModelLock.EnterReadLock();
|
||||
try
|
||||
if (ListCanDbcModel.Count > 0)
|
||||
{
|
||||
if (ListCanDbcModel.Count > 0)
|
||||
{
|
||||
ToomossCanDrive.IsCycleRevice = true;
|
||||
ToomossCanDrive.StartPrecisionCycleSendMsg();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||||
}
|
||||
ToomossCanDrive.IsCycleRevice = true;
|
||||
ToomossCanDrive.StartPrecisionCycleSendMsg();
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
_dbcModelLock.ExitReadLock();
|
||||
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -278,18 +255,10 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
if (!ToomossCanDrive.IsCycleRevice) return 0;
|
||||
|
||||
_dbcModelLock.EnterReadLock();
|
||||
try
|
||||
if (ListCanDbcModel.Any(a => a.Name == Name))
|
||||
{
|
||||
if (ListCanDbcModel.Any(a => a.Name == Name))
|
||||
{
|
||||
//double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1);
|
||||
return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbcModelLock.ExitReadLock();
|
||||
//double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1);
|
||||
return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -305,18 +274,10 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
if (!ToomossCanDrive.IsCycleRevice) return 0;
|
||||
|
||||
_dbcModelLock.EnterReadLock();
|
||||
try
|
||||
if (ListCanDbcModel.Any(a => a.Name == Name))
|
||||
{
|
||||
if (ListCanDbcModel.Any(a => a.Name == Name))
|
||||
{
|
||||
//double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1);
|
||||
return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbcModelLock.ExitReadLock();
|
||||
//double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1);
|
||||
return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace CapMachine.Wpf.Services
|
||||
public CanDriveService CanDriveService { get; }
|
||||
public LinDriveService LinDriveService { get; }
|
||||
public SysRunService SysRunService { get; }
|
||||
public ILogService LogService { get; }
|
||||
|
||||
/// <summary>
|
||||
/// PLCScanTask扫描Task
|
||||
@@ -112,7 +113,7 @@ namespace CapMachine.Wpf.Services
|
||||
/// </summary>
|
||||
/// <param name="eventAggregator"></param>
|
||||
public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService, ConfigService configService,
|
||||
CanDriveService canDriveService, LinDriveService linDriveService, SysRunService sysRunService)//, AlarmService alarmService
|
||||
CanDriveService canDriveService, LinDriveService linDriveService, SysRunService sysRunService, ILogService logService)//, AlarmService alarmService
|
||||
{
|
||||
//ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>();
|
||||
|
||||
@@ -130,6 +131,7 @@ namespace CapMachine.Wpf.Services
|
||||
CanDriveService = canDriveService;
|
||||
LinDriveService = linDriveService;
|
||||
SysRunService = sysRunService;
|
||||
LogService = logService;
|
||||
|
||||
//秒触发一次
|
||||
CycleTimer = new System.Timers.Timer(500);
|
||||
@@ -1108,12 +1110,19 @@ namespace CapMachine.Wpf.Services
|
||||
/// </summary>
|
||||
private void RtScanDeviceStart()
|
||||
{
|
||||
LogService.Info("RtScanDeviceStart 开始启动 PLC 扫描线程");
|
||||
PLCScanTask = Task.Run(async () =>
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
int cycleCount = 0;
|
||||
|
||||
while (ThreadEnable)
|
||||
{
|
||||
cycleCount++;
|
||||
if (cycleCount % 20 == 0) // 每10秒记录一次
|
||||
{
|
||||
LogService.Info($"RtScanDeviceStart 循环计数: {cycleCount}");
|
||||
}
|
||||
//await Task.Delay(5);
|
||||
await Task.CompletedTask;
|
||||
|
||||
@@ -1121,6 +1130,7 @@ namespace CapMachine.Wpf.Services
|
||||
DiagnosticsTime.Start();
|
||||
try
|
||||
{
|
||||
LogService.Debug($"RtScanDeviceStart 开始扫描周期 {cycleCount}");
|
||||
//TagInfo.RtValue.Value++;
|
||||
|
||||
//var data = TagManger.DicTags["转速"].ValueType.Name;
|
||||
@@ -1173,7 +1183,16 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
case CanLinEnum.Can:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯转速"));
|
||||
try
|
||||
{
|
||||
var speedValue = CanDriveService.GetDbcSpeedValueBySpeedName("通讯转速");
|
||||
LogService.Debug($"RtScanDeviceStart 读取CAN通讯转速: {speedValue}");
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)speedValue);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 读取CAN通讯转速失败: {ex.Message}");
|
||||
}
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1191,7 +1210,16 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
case CanLinEnum.Can:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯母线电压") * itemTag.Value.Precision));
|
||||
try
|
||||
{
|
||||
var voltageValue = CanDriveService.GetDbcValueByName("通讯母线电压");
|
||||
LogService.Debug($"RtScanDeviceStart 读取CAN通讯母线电压: {voltageValue}");
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(voltageValue * itemTag.Value.Precision));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 读取CAN通讯母线电压失败: {ex.Message}");
|
||||
}
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1209,7 +1237,16 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
case CanLinEnum.Can:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯母线电流") * itemTag.Value.Precision));
|
||||
try
|
||||
{
|
||||
var currentValue = CanDriveService.GetDbcValueByName("通讯母线电流");
|
||||
LogService.Debug($"RtScanDeviceStart 读取CAN通讯母线电流: {currentValue}");
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(currentValue * itemTag.Value.Precision));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 读取CAN通讯母线电流失败: {ex.Message}");
|
||||
}
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1227,7 +1264,16 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
case CanLinEnum.Can:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯相电流") * itemTag.Value.Precision));
|
||||
try
|
||||
{
|
||||
var phaseCurrentValue = CanDriveService.GetDbcValueByName("通讯相电流");
|
||||
LogService.Debug($"RtScanDeviceStart 读取CAN通讯相电流: {phaseCurrentValue}");
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(phaseCurrentValue * itemTag.Value.Precision));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 读取CAN通讯相电流失败: {ex.Message}");
|
||||
}
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1245,7 +1291,16 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
case CanLinEnum.Can:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯功率") * itemTag.Value.Precision));
|
||||
try
|
||||
{
|
||||
var powerValue = CanDriveService.GetDbcValueByName("通讯功率");
|
||||
LogService.Debug($"RtScanDeviceStart 读取CAN通讯功率: {powerValue}");
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(powerValue * itemTag.Value.Precision));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 读取CAN通讯功率失败: {ex.Message}");
|
||||
}
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1263,7 +1318,16 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
case CanLinEnum.Can:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯芯片温度") * itemTag.Value.Precision));
|
||||
try
|
||||
{
|
||||
var tempValue = CanDriveService.GetDbcValueByName("通讯芯片温度");
|
||||
LogService.Debug($"RtScanDeviceStart 读取CAN通讯芯片温度: {tempValue}");
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(tempValue * itemTag.Value.Precision));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 读取CAN通讯芯片温度失败: {ex.Message}");
|
||||
}
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1297,7 +1361,16 @@ namespace CapMachine.Wpf.Services
|
||||
if (itemTag.Value.Group == "CANLIN")
|
||||
{
|
||||
//回读CAN通信的DBC集合数据到集合中
|
||||
itemTag.Value.EngPvValue = CanDriveService.GetDbcValueByName(itemTag.Value.NameNoUnit);
|
||||
try
|
||||
{
|
||||
var dbcValue = CanDriveService.GetDbcValueByName(itemTag.Value.NameNoUnit);
|
||||
itemTag.Value.EngPvValue = dbcValue;
|
||||
LogService.Debug($"RtScanDeviceStart 回读CAN数据 {itemTag.Value.NameNoUnit}: {dbcValue}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"RtScanDeviceStart 回读CAN数据 {itemTag.Value.NameNoUnit} 失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
@@ -1438,8 +1511,11 @@ namespace CapMachine.Wpf.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}");
|
||||
|
||||
LogService.Error($"RtScanDeviceStart 扫描异常 (周期 {cycleCount}): {ex.Message}\r\n堆栈: {ex.StackTrace}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
DiagnosticsTime.Stop();
|
||||
}
|
||||
|
||||
DiagnosticsTime.Stop();
|
||||
|
||||
Reference in New Issue
Block a user