CAN FD 波特率等参数的增加和联动配置

This commit is contained in:
2025-07-09 22:15:19 +08:00
parent 6a2ce24cbb
commit 42c4502a8d
14 changed files with 430 additions and 29 deletions

View File

@@ -0,0 +1,53 @@
using FreeSql.DataAnnotations;
namespace CapMachine.Model.CANLIN
{
/// <summary>
/// CAN和LIN的配置信息数据
/// </summary>
[Table(Name = "CANFdConfigExd")]
public class CANFdConfigExd
{
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimary = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 数据波特率
/// </summary>
[Column(Name = "DataBaudRate")]
public int DataBaudRate { get; set; }
/// <summary>
/// 仲裁波特率
/// </summary>
[Column(Name = "ArbBaudRate")]
public int ArbBaudRate { get; set; }
/// <summary>
/// CAN FD标准 ISO是否启用
/// </summary>
[Column(Name = "ISOEnable")]
public bool ISOEnable { get; set; }
/// <summary>
/// 终端电阻 是否启用
/// </summary>
[Column(Name = "ResEnable")]
public bool ResEnable { get; set; }
/// <summary>
/// 周期
/// </summary>
[Column(Name = "Cycle")]
public int Cycle { get; set; }
/// <summary>
/// Dbc文件路径
/// </summary>
[Column(Name = "DbcPath", IsNullable = false, StringLength = 500)]
public string? DbcPath { get; set; }
}
}

View File

@@ -45,6 +45,13 @@ namespace CapMachine.Model.CANLIN
public List<CanLinRWConfig>? CanLinConfigContents { get; set; }
/// <summary>
/// ///////////////////////////////////////////导航属性 LIN 一对一///////////////////////////////////////////////////////
/// </summary>
public long CANFdConfigExdId { get; set; } // 外键字段,必要
public CANFdConfigExd CANFdConfigExd { get; set; }
/// <summary>
/// ///////////////////////////////////////////导航属性 CAN 一对一///////////////////////////////////////////////////////
/// </summary>
@@ -52,12 +59,12 @@ namespace CapMachine.Model.CANLIN
public CANConfigExd CANConfigExd { get; set; }
/// <summary>
/// ///////////////////////////////////////////导航属性 LIN 一对一///////////////////////////////////////////////////////
/// </summary>
public long LINConfigExdId { get; set; } // 外键字段,必要
public LINConfigExd LINConfigExd { get; set; }
}
}

View File

