CAN的更改

This commit is contained in:
2025-05-09 16:13:11 +08:00
parent df4b481bbb
commit 03fd92ac86
8 changed files with 176 additions and 131 deletions

View File

@@ -618,7 +618,7 @@ namespace CapMachine.Wpf.CanDrive
// 预先计算固定值
long CycleInTicks = (long)(SendCycle * TicksPerMs);
//临时测试用
long lastTicks = Stopwatcher.ElapsedTicks;
//long lastTicks = Stopwatcher.ElapsedTicks;
//IsCycleSend
while (IsCycleSend && !token.IsCancellationRequested)
{
@@ -664,8 +664,9 @@ namespace CapMachine.Wpf.CanDrive
}
// 使用Stopwatch记录实际的执行间隔而不是DateTime
Console.WriteLine($"--实际间隔(ms): {(Stopwatcher.ElapsedTicks - lastTicks) / TicksPerMs:F3}, 目标: {SendCycle}");
lastTicks = Stopwatcher.ElapsedTicks;
//Console.WriteLine($"--实际间隔(ms): {(Stopwatcher.ElapsedTicks - lastTicks) / TicksPerMs:F3}, 目标: {SendCycle}");
//lastTicks = Stopwatcher.ElapsedTicks;
//Console.WriteLine($"--当前时间(毫秒): {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}");

View File

@@ -134,7 +134,7 @@ namespace CapMachine.Wpf.Services
get { return _AutoSpeedSv; }
set
{
if (value!= _AutoSpeedSv)
if (value != _AutoSpeedSv)
{
_AutoSpeedSv = value;
RaisePropertyChanged();
@@ -225,19 +225,33 @@ namespace CapMachine.Wpf.Services
}
/// <summary>
/// 更新压缩机使能数据
/// 更新压缩机使能数据 自动时的赋值数据
/// </summary>
/// <param name="IsEnable"></param>
public void UpdateCapEnableCmdData(bool IsEnable)
{
if (!ToomossCanDrive.IsCycleSend) return;
if (!CanAutoHand) return;
if (CanAutoHand)
{
if (EnableCanCmdData != null)
{
EnableCanCmdData.SignalCmdValue = IsEnable ? 1 : 0;
}
}
}
/// <summary>
/// 更新压缩机使能数据 手动时的赋值数据
/// </summary>
/// <param name="IsEnable"></param>
public void UpdateCapEnableCmdDataByHand(bool IsEnable)
{
if (EnableCanCmdData != null)
{
EnableCanCmdData.SignalCmdValue = IsEnable ? 1 : 0;
Console.WriteLine("压缩机使能:" + IsEnable);
}
}
/// <summary>
/// 发送消息给CAN 驱动

View File

@@ -296,7 +296,10 @@ namespace CapMachine.Wpf.Services
/// <exception cref="NotImplementedException"></exception>
private async void ListenRecoredChannelAction()
{
while (await RecoredChannelInfo.Reader.WaitToReadAsync())
{
try
{
if (RecoredChannelInfo.Reader.TryRead(out var recordChannelData))
{
@@ -359,12 +362,19 @@ namespace CapMachine.Wpf.Services
//Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}-{LineName}-保存成功!");
//}
//stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("保存数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset();
}
}
catch (Exception ex)
{
LogService.Error($"时间:{DateTime.Now.ToString()}-【ListenRecoredChannelAction】-{ex.Message}");
}
}
}
/// <summary>
@@ -459,7 +469,7 @@ namespace CapMachine.Wpf.Services
catch (Exception ex)
{
//CycleTimer.Start(); //执行完毕后再开启器
LogService.Info($"时间:{DateTime.Now.ToString()}-【PwAnalyze-CycleAction】-{ex.Message}");
LogService.Error($"时间:{DateTime.Now.ToString()}-【PwAnalyze-CycleAction】-{ex.Message}");
}
}

View File

@@ -174,6 +174,8 @@ namespace CapMachine.Wpf.Services
private async void ListenCycleChannelAction()
{
while (await CycleChannelInfo.Reader.WaitToReadAsync())
{
try
{
if (CycleChannelInfo.Reader.TryRead(out var CycleChannelData))
{
@@ -205,6 +207,12 @@ namespace CapMachine.Wpf.Services
//stopwatch.Reset();
}
}
catch (Exception ex)
{
LogService.Error($"时间:{DateTime.Now.ToString()}-【ListenCycleChannelAction】-{ex.Message}");
}
}
}
#endregion

View File

