CAN曲线功能添加
This commit is contained in:
parent
7f2fa77dd2
commit
8923dd1ed8
6
BOB.sln
6
BOB.sln
@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessManager", "ProcessMa
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{E2897246-96B3-48BE-AA08-4E774BE2BCFB}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{E2897246-96B3-48BE-AA08-4E774BE2BCFB}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CAN驱动", "CAN驱动\CAN驱动.csproj", "{65DCA56F-A0EB-407F-80B9-C5C5F0E69681}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -63,6 +65,10 @@ Global
|
|||||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{E2897246-96B3-48BE-AA08-4E774BE2BCFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{65DCA56F-A0EB-407F-80B9-C5C5F0E69681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{65DCA56F-A0EB-407F-80B9-C5C5F0E69681}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{65DCA56F-A0EB-407F-80B9-C5C5F0E69681}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{65DCA56F-A0EB-407F-80B9-C5C5F0E69681}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -113,6 +113,7 @@ namespace BOB
|
|||||||
containerRegistry.RegisterDialog<SQ0030G1DView, SQ0030G1DViewModel>("SQ0030G1D");
|
containerRegistry.RegisterDialog<SQ0030G1DView, SQ0030G1DViewModel>("SQ0030G1D");
|
||||||
containerRegistry.RegisterDialog<WS_68030_380TView, WS_68030_380TViewModel>("WS_68030_380T");
|
containerRegistry.RegisterDialog<WS_68030_380TView, WS_68030_380TViewModel>("WS_68030_380T");
|
||||||
containerRegistry.RegisterDialog<ZXKSView, ZXKSViewModel>("ZXKS");
|
containerRegistry.RegisterDialog<ZXKSView, ZXKSViewModel>("ZXKS");
|
||||||
|
containerRegistry.RegisterDialog<CANView, CANViewModel>("CAN");
|
||||||
//注册全局单例变量
|
//注册全局单例变量
|
||||||
containerRegistry.RegisterSingleton<GlobalVariables>();
|
containerRegistry.RegisterSingleton<GlobalVariables>();
|
||||||
containerRegistry.RegisterSingleton<Devices>();
|
containerRegistry.RegisterSingleton<Devices>();
|
||||||
|
|||||||
@ -44,6 +44,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\CAN驱动\CAN驱动.csproj" />
|
||||||
<ProjectReference Include="..\Command\Command.csproj" />
|
<ProjectReference Include="..\Command\Command.csproj" />
|
||||||
<ProjectReference Include="..\Common\Common.csproj" />
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
<ProjectReference Include="..\DeviceCommand\DeviceCommand.csproj" />
|
<ProjectReference Include="..\DeviceCommand\DeviceCommand.csproj" />
|
||||||
|
|||||||
40
BOB/Converters/HexConverter.cs
Normal file
40
BOB/Converters/HexConverter.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
|
namespace BOB.Converters
|
||||||
|
{
|
||||||
|
public class HexConverter : IValueConverter
|
||||||
|
{
|
||||||
|
// 显示时:int → hex 字符串
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is int i)
|
||||||
|
return $"0x{i:X}"; // 例如 255 → 0xFF
|
||||||
|
return "0x0";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户输入时:hex 字符串 → int
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
var str = value?.ToString()?.Trim();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(str))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (str.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
||||||
|
str = str.Substring(2);
|
||||||
|
|
||||||
|
if (int.TryParse(str, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int result))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return 0; // 或 return DependencyProperty.UnsetValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,9 +1,11 @@
|
|||||||
using BOB.Services;
|
using BOB.Services;
|
||||||
|
using CAN驱动;
|
||||||
using Castle.DynamicProxy;
|
using Castle.DynamicProxy;
|
||||||
using DeviceCommand.Base;
|
using DeviceCommand.Base;
|
||||||
using DeviceCommand.Device;
|
using DeviceCommand.Device;
|
||||||
using Logger;
|
using Logger;
|
||||||
using Model;
|
using Model;
|
||||||
|
using Npgsql.TypeHandlers;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -171,6 +173,21 @@ namespace BOB.Singleton
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InitCan()
|
||||||
|
{
|
||||||
|
同星驱动类.DisConnect();
|
||||||
|
var re1 = 同星驱动类.Init("ATS测试系统");
|
||||||
|
var re2 = 同星驱动类.Connect();
|
||||||
|
if (re1 == 0 && re2 == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public async Task ConnectAllDevicesAsync()
|
public async Task ConnectAllDevicesAsync()
|
||||||
{
|
{
|
||||||
if (DeviceDic.Count == 0)
|
if (DeviceDic.Count == 0)
|
||||||
|
|||||||
107
BOB/ViewModels/Dialogs/CANViewModel.cs
Normal file
107
BOB/ViewModels/Dialogs/CANViewModel.cs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
using BOB.Singleton;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace BOB.ViewModels.Dialogs
|
||||||
|
{
|
||||||
|
public class CANViewModel : BindableBase, IDialogAware
|
||||||
|
{
|
||||||
|
|
||||||
|
#region 属性
|
||||||
|
private string _Title = "同星CAN";
|
||||||
|
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get { return _Title; }
|
||||||
|
set { SetProperty(ref _Title, value); }
|
||||||
|
}
|
||||||
|
private string _BLFPath;
|
||||||
|
|
||||||
|
public string BLFPath
|
||||||
|
{
|
||||||
|
get { return _BLFPath; }
|
||||||
|
set { SetProperty(ref _BLFPath, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region 命令
|
||||||
|
public ICommand SelectBLFPathCommand { get; set; }
|
||||||
|
public ICommand SaveBLFPathCommand { get; set; }
|
||||||
|
public ICommand StartTranscirbeCommand { get; set; }
|
||||||
|
public ICommand EndTranscirbeCommand { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private IEventAggregator _eventAggregator { get; set; }
|
||||||
|
private Devices _devices { get; set; }
|
||||||
|
private GlobalVariables _globalVariables { get; set; }
|
||||||
|
public CANViewModel(IContainerProvider containerProvider)
|
||||||
|
{
|
||||||
|
_devices = containerProvider.Resolve<Devices>();
|
||||||
|
_globalVariables = containerProvider.Resolve<GlobalVariables>();
|
||||||
|
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
|
||||||
|
SelectBLFPathCommand = new DelegateCommand(SelectBLFPath);
|
||||||
|
SaveBLFPathCommand = new DelegateCommand(SaveBLFPath);
|
||||||
|
StartTranscirbeCommand = new DelegateCommand(StartTranscirbe);
|
||||||
|
EndTranscirbeCommand = new DelegateCommand(EndTranscirbe);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 命令
|
||||||
|
private void EndTranscirbe()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartTranscirbe()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveBLFPath()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectBLFPath()
|
||||||
|
{
|
||||||
|
var dialog = new SaveFileDialog
|
||||||
|
{
|
||||||
|
Title = "保存 CAN报文回放 BLF 文件",
|
||||||
|
Filter = "BLF 文件 (*.blf)|*.blf|所有文件 (*.*)|*.*",
|
||||||
|
DefaultExt = ".blf",
|
||||||
|
FileName = "log.blf",
|
||||||
|
OverwritePrompt = true
|
||||||
|
};
|
||||||
|
if (dialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
BLFPath = Path.GetFullPath(dialog.FileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region dialog规范
|
||||||
|
public DialogCloseListener RequestClose { get; set; }
|
||||||
|
|
||||||
|
public bool CanCloseDialog()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDialogClosed()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDialogOpened(IDialogParameters parameters)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,6 +19,7 @@ namespace BOB.ViewModels.Dialogs
|
|||||||
{
|
{
|
||||||
public class EAEL9080ViewModel : BindableBase, IDialogAware
|
public class EAEL9080ViewModel : BindableBase, IDialogAware
|
||||||
{
|
{
|
||||||
|
|
||||||
#region 属性
|
#region 属性
|
||||||
private string _Title = "低压直流负载";
|
private string _Title = "低压直流负载";
|
||||||
private string _设备标识字符串;
|
private string _设备标识字符串;
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
using BOB.Singleton;
|
using BOB.Singleton;
|
||||||
|
using DeviceCommand.Device;
|
||||||
|
using Logger;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
@ -12,8 +16,26 @@ namespace BOB.ViewModels.Dialogs
|
|||||||
{
|
{
|
||||||
public class IOBoardViewModel : BindableBase, IDialogAware
|
public class IOBoardViewModel : BindableBase, IDialogAware
|
||||||
{
|
{
|
||||||
|
public enum Address : ushort
|
||||||
|
{
|
||||||
|
ushort0 = 0,
|
||||||
|
ushort1 = 1,
|
||||||
|
ushort2 = 2,
|
||||||
|
ushort3 = 3,
|
||||||
|
ushort4 = 4,
|
||||||
|
ushort5 = 5,
|
||||||
|
ushort6 = 6,
|
||||||
|
ushort7 = 7,
|
||||||
|
ushort8 = 8,
|
||||||
|
ushort9 = 9,
|
||||||
|
ushort10 = 10,
|
||||||
|
ushort11 = 11,
|
||||||
|
ushort12 = 12,
|
||||||
|
ushort13 = 13,
|
||||||
|
ushort14 = 14,
|
||||||
|
ushort15 = 15
|
||||||
|
}
|
||||||
#region 属性
|
#region 属性
|
||||||
|
|
||||||
private string _title = "IO板卡";
|
private string _title = "IO板卡";
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
@ -22,16 +44,7 @@ namespace BOB.ViewModels.Dialogs
|
|||||||
set { SetProperty(ref _title, value); }
|
set { SetProperty(ref _title, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _startAddress;
|
private string _offset="0";
|
||||||
public int StartAddress
|
|
||||||
{
|
|
||||||
get { return _startAddress; }
|
|
||||||
set { SetProperty(ref _startAddress, value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableCollection<string> AddressNames { get; set; }
|
|
||||||
|
|
||||||
private string _offset;
|
|
||||||
public string Offset
|
public string Offset
|
||||||
{
|
{
|
||||||
get { return _offset; }
|
get { return _offset; }
|
||||||
@ -44,6 +57,18 @@ namespace BOB.ViewModels.Dialogs
|
|||||||
get { return _batchWriteStatus; }
|
get { return _batchWriteStatus; }
|
||||||
set { SetProperty(ref _batchWriteStatus, value); }
|
set { SetProperty(ref _batchWriteStatus, value); }
|
||||||
}
|
}
|
||||||
|
private Address _SelectedAddress;
|
||||||
|
public Address SelectedAddress
|
||||||
|
{
|
||||||
|
get { return _SelectedAddress; }
|
||||||
|
set { SetProperty(ref _SelectedAddress, value); }
|
||||||
|
}
|
||||||
|
private List<Address> _AddressList=Enum.GetValues(typeof(Address)).Cast<Address>().ToList();
|
||||||
|
public List<Address> AddressList
|
||||||
|
{
|
||||||
|
get { return _AddressList; }
|
||||||
|
set { SetProperty(ref _AddressList, value); }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -62,56 +87,72 @@ namespace BOB.ViewModels.Dialogs
|
|||||||
|
|
||||||
private IEventAggregator _eventAggregator { get; set; }
|
private IEventAggregator _eventAggregator { get; set; }
|
||||||
private Devices _devices { get; set; }
|
private Devices _devices { get; set; }
|
||||||
|
private IOBoard device { get; set; }
|
||||||
private GlobalVariables _globalVariables { get; set; }
|
private GlobalVariables _globalVariables { get; set; }
|
||||||
public IOBoardViewModel(IContainerProvider containerProvider)
|
public IOBoardViewModel(IContainerProvider containerProvider)
|
||||||
{
|
{
|
||||||
_devices = containerProvider.Resolve<Devices>();
|
_devices = containerProvider.Resolve<Devices>();
|
||||||
_globalVariables = containerProvider.Resolve<GlobalVariables>();
|
_globalVariables = containerProvider.Resolve<GlobalVariables>();
|
||||||
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
|
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
|
||||||
ConnectCommand = new DelegateCommand(OnConnect);
|
ConnectCommand = new AsyncDelegateCommand(OnConnect);
|
||||||
DisconnectCommand = new DelegateCommand(OnDisconnect);
|
DisconnectCommand = new DelegateCommand(OnDisconnect);
|
||||||
PowerOnCommand = new DelegateCommand(OnPowerOn);
|
PowerOnCommand = new AsyncDelegateCommand(OnPowerOn);
|
||||||
PowerOffCommand = new DelegateCommand(OnPowerOff);
|
PowerOffCommand = new AsyncDelegateCommand(OnPowerOff);
|
||||||
SetCommand = new DelegateCommand(OnSet);
|
SetCommand = new AsyncDelegateCommand(OnSet);
|
||||||
ReadCommand = new DelegateCommand(OnRead);
|
ReadCommand = new AsyncDelegateCommand(OnRead);
|
||||||
CloseCommand = new DelegateCommand(OnClose);
|
CloseCommand = new DelegateCommand(OnClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnConnect()
|
private async Task OnConnect()
|
||||||
{
|
{
|
||||||
// 连接逻辑
|
await device.ConnectAsync();
|
||||||
Console.WriteLine("连接设备...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisconnect()
|
private void OnDisconnect()
|
||||||
{
|
{
|
||||||
// 断开连接逻辑
|
device.Close();
|
||||||
Console.WriteLine("断开设备...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPowerOn()
|
private async Task OnPowerOn()
|
||||||
{
|
{
|
||||||
// 开启电源逻辑
|
await device.写输出开关(1, (ushort)SelectedAddress, true);
|
||||||
Console.WriteLine("电源开启...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPowerOff()
|
private async Task OnPowerOff()
|
||||||
{
|
{
|
||||||
// 关闭电源逻辑
|
await device.写输出开关(1, (ushort)SelectedAddress, false);
|
||||||
Console.WriteLine("电源关闭...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSet()
|
private async Task OnSet()
|
||||||
{
|
{
|
||||||
// 设置逻辑
|
bool[] statusArray = JsonConvert.DeserializeObject<bool[]>(BatchWriteStatus);
|
||||||
Console.WriteLine("设置...");
|
|
||||||
|
if (ushort.TryParse(Offset, out ushort offset))
|
||||||
|
{
|
||||||
|
if (statusArray==null||statusArray.Length+offset>16||statusArray.Length<=0||offset<0)
|
||||||
|
{
|
||||||
|
LoggerHelper.Error("BatchWriteStatus 数组内容不符合预期");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await device.批量写输出开关(1, offset, System.Text.Json.JsonSerializer.Deserialize<bool[]>(BatchWriteStatus));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoggerHelper.Error("BatchWriteStatus 数组内容不符合预期");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRead()
|
private async Task OnRead()
|
||||||
{
|
{
|
||||||
// 读取逻辑
|
if (ushort.TryParse(Offset, out ushort offset))
|
||||||
Console.WriteLine("读取...");
|
{
|
||||||
|
BatchWriteStatus = System.Text.Json.JsonSerializer.Serialize( await device.批量读输出开关(1, offset, 16));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoggerHelper.Error("Offset 解析失败,确保其是有效的数字!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void OnClose()
|
private void OnClose()
|
||||||
{
|
{
|
||||||
@ -132,6 +173,23 @@ namespace BOB.ViewModels.Dialogs
|
|||||||
|
|
||||||
public void OnDialogOpened(IDialogParameters parameters)
|
public void OnDialogOpened(IDialogParameters parameters)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var a = _devices.DeviceDic["IOBoard"] as IOBoard;
|
||||||
|
if (a != null)
|
||||||
|
{
|
||||||
|
device = a;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoggerHelper.ErrorWithNotify("设备没有初始化无法打开测试界面");
|
||||||
|
RequestClose.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
LoggerHelper.ErrorWithNotify("找不到设备无法打开测试界面");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -44,6 +44,7 @@ namespace BOB.ViewModels
|
|||||||
{
|
{
|
||||||
_devices.Init(SystemConfig.Instance.DeviceList);
|
_devices.Init(SystemConfig.Instance.DeviceList);
|
||||||
await _devices.ConnectAllDevicesAsync();
|
await _devices.ConnectAllDevicesAsync();
|
||||||
|
_devices.InitCan();
|
||||||
_devices.StartPollingCollectionAsync();
|
_devices.StartPollingCollectionAsync();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using BOB.Models;
|
using BOB.Models;
|
||||||
using BOB.Singleton;
|
using BOB.Singleton;
|
||||||
using BOB.Views;
|
using BOB.Views;
|
||||||
|
using CAN驱动;
|
||||||
using Common.PubEvent;
|
using Common.PubEvent;
|
||||||
using Logger;
|
using Logger;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
@ -95,6 +96,8 @@ namespace BOB.ViewModels
|
|||||||
public ICommand SetDefaultCommand { get; set; }
|
public ICommand SetDefaultCommand { get; set; }
|
||||||
public ICommand LoadCommand { get; set; }
|
public ICommand LoadCommand { get; set; }
|
||||||
public ICommand NavigateCommand { get; set; }
|
public ICommand NavigateCommand { get; set; }
|
||||||
|
public ICommand SettingChannelCommand { get; set; }
|
||||||
|
public ICommand NavigateToCanPageCommand { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private IEventAggregator _eventAggregator;
|
private IEventAggregator _eventAggregator;
|
||||||
@ -102,14 +105,16 @@ namespace BOB.ViewModels
|
|||||||
private IContainerProvider _containerProvider;
|
private IContainerProvider _containerProvider;
|
||||||
private IRegionManager _regionManager;
|
private IRegionManager _regionManager;
|
||||||
private StepRunning _stepRunning;
|
private StepRunning _stepRunning;
|
||||||
|
private IDialogService _dialogService;
|
||||||
private Task? currentExecutionTask;
|
private Task? currentExecutionTask;
|
||||||
public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider,GlobalVariables globalVariables, StepRunning stepRunning,IRegionManager regionManager)
|
public ShellViewModel(IContainerProvider containerProvider)
|
||||||
{
|
{
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = containerProvider.Resolve<IEventAggregator>(); ;
|
||||||
_containerProvider = containerProvider;
|
_containerProvider = containerProvider;
|
||||||
_globalVariables = globalVariables;
|
_globalVariables = containerProvider.Resolve<GlobalVariables>(); ;
|
||||||
_regionManager = regionManager;
|
_regionManager = containerProvider.Resolve<IRegionManager>(); ;
|
||||||
_stepRunning =stepRunning;
|
_dialogService= containerProvider.Resolve<IDialogService>();
|
||||||
|
_stepRunning = containerProvider.Resolve<StepRunning>(); ;
|
||||||
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
|
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
|
||||||
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
|
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
|
||||||
MaximizeCommand = new DelegateCommand<Window>(MaximizeWindow);
|
MaximizeCommand = new DelegateCommand<Window>(MaximizeWindow);
|
||||||
@ -125,9 +130,29 @@ namespace BOB.ViewModels
|
|||||||
SetDefaultCommand = new DelegateCommand(SetDefault);
|
SetDefaultCommand = new DelegateCommand(SetDefault);
|
||||||
LoadCommand = new DelegateCommand(Load);
|
LoadCommand = new DelegateCommand(Load);
|
||||||
NavigateCommand = new DelegateCommand<string>(Navigate);
|
NavigateCommand = new DelegateCommand<string>(Navigate);
|
||||||
|
SettingChannelCommand = new DelegateCommand(SettingChannel);
|
||||||
|
NavigateToCanPageCommand = new DelegateCommand(NavigateToCanPage);
|
||||||
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
|
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region ToolBar命令
|
||||||
|
private bool isConnect = false;
|
||||||
|
|
||||||
|
private void SettingChannel()
|
||||||
|
{
|
||||||
|
var re = 同星驱动类.ShowChannelMappingWindow(true);
|
||||||
|
if (re != 0)
|
||||||
|
{
|
||||||
|
var msg = 同星驱动类.GetErrorDescription(re);
|
||||||
|
LoggerHelper.ErrorWithNotify($"同星通道映射界面打开失败:{msg}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void NavigateToCanPage()
|
||||||
|
{
|
||||||
|
_dialogService.Show("CAN");
|
||||||
|
}
|
||||||
private void Navigate(string content)
|
private void Navigate(string content)
|
||||||
{
|
{
|
||||||
switch (content)
|
switch (content)
|
||||||
@ -152,30 +177,6 @@ namespace BOB.ViewModels
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateRunIcon(string obj)
|
|
||||||
{
|
|
||||||
RunIcon= obj switch
|
|
||||||
{
|
|
||||||
"Play" => PackIconKind.Play,
|
|
||||||
"Pause" => PackIconKind.Pause,
|
|
||||||
_ => RunIcon
|
|
||||||
};
|
|
||||||
}
|
|
||||||
private void Load()
|
|
||||||
{
|
|
||||||
SystemConfig.Instance.LoadFromFile();
|
|
||||||
if (SystemConfig.Instance.DefaultSubProgramFilePath != null)
|
|
||||||
{
|
|
||||||
if (File.Exists(SystemConfig.Instance.DefaultSubProgramFilePath))
|
|
||||||
{
|
|
||||||
Open(SystemConfig.Instance.DefaultSubProgramFilePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Title = SystemConfig.Instance.Title;
|
|
||||||
}
|
|
||||||
#region ToolBar命令
|
|
||||||
|
|
||||||
private void SetDefault()
|
private void SetDefault()
|
||||||
{
|
{
|
||||||
if(_globalVariables.CurrentFilePath!=null)
|
if(_globalVariables.CurrentFilePath!=null)
|
||||||
@ -405,5 +406,27 @@ namespace BOB.ViewModels
|
|||||||
window?.Close();
|
window?.Close();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private void UpdateRunIcon(string obj)
|
||||||
|
{
|
||||||
|
RunIcon = obj switch
|
||||||
|
{
|
||||||
|
"Play" => PackIconKind.Play,
|
||||||
|
"Pause" => PackIconKind.Pause,
|
||||||
|
_ => RunIcon
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private void Load()
|
||||||
|
{
|
||||||
|
SystemConfig.Instance.LoadFromFile();
|
||||||
|
if (SystemConfig.Instance.DefaultSubProgramFilePath != null)
|
||||||
|
{
|
||||||
|
if (File.Exists(SystemConfig.Instance.DefaultSubProgramFilePath))
|
||||||
|
{
|
||||||
|
Open(SystemConfig.Instance.DefaultSubProgramFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Title = SystemConfig.Instance.Title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
225
BOB/Views/Dialogs/CANView.xaml
Normal file
225
BOB/Views/Dialogs/CANView.xaml
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
<UserControl x:Class="BOB.Views.Dialogs.CANView"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:BOB.Views.Dialogs"
|
||||||
|
xmlns:oxy="http://oxyplot.org/wpf"
|
||||||
|
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
xmlns:prism="http://prismlibrary.com/"
|
||||||
|
xmlns:cons="clr-namespace:BOB.Converters"
|
||||||
|
xmlns:ucs="clr-namespace:BOB.Views.UserControls"
|
||||||
|
Background="White"
|
||||||
|
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||||
|
Height="850"
|
||||||
|
Width="900">
|
||||||
|
<prism:Dialog.WindowStyle>
|
||||||
|
<Style BasedOn="{StaticResource DialogUserManageStyle}"
|
||||||
|
TargetType="Window" />
|
||||||
|
</prism:Dialog.WindowStyle>
|
||||||
|
<UserControl.Resources>
|
||||||
|
<cons:HexConverter x:Key="HexConverter" />
|
||||||
|
</UserControl.Resources>
|
||||||
|
<GroupBox Header="CAN手动设置"
|
||||||
|
Padding="0,0,0,0"
|
||||||
|
MouseLeftButtonDown="MouseLeftButtonDown">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!-- TreeView 用于显示不同选项 -->
|
||||||
|
<TreeView Grid.Row="1">
|
||||||
|
<!-- 调试选项 -->
|
||||||
|
<TreeViewItem Header="调试选项"
|
||||||
|
Visibility="{Binding 高级模式可见度}">
|
||||||
|
<Button Content="初始化TSMaster"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="初始化TSMaster" />
|
||||||
|
<Button Content="释放TSMaster"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="释放TSMaster" />
|
||||||
|
<Button Content="注册监听事件"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="注册监听事件" />
|
||||||
|
</TreeViewItem>
|
||||||
|
|
||||||
|
<!-- 监视选项 -->
|
||||||
|
<TreeViewItem Header="监视">
|
||||||
|
<Frame x:Name="监视Frame"
|
||||||
|
Height="400"
|
||||||
|
Width="700" />
|
||||||
|
</TreeViewItem>
|
||||||
|
|
||||||
|
<!-- DBC 配置 -->
|
||||||
|
<TreeViewItem Header="DBC">
|
||||||
|
<Label Content="请注意,要在断开CAN卡的情况下才能操作DBC!"
|
||||||
|
Foreground="Red" />
|
||||||
|
<Button Content="卸载所有DBC"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="卸载DBC" />
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Margin="0 0 10 0"
|
||||||
|
Content="更换DBC"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="更换DBC" />
|
||||||
|
<Button Content="加载DBC"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="加载DBC" />
|
||||||
|
<Label Content="通道(从0开始)"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<TextBox Text="{Binding DBC加载通道}"
|
||||||
|
MinWidth="100"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
|
</StackPanel>
|
||||||
|
<Button Content="查看DBC"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="查看DBC" />
|
||||||
|
</TreeViewItem>
|
||||||
|
|
||||||
|
<!-- CAN卡连接选项 -->
|
||||||
|
<TreeViewItem Header="CAN卡连接">
|
||||||
|
<Button Content="连接"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="连接" />
|
||||||
|
<Button Content="断开"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="断开" />
|
||||||
|
<Button Content="清空循环发送报文"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="清空循环发送报文" />
|
||||||
|
<Button Content="硬件配置"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="硬件配置" />
|
||||||
|
</TreeViewItem>
|
||||||
|
|
||||||
|
<!-- DBC报文发送 -->
|
||||||
|
<TreeViewItem Header="DBC报文发送">
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="报文" />
|
||||||
|
<ComboBox MinWidth="100"
|
||||||
|
SelectedIndex="{Binding 选中报文}"
|
||||||
|
ItemsSource="{Binding 报文}"
|
||||||
|
/>
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="信号" />
|
||||||
|
<ComboBox SelectedIndex="{Binding 选中信号}"
|
||||||
|
ItemsSource="{Binding 信号}"
|
||||||
|
MinWidth="100" />
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="信号值" />
|
||||||
|
<TextBox Text="{Binding can报文}"
|
||||||
|
MinWidth="100" />
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="循环发送时间间隔(ms)(0为单次发送)" />
|
||||||
|
<TextBox Text="{Binding dbc循环发送时间间隔}"
|
||||||
|
MinWidth="100" />
|
||||||
|
</DockPanel>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Label Content="通道(从0开始)"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<TextBox Text="{Binding 报文发送通道}"
|
||||||
|
MinWidth="100"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Margin="0,10,10,10" />
|
||||||
|
<Button Content="加载报文"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="加载报文"
|
||||||
|
Margin="10" />
|
||||||
|
<Button Content="设置信号并发送"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="设置" />
|
||||||
|
<CheckBox Content="直接发送"
|
||||||
|
IsChecked="{Binding 直接发送}" />
|
||||||
|
</StackPanel>
|
||||||
|
</TreeViewItem>
|
||||||
|
|
||||||
|
<!-- 自定义报文发送 -->
|
||||||
|
<TreeViewItem Header="自定义报文发送">
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="通道" />
|
||||||
|
<ComboBox MinWidth="100"
|
||||||
|
SelectedItem="{Binding AIdxChn}"
|
||||||
|
ItemsSource="{Binding APP_CHANNEL名称}"
|
||||||
|
/>
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="ID" />
|
||||||
|
<TextBox MinWidth="100"
|
||||||
|
Text="{Binding AID, Converter={StaticResource HexConverter}, Mode=TwoWay}" />
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="DLC" />
|
||||||
|
<TextBox MinWidth="200"
|
||||||
|
Text="{Binding ADLC}" />
|
||||||
|
<CheckBox Content="自动设定"
|
||||||
|
IsChecked="{Binding 自动设定}" />
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="报文" />
|
||||||
|
<TextBox MinWidth="200"
|
||||||
|
Text="{Binding 自定义报文}" />
|
||||||
|
</DockPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="循环发送时间间隔(ms)(0为单次发送)" />
|
||||||
|
<TextBox Text="{Binding 自定义循环发送时间间隔}"
|
||||||
|
MinWidth="100" />
|
||||||
|
</DockPanel>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<CheckBox Content="发送帧"
|
||||||
|
IsChecked="{Binding AIsTx}" />
|
||||||
|
<CheckBox Content="扩展帧"
|
||||||
|
IsChecked="{Binding AIsExt}" />
|
||||||
|
<CheckBox Content="远程帧"
|
||||||
|
IsChecked="{Binding AIsRemote}" />
|
||||||
|
<CheckBox Content="FD"
|
||||||
|
IsChecked="{Binding AIsFD}" />
|
||||||
|
<CheckBox Content="BRS"
|
||||||
|
IsChecked="{Binding AIsBRS}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Content="发送"
|
||||||
|
Command="{Binding ButtonClickCommand}"
|
||||||
|
CommandParameter="自定义报文发送" />
|
||||||
|
<CheckBox Margin="10"
|
||||||
|
Content="更新到数据库"
|
||||||
|
IsChecked="{Binding 更新到数据库}" />
|
||||||
|
</StackPanel>
|
||||||
|
</TreeViewItem>
|
||||||
|
|
||||||
|
<!-- 报文录制 -->
|
||||||
|
<TreeViewItem Header="报文录制">
|
||||||
|
<DockPanel>
|
||||||
|
<Label Content="路径(开始录制时使用)"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<TextBox MinWidth="100"
|
||||||
|
Text="{Binding BLFPath}"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
<Button Content="选择路径" Margin="10 0"
|
||||||
|
Command="{Binding SelectBLFPathCommand}"
|
||||||
|
CommandParameter="选择路径" />
|
||||||
|
<Button Content="保存路径"
|
||||||
|
Command="{Binding SaveBLFPathCommand}"
|
||||||
|
CommandParameter="保存路径" />
|
||||||
|
</DockPanel>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Content="开始录制"
|
||||||
|
Command="{Binding StartTranscirbeCommand}"
|
||||||
|
CommandParameter="开始录制" />
|
||||||
|
<Button Content="结束录制"
|
||||||
|
Margin="10 0"
|
||||||
|
Command="{Binding EndTranscirbeCommand}"
|
||||||
|
CommandParameter="结束录制" />
|
||||||
|
</StackPanel>
|
||||||
|
</TreeViewItem>
|
||||||
|
</TreeView>
|
||||||
|
</Grid>
|
||||||
|
</GroupBox>
|
||||||
|
</UserControl>
|
||||||
36
BOB/Views/Dialogs/CANView.xaml.cs
Normal file
36
BOB/Views/Dialogs/CANView.xaml.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace BOB.Views.Dialogs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// CANView.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class CANView : UserControl
|
||||||
|
{
|
||||||
|
public CANView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
|
{
|
||||||
|
Window.GetWindow(this)?.DragMove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:BOB.Views.Dialogs"
|
xmlns:local="clr-namespace:BOB.Views.Dialogs"
|
||||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
xmlns:prism="http://prismlibrary.com/"
|
xmlns:prism="http://prismlibrary.com/"
|
||||||
Background="White"
|
Background="White"
|
||||||
@ -42,8 +43,9 @@
|
|||||||
<Label Content="输出地址"
|
<Label Content="输出地址"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
<ComboBox SelectedIndex="{Binding StartAddress, Mode=TwoWay}"
|
<ComboBox SelectedItem="{Binding SelectedAddress, Mode=TwoWay}"
|
||||||
ItemsSource="{Binding AddressNames}"
|
ItemsSource="{Binding AddressList}"
|
||||||
|
materialDesign:HintAssist.Hint=""
|
||||||
MinWidth="100"
|
MinWidth="100"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
@ -57,6 +59,7 @@
|
|||||||
<TextBox Text="{Binding Offset}"
|
<TextBox Text="{Binding Offset}"
|
||||||
MinWidth="100"
|
MinWidth="100"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
|
materialDesign:HintAssist.Hint=""
|
||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
<Label Content="状态"
|
<Label Content="状态"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
@ -64,6 +67,7 @@
|
|||||||
<TextBox Text="{Binding BatchWriteStatus}"
|
<TextBox Text="{Binding BatchWriteStatus}"
|
||||||
MinWidth="100"
|
MinWidth="100"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
|
materialDesign:HintAssist.Hint=""
|
||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
|
|||||||
@ -128,29 +128,17 @@
|
|||||||
<materialDesign:PackIcon Kind="Tools"
|
<materialDesign:PackIcon Kind="Tools"
|
||||||
Foreground="White" />
|
Foreground="White" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
<MenuItem Header="系统设置"
|
|
||||||
Foreground="Black" />
|
|
||||||
<MenuItem Header="数据"
|
|
||||||
Foreground="Black">
|
|
||||||
<MenuItem Header="数据查询"
|
|
||||||
Foreground="Black" />
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="同星CAN"
|
<MenuItem Header="同星CAN"
|
||||||
Foreground="Black">
|
Foreground="Black">
|
||||||
<MenuItem Header="连接/断开"
|
|
||||||
Foreground="Black" />
|
|
||||||
<MenuItem Header="通道映射"
|
<MenuItem Header="通道映射"
|
||||||
|
Command="{Binding SettingChannelCommand}"
|
||||||
Foreground="Black" />
|
Foreground="Black" />
|
||||||
<MenuItem Header="加载数据库"
|
<MenuItem Header="CAN调试界面"
|
||||||
Foreground="Black" />
|
Command="{Binding NavigateToCanPageCommand}"
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="调试"
|
|
||||||
Foreground="Black">
|
|
||||||
<MenuItem Header="自动运行"
|
|
||||||
Foreground="Black" />
|
|
||||||
<MenuItem Header="清空数据库"
|
|
||||||
Foreground="Black" />
|
Foreground="Black" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<!-- 程序运行控制 -->
|
<!-- 程序运行控制 -->
|
||||||
|
|||||||
20
CAN驱动/CAN驱动.csproj
Normal file
20
CAN驱动/CAN驱动.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Interop.TSMasterAPI">
|
||||||
|
<HintPath>..\CanDriver\bin\Debug\net8.0\Interop.TSMasterAPI.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
269
CAN驱动/DBCParse.cs
Normal file
269
CAN驱动/DBCParse.cs
Normal file
@ -0,0 +1,269 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TSMaster;
|
||||||
|
|
||||||
|
namespace CAN驱动
|
||||||
|
{
|
||||||
|
public struct can_network
|
||||||
|
{
|
||||||
|
[JsonInclude]
|
||||||
|
public string network_name;
|
||||||
|
[JsonInclude]
|
||||||
|
public can_node[] can_nodes;
|
||||||
|
|
||||||
|
}
|
||||||
|
public struct can_node
|
||||||
|
{
|
||||||
|
[JsonInclude]
|
||||||
|
public string node_name;
|
||||||
|
[JsonInclude]
|
||||||
|
public can_message[] tx_can_Messages;
|
||||||
|
[JsonInclude]
|
||||||
|
public can_message[] rx_can_Messages;
|
||||||
|
}
|
||||||
|
public struct can_message
|
||||||
|
{
|
||||||
|
[JsonInclude]
|
||||||
|
public string message_name;
|
||||||
|
[JsonInclude]
|
||||||
|
public string[] signals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class _Msg_
|
||||||
|
{
|
||||||
|
public int msg_type { get; set; }
|
||||||
|
public int msg_id { get; set; }
|
||||||
|
public int msg_cyclic { get; set; }
|
||||||
|
public byte msg_dlc { get; set; }
|
||||||
|
public string msg_name { get; set; }
|
||||||
|
public string[] signal_Name { get; set; }
|
||||||
|
public int msg_brs { get; set; }
|
||||||
|
public TLIBCANFD ACANFD;
|
||||||
|
}
|
||||||
|
public enum Msg_Type
|
||||||
|
{
|
||||||
|
CAN = 0,
|
||||||
|
CANFD = 1,
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// DBC 文件信息类型枚举,用于指定 tsdb_get_can_db_info 查询的内容类型。
|
||||||
|
/// </summary>
|
||||||
|
public enum DBCINFO
|
||||||
|
{
|
||||||
|
/// <summary>网络名称</summary>
|
||||||
|
NETWORK_Name = 0,
|
||||||
|
|
||||||
|
/// <summary>CAN 报文总数</summary>
|
||||||
|
CAN_MSG_COUNT = 11,
|
||||||
|
/// <summary>CAN FD 报文总数</summary>
|
||||||
|
CANFD_MSG_COUNT = 12,
|
||||||
|
/// <summary>节点总数</summary>
|
||||||
|
NODE_COUNT = 14,
|
||||||
|
|
||||||
|
/// <summary>信号名称</summary>
|
||||||
|
SIGNAL_NAME = 33,
|
||||||
|
|
||||||
|
/// <summary>CAN 报文类型</summary>
|
||||||
|
CAN_MSG_TYPE = 40,
|
||||||
|
/// <summary>CAN 报文 DLC(数据长度码)</summary>
|
||||||
|
CAN_MSG_DLC = 41,
|
||||||
|
/// <summary>CAN 报文 ID</summary>
|
||||||
|
CAN_MSG_ID = 42,
|
||||||
|
/// <summary>CAN 报文周期</summary>
|
||||||
|
CAN_MSG_CYCLIC = 43,
|
||||||
|
/// <summary>CAN 报文名称</summary>
|
||||||
|
CAN_MSG_NAME = 44,
|
||||||
|
/// <summary>CAN 报文信号数量</summary>
|
||||||
|
CAN_MSG_SIGNAL_COUNT = 47,
|
||||||
|
/// <summary>CAN 报文信号名称索引</summary>
|
||||||
|
CAN_MSG_SIGNAL_NAME_INDEX = 48,
|
||||||
|
|
||||||
|
/// <summary>CAN FD 报文类型</summary>
|
||||||
|
CANFD_MSG_TYPE = 60,
|
||||||
|
/// <summary>CAN FD 报文 DLC(数据长度码)</summary>
|
||||||
|
CANFD_MSG_DLC = 61,
|
||||||
|
/// <summary>CAN FD 报文 ID</summary>
|
||||||
|
CANFD_MSG_ID = 62,
|
||||||
|
/// <summary>CAN FD 报文周期</summary>
|
||||||
|
CANFD_MSG_CYCLIC = 63,
|
||||||
|
/// <summary>CAN FD 报文名称</summary>
|
||||||
|
CANFD_MSG_NAME = 64,
|
||||||
|
/// <summary>CAN FD 报文信号数量</summary>
|
||||||
|
CANFD_MSG_SIGNAL_COUNT = 67,
|
||||||
|
/// <summary>CAN FD 报文信号名称索引</summary>
|
||||||
|
CANFD_MSG_SIGNAL_NAME_INDEX = 68,
|
||||||
|
|
||||||
|
/// <summary>节点名称</summary>
|
||||||
|
NODE_Name = 101,
|
||||||
|
/// <summary>节点发送 CAN 报文数量</summary>
|
||||||
|
NODE_TX_CAN_COUNT = 103,
|
||||||
|
/// <summary>节点发送 CAN 报文索引</summary>
|
||||||
|
NODE_TX_CAN_MESSAGE_INDEX = 104,
|
||||||
|
/// <summary>节点接收 CAN 报文数量</summary>
|
||||||
|
NODE_RX_CAN_COUNT = 105,
|
||||||
|
/// <summary>节点接收 CAN 报文索引</summary>
|
||||||
|
NODE_RX_CAN_MESSAGE_INDEX = 106,
|
||||||
|
/// <summary>节点发送 CAN FD 报文数量</summary>
|
||||||
|
NODE_TX_CANFD_COUNT = 107,
|
||||||
|
/// <summary>节点发送 CAN FD 报文索引</summary>
|
||||||
|
NODE_TX_CANFD_MESSAGE_INDEX = 108,
|
||||||
|
/// <summary>节点接收 CAN FD 报文数量</summary>
|
||||||
|
NODE_RX_CANFD_COUNT = 109,
|
||||||
|
/// <summary>节点接收 CAN FD 报文索引</summary>
|
||||||
|
NODE_RX_CANFD_MESSAGE_INDEX = 110,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DBCParse
|
||||||
|
{
|
||||||
|
public static List<List<_Msg_>> MsgDatabase { get; set; } =
|
||||||
|
[.. Enumerable.Range(0, 12).Select(_ => new List<_Msg_>())];
|
||||||
|
public static can_network can_Network;
|
||||||
|
public static string tsdb_get_can_db_info(uint ADatabaseId, int AType, int AIndex, int ASubIndex)
|
||||||
|
{
|
||||||
|
nint tmpInt = new nint();
|
||||||
|
int ret = TsMasterApi.tsdb_get_can_db_info(ADatabaseId, AType, AIndex, ASubIndex, ref tmpInt);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
return Marshal.PtrToStringAnsi(tmpInt) ?? "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void parse(uint Aid, int channel)
|
||||||
|
{
|
||||||
|
int CANcount = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_COUNT, 0, 0));
|
||||||
|
for (int i = 0; i < CANcount; i++)
|
||||||
|
{
|
||||||
|
_Msg_ temp = new _Msg_();
|
||||||
|
temp.msg_type = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_TYPE, i, 0));
|
||||||
|
temp.msg_dlc = byte.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_DLC, i, 0));
|
||||||
|
temp.msg_id = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_ID, i, 0));
|
||||||
|
temp.msg_name = tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_NAME, i, 0);
|
||||||
|
temp.msg_cyclic = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_CYCLIC, i, 0));
|
||||||
|
temp.signal_Name = new string[int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_SIGNAL_COUNT, i, 0))];
|
||||||
|
for (int signalcount = 0; signalcount < temp.signal_Name.Length; signalcount++)
|
||||||
|
{
|
||||||
|
temp.signal_Name[signalcount] = tsdb_get_can_db_info(Aid, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_SIGNAL_NAME_INDEX, i, signalcount)), 0);
|
||||||
|
}
|
||||||
|
temp.msg_brs = 0;
|
||||||
|
temp.ACANFD = new TLIBCANFD(APP_CHANNEL.CHN1,
|
||||||
|
temp.msg_id,
|
||||||
|
true,
|
||||||
|
temp.msg_type == 1 || temp.msg_type == 4 ? true : false,
|
||||||
|
false, temp.msg_dlc,
|
||||||
|
temp.msg_type < 2 ? false : true,
|
||||||
|
false);
|
||||||
|
MsgDatabase[channel].Add(temp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CANcount = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_COUNT, 0, 0));
|
||||||
|
for (int i = 0; i < CANcount; i++)
|
||||||
|
{
|
||||||
|
_Msg_ temp = new _Msg_();
|
||||||
|
temp.msg_type = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_TYPE, i, 0));
|
||||||
|
temp.msg_dlc = byte.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_DLC, i, 0));
|
||||||
|
temp.msg_id = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_ID, i, 0));
|
||||||
|
temp.msg_name = tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_NAME, i, 0);
|
||||||
|
temp.msg_cyclic = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_CYCLIC, i, 0));
|
||||||
|
temp.signal_Name = new string[int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_SIGNAL_COUNT, i, 0))];
|
||||||
|
for (int signalcount = 0; signalcount < temp.signal_Name.Length; signalcount++)
|
||||||
|
{
|
||||||
|
temp.signal_Name[signalcount] = tsdb_get_can_db_info(Aid, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_SIGNAL_NAME_INDEX, i, signalcount)), 0);
|
||||||
|
}
|
||||||
|
temp.msg_brs = int.Parse(tsdb_get_can_db_info(Aid, 69, i, 0));
|
||||||
|
temp.ACANFD = new TLIBCANFD(APP_CHANNEL.CHN1, temp.msg_id, true, temp.msg_type == 1 || temp.msg_type == 4 ? true : false, false, temp.msg_dlc, temp.msg_type < 2 ? false : true, temp.msg_brs == 1 ? true : false);
|
||||||
|
MsgDatabase[channel].Add(temp);
|
||||||
|
}
|
||||||
|
MsgDatabase[channel].Sort((a, b) => a.msg_id.CompareTo(b.msg_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rbs_parse(uint AID, int channel)
|
||||||
|
{
|
||||||
|
can_Network = new can_network();
|
||||||
|
can_Network.network_name = tsdb_get_can_db_info(AID, (int)DBCINFO.NETWORK_Name, 0, 0);
|
||||||
|
int Node_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_COUNT, 0, 0));
|
||||||
|
can_Network.can_nodes = new can_node[Node_count];
|
||||||
|
for (int i = 0; i < Node_count; i++)
|
||||||
|
{
|
||||||
|
can_Network.can_nodes[i].node_name = tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_Name, i, 0);
|
||||||
|
int tx_can_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CAN_COUNT, i, 0));
|
||||||
|
int tx_canfd_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CANFD_COUNT, i, 0));
|
||||||
|
|
||||||
|
int rx_can_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CAN_COUNT, i, 0));
|
||||||
|
int rx_canfd_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CANFD_COUNT, i, 0));
|
||||||
|
|
||||||
|
//获取tx_can结构体
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages = new can_message[tx_can_count + tx_canfd_count];
|
||||||
|
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages = new can_message[rx_can_count + rx_canfd_count];
|
||||||
|
//获取报文名以及信号名
|
||||||
|
//1 get can_message idnex
|
||||||
|
//2 get can message name
|
||||||
|
//3 get signal count
|
||||||
|
//4 get signal name
|
||||||
|
int tx_index = -1;
|
||||||
|
for (int tx_can = 0; tx_can < tx_can_count; tx_can++)
|
||||||
|
{
|
||||||
|
int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CAN_MESSAGE_INDEX, i, tx_can));
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages[tx_can].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_NAME, can_message_idnex, 0);
|
||||||
|
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages[tx_can].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_COUNT, can_message_idnex, 0))];
|
||||||
|
for (int signalcount = 0; signalcount < can_Network.can_nodes[i].tx_can_Messages[tx_can].signals.Length; signalcount++)
|
||||||
|
{
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages[tx_can].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tx_index = tx_can;
|
||||||
|
}
|
||||||
|
for (int tx_can = 0; tx_can < tx_canfd_count; tx_can++, tx_index++)
|
||||||
|
{
|
||||||
|
int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CANFD_MESSAGE_INDEX, i, tx_can));
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_NAME, can_message_idnex, 0);
|
||||||
|
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_COUNT, can_message_idnex, 0))];
|
||||||
|
for (int signalcount = 0; signalcount < can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].signals.Length; signalcount++)
|
||||||
|
{
|
||||||
|
can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int rx_index = -1;
|
||||||
|
for (int tx_can = 0; tx_can < rx_can_count; tx_can++)
|
||||||
|
{
|
||||||
|
int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CAN_MESSAGE_INDEX, i, tx_can));
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages[tx_can].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_NAME, can_message_idnex, 0);
|
||||||
|
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages[tx_can].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_COUNT, can_message_idnex, 0))];
|
||||||
|
for (int signalcount = 0; signalcount < can_Network.can_nodes[i].rx_can_Messages[tx_can].signals.Length; signalcount++)
|
||||||
|
{
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages[tx_can].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
rx_index = tx_can;
|
||||||
|
}
|
||||||
|
for (int tx_can = 0; tx_can < rx_canfd_count; tx_can++, rx_index++)
|
||||||
|
{
|
||||||
|
int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CANFD_MESSAGE_INDEX, i, tx_can));
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_NAME, can_message_idnex, 0);
|
||||||
|
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_COUNT, can_message_idnex, 0))];
|
||||||
|
for (int signalcount = 0; signalcount < can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].signals.Length; signalcount++)
|
||||||
|
{
|
||||||
|
can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
BIN
CAN驱动/Interop.TSMasterAPI.dll
Normal file
BIN
CAN驱动/Interop.TSMasterAPI.dll
Normal file
Binary file not shown.
BIN
CAN驱动/TSMaster.dll
Normal file
BIN
CAN驱动/TSMaster.dll
Normal file
Binary file not shown.
1048
CAN驱动/同星驱动类.cs
Normal file
1048
CAN驱动/同星驱动类.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
|||||||
using Common.Attributes;
|
using Common.Attributes;
|
||||||
using DeviceCommand.Base;
|
using DeviceCommand.Base;
|
||||||
using Logger;
|
using Logger;
|
||||||
|
using NModbus;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -34,6 +35,7 @@ namespace DeviceCommand.Device
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
await TcpClient.ConnectAsync(IPAddress, Port, ct);
|
await TcpClient.ConnectAsync(IPAddress, Port, ct);
|
||||||
|
Modbus = new ModbusFactory().CreateMaster(TcpClient);
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
StartHeartbeat();
|
StartHeartbeat();
|
||||||
return true;
|
return true;
|
||||||
@ -85,7 +87,7 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await WriteSingleRegisterAsync(1, 0, 1);
|
//await WriteSingleRegisterAsync(1, 0, 1);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -118,23 +120,21 @@ namespace DeviceCommand.Device
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public virtual async Task 写单一输出(byte 从站地址, ushort 起始地址, ushort 值)
|
public async Task 写输出开关(byte 站号, ushort 开始地址, bool data)
|
||||||
{
|
{
|
||||||
await WriteSingleRegisterAsync(从站地址, 起始地址, 值);
|
await Modbus.WriteSingleCoilAsync(站号, 开始地址, data);
|
||||||
}
|
}
|
||||||
|
public async Task 批量写输出开关(byte 站号, ushort 开始地址, bool[] datas)
|
||||||
public virtual async Task 写多输出(byte 从站地址, ushort 起始地址, ushort[] 值数组)
|
|
||||||
{
|
{
|
||||||
await WriteMultipleRegistersAsync(从站地址, 起始地址, 值数组);
|
await Modbus.WriteMultipleCoilsAsync(站号, 开始地址, datas);
|
||||||
}
|
}
|
||||||
public virtual async Task<ushort> 读单一输入(byte 从站地址, ushort 起始地址, CancellationToken ct = default)
|
public async Task 读输出开关(byte 站号, ushort 开始地址)
|
||||||
{
|
{
|
||||||
var result = await ReadInputRegistersAsync(从站地址, 起始地址, 1, ct);
|
await Modbus.ReadCoilsAsync(站号, 开始地址, 1);
|
||||||
return result[0];
|
|
||||||
}
|
}
|
||||||
public virtual async Task<ushort[]> 读多个输入(byte 从站地址, ushort 起始地址, ushort 数量, CancellationToken ct = default)
|
public async Task<bool[]> 批量读输出开关(byte 站号, ushort 开始地址,ushort 数量)
|
||||||
{
|
{
|
||||||
return await ReadInputRegistersAsync(从站地址, 起始地址, 数量, ct);
|
return await Modbus.ReadCoilsAsync(站号, 开始地址, 数量);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user