CAN 配置和报文记录的功能

This commit is contained in:
2024-12-23 21:33:19 +08:00
parent 713b9b02e6
commit 8b21846424
20 changed files with 1021 additions and 114 deletions

View File

@@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Core
{
/// <summary>
/// 高速规则帮助方法
/// </summary>
public class HighSpeedFileHelper
{
/// <summary>
/// 获取文件路径
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetFullFilePath(string FileRootPath, string DcInfo, string ExtInfo)
{
return $@"{FileRootPath}\{DateTime.Now.ToString("yyyy")}\{DcInfo}\{GetFileName(DcInfo)}{ExtInfo}.csv";
}
/// <summary>
/// 获取本地文件路径
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetLocalFullFilePath(string FileRootPath, string DcInfo, string ExtInfo)
{
return $@"{FileRootPath}\{DateTime.Now.ToString("yyyy")}\{DcInfo}\{GetFileName(DcInfo)}{ExtInfo}.csv";
}
/// <summary>
/// 获取文件路径
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetFilePath(string FileRootPath)
{
return $@"{FileRootPath}\{DateTime.Now.ToString("yyyy")}\";
}
/// <summary>
/// 获取试验工况文件路径
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetExpFilePath(string FileRootPath, string ExpName)
{
return $@"{FileRootPath}\{ExpName}";
}
/// <summary>
/// 获取CSV文件路径
/// 对于一个试验来说如果时间很长的话则一天一个CSV文件
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetCSVPath(string FileExpRootPath)
{
//return $@"{FileRootPath}\{DateTime.Now.ToString("yyyy")}\{DateTime.Now.ToString("MM-dd HHmm")}{workCond}.csv";
return $@"{FileExpRootPath}\{DateTime.Now.ToString("yyyy-MM-dd")}.csv";
}
/// <summary>
/// 获取CSV文件路径
/// 对于一个试验来说,按照小时存储数据
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetHourCSVPath(string FileExpRootPath, string HourFileName)
{
//return $@"{FileRootPath}\{DateTime.Now.ToString("yyyy")}\{DateTime.Now.ToString("MM-dd HHmm")}{workCond}.csv";
return $@"{FileExpRootPath}\{HourFileName}.csv";
}
/// <summary>
/// 获取CSV文件名称
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetFileName(string DcInfo)
{
return $"{DateTime.Now.ToString("yy")}{DcInfo}";
}
/// <summary>
/// 获取CSV文件名称
/// </summary>
/// <param name="DcInfo"></param>
/// <returns></returns>
public static string GetFileName(string DcInfo, string ExtInfo)
{
return $"{DateTime.Now.ToString("yy")}{DcInfo}{ExtInfo}.csv";
}
/// <summary>
/// 获取Title文件-在本地盘 F盘中
/// </summary>
/// <param name="Dcinfo"></param>
/// <returns></returns>
public static string GetTitlePath(string Dcinfo, string fileRootPath)
{
//return fileRootPath + @"\Title\Title" + Dcinfo + ".csv";
//return "F:" + @"\Title\Title" + Dcinfo + ".csv";
//return "D:" + @"\DCM\Title\Title" + Dcinfo + ".csv";
return "F:" + @"\Title\Title" + Dcinfo + ".csv";
}
///// <summary>
///// 获取UI显示名称信息
///// </summary>
///// <param name="DcInfo"></param>
///// <returns></returns>
//public static string GetUIShowInfo(int DataInof)
//{
// return $"{GetMonthInfo()} {GetDayInfo()}{GetClassInfo()}-{DataInof}";
//}
//public static int StartHour = 6;
//public static int EndHour = 18;
///// <summary>
///// 获取白班和夜班的信息
///// </summary>
///// <returns></returns>
//public static string GetClassInfo()
//{
// var NowTimeHour = DateTime.Now.Hour;
// if (NowTimeHour >= StartHour && NowTimeHour <= EndHour)
// {
// return "-";
// }
// else
// {
// return ":";
// }
//}
}
}

View File

@@ -32,7 +32,7 @@ namespace CapMachine.Model.CANLIN
public string? Name { get; set; }
/// <summary>
/// 配置项值
/// 配置项值 DBC里面的信号名称
/// </summary>
[Column(Name = "Content", IsNullable = false, StringLength = 100)]
public string? Content { get; set; }

View File

@@ -0,0 +1,40 @@
using FreeSql.DataAnnotations;
namespace CapMachine.Model
{
/// <summary>
/// 高速的消息文件信息
/// </summary>
[Table(Name = "HighMsgFileInfo")]
public class HighMsgFileInfo
{
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimary = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 试验名称
/// </summary>
[Column(Name = "Name", IsNullable = false, StringLength = 200)]
public string? ExpName { get; set; }
/// <summary>
/// Path
/// CSV文件路径
/// </summary>
[Column(Name = "FilePath", IsNullable = false, StringLength = 400)]
public string? FilePath { get; set; }
/// <summary>
/// FileInfo
/// 2024-12-23 17
/// </summary>
[Column(Name = "FileInfo", IsNullable = false, StringLength = 30)]
public string? FileInfo { get; set; }
[Column(ServerTime = DateTimeKind.Local, CanUpdate = false)]
public DateTime CreateTime { get; set; }
}
}

View File

@@ -3,6 +3,7 @@
<appSettings>
<add key="connecting1" value="Data Source=192.168.40.2;user instance=false;Initial Catalog=FrontLineMachine;User ID=sa;Password=ABCabc123"/>
<add key="connecting" value="Data Source=CT-PC;user instance=false;Encrypt=false;Initial Catalog=CapMachine;User ID=sa;Password=12345678"/>
<add key="connecting2" value="Data Source=DESKTOP-94B7RIE\SQLEXPRESS;user instance=false;Encrypt=false;Initial Catalog=CapMachine;User ID=sa;Password=12345678"/>
<add key="connecting5" value="Data Source=@Address@; Attachs=ems.db; Pooling=true;Min Pool Size=1"/>
<add key="PLCScan" value="600"/>
<add key="PLCIP" value="127.0.0.1"/>