@@ -62,7 +62,7 @@ namespace CapMachine.Wpf.Services
/// <summary>
/// 是否启用CAN报文显示
/// </summary>
private bool _IsDisplayEnabled=true;
private bool _IsDisplayEnabled = true;
public bool IsDisplayEnabled
{
get { return _IsDisplayEnabled; }
@@ -241,9 +241,11 @@ namespace CapMachine.Wpf.Services
/// </summary>
private async Task ProcessMessagesAsync()
{
try
{
while (await ReceiveChannel.Reader.WaitToReadAsync(TaskCancellationTokenSource.Token))
{
try
{
// 清空列表但保留容量
MessageBatch.Clear();
@@ -280,7 +282,6 @@ namespace CapMachine.Wpf.Services
await Task.Delay(20);
}
}
}
catch (OperationCanceledException ex)
{
// 服务被取消,正常退出
@@ -290,6 +291,9 @@ namespace CapMachine.Wpf.Services
{
LogService.Error($"消息处理任务异常: {ex.Message}");
}
}
}
/// <summary>

View File

@@ -2741,25 +2741,25 @@ namespace CapMachine.Wpf.Services
if (item.StateOperateResult.IsSuccess)
{
item.State = item.StateOperateResult.Content;
//根据PLC得到执行的步骤数据更新到CAN和LIN的数据
if (item.Name!.Equals("使能"))
{
switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin)
{
case CanLinEnum.Can:
//获取PLC的使能状态更新到CAN的使能状态
CanDriveService.UpdateCapEnableCmdData(item.State);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.Lin:
//获取PLC的使能状态更新到LIN的使能状态
LinDriveService.UpdateCapEnableCmdData(item.State);
//itemTag.Value.EngPvValue = 0;
break;
default:
break;
}
}
//根据PLC得到执行的步骤数据更新到CAN和LIN的数据压缩的使能时来自于程序的步骤配置不再接受PLC的指令数据
//if (item.Name!.Equals("使能"))
//{
// switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin)
// {
// case CanLinEnum.Can:
// //获取PLC的使能状态更新到CAN的使能状态
// CanDriveService.UpdateCapEnableCmdData(item.State);
// //itemTag.Value.EngPvValue = 0;
// break;
// case CanLinEnum.Lin:
// //获取PLC的使能状态更新到LIN的使能状态
// LinDriveService.UpdateCapEnableCmdData(item.State);
// //itemTag.Value.EngPvValue = 0;
// break;
// default:
// break;
// }
//}
}
}
@@ -3062,6 +3062,13 @@ namespace CapMachine.Wpf.Services
{
foreach (var itemStepExd in ProRunChannelData.ListStepExd)
{
//压缩机使能的参数直接给压缩机触发
if (itemStepExd.Name.Contains("压缩机使能"))
{
CanDriveService.UpdateCapEnableCmdData((bool)itemStepExd.Value);
continue;
}
var DataAdrees = ListPlcExdConfigCell.FirstOrDefault(a => a.Name == itemStepExd.Name);
if (DataAdrees != null)
{

View File

@@ -534,6 +534,7 @@ namespace CapMachine.Wpf.ViewModels
MsgName = item.MsgFrameName,
SignalName = item.SignalName,
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
LogicRuleDto = Mapper.Map<LogicRuleDto>(item.LogicRule),
});
//CanDriveService.CmdData.Add(new CanCmdData()
@@ -1075,7 +1076,7 @@ namespace CapMachine.Wpf.ViewModels
//ToDo cmd
CanDriveService.CanHandEnable = (bool)Data!;
//给使能数据
CanDriveService.UpdateCapEnableCmdData(CanDriveService.CanHandEnable);
CanDriveService.UpdateCapEnableCmdDataByHand((bool)Data!);
}
}

View File

@@ -609,7 +609,7 @@
Margin="10,0,0,0"
Command="{Binding CanAutoHandCmd}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
FontSize="11"
FontSize="8"
ToolTip="自动时:接受程序步骤的转速控制;手动时:手动发送转速数据">
<ToggleButton.Style>
<Style BasedOn="{StaticResource MaterialDesignSwitchToggleButton}" TargetType="ToggleButton">
@@ -647,7 +647,7 @@
Margin="10,0,0,0"
Command="{Binding CanHandEnableCmd}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
FontSize="11"
FontSize="8"
ToolTip="使能时:触发报文中使能;禁用时:触发报文中使能=False">
<ToggleButton.Style>
<Style BasedOn="{StaticResource MaterialDesignSwitchToggleButton}" TargetType="ToggleButton">