@@ -73,6 +73,38 @@ namespace CapMachine.Wpf.CanDrive
#region
/// <summary>
/// 仲裁波特率
/// </summary>
public uint ArbBaudRate { get; set; } = 500000;
/// <summary>
/// 数据波特率
/// </summary>
public uint DataBaudRate { get; set; } = 2000000;
/// <summary>
/// CAN FD标准 ISO是否启用
/// </summary>
public bool ISOEnable { get; set; } = true;
/// <summary>
/// 终端电阻 是否启用
/// </summary>
public bool ResEnable { get; set; } = true;
/// <summary>
/// 更新配置
/// </summary>
public void UpdateConfig(uint arbBaudRate, uint dataBaudRate, bool iSOEnable, bool resEnable)
{
ArbBaudRate = arbBaudRate;
DataBaudRate = dataBaudRate;
ISOEnable = iSOEnable;
ResEnable = resEnable;
}
/// <summary>
/// 设备固件信息
/// </summary>
@@ -256,7 +288,7 @@ namespace CapMachine.Wpf.CanDrive
public void GetCANConfig()
{
//获取CAN波特率参数
ret = USB2CANFD.CANFD_GetCANSpeedArg(DevHandle, ref CANConfig, 500000, 2000000);
ret = USB2CANFD.CANFD_GetCANSpeedArg(DevHandle, ref CANConfig, ArbBaudRate, DataBaudRate);
if (ret != USB2CANFD.CANFD_SUCCESS)
{
Console.WriteLine("Get CAN Speed failed!");
@@ -276,7 +308,8 @@ namespace CapMachine.Wpf.CanDrive
public void InitCAN()
{
//初始化CAN
CANConfig.ISOCRCEnable = 1;//使能ISOCRC
CANConfig.ISOCRCEnable = ISOEnable == true ? (byte)1 : (byte)0;//使能ISOCRC
CANConfig.ResEnable = ResEnable == true ? (byte)1 : (byte)0;//使能终端电阻
ret = USB2CANFD.CANFD_Init(DevHandle, WriteCANIndex, ref CANConfig);
if (ret != USB2CANFD.CANFD_SUCCESS)
{
@@ -554,7 +587,7 @@ namespace CapMachine.Wpf.CanDrive
//发送CAN数据
int SendedNum = USB2CANFD.CANFD_SendMsg(DevHandle, WriteCANIndex, CanMsg, (Int32)CanMsg.Length);
if (SendedNum >= 0)
{
//Console.WriteLine("Success send frames:{0}", SendedNum);

View File

@@ -0,0 +1,77 @@
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Dtos
{
public class CANFdConfigExdDto : BindableBase
{
/// <summary>
/// 主键
/// </summary>
public long Id { get; set; }
private int _DataBaudRate;
/// <summary>
/// 数据波特率
/// </summary>
public int DataBaudRate
{
get { return _DataBaudRate; }
set { _DataBaudRate = value; RaisePropertyChanged(); }
}
private int _ArbBaudRate;
/// <summary>
/// 仲裁波特率
/// </summary>
public int ArbBaudRate
{
get { return _ArbBaudRate; }
set { _ArbBaudRate = value; RaisePropertyChanged(); }
}
private bool _ISOEnable;
/// <summary>
/// ISO 使能
/// </summary>
public bool ISOEnable
{
get { return _ISOEnable; }
set { _ISOEnable = value; RaisePropertyChanged(); }
}
private bool _ResEnable;
/// <summary>
/// 终端电阻使能
/// </summary>
public bool ResEnable
{
get { return _ResEnable; }
set { _ResEnable = value; RaisePropertyChanged(); }
}
private int _Cycle;
/// <summary>
/// 周期
/// </summary>
public int Cycle
{
get { return _Cycle; }
set { _Cycle = value; RaisePropertyChanged(); }
}
private string? _DbcPath;
/// <summary>
/// Dbc文件路径
/// </summary>
public string? DbcPath
{
get { return _DbcPath; }
set { _DbcPath = value; RaisePropertyChanged(); }
}
}
}

View File

@@ -0,0 +1,19 @@
using AutoMapper;
using CapMachine.Model.CANLIN;
using CapMachine.Wpf.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.MapperProfile
{
public class CANFdConfigExdProfile : Profile
{
public CANFdConfigExdProfile()
{
CreateMap<CANFdConfigExd, CANFdConfigExdDto>().ReverseMap();
}
}
}

View File

@@ -602,7 +602,7 @@ namespace CapMachine.Wpf.Models.LightChart
//光标注释相对的位置 左上侧
CursorValueDisplay.LocationScreenCoords.Y = 35;
CursorValueDisplay.LocationScreenCoords.X = 1380;
CursorValueDisplay.LocationScreenCoords.X = 1100;
//CursorValueDisplay.TargetAxisValues.X = 0;
//CursorValueDisplay.TargetAxisValues.Y = 0;

View File

@@ -28,6 +28,11 @@ namespace CapMachine.Wpf.Models.Tag.Cell
/// </summary>
public string? Address { get; set; }
/// <summary>
/// 回写PLC地址一般是压缩机的参数回写到PLC的地址,比如压缩机母线电流反馈、压缩机母线电压反馈等信息
/// </summary>
public string? ReWritePLCAddress { get; set; }
/// <summary>
/// 启用
/// </summary>

View File

@@ -374,6 +374,7 @@ namespace CapMachine.Wpf.Services
//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 double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
}
return 0;
}

View File

@@ -352,6 +352,7 @@ namespace CapMachine.Wpf.Services
{
//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 12.3;
}
return 0;
}
@@ -372,6 +373,7 @@ namespace CapMachine.Wpf.Services
//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 double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
//return 2300;
}
return 0;
}

