LIN SCH的更改
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using CapMachine.Model.CANLIN;
|
||||
using CapMachine.Wpf.CanDrive;
|
||||
using CapMachine.Wpf.Dtos;
|
||||
using CapMachine.Wpf.Services;
|
||||
using ImTools;
|
||||
using Microsoft.VisualBasic;
|
||||
@@ -675,11 +676,25 @@ namespace CapMachine.Wpf.LinDrive
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 定时扫描更新数据 扫描Task
|
||||
/// </summary>
|
||||
private static Task CycleUpdateCmdTask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 定时更新时间
|
||||
/// </summary>
|
||||
private int UpdateCycle { get; set; } = 500;
|
||||
|
||||
/// <summary>
|
||||
/// 调度表数量
|
||||
/// </summary>
|
||||
public int SchCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// LIN 调度表的配置信息
|
||||
/// </summary>
|
||||
public List<LINScheduleConfigDto> ListLINScheduleConfig { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取LIN的LINScheduleConfig
|
||||
@@ -701,7 +716,7 @@ namespace CapMachine.Wpf.LinDrive
|
||||
SchTabIndex = i,
|
||||
MsgName = GetSchFrameName(SchName, j),
|
||||
MsgNameIndex = j,
|
||||
Cycle = 10,
|
||||
Cycle = 100,
|
||||
IsActive = false,
|
||||
});
|
||||
}
|
||||
@@ -752,7 +767,7 @@ namespace CapMachine.Wpf.LinDrive
|
||||
return pSchName.ToString();
|
||||
}
|
||||
|
||||
Random Random=new Random();
|
||||
Random Random = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// 开始调度表执行
|
||||
@@ -788,15 +803,77 @@ namespace CapMachine.Wpf.LinDrive
|
||||
}
|
||||
}
|
||||
|
||||
LDFParser.LDF_ExeSchToBus(LDFHandle, new StringBuilder(itemMsg.Key),1);
|
||||
LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(itemMsg.Key),1);
|
||||
LDFParser.LDF_ExeSchToBus(LDFHandle, new StringBuilder(itemMsg.Key), 1);
|
||||
LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(itemMsg.Key), 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 循环更新调度表的指令数据
|
||||
/// 定时更新数据到调度表中
|
||||
/// </summary>
|
||||
public void StartCycleUpdateCmd()
|
||||
{
|
||||
CycleUpdateCmdTask = Task.Run(async () =>
|
||||
{
|
||||
while (IsCycleSend)
|
||||
{
|
||||
await Task.Delay(UpdateCycle);
|
||||
try
|
||||
{
|
||||
|
||||
if (CmdData.Count() == 0) return;
|
||||
|
||||
//防止有多个不同的消息名称/帧,每个帧单独处理发送
|
||||
var GroupMsg = CmdData.GroupBy(x => x.MsgName);
|
||||
foreach (var itemMsg in GroupMsg)
|
||||
{
|
||||
foreach (var itemSignal in itemMsg)
|
||||
{
|
||||
if (itemSignal.ConfigName.Contains("速"))
|
||||
{
|
||||
itemSignal.SignalCmdValue = Random.NextDouble() * 1000;
|
||||
}
|
||||
//主机写操作,发送数据给从机
|
||||
LDFParser.LDF_SetSignalValue(LDFHandle, new StringBuilder(itemMsg.Key), new StringBuilder(itemSignal.SignalName), itemSignal.SignalCmdValue);
|
||||
}
|
||||
|
||||
////【0】参数注意
|
||||
//LDFParser.LDF_ExeFrameToBus(LDFHandle, new StringBuilder(itemMsg.Key), 0);
|
||||
|
||||
//读取当前的指令帧数据,LDF_ExeFrameToBus执行后就可以读取本身的数据
|
||||
foreach (var item in ListLinLdfModel)
|
||||
{
|
||||
if (CmdData.Any(a => a.MsgName == item.MsgName))
|
||||
{
|
||||
LDFParser.LDF_GetSignalValueStr(LDFHandle, new StringBuilder(item.MsgName), new StringBuilder(item.SignalName), ReadValueStr);
|
||||
item.SignalRtValueSb = ReadValueStr;
|
||||
}
|
||||
}
|
||||
|
||||
LDFParser.LDF_ExeSchToBus(LDFHandle, new StringBuilder(itemMsg.Key), 1);
|
||||
LDFParser.LDF_SetSchToTable(LDFHandle, new StringBuilder(itemMsg.Key), 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
IsSendOk = false;
|
||||
LoggerService.Info($"时间:{DateTime.Now.ToString()}-【MSG】-{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
IsSendOk = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void LinTest()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CapMachine.Model.CANLIN;
|
||||
using CapMachine.Wpf.Dtos;
|
||||
using CapMachine.Wpf.LinDrive;
|
||||
using ImTools;
|
||||
using Prism.Ioc;
|
||||
@@ -121,6 +122,11 @@ namespace CapMachine.Wpf.Services
|
||||
/// </summary>
|
||||
public List<LinCmdData> CmdData { get; set; } = new List<LinCmdData>();
|
||||
|
||||
/// <summary>
|
||||
/// 调度表LIN配置信息
|
||||
/// </summary>
|
||||
public List<LINScheduleConfigDto> ListLINScheduleConfig { get; set; } = new List<LINScheduleConfigDto>();
|
||||
|
||||
/// <summary>
|
||||
/// 增加发送的指令数据
|
||||
/// </summary>
|
||||
@@ -356,10 +362,42 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
if (CmdData.Count > 0)
|
||||
{
|
||||
ToomossLinDrive.IsCycleSend = true;
|
||||
//ToomossLinDrive.IsCycleSend = true;
|
||||
ToomossLinDrive.CmdData = CmdData;
|
||||
ToomossLinDrive.StartPrecisionCycleSendMsg();
|
||||
//ToomossLinDrive.StartPrecisionCycleSendMsg();
|
||||
//ToomossLinDrive.StartCycleSendMsg();
|
||||
|
||||
if (ToomossLinDrive.SchEnable)
|
||||
{
|
||||
//使用调度表的话,需要在调度表中配置信息后才可以进行操作
|
||||
var GroupMsg = ToomossLinDrive.CmdData.GroupBy(a => a.MsgName).ToList();
|
||||
foreach (var itemMsg in GroupMsg)
|
||||
{
|
||||
if (!ListLINScheduleConfig.ToList().Any(a => a.MsgName == itemMsg.Key))
|
||||
{
|
||||
System.Windows.MessageBox.Show($"你使能了调度表,但是调度表中没有设置【{itemMsg.Key}】信息,请设置后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ListLINScheduleConfig == null && ListLINScheduleConfig!.Count() == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("调度表配置为空数据,请检查!将无法发送数据", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||||
return;
|
||||
}
|
||||
|
||||
ToomossLinDrive.ListLINScheduleConfig = ListLINScheduleConfig!;
|
||||
ToomossLinDrive.StartSchedule();
|
||||
ToomossLinDrive.StartCycleUpdateCmd();
|
||||
}
|
||||
else
|
||||
{
|
||||
ToomossLinDrive.StartPrecisionCycleSendMsg();
|
||||
//ToomossCanDrive.StartCycleSendMsg();
|
||||
}
|
||||
|
||||
ToomossLinDrive.IsCycleSend = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -901,6 +901,48 @@ namespace CapMachine.Wpf.ViewModels
|
||||
set { _DataBaudRateCbxItems = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
|
||||
private DelegateCommand<object> _SchEnableCmd;
|
||||
/// <summary>
|
||||
/// 调度表的使能 操作的指令
|
||||
/// </summary>
|
||||
public DelegateCommand<object> SchEnableCmd
|
||||
{
|
||||
set
|
||||
{
|
||||
_SchEnableCmd = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
if (_SchEnableCmd == null)
|
||||
{
|
||||
_SchEnableCmd = new DelegateCommand<object>((Par) => SchEnableCmdCall(Par));
|
||||
}
|
||||
return _SchEnableCmd;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 调度表的使能信息
|
||||
/// </summary>
|
||||
/// <param name="par"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void SchEnableCmdCall(object par)
|
||||
{
|
||||
var dd = SelectedLINConfigExdDto.SchEnable;
|
||||
var Result = (bool)par;
|
||||
if (Result)
|
||||
{
|
||||
LinDriveService.ToomossLinDrive.SchEnable = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LinDriveService.ToomossLinDrive.SchEnable = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DelegateCommand<string> _LinOpCmd;
|
||||
/// <summary>
|
||||
/// LIN操作的指令
|
||||
@@ -1047,6 +1089,12 @@ namespace CapMachine.Wpf.ViewModels
|
||||
|
||||
break;
|
||||
case "CycleSend"://循环发送你
|
||||
|
||||
//有可能加载完毕后不手动改变状态,导致值没有传输,所以这里赋值
|
||||
LinDriveService.ToomossLinDrive.SchEnable = SelectedLINConfigExdDto.SchEnable;
|
||||
//无论有没有调度表,都要把这个配置给LinDriveService
|
||||
LinDriveService.ListLINScheduleConfig = ListLINScheduleConfigDto.ToList();
|
||||
|
||||
//循环发送数据
|
||||
LinDriveService.CycleSendMsg();
|
||||
|
||||
@@ -1260,8 +1308,8 @@ namespace CapMachine.Wpf.ViewModels
|
||||
|
||||
//LinDriveService.ToomossLinDrive.LinTest();
|
||||
|
||||
LinDriveService.ToomossLinDrive.StartSchedule();
|
||||
break;
|
||||
//LinDriveService.ToomossLinDrive.StartSchedule();
|
||||
//break;
|
||||
//
|
||||
if (LinDriveService.ToomossLinDrive.OpenState)
|
||||
{
|
||||
|
||||
@@ -652,8 +652,8 @@
|
||||
Width="40"
|
||||
Margin="5,2"
|
||||
Command="{Binding SchEnableCmd}"
|
||||
CommandParameter="{Binding SelectedCANConfigExdDto.SchEnable}"
|
||||
IsChecked="{Binding SelectedCANConfigExdDto.SchEnable}"
|
||||
CommandParameter="{Binding SelectedLINConfigExdDto.SchEnable}"
|
||||
IsChecked="{Binding SelectedLINConfigExdDto.SchEnable}"
|
||||
Style="{StaticResource MaterialDesignSwitchToggleButton}"
|
||||
ToolTip="启用调度表" />
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user