168 lines
5.0 KiB
C#
168 lines
5.0 KiB
C#
using CapMachine.Model.CANLIN;
|
|
using CapMachine.Wpf.CanDrive;
|
|
using ImTools;
|
|
using Prism.Ioc;
|
|
using Prism.Mvvm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CapMachine.Wpf.Services
|
|
{
|
|
/// <summary>
|
|
/// Can驱动服务
|
|
/// </summary>
|
|
public class CanDriveService : BindableBase
|
|
{
|
|
/// <summary>
|
|
/// 当前选中的CanLinConfigPro 程序
|
|
/// </summary>
|
|
public CanLinConfigPro SelectedCanLinConfigPro { get; set; }
|
|
public HighSpeedDataService HighSpeedDataService { get; }
|
|
|
|
/// <summary>
|
|
/// 实例化函数
|
|
/// </summary>
|
|
public CanDriveService(HighSpeedDataService highSpeedDataService, IContainerProvider containerProvider)
|
|
{
|
|
ToomossCanDrive = new ToomossCan(containerProvider);
|
|
//高速数据服务
|
|
HighSpeedDataService = highSpeedDataService;
|
|
|
|
//ToomossCanDrive.StartCanDrive();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 图莫斯 CAN Drive
|
|
/// ToomossCanDrive
|
|
/// </summary>
|
|
public ToomossCan ToomossCanDrive { get; set; }
|
|
|
|
/// <summary>
|
|
/// Dbc消息集合
|
|
/// 包括读取的实时值和数据
|
|
/// </summary>
|
|
public ObservableCollection<CanDbcModel> ListCanDbcModel { get; set; } = new ObservableCollection<CanDbcModel>();
|
|
|
|
/// <summary>
|
|
/// 初始化CAN的配置信息
|
|
/// </summary>
|
|
public void InitCanConfig(CanLinConfigPro selectedCanLinConfigPro)
|
|
{
|
|
//赋值配置数据
|
|
SelectedCanLinConfigPro = selectedCanLinConfigPro;
|
|
//为DBC实时数据关联配置的名称
|
|
foreach (var item in SelectedCanLinConfigPro.CanLinConfigContents)
|
|
{
|
|
var FindData = ListCanDbcModel.FindFirst(a => a.SignalName == item.SignalName);
|
|
if (FindData != null)
|
|
{
|
|
FindData.Name = item.Name;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始DBC 配置文件 加载
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ObservableCollection<CanDbcModel> StartDbc(string Path)
|
|
{
|
|
ListCanDbcModel = ToomossCanDrive.StartDbc(Path);
|
|
return ListCanDbcModel;
|
|
}
|
|
|
|
|
|
#region 程序驱动CAN
|
|
|
|
/// <summary>
|
|
/// 要发送的CAN指令数据
|
|
/// 在程序配置好后就确定要发送哪些数据
|
|
/// </summary>
|
|
public List<CanCmdData> CmdData { get; set; } = new List<CanCmdData>();
|
|
|
|
/// <summary>
|
|
/// 发送消息给CAN 驱动
|
|
/// </summary>
|
|
public void SendMsgToCanDrive()
|
|
{
|
|
if (ToomossCanDrive.OpenState)
|
|
{
|
|
if (CmdData.Count > 0)
|
|
{
|
|
ToomossCanDrive.SendCanMsg(CmdData);
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 循环发送数据到CAN
|
|
/// </summary>
|
|
public void CycleSendMsg()
|
|
{
|
|
if (ToomossCanDrive.OpenState)
|
|
{
|
|
if (ToomossCanDrive.IsCycleSend == false)
|
|
{
|
|
if (CmdData.Count > 0)
|
|
{
|
|
ToomossCanDrive.IsCycleSend = true;
|
|
ToomossCanDrive.CmdData = CmdData;
|
|
ToomossCanDrive.StartCycleSendMsg();
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToomossCanDrive.IsCycleSend = false;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///循环接收数据
|
|
/// </summary>
|
|
public void CycleReciveMsg()
|
|
{
|
|
if (ToomossCanDrive.OpenState)
|
|
{
|
|
if (ToomossCanDrive.IsCycleRevice == false)
|
|
{
|
|
if (ListCanDbcModel.Count > 0)
|
|
{
|
|
ToomossCanDrive.IsCycleRevice = true;
|
|
ToomossCanDrive.StartCycleReviceCanMsg();
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToomossCanDrive.IsCycleRevice = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|