View File

@@ -1435,7 +1435,7 @@ namespace CapMachine.Wpf.Services
if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? CanpVModel))
{
CanpVModel!.EngValue = CanDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速");
SiemensDrive.Write(CanpVModel!.Address!.Replace("W", ""), (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"));
SiemensDrive.Write(CanpVModel!.ReWritePLCAddress!, (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"));
//pVModel.EngSrcValue = 0;
}
break;
@@ -1444,7 +1444,7 @@ namespace CapMachine.Wpf.Services
if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? CanfdpVModel))
{
CanfdpVModel!.EngValue = CanFdDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速");
SiemensDrive.Write(CanfdpVModel!.Address!.Replace("W", ""), (short)CanFdDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"));
SiemensDrive.Write(CanfdpVModel!.ReWritePLCAddress!, (short)CanFdDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"));
//pVModel.EngSrcValue = 0;
}
break;
@@ -1453,7 +1453,7 @@ namespace CapMachine.Wpf.Services
if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? LinpVModel))
{
LinpVModel!.EngValue = LinDriveService.GetLdfSpeedValueBySpeedName("通讯Cmp转速");
SiemensDrive.Write(LinpVModel!.Address!.Replace("W", ""), (short)LinDriveService.GetLdfSpeedValueBySpeedName("通讯Cmp转速"));
SiemensDrive.Write(LinpVModel!.ReWritePLCAddress!, (short)LinDriveService.GetLdfSpeedValueBySpeedName("通讯Cmp转速"));
}
break;
default:
@@ -1469,25 +1469,28 @@ namespace CapMachine.Wpf.Services
//尝试获取模型信息
if (TagManger.TryGetCapPVModelByShortValueTag(itemCanLinGroup.Key, out MeterValueAttrCell? pVModel))
{
//没有这个地址则跳过
if (String.IsNullOrEmpty(pVModel!.ReWritePLCAddress)) continue;
switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin)
{
case CanLinEnum.Can:
//取得压缩机的CANLIN数据到数据集合中
pVModel!.EngValue = CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit);
//写入到PLC中
SiemensDrive.Write(pVModel!.Address!.Replace("W", ""), (short)(CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision));
SiemensDrive.Write(pVModel!.ReWritePLCAddress!, (short)(CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision));
break;
case CanLinEnum.CANFD:
//取得压缩机的CANLIN数据到数据集合中
pVModel!.EngValue = CanFdDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit);
//写入到PLC中
SiemensDrive.Write(pVModel!.Address!.Replace("W", ""), (short)(CanFdDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision));
SiemensDrive.Write(pVModel!.ReWritePLCAddress!, (short)(CanFdDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision));
break;
case CanLinEnum.Lin:
//取得压缩机的CANLIN数据
pVModel!.EngValue = LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit);
//写入到PLC中
SiemensDrive.Write(pVModel!.Address!.Replace("W", ""), (short)(LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision));
SiemensDrive.Write(pVModel!.ReWritePLCAddress!, (short)(LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision));
break;
case CanLinEnum.No:

View File