View File

@@ -97,7 +97,8 @@ namespace CapMachine.Wpf
containerRegistry.RegisterSingleton<MachineRtDataService>();
containerRegistry.RegisterSingleton<DataRecordService>();
containerRegistry.RegisterSingleton<CanDriveService>();
containerRegistry.RegisterSingleton<HighSpeedDataService>();
//注册AutoMapper 将IAutoMapperProvider注入IOC容器并对外提供IMapper注入类型。
containerRegistry.RegisterSingleton<IMapperProvider, MapperConfig>();
containerRegistry.Register(typeof(IMapper), GetMapper);
@@ -225,8 +226,9 @@ namespace CapMachine.Wpf
var appVersionService7 = ContainerLocator.Container.Resolve<RealTimeChartView>();
var appVersionService8 = ContainerLocator.Container.Resolve<CanDriveService>();
var appVersionService9 = ContainerLocator.Container.Resolve<DataRecordService>();
var appVersionService10 = ContainerLocator.Container.Resolve<HighSpeedDataService>();
//给当前的全局异常捕捉服务使用
LogService = ContainerLocator.Container.Resolve<ILogService>();
LogService.Error("ex.ToString()");

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

View File

@@ -12,46 +12,63 @@ namespace CapMachine.Wpf.CanDrive
/// </summary>
public class CAN_DBCParser
{
public const Int32 DBC_PARSER_OK = 0;//没有错误
public const Int32 DBC_PARSER_FILE_OPEN = (-1);//打开文件出错
public const Int32 DBC_PARSER_FILE_FORMAT = (-2);//文件格式错误
public const Int32 DBC_PARSER_DEV_DISCONNECT = (-3);//设备未连接
public const Int32 DBC_PARSER_HANDLE_ERROR = (-4);//LDF Handle错误
public const Int32 DBC_PARSER_GET_INFO_ERROR = (-5);//获取解析后的数据出错
public const Int32 DBC_PARSER_DATA_ERROR = (-6);//数据处理错误
public const Int32 DBC_PARSER_SLAVE_NACK = (-7);//从机未响应数据
public const Int32 DBC_PARSER_OK = 0;//没有错误
public const Int32 DBC_PARSER_FILE_OPEN = (-1);//打开文件出错
public const Int32 DBC_PARSER_FILE_FORMAT = (-2);//文件格式错误
public const Int32 DBC_PARSER_DEV_DISCONNECT = (-3);//设备未连接
public const Int32 DBC_PARSER_HANDLE_ERROR = (-4);//LDF Handle错误
public const Int32 DBC_PARSER_GET_INFO_ERROR = (-5);//获取解析后的数据出错
public const Int32 DBC_PARSER_DATA_ERROR = (-6);//数据处理错误
public const Int32 DBC_PARSER_SLAVE_NACK = (-7);//从机未响应数据
[DllImport("USB2XXX.dll")]
public static extern UInt64 DBC_ParserFile(int DevHandle, StringBuilder pDBCFileName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgQuantity(UInt64 DBCHandle);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgName(UInt64 DBCHandle, int index, StringBuilder pMsgName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgSignalQuantity(UInt64 DBCHandle, StringBuilder pMsgName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgSignalName(UInt64 DBCHandle, StringBuilder pMsgName, int index, StringBuilder pSignalName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgPublisher(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pPublisher);
//设置信号值
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SetSignalValue(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pSignalName, double Value);
//获取信号值
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetSignalValue(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pSignalName, double[] pValue);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetSignalValueStr(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pSignalName, StringBuilder pValueStr);
[DllImport("USB2XXX.dll")]
public static extern UInt64 DBC_ParserFile(int DevHandle, StringBuilder pDBCFileName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgQuantity(UInt64 DBCHandle);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgName(UInt64 DBCHandle, int index, StringBuilder pMsgName);
/// <summary>
///
/// </summary>
/// <param name="DBCHandle"></param>
/// <param name="ID"></param>
/// <param name="pMsgName"></param>
/// <returns></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgNameByID(UInt64 DBCHandle, int ID, StringBuilder pMsgName);
/// <summary>
/// 获取ID根据名称
/// </summary>
/// <param name="DBCHandle"></param>
/// <param name="pMsgName"></param>
/// <returns></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgIDByName(UInt64 DBCHandle, StringBuilder pMsgName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgSignalQuantity(UInt64 DBCHandle, StringBuilder pMsgName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgSignalName(UInt64 DBCHandle, StringBuilder pMsgName, int index, StringBuilder pSignalName);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetMsgPublisher(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pPublisher);
//设置信号值
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SetSignalValue(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pSignalName, double Value);
//获取信号值
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetSignalValue(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pSignalName, double[] pValue);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_GetSignalValueStr(UInt64 DBCHandle, StringBuilder pMsgName, StringBuilder pSignalName, StringBuilder pValueStr);
//将CAN消息数据填充到信号里面
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncCANMsgToValue(UInt64 DBCHandle, IntPtr pCANMsg, int MsgLen);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncCANFDMsgToValue(UInt64 DBCHandle, IntPtr pCANFDMsg, int MsgLen);
//将信号数据填充到CAN消息里面
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncValueToCANMsg(UInt64 DBCHandle, StringBuilder pMsgName, IntPtr pCANMsg);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncValueToCANFDMsg(UInt64 DBCHandle, StringBuilder pMsgName, IntPtr pCANFDMsg);
//将CAN消息数据填充到信号里面
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncCANMsgToValue(UInt64 DBCHandle, IntPtr pCANMsg, int MsgLen);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncCANFDMsgToValue(UInt64 DBCHandle, IntPtr pCANFDMsg, int MsgLen);
//将信号数据填充到CAN消息里面
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncValueToCANMsg(UInt64 DBCHandle, StringBuilder pMsgName, IntPtr pCANMsg);
[DllImport("USB2XXX.dll")]
public static extern Int32 DBC_SyncValueToCANFDMsg(UInt64 DBCHandle, StringBuilder pMsgName, IntPtr pCANFDMsg);
}
}

View File

@@ -10,13 +10,20 @@ namespace CapMachine.Wpf.CanDrive
/// <summary>
/// Dbc 信息
/// </summary>
public class CanDbcModel:BindableBase
public class CanDbcModel : BindableBase
{
/// <summary>
/// 消息Id
/// </summary>
public string? MsgId { get; set; }
/// <summary>
/// 配置的中文名称:速度,转速限制,使能等常用的信息数据
/// 但不是所有的SignalName都会配置一个Name只是需要时才会配置名称
/// 但是CanDbcModel集合会包括所有的SignalName名称的
/// </summary>
public string? Name { get; set; }
/// <summary>
/// 消息名称
/// </summary>
@@ -38,20 +45,39 @@ namespace CapMachine.Wpf.CanDrive
public string? SignalUnit { get; set; }
private string? _SignalRtValue;
private string? _SignalRtValue = "--";
/// <summary>
/// 信号实时值
/// </summary>
public string? SignalRtValue
{
get { return _SignalRtValue; }
set { _SignalRtValue = value;RaisePropertyChanged(); }
set { _SignalRtValue = value; RaisePropertyChanged(); }
}
private StringBuilder _SignalRtValueSb = new StringBuilder(10);
/// <summary>
/// 信号实时值 StringBuilder
/// </summary>
public StringBuilder SignalRtValueSb
{
get { return _SignalRtValueSb; }
set
{
if (_SignalRtValueSb != value)
{
SignalRtValue = value.ToString();
_SignalRtValueSb = value;
}
}
}
/// <summary>
/// 发布者
/// </summary>
public string? Publisher { get; set; }
}
}

View File

@@ -1,5 +1,8 @@
using CapMachine.Wpf.Models.Tag;
using CapMachine.Wpf.Services;
using HslCommunication;
using NPOI.OpenXmlFormats.Wordprocessing;
using Prism.Ioc;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
@@ -12,6 +15,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Interop;
using static CapMachine.Wpf.CanDrive.USB2CAN;
namespace CapMachine.Wpf.CanDrive
{
@@ -20,12 +24,15 @@ namespace CapMachine.Wpf.CanDrive
/// </summary>
public class ToomossCan : BindableBase
{
private readonly IContainerProvider ContainerProvider;
/// <summary>
/// 实例化函数
/// </summary>
public ToomossCan()
public ToomossCan(IContainerProvider containerProvider)
{
ContainerProvider = containerProvider;
HighSpeedDataService = ContainerProvider.Resolve<HighSpeedDataService>();
}
/// <summary>
@@ -42,16 +49,31 @@ namespace CapMachine.Wpf.CanDrive
}
/// <summary>
/// HighSpeedDataService 实例
/// </summary>
public HighSpeedDataService HighSpeedDataService { get; set; }
/// <summary>
/// 开始Dbc文件写入
/// </summary>
public void StartDbc(string DbcPath)
public ObservableCollection<CanDbcModel> StartDbc(string DbcPath)
{
DBC_Parser(DbcPath);
return ListCanDbcModel;
}
///// <summary>
///// 获取Can DBC数据集合
///// </summary>
//public void LoadCanDbcData(ObservableCollection<CanDbcModel> canDbcModels)
//{
// ListCanDbcModel = canDbcModels;
//}
/// <summary>
/// Dbc消息集合
/// 包括读取的实时值和数据
/// </summary>
public ObservableCollection<CanDbcModel> ListCanDbcModel { get; set; } = new ObservableCollection<CanDbcModel>();
@@ -69,6 +91,7 @@ namespace CapMachine.Wpf.CanDrive
USB2CAN.CAN_INIT_CONFIG CANConfig = new USB2CAN.CAN_INIT_CONFIG();
/// <summary>
/// DBC加载后获取的Handle
/// DBC Handle
/// </summary>
public UInt64 DBCHandle { get; set; }
@@ -82,15 +105,40 @@ namespace CapMachine.Wpf.CanDrive
/// 扫描设备Handle
/// </summary>
public Int32 DevHandle { get; set; } = 0;
/// <summary>
/// Write CAN Index
/// 通道的含义
/// 描述:
/// 读取接收到的CAN消息推荐使用该函数。
///原型:
///int WINAPI CAN_GetMsgWithSize(int DevHandle, unsigned char CANIndex, CAN_MSG* pCanGetMsg, int BufferSize);
///参数:
///DevHandle 设备句柄本质为设备序号的低4字节可以通过调用USB_ScanDevice函数获得。
///CANIndex CAN通道索引号0-对应CAN1,1-对应CAN2。
///pCanGetMsg 存储CAN消息缓冲区首地址。
///BufferSize 存储CAN消息缓冲区大小。
///返回值:
//大于等于0表示从CAN适配器内部成功读取到的CAN消息帧数若返回值小于0则说明调用该函数失败。
/// </summary>
public Byte WriteCANIndex { get; set; } = 0;
/// <summary>
/// Read CAN Index
/// 通道的含义
/// 描述:
///读取接收到的CAN消息推荐使用该函数。
///原型:
///int WINAPI CAN_GetMsgWithSize(int DevHandle, unsigned char CANIndex, CAN_MSG* pCanGetMsg, int BufferSize);
///参数:
///DevHandle 设备句柄本质为设备序号的低4字节可以通过调用USB_ScanDevice函数获得。
///CANIndex CAN通道索引号0-对应CAN1,1-对应CAN2。
///pCanGetMsg 存储CAN消息缓冲区首地址。
///BufferSize 存储CAN消息缓冲区大小。
///返回值:
///大于等于0表示从CAN适配器内部成功读取到的CAN消息帧数若返回值小于0则说明调用该函数失败。
/// </summary>
public Byte ReadCANIndex { get; set; } = 1;
public Byte ReadCANIndex { get; set; } = 0;
private bool _OpenState;
@@ -219,6 +267,7 @@ namespace CapMachine.Wpf.CanDrive
/// </summary>
public void GetCANConfig()
{
CANConfig.CAN_Mode = 0x80;//正常模式并接入终端电阻
//获取CAN波特率参数
ret = USB2CAN.CAN_GetCANSpeedArg(DevHandle, ref CANConfig, 500000);
if (ret != USB2CAN.CAN_SUCCESS)
@@ -295,6 +344,9 @@ namespace CapMachine.Wpf.CanDrive
int DBCSigNum = CAN_DBCParser.DBC_GetMsgSignalQuantity(DBCHandle, MsgName);
StringBuilder Publisher = new StringBuilder(32);
CAN_DBCParser.DBC_GetMsgPublisher(DBCHandle, MsgName, Publisher);
long MsgId;
MsgId = CAN_DBCParser.DBC_GetMsgIDByName(DBCHandle, MsgName);
Console.Write("Signals:");
for (int j = 0; j < DBCSigNum; j++)
{
@@ -306,7 +358,7 @@ namespace CapMachine.Wpf.CanDrive
ListCanDbcModel.Add(new CanDbcModel()
{
MsgName = MsgName.ToString(),
MsgId = "",
MsgId = "0x" + MsgId.ToString("X8"),
SignalName = SigName.ToString(),
SignalDesc = "",
SignalUnit = "",
@@ -352,7 +404,7 @@ namespace CapMachine.Wpf.CanDrive
//通过DBC写入数据后生成CanMsg
//将信号值填入CAN消息里面
//释放申请的临时缓冲区
Marshal.FreeHGlobal(msgPt);
@@ -379,6 +431,8 @@ namespace CapMachine.Wpf.CanDrive
/// </summary>
private static Task CycleReviceTask { get; set; }
StringBuilder ValueSb = new StringBuilder(16);
/// <summary>
/// 循环获取CAN消息
/// </summary>
@@ -388,7 +442,7 @@ namespace CapMachine.Wpf.CanDrive
{
while (IsCycleRevice)
{
await Task.Delay(1000);
await Task.Delay(500);
try
{
//另外一个CAN通道读取数据
@@ -400,7 +454,9 @@ namespace CapMachine.Wpf.CanDrive
Console.WriteLine("Read CanMsgNum = {0}", CanNum);
for (int i = 0; i < CanNum; i++)
{
CanMsgBuffer[i] = (USB2CAN.CAN_MSG)Marshal.PtrToStructure((IntPtr)((UInt32)msgPt + i * Marshal.SizeOf(typeof(USB2CAN.CAN_MSG))), typeof(USB2CAN.CAN_MSG));
//CanMsgBuffer[i] = (USB2CAN.CAN_MSG)Marshal.PtrToStructure((IntPtr)((UInt32)msgPt + i * Marshal.SizeOf(typeof(USB2CAN.CAN_MSG))), typeof(USB2CAN.CAN_MSG)); //有溢出报错
CanMsgBuffer[i] = (USB2CAN.CAN_MSG)Marshal.PtrToStructure((IntPtr)(msgPt + i * Marshal.SizeOf(typeof(USB2CAN.CAN_MSG))), typeof(USB2CAN.CAN_MSG));
Console.WriteLine("CanMsg[{0}].ID = 0x{1}", i, CanMsgBuffer[i].ID.ToString("X8"));
//Console.WriteLine("CanMsg[{0}].TimeStamp = {1}",i,CanMsgBuffer[i].TimeStamp);
Console.Write("CanMsg[{0}].Data = ", i);
@@ -409,6 +465,14 @@ namespace CapMachine.Wpf.CanDrive
Console.Write("{0} ", CanMsgBuffer[i].Data[j].ToString("X2"));
}
Console.WriteLine("");
HighSpeedDataService.AppendOrUpdateMsg(new Models.HighSpeed.CommMsg()
{
Category="CAN",
MsgInfo="0x"+CanMsgBuffer[i].ID.ToString("X8"),
MsgData= CanMsgBuffer[i].Data.ToArrayString(),
Time=DateTime.Now.ToString()
});
}
}
else if (CanNum == 0)
@@ -421,16 +485,29 @@ namespace CapMachine.Wpf.CanDrive
}
Console.WriteLine("");
//将CAN消息数据填充到信号里面
//将CAN消息数据填充到信号里面用DBC解析数据
CAN_DBCParser.DBC_SyncCANMsgToValue(DBCHandle, msgPt, CanNum);
//获取信号值并打印出来
StringBuilder ValueStr = new StringBuilder(32);
CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder("msg_moto_speed"), new StringBuilder("moto_speed"), ValueStr);
Console.WriteLine("moto_speed = {0}", ValueStr);
CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder("msg_oil_pressure"), new StringBuilder("oil_pressure"), ValueStr);
Console.WriteLine("oil_pressure = {0}", ValueStr);
CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder("msg_speed_can"), new StringBuilder("speed_can"), ValueStr);
Console.WriteLine("speed_can = {0}", ValueStr);
//循环获取消息的数据
foreach (var item in ListCanDbcModel)
{
//有配置的名称的,认为是有用的,则需要读取数据
//if (!string.IsNullOrEmpty(item.Name))
//{
CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder(item.MsgName), new StringBuilder(item.SignalName), ValueSb);
item.SignalRtValueSb = ValueSb;
//}
}
////获取信号值并打印出来
//StringBuilder ValueStr = new StringBuilder(32);
//CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder("msg_moto_speed"), new StringBuilder("moto_speed"), ValueStr);
//Console.WriteLine("moto_speed = {0}", ValueStr);
//CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder("msg_oil_pressure"), new StringBuilder("oil_pressure"), ValueStr);
//Console.WriteLine("oil_pressure = {0}", ValueStr);
//CAN_DBCParser.DBC_GetSignalValueStr(DBCHandle, new StringBuilder("msg_speed_can"), new StringBuilder("speed_can"), ValueStr);
//Console.WriteLine("speed_can = {0}", ValueStr);
}
catch (Exception ex)
{

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
@@ -84,6 +84,9 @@
</Resource>
</ItemGroup>
<ItemGroup>
<None Update="Assets\Images\CapMachineOutput1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Db\CapMachine.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Models.HighSpeed
{
/// <summary>
/// 通信数据的消息
/// </summary>
public class CommMsg
{
/// <summary>
/// 时间
/// </summary>
public string? Time { get; set; }
/// <summary>
/// 分类
/// CAN/LIN
/// </summary>
public string? Category { get; set; }
/// <summary>
/// Msg名称或者Id
/// 等其他信息
/// </summary>
public string? MsgInfo { get; set; }
/// <summary>
/// 消息数据
/// </summary>
public string? MsgData { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Models.HighSpeed
{
/// <summary>
/// 高速片段数据
/// </summary>
public class HighFragMsg
{
public HighFragMsg()
{
ListCommMsg = new List<CommMsg>();
}
/// <summary>
/// 状态
/// </summary>
public bool State { get; set; }
/// <summary>
/// Index
/// </summary>
public int Index { get; set; }
/// <summary>
/// 小时数据
/// </summary>
public List<CommMsg> ListCommMsg { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
using CsvHelper.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Models.HighSpeed
{
/// <summary>
/// 高速记录的模型Map
/// </summary>
public class HighRecordMsgMap : ClassMap<CommMsg>
{
/// <summary>
/// 实例化函数
/// </summary>
public HighRecordMsgMap()
{
Map(m => m.Time).Name("时间");
Map(m => m.Category).Name("分类");
Map(m => m.MsgInfo).Name("消息信息");
Map(m => m.MsgData).Name("消息");
}
}
}

View File

@@ -1,7 +1,11 @@
using CapMachine.Wpf.CanDrive;
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;
@@ -11,17 +15,64 @@ namespace CapMachine.Wpf.Services
/// <summary>
/// Can驱动服务
/// </summary>
public class CanDriveService:BindableBase
public class CanDriveService : BindableBase
{
public CanDriveService()
/// <summary>
/// 实例化函数
/// </summary>
public CanDriveService(HighSpeedDataService highSpeedDataService,IContainerProvider containerProvider)
{
ToomossCanDrive=new ToomossCan();
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.Content);
if (FindData != null)
{
FindData.Name = item.Name;
}
}
}
/// <summary>
/// 开始DBC 配置文件 加载
/// </summary>
/// <returns></returns>
public ObservableCollection<CanDbcModel> StartDbc(string Path)
{
ListCanDbcModel = ToomossCanDrive.StartDbc(Path);
return ListCanDbcModel;
}
/// <summary>
/// 当前选中的CanLinConfigPro 程序
/// </summary>
public CanLinConfigPro SelectedCanLinConfigPro { get; set; }
public HighSpeedDataService HighSpeedDataService { get; }
}
}

View File

@@ -21,6 +21,17 @@ namespace CapMachine.Wpf.Services
/// </summary>
public static readonly object CsvFileLock = new object();
/// <summary>
/// 高速 消息数据的 Csv文件锁
/// 防止同时读取数据
/// </summary>
public static readonly object HighSpeedMsgCsvFileLock = new object();
/// <summary>
/// 高速数据文件缓存小时数
/// </summary>
public short HighSpeedMsgCsvFileCacheHour { get; set; } = 5;
/// <summary>
/// 记录周期
/// </summary>
@@ -36,6 +47,11 @@ namespace CapMachine.Wpf.Services
/// </summary>
public string SaveCsvRootPath { get; set; } = "D:\\TestData";
/// <summary>
/// 高速 消息数据的 SCV保存的根路径
/// </summary>
public string HighSpeedMsgSaveCsvRootPath { get; set; } = "D:\\TestData";
/// <summary>
/// 实时曲线数据缓存的时间(秒)
/// </summary>

View File

@@ -0,0 +1,339 @@
using CapMachine.Wpf.ChannelModel;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.Models.HighSpeed;
using CapMachine.Wpf.PrismEvent;
using CsvHelper.Configuration;
using CsvHelper;
using Prism.Mvvm;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Timers;
using CapMachine.Core;
using CapMachine.Model;
using System.Security.Cryptography.Xml;
using Prism.Ioc;
namespace CapMachine.Wpf.Services
{
/// <summary>
/// 高速数据
/// 通信的数据缓存
/// </summary>
public class HighSpeedDataService : BindableBase
{
public HighSpeedDataService(ConfigService configService, ILogService logService, IFreeSql FreeSql,IContainerProvider containerProvider)
{
ConfigService = configService;
LogService = logService;
this.FreeSql = FreeSql;
ContainerProvider = containerProvider;
CacheHighFragMsg = new List<CommMsg>();
//100ms 触发一次
CycleTimer = new System.Timers.Timer(100);
CycleTimer.Elapsed += CycleAction;
CycleTimer.AutoReset = true;
CycleTimer.Enabled = true;
//实时数据记录管道数据监听
Task.Run(() => ListenCycleChannelAction());
}
public ConfigService ConfigService { get; }
public ILogService LogService { get; }
public IFreeSql FreeSql { get; }
public IContainerProvider ContainerProvider { get; }
/// <summary>
/// 时间到
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
private void CycleAction(object? sender, ElapsedEventArgs e)
{
if (IsEnable)
{
//本体数据记录
CycleChannelInfo.Writer.WriteAsync(CurListMsg);
}
}
/// <summary>
/// 添加或者更新消息数据
/// </summary>
public void AppendOrUpdateMsg(CommMsg commMsg)
{
if (!CurListMsg.Exists(a => a.MsgInfo == commMsg.MsgInfo))
{
//不存在则新增
CurListMsg.Add(commMsg);
}
else
{
//存在则更新数据
var Data = CurListMsg.Find(a => a.MsgInfo == commMsg.MsgInfo);
//Data!.MsgInfo = commMsg.MsgInfo;
//Data!.Category = commMsg.Category;
Data!.MsgData = commMsg.MsgData;
Data!.Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
}
}
/// <summary>
/// 初始化高速数据
/// </summary>
public void InitHighData()
{
//报文重新清零
CurListMsg = new List<CommMsg>();
}
/// <summary>
/// 当前的报文消息集合
/// </summary>
private List<CommMsg> CurListMsg { get; set; } = new List<CommMsg>()
{
new CommMsg() { Category = "CAN2",MsgInfo = "0x000003E3",Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),MsgData = "33 00 00 00 37 00 04 00"},
new CommMsg() { Category = "CAN1",MsgInfo = "0x000003E3",Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),MsgData = "33 00 00 00 37 00 04 00"},
new CommMsg() { Category = "CAN2",MsgInfo = "0x000003E3",Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),MsgData = "33 00 00 00 37 00 04 00"},
new CommMsg() { Category = "CAN3",MsgInfo = "0x000003E3",Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),MsgData = "33 00 00 00 37 00 04 00"},
new CommMsg() { Category = "CAN4",MsgInfo = "0x000003E3",Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),MsgData = "33 00 00 00 37 00 04 00"},
new CommMsg() { Category = "CAN5",MsgInfo = "0x000003E3",Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),MsgData = "33 00 00 00 37 00 04 00"},
};
/// <summary>
/// 周期定时器
/// </summary>
private System.Timers.Timer CycleTimer { get; set; }
private bool _IsEnable=true;
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnable
{
get { return _IsEnable; }
set { _IsEnable = value; RaisePropertyChanged(); }
}
#region
/// <summary>
/// 缓存数据
/// </summary>
public List<CommMsg> CacheHighFragMsg { get; set; }
/// <summary>
/// 队列通道
/// 当前队列消费周期触发的数据记录
/// </summary>
public Channel<List<CommMsg>> CycleChannelInfo = Channel.CreateBounded<List<CommMsg>>(new BoundedChannelOptions(100000)
{
FullMode = BoundedChannelFullMode.DropOldest, //消息满了 等待消费 新的消息不插入
SingleWriter = false,//允许一次写入多条数据
SingleReader = true, //一次只能读取一条消息
});
/// <summary>
/// 缓存的集合数据
/// </summary>
public List<RecordChannelData> CacheRecordData { get; set; } = new List<RecordChannelData>();
/// <summary>
/// 当前缓存的队列信息
/// 高效的队列数据
/// </summary>
public ConcurrentQueue<RecordChannelData> ConcurrentQueueData { get; set; } = new ConcurrentQueue<RecordChannelData>();
/// <summary>
/// 最大的缓存单元数据
/// 存储超过规定600个缓存数据后进行判断后删除
/// </summary>
private int MaxCacheCellCount { get; set; } = 0;
/// <summary>
/// 数据记录管道监听方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private async void ListenCycleChannelAction()
{
while (await CycleChannelInfo.Reader.WaitToReadAsync())
{
if (CycleChannelInfo.Reader.TryRead(out var CycleChannelData))
{
////第一次计时
//stopwatch.Start(); //启动Stopwatch
//新增数据
CacheHighFragMsg.AddRange(CycleChannelData);
MaxCacheCellCount++;
if (MaxCacheCellCount >= 600)
{
//CSV文件保存
SaveToCsv(CacheHighFragMsg);
CacheHighFragMsg.Clear();
MaxCacheCellCount = 0;
}
//}
//CacheRecordData.Clear();
//Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}-{LineName}-保存成功!");
//}
//stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("保存数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset();
}
}
}
#endregion
#region CSV Helper CSV
/// <summary>
/// 当前的小时文件信息
/// </summary>
private string CurHourFileName { get; set; }
/// <summary>
/// CSV文件保存根路径
/// </summary>
private string SaveCsvRootPath { get; set; }
/// <summary>
/// Append to the file.
/// </summary>
CsvConfiguration CSVconfig { get; set; } = new CsvConfiguration(CultureInfo.CurrentCulture)
{
// Don't write the header again.
HasHeaderRecord = false,
};
/// <summary>
/// 保存到CSV文件
/// </summary>
private void SaveToCsv(List<CommMsg> CacheData)
{
CurHourFileName = DateTime.Now.ToString("yyyy-MM-dd HH");
//年份的文件是否存在
var FilePath = HighSpeedFileHelper.GetExpFilePath(ConfigService.HighSpeedMsgSaveCsvRootPath, "ConfigService.CurExpInfo.Name");
if (!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}
//文件全部路径信息
var FileFullInfo = HighSpeedFileHelper.GetHourCSVPath(FilePath, CurHourFileName);
if (!File.Exists(FileFullInfo))//是否存在文件
{
//新增文件
lock (ConfigService.HighSpeedMsgCsvFileLock)
{
//新增的文件
using (var writer = new StreamWriter(FileFullInfo, false, Encoding.UTF8))
using (var csv = new CsvWriter(writer, CultureInfo.CurrentCulture))
{
var Result = csv.Context.RegisterClassMap<HighRecordMsgMap>();
csv.WriteRecords(CacheData);
}
}
//先保存当前的文件信息
FreeSql.Insert<HighMsgFileInfo>(new HighMsgFileInfo()
{
ExpName = "ConfigService.CurExpInfo.Name",
FileInfo = CurHourFileName,
FilePath = FileFullInfo
}).ExecuteInserted();
//删除时间范围之外的文件
var DeleteInfo = FreeSql.Delete<HighMsgFileInfo>().Where(a => a.CreateTime < DateTime.Now.AddHours(-ConfigService.HighSpeedMsgCsvFileCacheHour)).ExecuteDeleted();
if (DeleteInfo.Count > 0)
{
//DB删除成功的话开始删除实体文件
foreach (var item in DeleteInfo)
{
DeleteFile(item.FilePath);
}
}
}
else//存在文件的话则新增数据
{
lock (ConfigService.HighSpeedMsgCsvFileLock)
{
//往已有的文件增加数据
using (var stream = File.Open(FileFullInfo, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
//using (var stream = new FileStream(FileFullInfo, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
using (var writer = new StreamWriter(stream))
using (var csv = new CsvWriter(writer, CSVconfig))
{
csv.Context.RegisterClassMap<HighRecordMsgMap>();
csv.WriteRecords(CacheData);
}
}
}
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name="FilePath"></param>
private bool DeleteFile(string FilePath)
{
try
{
if (File.Exists(FilePath))
{
File.Delete(FilePath);
Console.WriteLine("文件已成功删除");
return true;
}
else
{
Console.WriteLine("文件不存在");
return true;
}
}
catch (Exception ex)
{
Console.WriteLine("删除文件时发生错误: " + ex.Message);
return false;
}
}
}
#endregion
}

View File

@@ -22,7 +22,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Documents;
namespace CapMachine.Wpf.ViewModels
{
@@ -135,8 +135,6 @@ namespace CapMachine.Wpf.ViewModels
}
//CanLinConfigPromdCmd
private DelegateCommand<string> _CanLinConfigPromdCmd;
/// <summary>
/// CanConfigPro操作的指令
@@ -254,7 +252,7 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;
@@ -281,7 +279,7 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
@@ -289,11 +287,16 @@ namespace CapMachine.Wpf.ViewModels
case "Active":
if (SelectCanLinConfigPro != null)
{
//控件的激活
IsCanConfigProActive = !IsCanConfigProActive;
//当前使用的CAN 配置信息
CanDriveService.InitCanConfig(SelectCanLinConfigPro);
}
else
{
MessageBox.Show("选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;
@@ -385,6 +388,55 @@ namespace CapMachine.Wpf.ViewModels
}
private DelegateCommand<object> _CanConfigProGridPreviewMouseLeftButtonDownCmd;
/// <summary>
/// CAN 配置程序 选中行之前的数据命令 Preview
/// 防止CAN 打开后没有关闭就开始切换CAN 配置程序信息
/// 要关闭后再切换
/// </summary>
public DelegateCommand<object> CanConfigProGridPreviewMouseLeftButtonDownCmd
{
set
{
_CanConfigProGridPreviewMouseLeftButtonDownCmd = value;
}
get
{
if (_CanConfigProGridPreviewMouseLeftButtonDownCmd == null)
{
_CanConfigProGridPreviewMouseLeftButtonDownCmd = new DelegateCommand<object>((par) => CanConfigProGridPreviewMouseLeftButtonDownCmdMethod(par));
}
return _CanConfigProGridPreviewMouseLeftButtonDownCmd;
}
}
/// <summary>
/// 防止CAN 打开后没有关闭就开始切换CAN 配置程序信息
/// 要关闭后再切换
/// </summary>
/// <param name="par"></param>
private void CanConfigProGridPreviewMouseLeftButtonDownCmdMethod(object par)
{
if (par == null)
{
return;
}
if (par is System.Windows.Input.MouseButtonEventArgs)
{
var handler = par as System.Windows.Input.MouseButtonEventArgs;
if (!CanDriveService.ToomossCanDrive.OpenState)
{
// 防止默认的行选择行为发生
handler.Handled = false;
}
else
{
System.Windows.MessageBox.Show("关闭CAN连接后再点击切换CAN配置", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
handler.Handled = true;
}
}
}
#endregion
@@ -454,7 +506,7 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
@@ -464,7 +516,7 @@ namespace CapMachine.Wpf.ViewModels
}
catch (Exception ex)
{
MessageBox.Show("可能未选择信息", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("可能未选择信息", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand);
}
}
@@ -504,6 +556,12 @@ namespace CapMachine.Wpf.ViewModels
SelectedCanDbcModel = par as CanDbcModel;
return;
}
if ((par as SelectionChangedEventArgs)!.AddedItems[0] == null)
{
return;
}
//先判断是否是正确的集合数据防止DataGrid的数据源刷新导致的触发事件
var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as CanDbcModel;
@@ -593,8 +651,6 @@ namespace CapMachine.Wpf.ViewModels
set { _SelectedCANConfigExdDto = value; RaisePropertyChanged(); }
}
private DelegateCommand<string> _CanOpCmd;
/// <summary>
/// CAN操作的指令
@@ -625,13 +681,22 @@ namespace CapMachine.Wpf.ViewModels
case "Open":
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
//打开连接
CanDriveService.ToomossCanDrive.StartCanDrive();
//CAN DBC配置 有DBC配置的话则直接加载DBC信息
if (!string.IsNullOrEmpty(SelectCanLinConfigPro.CANConfigExd.DbcPath))
{
var DbcData = CanDriveService.StartDbc(SelectedCANConfigExdDto.DbcPath);
ListCanDbcModel = DbcData;
}
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;
@@ -644,7 +709,7 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;
@@ -666,16 +731,28 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;
case "Parse":
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
//打开之后连接
if (CanDriveService.ToomossCanDrive.OpenState)
{
//CAN DBC配置 有DBC配置的话则加载DBC信息
if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath))
{
var DbcData = CanDriveService.StartDbc(SelectedCANConfigExdDto.DbcPath);
ListCanDbcModel = DbcData;
}
else
{
System.Windows.MessageBox.Show("请选择DBC文件后再操作", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand);
}
}
// ListCanDbcModel = new ObservableCollection<CanDbcModel>()
//{
// new CanDbcModel(){ MsgName="DSDF1",SignalName="FASDFA11",Publisher="DFAD1",SignalDesc="ASDFASD1"},
@@ -687,20 +764,11 @@ namespace CapMachine.Wpf.ViewModels
// return;
if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath))
{
CanDriveService.ToomossCanDrive.StartDbc(SelectedCANConfigExdDto.DbcPath);
ListCanDbcModel = CanDriveService.ToomossCanDrive.ListCanDbcModel;
}
else
{
MessageBox.Show("请选择DBC文件后再操作", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
@@ -720,7 +788,13 @@ namespace CapMachine.Wpf.ViewModels
CanDriveService.ToomossCanDrive.IsCycleRevice = true;
CanDriveService.ToomossCanDrive.StartCycleReviceCanMsg();
//Listen
break;
case "Listen":
CanDriveService.ToomossCanDrive.IsCycleRevice = true;
CanDriveService.ToomossCanDrive.StartCycleReviceCanMsg();
//Listen
break;
default:
break;
@@ -731,7 +805,7 @@ namespace CapMachine.Wpf.ViewModels
#region
private ObservableCollection<CbxItems> _WriteNameCbxItems;
/// <summary>
/// 写入的Name
@@ -849,7 +923,7 @@ namespace CapMachine.Wpf.ViewModels
{
if (SelectCanLinConfigPro == null)
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
return;
}
@@ -895,7 +969,7 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("请选中后再进行【删除】操作?", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;
@@ -984,7 +1058,7 @@ namespace CapMachine.Wpf.ViewModels
{
if (SelectCanLinConfigPro == null)
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("新建CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
return;
}
@@ -1029,7 +1103,7 @@ namespace CapMachine.Wpf.ViewModels
}
else
{
MessageBox.Show("请选中后再进行【删除】操作?", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
break;

View File

@@ -71,9 +71,9 @@
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="360" />
<ColumnDefinition Width="400" />
<ColumnDefinition />
<ColumnDefinition Width="800" />
<ColumnDefinition Width="500" />
</Grid.ColumnDefinitions>
<Grid Margin="3">
@@ -87,7 +87,10 @@
Background="{DynamicResource MaterialDesignLightBackground}"
Foreground="{DynamicResource PrimaryHueLightForegroundBrush}"
UniformCornerRadius="5">
<StackPanel Margin="5" Orientation="Horizontal">
<StackPanel
Margin="5"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button
Margin="2,0"
Command="{Binding CanLinConfigPromdCmd}"
@@ -191,8 +194,12 @@
<i:EventTrigger EventName="SelectionChanged">
<prism:InvokeCommandAction Command="{Binding CanConfigProGridSelectionChangedCmd}" CommandParameter="{Binding ElementName=CANConfigDatagrid, Path=SelectedItem}" />
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<prism:InvokeCommandAction Command="{Binding CanConfigProGridPreviewMouseLeftButtonDownCmd}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
</Grid>
@@ -368,7 +375,7 @@
<StackPanel
Grid.Row="2"
Grid.ColumnSpan="2"
Grid.ColumnSpan="3"
Orientation="Horizontal">
<TextBlock
Margin="10,0,10,0"
@@ -401,13 +408,22 @@
</Border>
<Button
Margin="5,0"
Command="{Binding CanOpCmd}"
CommandParameter="SendTest1"
Content="发送测试数据" />
<Button
Margin="5,0"
Command="{Binding CanOpCmd}"
CommandParameter="SendTest2"
Content="发送测试数据" />
<Button
Margin="5,0"
Background="Green"
Command="{Binding CanOpCmd}"
CommandParameter="Listen"
Content="监听报文"
Foreground="White" />
</StackPanel>
</Grid>
@@ -672,11 +688,11 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Width="200" Binding="{Binding Name}">
<!--<DataGridTextColumn Width="200" Binding="{Binding Name}">
<DataGridTextColumn.Header>
<TextBlock FontWeight="Bold" Text="名称" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGridTextColumn>-->
<DataGridTextColumn Binding="{Binding Content}" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock FontWeight="Bold" Text="配置内容" />
@@ -776,17 +792,17 @@
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding SignalDesc}">
<!--<DataGridTextColumn Binding="{Binding SignalDesc}">
<DataGridTextColumn.Header>
<TextBlock FontWeight="Bold" Text="信号描述" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGridTextColumn>-->
<DataGridTextColumn Binding="{Binding SignalUnit}">
<!--<DataGridTextColumn Binding="{Binding SignalUnit}">
<DataGridTextColumn.Header>
<TextBlock FontWeight="Bold" Text="信号单位" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGridTextColumn>-->
<DataGridTextColumn Binding="{Binding SignalRtValue}">
<DataGridTextColumn.Header>

View File

@@ -757,9 +757,9 @@
<!--<svg1:SVGImage Grid.Column="1" Source="E:\图库资源\SVGEdit\CapMachineOutput.svg" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="3" />-->
<Canvas Grid.Column="1">
<Canvas.Background>
<ImageBrush ImageSource="E:\图库资源\SVGEdit\CapMachineOutput1.png" />
</Canvas.Background>
<!--<Canvas.Background>
<ImageBrush ImageSource="\Assets\Images\CapMachineOutput1.png" />
</Canvas.Background>-->
<Rectangle
Canvas.Left="30"
Canvas.Top="107"

View File

@@ -561,7 +561,11 @@
<TextBlock FontWeight="Bold" Text="序号" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding SpeedCycle.Cycle}" CanUserSort="False">
<DataGridTextColumn
Binding="{Binding SpeedCycle.Cycle}"
CanUserSort="False"
FontSize="16"
Foreground="Blue">
<DataGridTextColumn.Header>
<TextBlock FontWeight="Bold" Text="转速&#x0A;循环次数" />
</DataGridTextColumn.Header>
@@ -1787,7 +1791,7 @@
SwitchConstSlopCommand="{Binding MeterOS2TempSwitchConstSlopCmd}"
TotalSlopTime="{Binding MeterOS2TempExDto.SlopTime}" />
</TabItem>
<!--<TabItem>
<TabItem.Header>
<StackPanel