@@ -15,6 +15,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15000",
"ReWritePLCAddress": "V14100",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -295,7 +296,7 @@
"MaxValue": 10000,
"IsMeter": false,
"DecimalPoint": 1,
"Precision": 10,
"Precision": 100,
"Unit": "℃",
"DataType": "Short",
"RWInfo": "PLCRead",
@@ -317,7 +318,7 @@
"MaxValue": 10000,
"IsMeter": false,
"DecimalPoint": 1,
"Precision": 10,
"Precision": 100,
"Unit": "%",
"DataType": "Short",
"RWInfo": "PLCRead",
@@ -675,12 +676,59 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15060",
"ReWritePLCAddress": "V14102",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
"BlockIndex": 60
}
},
{
"Id": 320,
"Name": "通讯Cmp母线电压[V]",
"NameNoUnit": "通讯Cmp母线电压",
"EnName": "ComCapBusVol",
"Group": "压缩机",
"MinValue": 0,
"MaxValue": 10000,
"IsMeter": false,
"DecimalPoint": 2,
"Precision": 100,
"Unit": "V",
"DataType": "Short",
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15062",
"ReWritePLCAddress": "V14104",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
"BlockIndex": 62
}
},
{
"Id": 330,
"Name": "通讯Cmp逆变器温度[℃]",
"NameNoUnit": "通讯Cmp逆变器温度",
"EnName": "ComCapInvTemp",
"Group": "压缩机",
"MinValue": 0,
"MaxValue": 10000,
"IsMeter": false,
"DecimalPoint": 2,
"Precision": 100,
"Unit": "℃",
"DataType": "Short",
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15064",
"ReWritePLCAddress": "V14106",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
"BlockIndex": 64
}
},
{
"Id": 340,
"Name": "通讯Cmp相电流[A]",
@@ -697,6 +745,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15066",
"ReWritePLCAddress": "V14108",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -719,6 +768,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15068",
"ReWritePLCAddress": "V14110",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -741,6 +791,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15070",
"ReWritePLCAddress": "V14112",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -763,6 +814,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15072",
"ReWritePLCAddress": "V14120",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -785,6 +837,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15074",
"ReWritePLCAddress": "V14122",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -807,6 +860,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15076",
"ReWritePLCAddress": "V14124",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -829,6 +883,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15078",
"ReWritePLCAddress": "V14126",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -851,6 +906,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15080",
"ReWritePLCAddress": "V14128",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",
@@ -873,6 +929,7 @@
"RWInfo": "PLCRead",
"PVModel": {
"Address": "VW15082",
"ReWritePLCAddress": "V14130",
"EngValue": 0,
"EngValueStr": "",
"Block": "PV",

View File

@@ -73,6 +73,7 @@ namespace CapMachine.Wpf.ViewModels
new CbxItems(){ Key="通讯Cmp转速",Text="通讯Cmp转速"},
new CbxItems(){ Key="通讯Cmp母线电压",Text="通讯Cmp母线电压"},
new CbxItems(){ Key="通讯Cmp母线电流",Text="通讯Cmp母线电流"},
new CbxItems(){ Key="通讯Cmp逆变器温度",Text="通讯Cmp逆变器温度"},
new CbxItems(){ Key="通讯Cmp相电流",Text="通讯Cmp相电流"},
new CbxItems(){ Key="通讯Cmp功率",Text="通讯Cmp功率"},
new CbxItems(){ Key="通讯Cmp芯片温度",Text="通讯Cmp芯片温度"},

View File

@@ -52,6 +52,50 @@ namespace CapMachine.Wpf.ViewModels
//MachineDataService = machineDataService;
DialogService = dialogService;
//仲裁波特率
ArbBaudRateCbxItems = new ObservableCollection<CbxItems>()
{
new CbxItems(){ Key="10000",Text="10 Kbps"},
new CbxItems(){ Key="20000",Text="20 Kbps"},
new CbxItems(){ Key="33000",Text="33 Kbps"},
new CbxItems(){ Key="50000",Text="50Kbps"},
new CbxItems(){ Key="83000",Text="83 Kbps"},
new CbxItems(){ Key="100000",Text="100 Kbps"},
new CbxItems(){ Key="125000",Text="125 Kbps"},
new CbxItems(){ Key="150000",Text="150 Kbps"},
new CbxItems(){ Key="200000",Text="200 Kbps"},
new CbxItems(){ Key="250000",Text="250 Kbps"},
new CbxItems(){ Key="300000",Text="300 Kbps"},
new CbxItems(){ Key="400000",Text="400 Kbps"},
new CbxItems(){ Key="500000",Text="500 Kbps"},
new CbxItems(){ Key="666000",Text="666 Kbps"},
new CbxItems(){ Key="800000",Text="800 Kbps"},
new CbxItems(){ Key="1000000",Text="1.0 Mbps"},
};
//数据波特率
DataBaudRateCbxItems = new ObservableCollection<CbxItems>()
{
new CbxItems(){ Key="100000",Text="100 Kbps"},
new CbxItems(){ Key="125000",Text="125 Kbps"},
new CbxItems(){ Key="200000",Text="200 Kbps"},
new CbxItems(){ Key="250000",Text="250 Kbps"},
new CbxItems(){ Key="400000",Text="400 Kbps"},
new CbxItems(){ Key="500000",Text="500 Kbps"},
new CbxItems(){ Key="666000",Text="666 Kbps"},
new CbxItems(){ Key="800000",Text="800 Kbps"},
new CbxItems(){ Key="1000000",Text="1.0 Mbps"},
new CbxItems(){ Key="1500000",Text="1.5 Mbps"},
new CbxItems(){ Key="2000000",Text="2.0 Mbps"},
new CbxItems(){ Key="3000000",Text="3.0 Mbps"},
new CbxItems(){ Key="4000000",Text="4.0 Mbps"},
new CbxItems(){ Key="5000000",Text="5.0 Mbps"},
new CbxItems(){ Key="6700000",Text="6.7 Mbps"},
new CbxItems(){ Key="8000000",Text="8.0 Mbps"},
new CbxItems(){ Key="10000000",Text="10.0 Mbps"},
};
WriteNameCbxItems = new ObservableCollection<CbxItems>()
{
new CbxItems(){ Key="转速",Text="转速"},
@@ -70,6 +114,7 @@ namespace CapMachine.Wpf.ViewModels
new CbxItems(){ Key="通讯Cmp转速",Text="通讯Cmp转速"},
new CbxItems(){ Key="通讯Cmp母线电压",Text="通讯Cmp母线电压"},
new CbxItems(){ Key="通讯Cmp母线电流",Text="通讯Cmp母线电流"},
new CbxItems(){ Key="通讯Cmp逆变器温度",Text="通讯Cmp逆变器温度"},
new CbxItems(){ Key="通讯Cmp相电流",Text="通讯Cmp相电流"},
new CbxItems(){ Key="通讯Cmp功率",Text="通讯Cmp功率"},
new CbxItems(){ Key="通讯Cmp芯片温度",Text="通讯Cmp芯片温度"},
@@ -115,7 +160,7 @@ namespace CapMachine.Wpf.ViewModels
{
//CAN配置集合数据
canLinConfigPros = FreeSql.Select<CanLinConfigPro>().Where(a => a.CANLINInfo == CANLIN.CANFD)
.Include(a => a.CANConfigExd)
.Include(a => a.CANFdConfigExd)
.IncludeMany(a => a.CanLinConfigContents)
.ToList();
@@ -126,7 +171,13 @@ namespace CapMachine.Wpf.ViewModels
//无数据就返回
if (SelectCanLinConfigPro == null) return;
SelectedCANConfigExdDto = Mapper.Map<CANConfigExdDto>(SelectCanLinConfigPro!.CANConfigExd);
SelectedCANConfigExdDto = Mapper.Map<CANFdConfigExdDto>(SelectCanLinConfigPro!.CANFdConfigExd);
if (SelectedCANConfigExdDto != null)
{
//更新波特率等配置信息
CanFdDriveService.ToomossCanFDDrive.UpdateConfig((uint)SelectedCANConfigExdDto.ArbBaudRate,
(uint)SelectedCANConfigExdDto.DataBaudRate, SelectedCANConfigExdDto.ISOEnable, SelectedCANConfigExdDto.ResEnable);
}
//配置信息
var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
@@ -271,9 +322,10 @@ namespace CapMachine.Wpf.ViewModels
var ReturnValue = par.Parameters.GetValue<string>("Name");
//加载默认的数据 CANConfigExd
var InsertCANConfigExd = FreeSql.Insert<CANConfigExd>(new CANConfigExd()
var InsertCANConfigExd = FreeSql.Insert<CANFdConfigExd>(new CANFdConfigExd()
{
BaudRate = 250,
DataBaudRate = 250,
ArbBaudRate = 2000,
DbcPath = "请配置DBC路径",
Cycle = 100,
}).ExecuteInserted();
@@ -283,7 +335,7 @@ namespace CapMachine.Wpf.ViewModels
{
ConfigName = ReturnValue,
CANLINInfo = CANLIN.CANFD,
CANConfigExdId = InsertCANConfigExd.FirstOrDefault()!.Id
CANFdConfigExdId = InsertCANConfigExd.FirstOrDefault()!.Id
}).ExecuteInserted();
if (InsertData != null)
{
@@ -364,7 +416,7 @@ namespace CapMachine.Wpf.ViewModels
repo.DbContextOptions.EnableCascadeSave = true; //关键设置
var DeleteData = repo.Select
.Include(a => a.CANConfigExd)
.Include(a => a.CANFdConfigExd)
.IncludeMany(a => a.CanLinConfigContents)
.Where(a => a.Id == SelectCanLinConfigPro.Id)
.ToList();
@@ -372,7 +424,7 @@ namespace CapMachine.Wpf.ViewModels
repo.Delete(DeleteData);
foreach (var item in DeleteData)
{
FreeSql.Delete<CANConfigExd>(item.CANConfigExdId).ExecuteAffrows();
FreeSql.Delete<CANFdConfigExd>(item.CANFdConfigExdId).ExecuteAffrows();
}
InitLoadCanConfigPro();
}
@@ -480,7 +532,13 @@ namespace CapMachine.Wpf.ViewModels
SelectCanLinConfigPro = par as CanLinConfigPro;
//CANConfigExdDto 数据
SelectedCANConfigExdDto = Mapper.Map<CANConfigExdDto>(SelectCanLinConfigPro!.CANConfigExd);
SelectedCANConfigExdDto = Mapper.Map<CANFdConfigExdDto>(SelectCanLinConfigPro!.CANFdConfigExd);
if (SelectedCANConfigExdDto!=null)
{
//更新波特率等配置信息
CanFdDriveService.ToomossCanFDDrive.UpdateConfig((uint)SelectedCANConfigExdDto.ArbBaudRate,
(uint)SelectedCANConfigExdDto.DataBaudRate, SelectedCANConfigExdDto.ISOEnable, SelectedCANConfigExdDto.ResEnable);
}
var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
if (WirteData != null && WirteData.Count > 0)
@@ -789,16 +847,36 @@ namespace CapMachine.Wpf.ViewModels
#region CAN操作
private CANConfigExdDto _SelectedCANConfigExdDto;
private CANFdConfigExdDto _SelectedCANConfigExdDto;
/// <summary>
/// 选中的CAN操作
/// </summary>
public CANConfigExdDto SelectedCANConfigExdDto
public CANFdConfigExdDto SelectedCANConfigExdDto
{
get { return _SelectedCANConfigExdDto; }
set { _SelectedCANConfigExdDto = value; RaisePropertyChanged(); }
}
private ObservableCollection<CbxItems> _DataBaudRateCbxItems;
/// <summary>
/// CAN FD 数据波特率
/// </summary>
public ObservableCollection<CbxItems> DataBaudRateCbxItems
{
get { return _DataBaudRateCbxItems; }
set { _DataBaudRateCbxItems = value; RaisePropertyChanged(); }
}
private ObservableCollection<CbxItems> _ArbBaudRateCbxItems;
/// <summary>
/// CAN FD 仲裁波特率
/// </summary>
public ObservableCollection<CbxItems> ArbBaudRateCbxItems
{
get { return _ArbBaudRateCbxItems; }
set { _ArbBaudRateCbxItems = value; RaisePropertyChanged(); }
}
private DelegateCommand<string> _CanOpCmd;
/// <summary>
/// CAN操作的指令
@@ -844,7 +922,7 @@ namespace CapMachine.Wpf.ViewModels
}
//CAN DBC配置 有DBC配置的话则直接加载DBC信息
if (!string.IsNullOrEmpty(SelectCanLinConfigPro.CANConfigExd.DbcPath))
if (!string.IsNullOrEmpty(SelectCanLinConfigPro.CANFdConfigExd.DbcPath))
{
var DbcData = CanFdDriveService.StartDbc(SelectedCANConfigExdDto.DbcPath);
ListCanDbcModel = DbcData;
@@ -882,10 +960,13 @@ namespace CapMachine.Wpf.ViewModels
//保存Can 配置
if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath))
{
var Update = FreeSql.Update<CANConfigExd>()
var Update = FreeSql.Update<CANFdConfigExd>()
.Set(a => a.DbcPath, SelectedCANConfigExdDto.DbcPath)
.Set(a => a.Cycle, SelectedCANConfigExdDto.Cycle)
.Set(a => a.BaudRate, SelectedCANConfigExdDto.BaudRate)
.Set(a => a.DataBaudRate, SelectedCANConfigExdDto.DataBaudRate)
.Set(a => a.ArbBaudRate, SelectedCANConfigExdDto.ArbBaudRate)
.Set(a => a.ISOEnable, SelectedCANConfigExdDto.ISOEnable)
.Set(a => a.ResEnable, SelectedCANConfigExdDto.ResEnable)
.Where(a => a.Id == SelectedCANConfigExdDto.Id)
.ExecuteUpdated();
}

View File

@@ -405,8 +405,70 @@
FontFamily="/Assets/Fonts/#iconfont"
FontSize="18"
Text="&#xe9f8;" />
<TextBlock Style="{StaticResource TextBlockStyle}" Text="波特率" />
<TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding SelectedCANConfigExdDto.BaudRate}" />
<TextBlock Style="{StaticResource TextBlockStyle}" Text="仲裁波特率" />
<ComboBox
Width="100"
DisplayMemberPath="Text"
FontSize="16"
ItemsSource="{Binding ArbBaudRateCbxItems}"
SelectedValue="{Binding SelectedCANConfigExdDto.ArbBaudRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="Key" />
<!--<TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding SelectedCANConfigExdDto.DataBaudRate}" />-->
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock
Margin="10,0,10,0"
VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont"
FontSize="18"
Text="&#xe9f8;" />
<TextBlock Style="{StaticResource TextBlockStyle}" Text="数据波特率" />
<ComboBox
Width="100"
DisplayMemberPath="Text"
FontSize="16"
ItemsSource="{Binding DataBaudRateCbxItems}"
SelectedValue="{Binding SelectedCANConfigExdDto.DataBaudRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="Key" />
<!--<TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding SelectedCANConfigExdDto.ArbBaudRate}" />-->
</StackPanel>
<StackPanel
Grid.Row="0"
Grid.Column="2"
Orientation="Horizontal">
<TextBlock
Margin="5,0,5,0"
VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont"
FontSize="18"
Text="&#xe9f8;" />
<TextBlock
Width="auto"
Style="{StaticResource TextBlockStyle}"
Text="ISO标准" />
<ToggleButton
Margin="5,0,5,0"
IsChecked="{Binding SelectedCANConfigExdDto.ISOEnable}"
Style="{StaticResource MaterialDesignSwitchToggleButton}"
ToolTip="{Binding Name}" />
<TextBlock
Margin="5,0,5,0"
VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont"
FontSize="18"
Text="&#xe9f8;" />
<TextBlock
Width="auto"
Style="{StaticResource TextBlockStyle}"
Text="终端电阻" />
<ToggleButton
Margin="5,0,5,0"
IsChecked="{Binding SelectedCANConfigExdDto.ResEnable}"
Style="{StaticResource MaterialDesignSwitchToggleButton}"
ToolTip="{Binding Name}" />
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">