添加视图
This commit is contained in:
parent
0f32957416
commit
3027c288c3
@ -50,6 +50,8 @@ namespace BOB
|
|||||||
{
|
{
|
||||||
//注册视图
|
//注册视图
|
||||||
containerRegistry.RegisterForNavigation<MainView>("MainView");
|
containerRegistry.RegisterForNavigation<MainView>("MainView");
|
||||||
|
containerRegistry.RegisterForNavigation<MonitorView>("MonitorView");
|
||||||
|
containerRegistry.RegisterForNavigation<Views.DataView>("DataView");
|
||||||
//注册弹窗
|
//注册弹窗
|
||||||
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>("MessageBox");
|
containerRegistry.RegisterDialog<MessageBoxView, MessageBoxViewModel>("MessageBox");
|
||||||
containerRegistry.RegisterDialog<ParameterSetting, ParameterSettingViewModel>("ParameterSetting");
|
containerRegistry.RegisterDialog<ParameterSetting, ParameterSettingViewModel>("ParameterSetting");
|
||||||
|
|||||||
@ -39,6 +39,7 @@
|
|||||||
<PackageReference Include="MaterialDesignThemes" Version="5.3.0" />
|
<PackageReference Include="MaterialDesignThemes" Version="5.3.0" />
|
||||||
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
|
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
|
<PackageReference Include="OxyPlot.Wpf" Version="2.2.0" />
|
||||||
<PackageReference Include="Prism.Unity" Version="9.0.537" />
|
<PackageReference Include="Prism.Unity" Version="9.0.537" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,10 @@ namespace BOB.Singleton
|
|||||||
private ITcp SQ0030G1DTDevice { get; set; }
|
private ITcp SQ0030G1DTDevice { get; set; }
|
||||||
private IModbusDevice ZXKSTDevice { get; set; }
|
private IModbusDevice ZXKSTDevice { get; set; }
|
||||||
|
|
||||||
public Devices(List<DeviceConfigModel> deviceList)
|
public Devices()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public void Init(List<DeviceConfigModel> deviceList)
|
||||||
{
|
{
|
||||||
foreach (var device in deviceList)
|
foreach (var device in deviceList)
|
||||||
{
|
{
|
||||||
@ -43,7 +46,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.E36233A":
|
case "DeviceCommand.Device.E36233A":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp1)
|
if (device.CommunicationConfig is TcpConfig tcp1)
|
||||||
{
|
{
|
||||||
E36233ADevice = _proxyGen.CreateInterfaceProxyWithTarget<ITcp>(
|
E36233ADevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new E36233A(tcp1.IPAddress, tcp1.Port, tcp1.ReadTimeout, tcp1.WriteTimeout),
|
new E36233A(tcp1.IPAddress, tcp1.Port, tcp1.ReadTimeout, tcp1.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -55,7 +58,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.IT6724C":
|
case "DeviceCommand.Device.IT6724C":
|
||||||
if (device.CommunicationConfig is SerialPortConfig sp1)
|
if (device.CommunicationConfig is SerialPortConfig sp1)
|
||||||
{
|
{
|
||||||
IT6724CDevice = _proxyGen.CreateInterfaceProxyWithTarget<ISerialPort>(
|
IT6724CDevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new IT6724C(sp1.COMPort, sp1.BaudRate, sp1.DataBit, sp1.StopBit, sp1.ParityBit, sp1.ReadTimeout, sp1.WriteTimeout),
|
new IT6724C(sp1.COMPort, sp1.BaudRate, sp1.DataBit, sp1.StopBit, sp1.ParityBit, sp1.ReadTimeout, sp1.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -67,19 +70,19 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.IT6724CReverse":
|
case "DeviceCommand.Device.IT6724CReverse":
|
||||||
if (device.CommunicationConfig is SerialPortConfig sp3)
|
if (device.CommunicationConfig is SerialPortConfig sp3)
|
||||||
{
|
{
|
||||||
IT6724CReverseDevice = _proxyGen.CreateInterfaceProxyWithTarget<ISerialPort>(
|
IT6724CReverseDevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new IT6724C(sp3.COMPort, sp3.BaudRate, sp3.DataBit, sp3.StopBit, sp3.ParityBit, sp3.ReadTimeout, sp3.WriteTimeout),
|
new IT6724C(sp3.COMPort, sp3.BaudRate, sp3.DataBit, sp3.StopBit, sp3.ParityBit, sp3.ReadTimeout, sp3.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
DeviceDic["IT6724CReverse"] = IT6724CReverseDevice;
|
DeviceDic["IT6724CReverse"] = IT6724CReverseDevice;
|
||||||
}
|
}
|
||||||
else throw new InvalidOperationException("IT6724C 必须使用 SerialPortConfig");
|
else throw new InvalidOperationException("IT6724CReverse 必须使用 SerialPortConfig");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "DeviceCommand.Device.LQ7500_D":
|
case "DeviceCommand.Device.LQ7500_D":
|
||||||
if (device.CommunicationConfig is SerialPortConfig sp2)
|
if (device.CommunicationConfig is SerialPortConfig sp2)
|
||||||
{
|
{
|
||||||
LQ7500_DDevice = _proxyGen.CreateInterfaceProxyWithTarget<IModbusDevice>(
|
LQ7500_DDevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new LQ7500_D(sp2.COMPort, sp2.BaudRate, sp2.DataBit, sp2.StopBit, sp2.ParityBit, sp2.ReadTimeout, sp2.WriteTimeout),
|
new LQ7500_D(sp2.COMPort, sp2.BaudRate, sp2.DataBit, sp2.StopBit, sp2.ParityBit, sp2.ReadTimeout, sp2.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -91,7 +94,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.EAEL9080":
|
case "DeviceCommand.Device.EAEL9080":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp2)
|
if (device.CommunicationConfig is TcpConfig tcp2)
|
||||||
{
|
{
|
||||||
EAEL9080Device = _proxyGen.CreateInterfaceProxyWithTarget<IModbusDevice>(
|
EAEL9080Device = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new EAEL9080(tcp2.IPAddress, tcp2.Port, tcp2.ReadTimeout, tcp2.WriteTimeout),
|
new EAEL9080(tcp2.IPAddress, tcp2.Port, tcp2.ReadTimeout, tcp2.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -103,7 +106,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.IOBoard":
|
case "DeviceCommand.Device.IOBoard":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp3)
|
if (device.CommunicationConfig is TcpConfig tcp3)
|
||||||
{
|
{
|
||||||
IOBoardevice = _proxyGen.CreateInterfaceProxyWithTarget<IModbusDevice>(
|
IOBoardevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new IOBoard(tcp3.IPAddress, tcp3.Port, tcp3.ReadTimeout, tcp3.WriteTimeout),
|
new IOBoard(tcp3.IPAddress, tcp3.Port, tcp3.ReadTimeout, tcp3.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -115,7 +118,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.PSB11000":
|
case "DeviceCommand.Device.PSB11000":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp4)
|
if (device.CommunicationConfig is TcpConfig tcp4)
|
||||||
{
|
{
|
||||||
PSB11000Device = _proxyGen.CreateInterfaceProxyWithTarget<IModbusDevice>(
|
PSB11000Device = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new PSB11000(tcp4.IPAddress, tcp4.Port, tcp4.ReadTimeout, tcp4.WriteTimeout),
|
new PSB11000(tcp4.IPAddress, tcp4.Port, tcp4.ReadTimeout, tcp4.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -127,7 +130,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.WS_68030_380T":
|
case "DeviceCommand.Device.WS_68030_380T":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp5)
|
if (device.CommunicationConfig is TcpConfig tcp5)
|
||||||
{
|
{
|
||||||
WS_68030_380TDevice = _proxyGen.CreateInterfaceProxyWithTarget<IModbusDevice>(
|
WS_68030_380TDevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new WS_68030_380T(tcp5.IPAddress, tcp5.Port, tcp5.ReadTimeout, tcp5.WriteTimeout),
|
new WS_68030_380T(tcp5.IPAddress, tcp5.Port, tcp5.ReadTimeout, tcp5.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -139,7 +142,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.SQ0030G1D":
|
case "DeviceCommand.Device.SQ0030G1D":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp7)
|
if (device.CommunicationConfig is TcpConfig tcp7)
|
||||||
{
|
{
|
||||||
SQ0030G1DTDevice = _proxyGen.CreateInterfaceProxyWithTarget<ITcp>(
|
SQ0030G1DTDevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new SQ0030G1D(tcp7.IPAddress, tcp7.Port, tcp7.ReadTimeout, tcp7.WriteTimeout),
|
new SQ0030G1D(tcp7.IPAddress, tcp7.Port, tcp7.ReadTimeout, tcp7.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -151,7 +154,7 @@ namespace BOB.Singleton
|
|||||||
case "DeviceCommand.Device.ZXKS":
|
case "DeviceCommand.Device.ZXKS":
|
||||||
if (device.CommunicationConfig is TcpConfig tcp6)
|
if (device.CommunicationConfig is TcpConfig tcp6)
|
||||||
{
|
{
|
||||||
ZXKSTDevice = _proxyGen.CreateInterfaceProxyWithTarget<IModbusDevice>(
|
ZXKSTDevice = _proxyGen.CreateClassProxyWithTarget(
|
||||||
new ZXKS(tcp6.IPAddress, tcp6.Port, tcp6.ReadTimeout, tcp6.WriteTimeout),
|
new ZXKS(tcp6.IPAddress, tcp6.Port, tcp6.ReadTimeout, tcp6.WriteTimeout),
|
||||||
_loggingInterceptor
|
_loggingInterceptor
|
||||||
);
|
);
|
||||||
@ -163,6 +166,7 @@ namespace BOB.Singleton
|
|||||||
default:
|
default:
|
||||||
throw new NotSupportedException($"未知设备类型:{device.DeviceType}");
|
throw new NotSupportedException($"未知设备类型:{device.DeviceType}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace BOB
|
|||||||
{
|
{
|
||||||
_globalVariables = containerProvider.Resolve<GlobalVariables>();
|
_globalVariables = containerProvider.Resolve<GlobalVariables>();
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
|
_devices = containerProvider.Resolve<Devices>();
|
||||||
}
|
}
|
||||||
public async Task<bool> ExecuteSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default)
|
public async Task<bool> ExecuteSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -32,6 +32,8 @@ namespace BOB
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string SystemPath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BOB");
|
public string SystemPath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BOB");
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
|
public int SaveDay { get; set; }
|
||||||
|
public string DBSavePath { get; set; } = "";
|
||||||
|
|
||||||
public int PerformanceLevel { get; set; } = 50;
|
public int PerformanceLevel { get; set; } = 50;
|
||||||
|
|
||||||
|
|||||||
@ -273,6 +273,7 @@ namespace BOB.ViewModels
|
|||||||
var types = assembly.GetTypes().Where(t =>
|
var types = assembly.GetTypes().Where(t =>
|
||||||
t.IsPublic &&
|
t.IsPublic &&
|
||||||
!t.IsNested &&
|
!t.IsNested &&
|
||||||
|
|
||||||
(t.IsClass || t.IsValueType) &&
|
(t.IsClass || t.IsValueType) &&
|
||||||
(!t.IsAbstract || t.IsSealed) &&
|
(!t.IsAbstract || t.IsSealed) &&
|
||||||
t.GetCustomAttribute<BOBCommandAttribute>() != null);
|
t.GetCustomAttribute<BOBCommandAttribute>() != null);
|
||||||
|
|||||||
48
BOB/ViewModels/DataViewModel.cs
Normal file
48
BOB/ViewModels/DataViewModel.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using BOB.Singleton;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BOB.ViewModels
|
||||||
|
{
|
||||||
|
public class DataViewModel : BindableBase, INavigationAware
|
||||||
|
{
|
||||||
|
#region 属性
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region 命令
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private IEventAggregator _eventAggregator;
|
||||||
|
private IDialogService _dialogService;
|
||||||
|
private Devices _devices { get; set; }
|
||||||
|
public DataViewModel(IEventAggregator eventAggregator, IDialogService dialogService, IContainerProvider containerProvider)
|
||||||
|
{
|
||||||
|
_dialogService = dialogService;
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
|
_devices = containerProvider.Resolve<Devices>();
|
||||||
|
|
||||||
|
}
|
||||||
|
#region 导航
|
||||||
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,14 +15,13 @@ using System.Windows.Input;
|
|||||||
|
|
||||||
namespace BOB.ViewModels
|
namespace BOB.ViewModels
|
||||||
{
|
{
|
||||||
public class MainViewModel : BindableBase,INavigationAware,IDialogAware
|
public class MainViewModel : BindableBase,INavigationAware
|
||||||
{
|
{
|
||||||
#region 属性
|
#region 属性
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region 命令
|
#region 命令
|
||||||
public ICommand testcommand { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -35,26 +34,15 @@ namespace BOB.ViewModels
|
|||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_devices=containerProvider.Resolve<Devices>();
|
_devices=containerProvider.Resolve<Devices>();
|
||||||
testcommand = new DelegateCommand(test);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private void test()
|
|
||||||
{
|
|
||||||
//_eventAggregator.GetEvent<OverlayEvent>().Publish(true);
|
|
||||||
//var parameters = new DialogParameters
|
|
||||||
//{
|
|
||||||
// { "Title", "提示" },
|
|
||||||
// { "Message", "操作成功!" },
|
|
||||||
// { "Icon", "info" },
|
|
||||||
// { "ShowOk", true }
|
|
||||||
//};
|
|
||||||
//_dialogService.ShowDialog("MessageBox",parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task InitializeDevicesAsync()
|
private async Task InitializeDevicesAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_devices.Init(SystemConfig.Instance.DeviceList);
|
||||||
await _devices.ConnectAllDevicesAsync();
|
await _devices.ConnectAllDevicesAsync();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -67,11 +55,18 @@ namespace BOB.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#region 导航
|
#region 导航
|
||||||
|
private bool _isInitialized = false;
|
||||||
|
|
||||||
public void OnNavigatedTo(NavigationContext navigationContext)
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
if (!_isInitialized)
|
||||||
{
|
{
|
||||||
_eventAggregator.GetEvent<WaitingEvent>().Publish(true);
|
_eventAggregator.GetEvent<WaitingEvent>().Publish(true);
|
||||||
_=InitializeDevicesAsync();
|
_ = InitializeDevicesAsync();
|
||||||
|
_isInitialized = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool IsNavigationTarget(NavigationContext navigationContext)
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||||||
{
|
{
|
||||||
@ -84,21 +79,6 @@ namespace BOB.ViewModels
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 弹窗
|
|
||||||
public bool CanCloseDialog()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnDialogClosed()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnDialogOpened(IDialogParameters parameters)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
353
BOB/ViewModels/MonitorViewModel.cs
Normal file
353
BOB/ViewModels/MonitorViewModel.cs
Normal file
@ -0,0 +1,353 @@
|
|||||||
|
using BOB.Singleton;
|
||||||
|
using Common.PubEvents;
|
||||||
|
using Logger;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using OxyPlot;
|
||||||
|
using OxyPlot.Legends;
|
||||||
|
using OxyPlot.Series;
|
||||||
|
using Prism.Dialogs;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
|
||||||
|
namespace BOB.ViewModels
|
||||||
|
{
|
||||||
|
public class MonitorViewModel : BindableBase, INavigationAware
|
||||||
|
{
|
||||||
|
#region 属性
|
||||||
|
private PlotModel _CurveModel=new();
|
||||||
|
|
||||||
|
public PlotModel CurveModel
|
||||||
|
{
|
||||||
|
get => _CurveModel;
|
||||||
|
set => SetProperty(ref _CurveModel, value);
|
||||||
|
}
|
||||||
|
private List<LineSeries> _signalSeries = new List<LineSeries>();
|
||||||
|
|
||||||
|
public List<LineSeries> SignalSeries
|
||||||
|
{
|
||||||
|
get => _signalSeries;
|
||||||
|
set => SetProperty(ref _signalSeries, value);
|
||||||
|
}
|
||||||
|
private Dictionary<string, LineSeries> _SeriesDic = new ();
|
||||||
|
|
||||||
|
public Dictionary<string,LineSeries> SeriesDic
|
||||||
|
{
|
||||||
|
get => _SeriesDic;
|
||||||
|
set => SetProperty(ref _SeriesDic, value);
|
||||||
|
}
|
||||||
|
private string _FilePath;
|
||||||
|
|
||||||
|
public string FilePath
|
||||||
|
{
|
||||||
|
get => _FilePath;
|
||||||
|
set => SetProperty(ref _FilePath, value);
|
||||||
|
}
|
||||||
|
private string _SelectCurve;
|
||||||
|
|
||||||
|
public string SelectCurve
|
||||||
|
{
|
||||||
|
get => _SelectCurve;
|
||||||
|
set => SetProperty(ref _SelectCurve, value);
|
||||||
|
}
|
||||||
|
private string _SelectDeleteCurve;
|
||||||
|
|
||||||
|
public string SelectDeleteCurve
|
||||||
|
{
|
||||||
|
get => _SelectDeleteCurve;
|
||||||
|
set => SetProperty(ref _SelectDeleteCurve, value);
|
||||||
|
}
|
||||||
|
private string _SelectedSaveDays;
|
||||||
|
|
||||||
|
public string SelectedSaveDays
|
||||||
|
{
|
||||||
|
get => _SelectedSaveDays;
|
||||||
|
set => SetProperty(ref _SelectedSaveDays, value);
|
||||||
|
}
|
||||||
|
private ObservableCollection<string> _CurSingleList=new();
|
||||||
|
|
||||||
|
public ObservableCollection<string> CurSingleList
|
||||||
|
{
|
||||||
|
get => _CurSingleList;
|
||||||
|
set => SetProperty(ref _CurSingleList, value);
|
||||||
|
}
|
||||||
|
private ObservableCollection<string> _DeviceSingleList = new();
|
||||||
|
|
||||||
|
public ObservableCollection<string> DeviceSingleList
|
||||||
|
{
|
||||||
|
get => _DeviceSingleList;
|
||||||
|
set => SetProperty(ref _DeviceSingleList, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region 命令
|
||||||
|
public ICommand ResetViewCommand { get; set; }
|
||||||
|
public ICommand AddSignalCommand { get; set; }
|
||||||
|
public ICommand RemoveSignalCommand { get; set; }
|
||||||
|
public ICommand ChanegPathCommand { get; set; }
|
||||||
|
public ICommand SaveCommand { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private IEventAggregator _eventAggregator;
|
||||||
|
private IDialogService _dialogService;
|
||||||
|
private static Random _random = new Random();
|
||||||
|
private Devices _devices { get; set; }
|
||||||
|
public MonitorViewModel(IEventAggregator eventAggregator, IDialogService dialogService, IContainerProvider containerProvider )
|
||||||
|
{
|
||||||
|
_dialogService = dialogService;
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
|
_devices = containerProvider.Resolve<Devices>();
|
||||||
|
ResetViewCommand = new DelegateCommand(ResetView);
|
||||||
|
AddSignalCommand = new DelegateCommand(AddSignal);
|
||||||
|
RemoveSignalCommand = new DelegateCommand(RemoveSignal);
|
||||||
|
ChanegPathCommand = new DelegateCommand(ChanegPath);
|
||||||
|
SaveCommand = new DelegateCommand(Save);
|
||||||
|
InitData();
|
||||||
|
|
||||||
|
// 初始化模拟量曲线
|
||||||
|
InitializeSimulatedSignals();
|
||||||
|
|
||||||
|
// 设置定时器定时更新模拟数据
|
||||||
|
_timer = new DispatcherTimer
|
||||||
|
{
|
||||||
|
Interval = TimeSpan.FromSeconds(0.5) // 每1秒更新一次
|
||||||
|
};
|
||||||
|
_timer.Tick += (s, e) => UpdateSimulatedData();
|
||||||
|
_timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitData()
|
||||||
|
{
|
||||||
|
SelectedSaveDays=SystemConfig.Instance.SaveDay.ToString();
|
||||||
|
FilePath= SystemConfig.Instance.DBSavePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region 模拟量
|
||||||
|
|
||||||
|
private DispatcherTimer _timer;
|
||||||
|
private double _time = 0;
|
||||||
|
|
||||||
|
private void InitializeSimulatedSignals()
|
||||||
|
{
|
||||||
|
CurveModel.Legends.Add(new Legend
|
||||||
|
{
|
||||||
|
LegendPosition= LegendPosition.TopLeft,
|
||||||
|
IsLegendVisible=true
|
||||||
|
});
|
||||||
|
// 模拟四个信号的初始化
|
||||||
|
|
||||||
|
// 模拟量1:正弦波
|
||||||
|
var sineSignal = new LineSeries
|
||||||
|
{
|
||||||
|
Title = "正弦波信号",
|
||||||
|
MarkerType = MarkerType.Circle,
|
||||||
|
StrokeThickness = 2,
|
||||||
|
Color = OxyColors.Red
|
||||||
|
};
|
||||||
|
_signalSeries.Add(sineSignal);
|
||||||
|
SeriesDic.Add(sineSignal.Title, sineSignal);
|
||||||
|
|
||||||
|
// 模拟量2:线性增长
|
||||||
|
var linearSignal = new LineSeries
|
||||||
|
{
|
||||||
|
Title = "线性增长信号",
|
||||||
|
MarkerType = MarkerType.Square,
|
||||||
|
StrokeThickness = 2,
|
||||||
|
Color = OxyColors.Green
|
||||||
|
};
|
||||||
|
_signalSeries.Add(linearSignal);
|
||||||
|
SeriesDic.Add(linearSignal.Title, linearSignal);
|
||||||
|
|
||||||
|
// 模拟量3:随机波动
|
||||||
|
var randomSignal = new LineSeries
|
||||||
|
{
|
||||||
|
Title = "随机波动信号",
|
||||||
|
MarkerType = MarkerType.Triangle,
|
||||||
|
StrokeThickness = 2,
|
||||||
|
Color = OxyColors.Blue
|
||||||
|
};
|
||||||
|
_signalSeries.Add(randomSignal);
|
||||||
|
SeriesDic.Add(randomSignal.Title, randomSignal);
|
||||||
|
|
||||||
|
// 模拟量4:指数衰减
|
||||||
|
var exponentialSignal = new LineSeries
|
||||||
|
{
|
||||||
|
Title = "指数衰减信号",
|
||||||
|
MarkerType = MarkerType.Diamond,
|
||||||
|
StrokeThickness = 2,
|
||||||
|
Color = OxyColors.Orange
|
||||||
|
};
|
||||||
|
_signalSeries.Add(exponentialSignal);
|
||||||
|
SeriesDic.Add(exponentialSignal.Title, exponentialSignal);
|
||||||
|
|
||||||
|
// 将模拟量曲线添加到图表中
|
||||||
|
foreach (var signal in _signalSeries)
|
||||||
|
{
|
||||||
|
CurveModel.Series.Add(signal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateSimulatedData()
|
||||||
|
{
|
||||||
|
// 更新模拟量的值并添加新的数据点
|
||||||
|
|
||||||
|
// 模拟量1:正弦波
|
||||||
|
var sineSignal = _signalSeries[0];
|
||||||
|
sineSignal.Points.Add(new DataPoint(_time, Math.Sin(_time)));
|
||||||
|
if (sineSignal.Points.Count > 1000) sineSignal.Points.RemoveAt(0); // 保持最多100个点
|
||||||
|
|
||||||
|
// 模拟量2:线性增长
|
||||||
|
var linearSignal = _signalSeries[1];
|
||||||
|
linearSignal.Points.Add(new DataPoint(_time, _time));
|
||||||
|
if (linearSignal.Points.Count > 1000) linearSignal.Points.RemoveAt(0); // 保持最多100个点
|
||||||
|
|
||||||
|
// 模拟量3:随机波动
|
||||||
|
var randomSignal = _signalSeries[2];
|
||||||
|
var randomValue = 10 * (2 * new Random().NextDouble() - 1); // 随机波动范围 [-10, 10]
|
||||||
|
randomSignal.Points.Add(new DataPoint(_time, randomValue));
|
||||||
|
if (randomSignal.Points.Count > 1000) randomSignal.Points.RemoveAt(0); // 保持最多100个点
|
||||||
|
|
||||||
|
// 模拟量4:指数衰减
|
||||||
|
var exponentialSignal = _signalSeries[3];
|
||||||
|
exponentialSignal.Points.Add(new DataPoint(_time, Math.Exp(-0.1 * _time)));
|
||||||
|
if (exponentialSignal.Points.Count > 1000) exponentialSignal.Points.RemoveAt(0); // 保持最多100个点
|
||||||
|
|
||||||
|
// 更新图表
|
||||||
|
CurveModel.InvalidatePlot(true);
|
||||||
|
|
||||||
|
// 时间前进
|
||||||
|
_time += 0.5; // 每次增加0.1秒
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
private OxyColor GetRandomColor()
|
||||||
|
{
|
||||||
|
// 生成随机的红色、绿色、蓝色分量,范围是 0 到 255
|
||||||
|
byte r = (byte)_random.Next(0, 256);
|
||||||
|
byte g = (byte)_random.Next(0, 256);
|
||||||
|
byte b = (byte)_random.Next(0, 256);
|
||||||
|
|
||||||
|
// 返回一个随机的颜色
|
||||||
|
return OxyColor.FromRgb(r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddSignal()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_SeriesDic.ContainsKey(SelectCurve))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 开启资源
|
||||||
|
|
||||||
|
var sineSignal = new LineSeries
|
||||||
|
{
|
||||||
|
Title = SelectCurve,
|
||||||
|
MarkerType = MarkerType.Circle,
|
||||||
|
StrokeThickness = 2,
|
||||||
|
Color = GetRandomColor()
|
||||||
|
};
|
||||||
|
CurveModel.Series.Add(sineSignal);
|
||||||
|
SeriesDic.Add(SelectCurve, sineSignal);
|
||||||
|
CurSingleList.Add(SelectCurve);
|
||||||
|
CurveModel.InvalidatePlot(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LoggerHelper.ErrorWithNotify("添加曲线失败", ex.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void RemoveSignal()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_SeriesDic.ContainsKey(SelectDeleteCurve))
|
||||||
|
{
|
||||||
|
var signalToRemove = _SeriesDic[SelectDeleteCurve];
|
||||||
|
_SeriesDic.Remove(SelectDeleteCurve);
|
||||||
|
CurveModel.Series.Remove(signalToRemove);
|
||||||
|
CurSingleList.Remove(SelectDeleteCurve);
|
||||||
|
CurveModel.InvalidatePlot(true);
|
||||||
|
|
||||||
|
// 释放资源
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LoggerHelper.ErrorWithNotify("删除曲线失败",ex.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void Save()
|
||||||
|
{
|
||||||
|
SelectedSaveDays = SelectedSaveDays ?? "30";
|
||||||
|
if (int.TryParse(SelectedSaveDays, out int saveDays))
|
||||||
|
{
|
||||||
|
if (saveDays > 0 && saveDays <= 30)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"保存天数: {saveDays}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//_dialogService.ShowDialog("请输入1到30之间的有效天数。", "无效输入");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//_dialogService.ShowDialog("请输入有效的数字。", "无效输入");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void ChanegPath()
|
||||||
|
{
|
||||||
|
var openFileDialog = new OpenFileDialog
|
||||||
|
{
|
||||||
|
CheckFileExists = false,
|
||||||
|
CheckPathExists = true,
|
||||||
|
FileName = "Folder",
|
||||||
|
ValidateNames = false,
|
||||||
|
Filter = "All files (*.*)|*.*"
|
||||||
|
};
|
||||||
|
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||||
|
if (openFileDialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
FilePath = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
|
||||||
|
SystemConfig.Instance.DBSavePath = FilePath;
|
||||||
|
SystemConfig.Instance.SaveToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetView()
|
||||||
|
{
|
||||||
|
CurveModel.ResetAllAxes();
|
||||||
|
CurveModel.InvalidatePlot(true);
|
||||||
|
}
|
||||||
|
#region 导航
|
||||||
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -94,19 +94,21 @@ namespace BOB.ViewModels
|
|||||||
public ICommand NewCommand { get; set; }
|
public ICommand NewCommand { get; set; }
|
||||||
public ICommand SetDefaultCommand { get; set; }
|
public ICommand SetDefaultCommand { get; set; }
|
||||||
public ICommand LoadCommand { get; set; }
|
public ICommand LoadCommand { get; set; }
|
||||||
public ICommand NavigateOneCommand { get; set; }
|
public ICommand NavigateCommand { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private IEventAggregator _eventAggregator;
|
private IEventAggregator _eventAggregator;
|
||||||
private GlobalVariables _globalVariables;
|
private GlobalVariables _globalVariables;
|
||||||
private IContainerProvider _containerProvider;
|
private IContainerProvider _containerProvider;
|
||||||
|
private IRegionManager _regionManager;
|
||||||
private StepRunning _stepRunning;
|
private StepRunning _stepRunning;
|
||||||
private Task? currentExecutionTask;
|
private Task? currentExecutionTask;
|
||||||
public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider,GlobalVariables globalVariables, StepRunning stepRunning)
|
public ShellViewModel(IEventAggregator eventAggregator, IContainerProvider containerProvider,GlobalVariables globalVariables, StepRunning stepRunning,IRegionManager regionManager)
|
||||||
{
|
{
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_containerProvider = containerProvider;
|
_containerProvider = containerProvider;
|
||||||
_globalVariables = globalVariables;
|
_globalVariables = globalVariables;
|
||||||
|
_regionManager = regionManager;
|
||||||
_stepRunning =stepRunning;
|
_stepRunning =stepRunning;
|
||||||
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
|
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
|
||||||
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
|
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
|
||||||
@ -122,9 +124,34 @@ namespace BOB.ViewModels
|
|||||||
SaveCommand = new DelegateCommand(Save);
|
SaveCommand = new DelegateCommand(Save);
|
||||||
SetDefaultCommand = new DelegateCommand(SetDefault);
|
SetDefaultCommand = new DelegateCommand(SetDefault);
|
||||||
LoadCommand = new DelegateCommand(Load);
|
LoadCommand = new DelegateCommand(Load);
|
||||||
|
NavigateCommand = new DelegateCommand<string>(Navigate);
|
||||||
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
|
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Navigate(string content)
|
||||||
|
{
|
||||||
|
switch (content)
|
||||||
|
{
|
||||||
|
case "程序界面":
|
||||||
|
_regionManager.RequestNavigate("ShellViewManager", "MainView");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "监控界面":
|
||||||
|
_regionManager.RequestNavigate("ShellViewManager", "MonitorView");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "数据管理":
|
||||||
|
_regionManager.RequestNavigate("ShellViewManager", "DataView");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "更新信息":
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateRunIcon(string obj)
|
private void UpdateRunIcon(string obj)
|
||||||
{
|
{
|
||||||
@ -138,7 +165,6 @@ namespace BOB.ViewModels
|
|||||||
private void Load()
|
private void Load()
|
||||||
{
|
{
|
||||||
SystemConfig.Instance.LoadFromFile();
|
SystemConfig.Instance.LoadFromFile();
|
||||||
_containerProvider.Resolve<Devices>((typeof(List<DeviceConfigModel>), SystemConfig.Instance.DeviceList));
|
|
||||||
if (SystemConfig.Instance.DefaultSubProgramFilePath != null)
|
if (SystemConfig.Instance.DefaultSubProgramFilePath != null)
|
||||||
{
|
{
|
||||||
if (File.Exists(SystemConfig.Instance.DefaultSubProgramFilePath))
|
if (File.Exists(SystemConfig.Instance.DefaultSubProgramFilePath))
|
||||||
|
|||||||
60
BOB/Views/DataView.xaml
Normal file
60
BOB/Views/DataView.xaml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<UserControl x:Class="BOB.Views.DataView"
|
||||||
|
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:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:vs="clr-namespace:BOB.Views"
|
||||||
|
xmlns:oxy="http://oxyplot.org/wpf"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
xmlns:prism="http://prismlibrary.com/"
|
||||||
|
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||||
|
d:DesignHeight="1080"
|
||||||
|
d:DesignWidth="1920">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<GroupBox Header="数据处理"
|
||||||
|
Grid.Row="1"
|
||||||
|
Margin="5"
|
||||||
|
Padding="0">
|
||||||
|
<StackPanel Orientation="Horizontal"
|
||||||
|
Margin="5">
|
||||||
|
<!-- 数据保存按钮 -->
|
||||||
|
<Button Content="保存数据"
|
||||||
|
Command="{Binding SaveCommand}"
|
||||||
|
Margin="10,0,10,0" />
|
||||||
|
|
||||||
|
<!-- 查询输入框 -->
|
||||||
|
<TextBox x:Name="QueryTextBox"
|
||||||
|
Width="200"
|
||||||
|
Margin="0,0,10,0" />
|
||||||
|
<TextBlock VerticalAlignment="Center"
|
||||||
|
Margin="10,0,10,0"
|
||||||
|
Text="起始日期:" />
|
||||||
|
<DatePicker x:Name="StartDatePicker"
|
||||||
|
Width="120"
|
||||||
|
Margin="0,0,10,0"
|
||||||
|
SelectedDate="{Binding StartDate, Mode=TwoWay}" />
|
||||||
|
|
||||||
|
<TextBlock VerticalAlignment="Center"
|
||||||
|
Margin="10,0,10,0"
|
||||||
|
Text="结束日期:" />
|
||||||
|
<DatePicker x:Name="EndDatePicker"
|
||||||
|
Width="120"
|
||||||
|
Margin="0,0,10,0"
|
||||||
|
SelectedDate="{Binding EndDate, Mode=TwoWay}" />
|
||||||
|
<!-- 查询按钮 -->
|
||||||
|
<Button Content="查询"
|
||||||
|
Command="{Binding QueryCommand}"
|
||||||
|
CommandParameter="{Binding Text, ElementName=QueryTextBox}"
|
||||||
|
Margin="10,0,0,0" />
|
||||||
|
</StackPanel>
|
||||||
|
</GroupBox>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
28
BOB/Views/DataView.xaml.cs
Normal file
28
BOB/Views/DataView.xaml.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// DataView.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class DataView : UserControl
|
||||||
|
{
|
||||||
|
public DataView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
139
BOB/Views/MonitorView.xaml
Normal file
139
BOB/Views/MonitorView.xaml
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<UserControl x:Class="BOB.Views.MonitorView"
|
||||||
|
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:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:vs="clr-namespace:BOB.Views"
|
||||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
|
xmlns:oxy="http://oxyplot.org/wpf"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
xmlns:prism="http://prismlibrary.com/"
|
||||||
|
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||||
|
d:DesignHeight="1080"
|
||||||
|
d:DesignWidth="1920">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
|
||||||
|
<GroupBox Header="自定义监视曲线"
|
||||||
|
Grid.Row="0"
|
||||||
|
Margin="5"
|
||||||
|
Padding="0">
|
||||||
|
<oxy:PlotView x:Name="CustomPlotView"
|
||||||
|
|
||||||
|
Model="{Binding CurveModel}"
|
||||||
|
Background="Transparent">
|
||||||
|
<oxy:PlotView.ContextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<MenuItem Header="视图复位"
|
||||||
|
Command="{Binding ResetViewCommand}" />
|
||||||
|
|
||||||
|
</ContextMenu>
|
||||||
|
</oxy:PlotView.ContextMenu>
|
||||||
|
</oxy:PlotView>
|
||||||
|
</GroupBox>
|
||||||
|
|
||||||
|
|
||||||
|
<GroupBox Header="编辑曲线"
|
||||||
|
Grid.Row="1"
|
||||||
|
Margin="5"
|
||||||
|
Padding="0"
|
||||||
|
Height="120">
|
||||||
|
<Grid>
|
||||||
|
<!-- 创建4个列来平分区域 -->
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<!-- 第一个 StackPanel -->
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<!-- 第二个 StackPanel -->
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<!-- 第三个 StackPanel -->
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<!-- 第四个 StackPanel -->
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<!-- 第一个 StackPanel - 曲线名称和添加曲线按钮 -->
|
||||||
|
<StackPanel Orientation="Horizontal"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="30 10">
|
||||||
|
<TextBlock Text="曲线名称:"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
|
<ComboBox Name="SignalComboBox"
|
||||||
|
SelectedItem="{Binding SelectCurve,Mode=TwoWay}"
|
||||||
|
MaxWidth="200"
|
||||||
|
MinWidth="120"
|
||||||
|
Margin="10"
|
||||||
|
ItemsSource="{Binding DeviceSingleList}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
materialDesign:HintAssist.Hint="曲线名称" />
|
||||||
|
|
||||||
|
<Button Content="添加曲线"
|
||||||
|
Height="40"
|
||||||
|
Command="{Binding AddSignalCommand}"
|
||||||
|
Margin="10,0,10,0" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- 第二个 StackPanel - 已有曲线和删除曲线按钮 -->
|
||||||
|
<StackPanel Orientation="Horizontal"
|
||||||
|
Grid.Column="1"
|
||||||
|
Margin="30 10">
|
||||||
|
<TextBlock Text="已有曲线:"
|
||||||
|
materialDesign:HintAssist.Hint="已有曲线"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
|
<ComboBox MaxWidth="200"
|
||||||
|
MinWidth="120"
|
||||||
|
SelectedItem="{Binding SelectDeleteCurve,Mode=TwoWay}"
|
||||||
|
Margin="10"
|
||||||
|
ItemsSource="{Binding CurSingleList}"
|
||||||
|
materialDesign:HintAssist.Hint="已有曲线"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
|
|
||||||
|
|
||||||
|
<Button Content="删除曲线"
|
||||||
|
Height="40"
|
||||||
|
Command="{Binding RemoveSignalCommand}"
|
||||||
|
Margin="10,0,10,0" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- 第三个 StackPanel - 曲线默认保存路径 -->
|
||||||
|
<StackPanel Orientation="Horizontal"
|
||||||
|
Grid.Column="2"
|
||||||
|
Margin="30 10">
|
||||||
|
<TextBlock Text="曲线保存路径:"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
|
<TextBlock Text="{Binding FilePath}"
|
||||||
|
MaxWidth="200"
|
||||||
|
MinWidth="90"
|
||||||
|
Margin="15 0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Cursor="" />
|
||||||
|
<Button Content="更改"
|
||||||
|
Command="{Binding ChanegPathCommand}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- 第四个 StackPanel - 保存时间选中 -->
|
||||||
|
<StackPanel Orientation="Horizontal"
|
||||||
|
Grid.Column="3"
|
||||||
|
Margin="30 10">
|
||||||
|
<TextBlock Text="保存时间选中:"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
|
<TextBox MaxWidth="100"
|
||||||
|
MinWidth="60"
|
||||||
|
Margin="10"
|
||||||
|
Text="{Binding SelectedSaveDays,Mode=TwoWay}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
materialDesign:HintAssist.Hint="保存天数" />
|
||||||
|
<Button Content="保存"
|
||||||
|
Command="{Binding SaveCommand}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</GroupBox>
|
||||||
|
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
28
BOB/Views/MonitorView.xaml.cs
Normal file
28
BOB/Views/MonitorView.xaml.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MonitorView.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class MonitorView : UserControl
|
||||||
|
{
|
||||||
|
public MonitorView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -38,15 +38,30 @@
|
|||||||
Margin="16"
|
Margin="16"
|
||||||
Foreground="{DynamicResource PrimaryHueMidBrush}" />
|
Foreground="{DynamicResource PrimaryHueMidBrush}" />
|
||||||
<Separator Margin="0,0,0,8" />
|
<Separator Margin="0,0,0,8" />
|
||||||
<Button Content="系统设置"
|
<Button Content="程序界面"
|
||||||
|
Command="{Binding NavigateCommand}"
|
||||||
|
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||||
Style="{StaticResource MaterialDesignFlatButton}"
|
Style="{StaticResource MaterialDesignFlatButton}"
|
||||||
Margin="8" />
|
Margin="8" />
|
||||||
|
|
||||||
|
<Button Content="监控界面"
|
||||||
|
Command="{Binding NavigateCommand}"
|
||||||
|
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||||
|
Style="{StaticResource MaterialDesignFlatButton}"
|
||||||
|
Margin="8" />
|
||||||
|
|
||||||
<Button Content="数据管理"
|
<Button Content="数据管理"
|
||||||
|
Command="{Binding NavigateCommand}"
|
||||||
|
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||||
Style="{StaticResource MaterialDesignFlatButton}"
|
Style="{StaticResource MaterialDesignFlatButton}"
|
||||||
Margin="8" />
|
Margin="8" />
|
||||||
|
|
||||||
<Button Content="更新信息"
|
<Button Content="更新信息"
|
||||||
|
Command="{Binding NavigateCommand}"
|
||||||
|
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||||
Style="{StaticResource MaterialDesignFlatButton}"
|
Style="{StaticResource MaterialDesignFlatButton}"
|
||||||
Margin="8" />
|
Margin="8" />
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</materialDesign:DrawerHost.LeftDrawerContent>
|
</materialDesign:DrawerHost.LeftDrawerContent>
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|||||||
@ -22,15 +22,15 @@ namespace DeviceCommand.Device
|
|||||||
#region 基础系统命令(必须保留)
|
#region 基础系统命令(必须保留)
|
||||||
|
|
||||||
/// <summary>查询设备身份</summary>
|
/// <summary>查询设备身份</summary>
|
||||||
public Task<string> QueryIDAsync(CancellationToken ct = default)
|
public virtual Task<string> QueryIDAsync(CancellationToken ct = default)
|
||||||
=> SendCommandReadAsync("*IDN?", ct);
|
=> SendCommandReadAsync("*IDN?", ct);
|
||||||
|
|
||||||
/// <summary>清除错误与状态</summary>
|
/// <summary>清除错误与状态</summary>
|
||||||
public Task ClearStatusAsync(CancellationToken ct = default)
|
public virtual Task ClearStatusAsync(CancellationToken ct = default)
|
||||||
=> SendAsync("*CLS\r\n", ct);
|
=> SendAsync("*CLS\r\n", ct);
|
||||||
|
|
||||||
/// <summary>系统复位</summary>
|
/// <summary>系统复位</summary>
|
||||||
public Task ResetAsync(CancellationToken ct = default)
|
public virtual Task ResetAsync(CancellationToken ct = default)
|
||||||
=> SendAsync("*RST\r\n", ct);
|
=> SendAsync("*RST\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -38,7 +38,7 @@ namespace DeviceCommand.Device
|
|||||||
#region 通道与输出控制
|
#region 通道与输出控制
|
||||||
|
|
||||||
/// <summary>选择通道 CH1 或 CH2</summary>
|
/// <summary>选择通道 CH1 或 CH2</summary>
|
||||||
public Task SelectChannelAsync(int channel, CancellationToken ct = default)
|
public virtual Task SelectChannelAsync(int channel, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (channel < 1 || channel > 2)
|
if (channel < 1 || channel > 2)
|
||||||
throw new ArgumentOutOfRangeException(nameof(channel));
|
throw new ArgumentOutOfRangeException(nameof(channel));
|
||||||
@ -47,7 +47,7 @@ namespace DeviceCommand.Device
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>开关输出</summary>
|
/// <summary>开关输出</summary>
|
||||||
public Task SetOutputAsync(bool on, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetOutputAsync(bool on, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"OUTP {(on ? "ON" : "OFF")},(@{channels})\r\n", ct);
|
=> SendAsync($"OUTP {(on ? "ON" : "OFF")},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -55,29 +55,29 @@ namespace DeviceCommand.Device
|
|||||||
#region 电压/电流设置
|
#region 电压/电流设置
|
||||||
|
|
||||||
/// <summary>设置电压 (0~30.9V)</summary>
|
/// <summary>设置电压 (0~30.9V)</summary>
|
||||||
public Task SetVoltageAsync(double volt, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetVoltageAsync(double volt, string channels = "1", CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (volt < 0 || volt > 30.9) throw new ArgumentOutOfRangeException(nameof(volt));
|
if (volt < 0 || volt > 30.9) throw new ArgumentOutOfRangeException(nameof(volt));
|
||||||
return SendAsync($"SOUR:VOLT {volt},(@{channels})\r\n", ct);
|
return SendAsync($"SOUR:VOLT {volt},(@{channels})\r\n", ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>设置电流限值 (0~20.6A)</summary>
|
/// <summary>设置电流限值 (0~20.6A)</summary>
|
||||||
public Task SetCurrentAsync(double curr, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetCurrentAsync(double curr, string channels = "1", CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (curr < 0 || curr > 20.6) throw new ArgumentOutOfRangeException(nameof(curr));
|
if (curr < 0 || curr > 20.6) throw new ArgumentOutOfRangeException(nameof(curr));
|
||||||
return SendAsync($"SOUR:CURR {curr},(@{channels})\r\n", ct);
|
return SendAsync($"SOUR:CURR {curr},(@{channels})\r\n", ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>设置过压保护</summary>
|
/// <summary>设置过压保护</summary>
|
||||||
public Task SetOVPAsync(double ovp, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetOVPAsync(double ovp, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:VOLT:PROT {ovp},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:VOLT:PROT {ovp},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
/// <summary>设置过流保护</summary>
|
/// <summary>设置过流保护</summary>
|
||||||
public Task SetOCPAsync(double ocp, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetOCPAsync(double ocp, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:CURR:PROT {ocp},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:CURR:PROT {ocp},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
/// <summary>清除 OVP/OCP 错误</summary>
|
/// <summary>清除 OVP/OCP 错误</summary>
|
||||||
public Task ClearProtectionAsync(string channels = "1", CancellationToken ct = default)
|
public virtual Task ClearProtectionAsync(string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:VOLT:PROT:CLE (@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:VOLT:PROT:CLE (@{channels})\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -85,11 +85,11 @@ namespace DeviceCommand.Device
|
|||||||
#region 斜率设置(用于启动测试)
|
#region 斜率设置(用于启动测试)
|
||||||
|
|
||||||
/// <summary>设置电压上升斜率</summary>
|
/// <summary>设置电压上升斜率</summary>
|
||||||
public Task SetRiseSlewAsync(double slew, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetRiseSlewAsync(double slew, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:VOLT:SLEW:RIS {slew},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:VOLT:SLEW:RIS {slew},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
/// <summary>设置电压下降斜率</summary>
|
/// <summary>设置电压下降斜率</summary>
|
||||||
public Task SetFallSlewAsync(double slew, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetFallSlewAsync(double slew, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:VOLT:SLEW:FALL {slew},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:VOLT:SLEW:FALL {slew},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -97,14 +97,14 @@ namespace DeviceCommand.Device
|
|||||||
#region 测量
|
#region 测量
|
||||||
|
|
||||||
/// <summary>测量电压(V)</summary>
|
/// <summary>测量电压(V)</summary>
|
||||||
public async Task<double> MeasureVoltageAsync(string channels = "1", CancellationToken ct = default)
|
public virtual async Task<double> MeasureVoltageAsync(string channels = "1", CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
string result = await SendCommandReadAsync($"MEAS:VOLT? (@{channels})", ct);
|
string result = await SendCommandReadAsync($"MEAS:VOLT? (@{channels})", ct);
|
||||||
return double.TryParse(result, out var value) ? value : 0;
|
return double.TryParse(result, out var value) ? value : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>测量电流(A)</summary>
|
/// <summary>测量电流(A)</summary>
|
||||||
public async Task<double> MeasureCurrentAsync(string channels = "1", CancellationToken ct = default)
|
public virtual async Task<double> MeasureCurrentAsync(string channels = "1", CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
string result = await SendCommandReadAsync($"MEAS:CURR? (@{channels})", ct);
|
string result = await SendCommandReadAsync($"MEAS:CURR? (@{channels})", ct);
|
||||||
return double.TryParse(result, out var value) ? value : 0;
|
return double.TryParse(result, out var value) ? value : 0;
|
||||||
@ -114,13 +114,13 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 保护状态查询
|
#region 保护状态查询
|
||||||
|
|
||||||
public async Task<bool> QueryOVPTrippedAsync(string channels = "1", CancellationToken ct = default)
|
public virtual async Task<bool> QueryOVPTrippedAsync(string channels = "1", CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
string result = await SendCommandReadAsync($"SOUR:VOLT:PROT:TRIP? (@{channels})", ct);
|
string result = await SendCommandReadAsync($"SOUR:VOLT:PROT:TRIP? (@{channels})", ct);
|
||||||
return result == "1";
|
return result == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> QueryOCPTrippedAsync(string channels = "1", CancellationToken ct = default)
|
public virtual async Task<bool> QueryOCPTrippedAsync(string channels = "1", CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
string result = await SendCommandReadAsync($"SOUR:CURR:PROT:TRIP? (@{channels})", ct);
|
string result = await SendCommandReadAsync($"SOUR:CURR:PROT:TRIP? (@{channels})", ct);
|
||||||
return result == "1";
|
return result == "1";
|
||||||
@ -130,26 +130,26 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 序列(用于阶梯电压/耐久测试)
|
#region 序列(用于阶梯电压/耐久测试)
|
||||||
|
|
||||||
public Task SetVoltageListAsync(double[] voltages, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetVoltageListAsync(double[] voltages, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:LIST:VOLT {string.Join(",", voltages)},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:LIST:VOLT {string.Join(",", voltages)},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
public Task SetCurrentListAsync(double[] currents, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetCurrentListAsync(double[] currents, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:LIST:CURR {string.Join(",", currents)},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:LIST:CURR {string.Join(",", currents)},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
public Task SetDwellListAsync(double[] times, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetDwellListAsync(double[] times, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:LIST:DWEL {string.Join(",", times)},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:LIST:DWEL {string.Join(",", times)},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
public Task SetSequenceRepeatAsync(string count, string channels = "1", CancellationToken ct = default)
|
public virtual Task SetSequenceRepeatAsync(string count, string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"SOUR:LIST:COUN {count},(@{channels})\r\n", ct);
|
=> SendAsync($"SOUR:LIST:COUN {count},(@{channels})\r\n", ct);
|
||||||
|
|
||||||
public Task StartSequenceAsync(string channels = "1", CancellationToken ct = default)
|
public virtual Task StartSequenceAsync(string channels = "1", CancellationToken ct = default)
|
||||||
=> SendAsync($"INIT (@{channels})\r\n", ct);
|
=> SendAsync($"INIT (@{channels})\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 辅助方法
|
#region 辅助方法
|
||||||
|
|
||||||
private async Task<string> SendCommandReadAsync(string cmd, CancellationToken ct = default)
|
protected virtual async Task<string> SendCommandReadAsync(string cmd, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync(cmd + "\r\n", ct);
|
await SendAsync(cmd + "\r\n", ct);
|
||||||
return await ReadAsync("\n", ct);
|
return await ReadAsync("\n", ct);
|
||||||
|
|||||||
@ -11,51 +11,49 @@ namespace DeviceCommand.Device
|
|||||||
public EAEL9080(string IpAddress, int port, int SendTimeout, int ReceiveTimeout)
|
public EAEL9080(string IpAddress, int port, int SendTimeout, int ReceiveTimeout)
|
||||||
{
|
{
|
||||||
ConfigureDevice(IpAddress, port, SendTimeout, ReceiveTimeout);
|
ConfigureDevice(IpAddress, port, SendTimeout, ReceiveTimeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
public EAEL9080()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public EAEL9080() { }
|
||||||
|
|
||||||
#region 一、基础控制
|
#region 一、基础控制
|
||||||
|
|
||||||
public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(activate ? 0xFF00 : 0x0000);
|
ushort value = (ushort)(activate ? 0xFF00 : 0x0000);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 402, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 402, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetOutputAsync(bool on, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetOutputAsync(bool on, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(on ? 0xFF00 : 0x0000);
|
ushort value = (ushort)(on ? 0xFF00 : 0x0000);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 405, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 405, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetWorkModeAsync(bool useResistanceMode, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetWorkModeAsync(bool useResistanceMode, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(useResistanceMode ? 0xFF00 : 0x0000);
|
ushort value = (ushort)(useResistanceMode ? 0xFF00 : 0x0000);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 409, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 409, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<uint> ReadDeviceStatusAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<uint> ReadDeviceStatusAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 505, 2, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 505, 2, ct);
|
||||||
return (uint)(reg[0] << 16 | reg[1]);
|
return (uint)(reg[0] << 16 | reg[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IsDcOnAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<bool> IsDcOnAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
||||||
return (status & (1 << 7)) != 0;
|
return (status & (1 << 7)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IsRemoteActiveAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<bool> IsRemoteActiveAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
||||||
return (status & (1 << 10)) != 0;
|
return (status & (1 << 10)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IsSinkModeActiveAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<bool> IsSinkModeActiveAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
||||||
return (status & (1 << 12)) != 0;
|
return (status & (1 << 12)) != 0;
|
||||||
@ -65,49 +63,49 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 二、电压 / 电流 / 功率 / 电阻设定值
|
#region 二、电压 / 电流 / 功率 / 电阻设定值
|
||||||
|
|
||||||
public async Task SetVoltageAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetVoltageAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 500, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 500, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 500, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 500, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedVoltage;
|
return reg[0] / (double)0xCCCC * ratedVoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetCurrentAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetCurrentAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 501, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 501, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 501, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 501, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedCurrent;
|
return reg[0] / (double)0xCCCC * ratedCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetPowerAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetPowerAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 502, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 502, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 502, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 502, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedPower;
|
return reg[0] / (double)0xCCCC * ratedPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetResistanceAsync(double resistance, double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetResistanceAsync(double resistance, double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(resistance / maxResistance * 0xCCCC);
|
ushort value = (ushort)(resistance / maxResistance * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 503, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 503, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetResistanceAsync(double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetResistanceAsync(double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 503, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 503, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * maxResistance;
|
return reg[0] / (double)0xCCCC * maxResistance;
|
||||||
@ -117,37 +115,37 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 三、Sink 模式
|
#region 三、Sink 模式
|
||||||
|
|
||||||
public async Task SetSinkPowerAsync(double power, double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetSinkPowerAsync(double power, double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(power / sinkRatedPower * 0xCCCC);
|
ushort value = (ushort)(power / sinkRatedPower * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 498, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 498, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetSinkCurrentAsync(double current, double sinkRatedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetSinkCurrentAsync(double current, double sinkRatedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(current / sinkRatedCurrent * 0xCCCC);
|
ushort value = (ushort)(current / sinkRatedCurrent * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 499, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 499, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetSinkResistanceAsync(double resistance, double sinkMaxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetSinkResistanceAsync(double resistance, double sinkMaxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(resistance / sinkMaxResistance * 0xCCCC);
|
ushort value = (ushort)(resistance / sinkMaxResistance * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 504, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 504, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetSinkPowerAsync(double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetSinkPowerAsync(double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 498, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 498, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * sinkRatedPower;
|
return reg[0] / (double)0xCCCC * sinkRatedPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetSinkCurrentAsync(double sinkRatedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetSinkCurrentAsync(double sinkRatedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 499, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 499, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * sinkRatedCurrent;
|
return reg[0] / (double)0xCCCC * sinkRatedCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetSinkResistanceAsync(double sinkMaxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetSinkResistanceAsync(double sinkMaxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 504, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 504, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * sinkMaxResistance;
|
return reg[0] / (double)0xCCCC * sinkMaxResistance;
|
||||||
@ -157,13 +155,13 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 四、实时测量
|
#region 四、实时测量
|
||||||
|
|
||||||
public async Task<double> ReadActualVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> ReadActualVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 507, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 507, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedVoltage;
|
return reg[0] / (double)0xCCCC * ratedVoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> ReadActualCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> ReadActualCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 508, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 508, 1, ct);
|
||||||
double current = reg[0] / (double)0xCCCC * ratedCurrent;
|
double current = reg[0] / (double)0xCCCC * ratedCurrent;
|
||||||
@ -171,7 +169,7 @@ namespace DeviceCommand.Device
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> ReadActualPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> ReadActualPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 509, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 509, 1, ct);
|
||||||
double power = reg[0] / (double)0xCCCC * ratedPower;
|
double power = reg[0] / (double)0xCCCC * ratedPower;
|
||||||
@ -183,19 +181,19 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 五、保护阈值
|
#region 五、保护阈值
|
||||||
|
|
||||||
public async Task SetOverVoltageLimitAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetOverVoltageLimitAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 510, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 510, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetOverCurrentLimitAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetOverCurrentLimitAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 511, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 511, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetOverPowerLimitAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetOverPowerLimitAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 512, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 512, value, ct);
|
||||||
|
|||||||
@ -20,12 +20,12 @@ namespace DeviceCommand.Device
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
public async Task WriteOutput(byte slaveId, ushort startAddress, ushort value)
|
public virtual async Task WriteOutput(byte slaveId, ushort startAddress, ushort value)
|
||||||
{
|
{
|
||||||
await WriteSingleRegisterAsync(slaveId, startAddress, value);
|
await WriteSingleRegisterAsync(slaveId, startAddress, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteOutputsBatch(byte slaveId, ushort startAddress, ushort[] values)
|
public virtual async Task WriteOutputsBatch(byte slaveId, ushort startAddress, ushort[] values)
|
||||||
{
|
{
|
||||||
await WriteMultipleRegistersAsync(slaveId, startAddress, values);
|
await WriteMultipleRegistersAsync(slaveId, startAddress, values);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,88 +10,85 @@ namespace DeviceCommand.Device
|
|||||||
[BOBCommand]
|
[BOBCommand]
|
||||||
public class IT6724C : Serial_Port
|
public class IT6724C : Serial_Port
|
||||||
{
|
{
|
||||||
public IT6724C(string COMPort,int BaudRate,int DataBits, StopBits stopBits, Parity parity,int ReadTimeout,int ReceiveTimeout)
|
public IT6724C(string COMPort, int BaudRate, int DataBits, StopBits stopBits, Parity parity, int ReadTimeout, int ReceiveTimeout)
|
||||||
{
|
{
|
||||||
ConfigureDevice(COMPort,BaudRate,DataBits,stopBits,parity, ReadTimeout, ReceiveTimeout);
|
ConfigureDevice(COMPort, BaudRate, DataBits, stopBits, parity, ReadTimeout, ReceiveTimeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
public IT6724C()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public IT6724C() { }
|
||||||
|
|
||||||
#region 设置命令
|
#region 设置命令
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置输出状态,true 为开,false 为关
|
/// 设置输出状态,true 为开,false 为关
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetOutputAsync(bool state, CancellationToken ct = default)
|
public virtual Task SetOutputAsync(bool state, CancellationToken ct = default)
|
||||||
=> SendAsync($"OUTPut {(state ? 1 : 0)}\r\n", ct);
|
=> SendAsync($"OUTPut {(state ? 1 : 0)}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 切换到远程控制模式
|
/// 切换到远程控制模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetRemoteModeAsync(CancellationToken ct = default)
|
public virtual Task SetRemoteModeAsync(CancellationToken ct = default)
|
||||||
=> SendAsync("SYSTem:REMote\r\n", ct);
|
=> SendAsync("SYSTem:REMote\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 蜂鸣器测试
|
/// 蜂鸣器测试
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task BeeperTestAsync(CancellationToken ct = default)
|
public virtual Task BeeperTestAsync(CancellationToken ct = default)
|
||||||
=> SendAsync("SYSTem:BEEPer\r\n", ct);
|
=> SendAsync("SYSTem:BEEPer\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置输出电流(单位:A)
|
/// 设置输出电流(单位:A)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetCurrentAsync(double current, CancellationToken ct = default)
|
public virtual Task SetCurrentAsync(double current, CancellationToken ct = default)
|
||||||
=> SendAsync($"CURRent {current}\r\n", ct);
|
=> SendAsync($"CURRent {current}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置过流保护电流(OCP,单位:A)
|
/// 设置过流保护电流(OCP,单位:A)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetOCPCurrentAsync(double current, CancellationToken ct = default)
|
public virtual Task SetOCPCurrentAsync(double current, CancellationToken ct = default)
|
||||||
=> SendAsync($"CURRent:PROTection {current}\r\n", ct);
|
=> SendAsync($"CURRent:PROTection {current}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置过流保护状态,true 为启用,false 为禁用
|
/// 设置过流保护状态,true 为启用,false 为禁用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetOCPStateAsync(bool state, CancellationToken ct = default)
|
public virtual Task SetOCPStateAsync(bool state, CancellationToken ct = default)
|
||||||
=> SendAsync($"CURRent:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
=> SendAsync($"CURRent:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 清除过流保护触发状态
|
/// 清除过流保护触发状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task ClearOCPAsync(CancellationToken ct = default)
|
public virtual Task ClearOCPAsync(CancellationToken ct = default)
|
||||||
=> SendAsync("CURRent:PROTection:CLEar\r\n", ct);
|
=> SendAsync("CURRent:PROTection:CLEar\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置输出电压(单位:V)
|
/// 设置输出电压(单位:V)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetVoltageAsync(double voltage, CancellationToken ct = default)
|
public virtual Task SetVoltageAsync(double voltage, CancellationToken ct = default)
|
||||||
=> SendAsync($"VOLTage {voltage}\r\n", ct);
|
=> SendAsync($"VOLTage {voltage}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置过压保护电压(OVP,单位:V)
|
/// 设置过压保护电压(OVP,单位:V)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetOVPVoltageAsync(double voltage, CancellationToken ct = default)
|
public virtual Task SetOVPVoltageAsync(double voltage, CancellationToken ct = default)
|
||||||
=> SendAsync($"VOLT:PROTection {voltage}\r\n", ct);
|
=> SendAsync($"VOLT:PROTection {voltage}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置过压保护状态,true 为启用,false 为禁用
|
/// 设置过压保护状态,true 为启用,false 为禁用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SetOVPStateAsync(bool state, CancellationToken ct = default)
|
public virtual Task SetOVPStateAsync(bool state, CancellationToken ct = default)
|
||||||
=> SendAsync($"VOLT:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
=> SendAsync($"VOLT:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 清除过压保护触发状态
|
/// 清除过压保护触发状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task ClearOVPAsync(CancellationToken ct = default)
|
public virtual Task ClearOVPAsync(CancellationToken ct = default)
|
||||||
=> SendAsync("VOLT:PROTection:CLEar\r\n", ct);
|
=> SendAsync("VOLT:PROTection:CLEar\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送自定义命令
|
/// 发送自定义命令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task SendCustomCommandAsync(string command, CancellationToken ct = default)
|
public virtual Task SendCustomCommandAsync(string command, CancellationToken ct = default)
|
||||||
=> SendAsync($"{command}\r\n", ct);
|
=> SendAsync($"{command}\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -101,7 +98,7 @@ namespace DeviceCommand.Device
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询仪器标识,返回制造商、型号、序列号、固件版本
|
/// 查询仪器标识,返回制造商、型号、序列号、固件版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<string> QueryIDAsync(CancellationToken ct = default)
|
public virtual async Task<string> QueryIDAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync("*IDN?\r\n", ct);
|
await SendAsync("*IDN?\r\n", ct);
|
||||||
return await ReadAsync(ct: ct);
|
return await ReadAsync(ct: ct);
|
||||||
@ -110,7 +107,7 @@ namespace DeviceCommand.Device
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询过流保护是否触发,返回 true 表示触发
|
/// 查询过流保护是否触发,返回 true 表示触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<bool> QueryOCPTrippedAsync(CancellationToken ct = default)
|
public virtual async Task<bool> QueryOCPTrippedAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync("CURRent:PROTection:TRIPed?\r\n", ct);
|
await SendAsync("CURRent:PROTection:TRIPed?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
@ -120,7 +117,7 @@ namespace DeviceCommand.Device
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询过压保护是否触发,返回 true 表示触发
|
/// 查询过压保护是否触发,返回 true 表示触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<bool> QueryOVPTrippedAsync(CancellationToken ct = default)
|
public virtual async Task<bool> QueryOVPTrippedAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync("VOLT:PROTection:TRIPed?\r\n", ct);
|
await SendAsync("VOLT:PROTection:TRIPed?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
@ -130,7 +127,7 @@ namespace DeviceCommand.Device
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询实际输出电流(单位:A)
|
/// 查询实际输出电流(单位:A)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<double> QueryCurrentAsync(CancellationToken ct = default)
|
public virtual async Task<double> QueryCurrentAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync("MEASure:CURRent?\r\n", ct);
|
await SendAsync("MEASure:CURRent?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
@ -140,7 +137,7 @@ namespace DeviceCommand.Device
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询实际输出电压(单位:V)
|
/// 查询实际输出电压(单位:V)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<double> QueryVoltageAsync(CancellationToken ct = default)
|
public virtual async Task<double> QueryVoltageAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync("MEASure:VOLTage?\r\n", ct);
|
await SendAsync("MEASure:VOLTage?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
@ -150,7 +147,7 @@ namespace DeviceCommand.Device
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询实际输出功率(单位:W)
|
/// 查询实际输出功率(单位:W)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<double> QueryPowerAsync(CancellationToken ct = default)
|
public virtual async Task<double> QueryPowerAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync("MEASure:POWer?\r\n", ct);
|
await SendAsync("MEASure:POWer?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
@ -158,6 +155,5 @@ namespace DeviceCommand.Device
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,147 +10,90 @@ namespace DeviceCommand.Device
|
|||||||
[BOBCommand]
|
[BOBCommand]
|
||||||
public class IT6724CReverse : Serial_Port
|
public class IT6724CReverse : Serial_Port
|
||||||
{
|
{
|
||||||
public IT6724CReverse(string COMPort,int BaudRate,int DataBits, StopBits stopBits, Parity parity,int ReadTimeout,int ReceiveTimeout)
|
public IT6724CReverse(string COMPort, int BaudRate, int DataBits, StopBits stopBits, Parity parity, int ReadTimeout, int ReceiveTimeout)
|
||||||
{
|
{
|
||||||
ConfigureDevice(COMPort,BaudRate,DataBits,stopBits,parity, ReadTimeout, ReceiveTimeout);
|
ConfigureDevice(COMPort, BaudRate, DataBits, stopBits, parity, ReadTimeout, ReceiveTimeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
public IT6724CReverse()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public IT6724CReverse() { }
|
||||||
|
|
||||||
#region 设置命令
|
#region 设置命令
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetOutputAsync(bool state, CancellationToken ct = default)
|
||||||
/// 设置输出状态,true 为开,false 为关
|
|
||||||
/// </summary>
|
|
||||||
public Task SetOutputAsync(bool state, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"OUTPut {(state ? 1 : 0)}\r\n", ct);
|
=> SendAsync($"OUTPut {(state ? 1 : 0)}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetRemoteModeAsync(CancellationToken ct = default)
|
||||||
/// 切换到远程控制模式
|
|
||||||
/// </summary>
|
|
||||||
public Task SetRemoteModeAsync(CancellationToken ct = default)
|
|
||||||
=> SendAsync("SYSTem:REMote\r\n", ct);
|
=> SendAsync("SYSTem:REMote\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task BeeperTestAsync(CancellationToken ct = default)
|
||||||
/// 蜂鸣器测试
|
|
||||||
/// </summary>
|
|
||||||
public Task BeeperTestAsync(CancellationToken ct = default)
|
|
||||||
=> SendAsync("SYSTem:BEEPer\r\n", ct);
|
=> SendAsync("SYSTem:BEEPer\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetCurrentAsync(double current, CancellationToken ct = default)
|
||||||
/// 设置输出电流(单位:A)
|
|
||||||
/// </summary>
|
|
||||||
public Task SetCurrentAsync(double current, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"CURRent {current}\r\n", ct);
|
=> SendAsync($"CURRent {current}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetOCPCurrentAsync(double current, CancellationToken ct = default)
|
||||||
/// 设置过流保护电流(OCP,单位:A)
|
|
||||||
/// </summary>
|
|
||||||
public Task SetOCPCurrentAsync(double current, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"CURRent:PROTection {current}\r\n", ct);
|
=> SendAsync($"CURRent:PROTection {current}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetOCPStateAsync(bool state, CancellationToken ct = default)
|
||||||
/// 设置过流保护状态,true 为启用,false 为禁用
|
|
||||||
/// </summary>
|
|
||||||
public Task SetOCPStateAsync(bool state, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"CURRent:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
=> SendAsync($"CURRent:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task ClearOCPAsync(CancellationToken ct = default)
|
||||||
/// 清除过流保护触发状态
|
|
||||||
/// </summary>
|
|
||||||
public Task ClearOCPAsync(CancellationToken ct = default)
|
|
||||||
=> SendAsync("CURRent:PROTection:CLEar\r\n", ct);
|
=> SendAsync("CURRent:PROTection:CLEar\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetVoltageAsync(double voltage, CancellationToken ct = default)
|
||||||
/// 设置输出电压(单位:V)
|
|
||||||
/// </summary>
|
|
||||||
public Task SetVoltageAsync(double voltage, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"VOLTage {voltage}\r\n", ct);
|
=> SendAsync($"VOLTage {voltage}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetOVPVoltageAsync(double voltage, CancellationToken ct = default)
|
||||||
/// 设置过压保护电压(OVP,单位:V)
|
|
||||||
/// </summary>
|
|
||||||
public Task SetOVPVoltageAsync(double voltage, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"VOLT:PROTection {voltage}\r\n", ct);
|
=> SendAsync($"VOLT:PROTection {voltage}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SetOVPStateAsync(bool state, CancellationToken ct = default)
|
||||||
/// 设置过压保护状态,true 为启用,false 为禁用
|
|
||||||
/// </summary>
|
|
||||||
public Task SetOVPStateAsync(bool state, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"VOLT:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
=> SendAsync($"VOLT:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task ClearOVPAsync(CancellationToken ct = default)
|
||||||
/// 清除过压保护触发状态
|
|
||||||
/// </summary>
|
|
||||||
public Task ClearOVPAsync(CancellationToken ct = default)
|
|
||||||
=> SendAsync("VOLT:PROTection:CLEar\r\n", ct);
|
=> SendAsync("VOLT:PROTection:CLEar\r\n", ct);
|
||||||
|
|
||||||
/// <summary>
|
public virtual Task SendCustomCommandAsync(string command, CancellationToken ct = default)
|
||||||
/// 发送自定义命令
|
|
||||||
/// </summary>
|
|
||||||
public Task SendCustomCommandAsync(string command, CancellationToken ct = default)
|
|
||||||
=> SendAsync($"{command}\r\n", ct);
|
=> SendAsync($"{command}\r\n", ct);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 查询命令
|
#region 查询命令
|
||||||
|
|
||||||
/// <summary>
|
public virtual async Task<string> QueryIDAsync(CancellationToken ct = default)
|
||||||
/// 查询仪器标识,返回制造商、型号、序列号、固件版本
|
|
||||||
/// </summary>
|
|
||||||
public async Task<string> QueryIDAsync(CancellationToken ct = default)
|
|
||||||
{
|
{
|
||||||
await SendAsync("*IDN?\r\n", ct);
|
await SendAsync("*IDN?\r\n", ct);
|
||||||
return await ReadAsync(ct: ct);
|
return await ReadAsync(ct: ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual async Task<bool> QueryOCPTrippedAsync(CancellationToken ct = default)
|
||||||
/// 查询过流保护是否触发,返回 true 表示触发
|
|
||||||
/// </summary>
|
|
||||||
public async Task<bool> QueryOCPTrippedAsync(CancellationToken ct = default)
|
|
||||||
{
|
{
|
||||||
await SendAsync("CURRent:PROTection:TRIPed?\r\n", ct);
|
await SendAsync("CURRent:PROTection:TRIPed?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
return result == "1";
|
return result == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual async Task<bool> QueryOVPTrippedAsync(CancellationToken ct = default)
|
||||||
/// 查询过压保护是否触发,返回 true 表示触发
|
|
||||||
/// </summary>
|
|
||||||
public async Task<bool> QueryOVPTrippedAsync(CancellationToken ct = default)
|
|
||||||
{
|
{
|
||||||
await SendAsync("VOLT:PROTection:TRIPed?\r\n", ct);
|
await SendAsync("VOLT:PROTection:TRIPed?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
return result == "1";
|
return result == "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual async Task<double> QueryCurrentAsync(CancellationToken ct = default)
|
||||||
/// 查询实际输出电流(单位:A)
|
|
||||||
/// </summary>
|
|
||||||
public async Task<double> QueryCurrentAsync(CancellationToken ct = default)
|
|
||||||
{
|
{
|
||||||
await SendAsync("MEASure:CURRent?\r\n", ct);
|
await SendAsync("MEASure:CURRent?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
return Convert.ToDouble(result);
|
return Convert.ToDouble(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual async Task<double> QueryVoltageAsync(CancellationToken ct = default)
|
||||||
/// 查询实际输出电压(单位:V)
|
|
||||||
/// </summary>
|
|
||||||
public async Task<double> QueryVoltageAsync(CancellationToken ct = default)
|
|
||||||
{
|
{
|
||||||
await SendAsync("MEASure:VOLTage?\r\n", ct);
|
await SendAsync("MEASure:VOLTage?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
return Convert.ToDouble(result);
|
return Convert.ToDouble(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual async Task<double> QueryPowerAsync(CancellationToken ct = default)
|
||||||
/// 查询实际输出功率(单位:W)
|
|
||||||
/// </summary>
|
|
||||||
public async Task<double> QueryPowerAsync(CancellationToken ct = default)
|
|
||||||
{
|
{
|
||||||
await SendAsync("MEASure:POWer?\r\n", ct);
|
await SendAsync("MEASure:POWer?\r\n", ct);
|
||||||
var result = await ReadAsync(ct: ct);
|
var result = await ReadAsync(ct: ct);
|
||||||
@ -158,6 +101,5 @@ namespace DeviceCommand.Device
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,12 +14,10 @@ namespace DeviceCommand.Device
|
|||||||
public LQ7500_D(string COMPort, int BaudRate, int DataBits, StopBits stopBits, Parity parity, int ReadTimeout, int ReceiveTimeout)
|
public LQ7500_D(string COMPort, int BaudRate, int DataBits, StopBits stopBits, Parity parity, int ReadTimeout, int ReceiveTimeout)
|
||||||
{
|
{
|
||||||
ConfigureDevice(COMPort, BaudRate, DataBits, stopBits, parity, ReadTimeout, ReceiveTimeout);
|
ConfigureDevice(COMPort, BaudRate, DataBits, stopBits, parity, ReadTimeout, ReceiveTimeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
public LQ7500_D()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public LQ7500_D() { }
|
||||||
|
|
||||||
public byte SlaveAddress { get; set; } = 1; // default slave address
|
public byte SlaveAddress { get; set; } = 1; // default slave address
|
||||||
|
|
||||||
private static readonly int[] Pow10Table =
|
private static readonly int[] Pow10Table =
|
||||||
@ -33,13 +31,13 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region Read Methods
|
#region Read Methods
|
||||||
|
|
||||||
public async Task<ushort> ReadTemperatureResolutionAsync()
|
public virtual async Task<ushort> ReadTemperatureResolutionAsync()
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
return (await ReadHoldingRegistersAsync(SlaveAddress, 35, 1))[0];
|
return (await ReadHoldingRegistersAsync(SlaveAddress, 35, 1))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> ReadInternalSensorTemperatureAsync(ushort resolution = 0)
|
public virtual async Task<double> ReadInternalSensorTemperatureAsync(ushort resolution = 0)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
if (resolution == 0) resolution = await ReadTemperatureResolutionAsync();
|
if (resolution == 0) resolution = await ReadTemperatureResolutionAsync();
|
||||||
@ -47,7 +45,7 @@ namespace DeviceCommand.Device
|
|||||||
return Math.Round(data[0] / (double)Pow10Table[resolution], resolution + 1);
|
return Math.Round(data[0] / (double)Pow10Table[resolution], resolution + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> ReadExternalSensorTemperatureAsync(ushort resolution = 0)
|
public virtual async Task<double> ReadExternalSensorTemperatureAsync(ushort resolution = 0)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
if (resolution == 0) resolution = await ReadTemperatureResolutionAsync();
|
if (resolution == 0) resolution = await ReadTemperatureResolutionAsync();
|
||||||
@ -55,25 +53,25 @@ namespace DeviceCommand.Device
|
|||||||
return data[0] / (double)Pow10Table[resolution];
|
return data[0] / (double)Pow10Table[resolution];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ushort> ReadFaultCodeAsync()
|
public virtual async Task<ushort> ReadFaultCodeAsync()
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
return (await ReadHoldingRegistersAsync(SlaveAddress, 1, 1))[0];
|
return (await ReadHoldingRegistersAsync(SlaveAddress, 1, 1))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ushort> ReadDeviceStatusAsync()
|
public virtual async Task<ushort> ReadDeviceStatusAsync()
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
return (await ReadHoldingRegistersAsync(SlaveAddress, 3, 1))[0];
|
return (await ReadHoldingRegistersAsync(SlaveAddress, 3, 1))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ushort> ReadPumpStatusAsync()
|
public virtual async Task<ushort> ReadPumpStatusAsync()
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
return (await ReadHoldingRegistersAsync(SlaveAddress, 4, 1))[0];
|
return (await ReadHoldingRegistersAsync(SlaveAddress, 4, 1))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> ReadFlowAsync()
|
public virtual async Task<double> ReadFlowAsync()
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
var data = await ReadHoldingRegistersAsync(SlaveAddress, 17, 1);
|
var data = await ReadHoldingRegistersAsync(SlaveAddress, 17, 1);
|
||||||
@ -84,7 +82,7 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region Write Methods
|
#region Write Methods
|
||||||
|
|
||||||
public async Task WriteFlowSettingAsync(double value)
|
public virtual async Task WriteFlowSettingAsync(double value)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
short temp = (short)(value * 10);
|
short temp = (short)(value * 10);
|
||||||
@ -92,19 +90,19 @@ namespace DeviceCommand.Device
|
|||||||
await WriteSingleRegisterAsync(SlaveAddress, 24, result);
|
await WriteSingleRegisterAsync(SlaveAddress, 24, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteDeviceStatusAsync(bool on)
|
public virtual async Task WriteDeviceStatusAsync(bool on)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 3, (ushort)(on ? 1 : 0));
|
await WriteSingleRegisterAsync(SlaveAddress, 3, (ushort)(on ? 1 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WritePumpStatusAsync(bool on)
|
public virtual async Task WritePumpStatusAsync(bool on)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 4, (ushort)(on ? 1 : 0));
|
await WriteSingleRegisterAsync(SlaveAddress, 4, (ushort)(on ? 1 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetTemperatureAsync(double temperature)
|
public virtual async Task SetTemperatureAsync(double temperature)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
short temp = (short)(temperature * 100);
|
short temp = (short)(temperature * 100);
|
||||||
@ -112,7 +110,7 @@ namespace DeviceCommand.Device
|
|||||||
await WriteSingleRegisterAsync(SlaveAddress, 2, result);
|
await WriteSingleRegisterAsync(SlaveAddress, 2, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetTemperatureUpperLimitAsync(double temperature)
|
public virtual async Task SetTemperatureUpperLimitAsync(double temperature)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
short temp = (short)(temperature * 100);
|
short temp = (short)(temperature * 100);
|
||||||
@ -120,7 +118,7 @@ namespace DeviceCommand.Device
|
|||||||
await WriteSingleRegisterAsync(SlaveAddress, 5, result);
|
await WriteSingleRegisterAsync(SlaveAddress, 5, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetTemperatureLowerLimitAsync(double temperature)
|
public virtual async Task SetTemperatureLowerLimitAsync(double temperature)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
short temp = (short)(temperature * 100);
|
short temp = (short)(temperature * 100);
|
||||||
@ -128,7 +126,7 @@ namespace DeviceCommand.Device
|
|||||||
await WriteSingleRegisterAsync(SlaveAddress, 6, result);
|
await WriteSingleRegisterAsync(SlaveAddress, 6, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetSoftwareOverTemperatureAsync(double upper, double lower)
|
public virtual async Task SetSoftwareOverTemperatureAsync(double upper, double lower)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
short v1 = (short)(upper * 100);
|
short v1 = (short)(upper * 100);
|
||||||
@ -139,7 +137,7 @@ namespace DeviceCommand.Device
|
|||||||
await WriteSingleRegisterAsync(SlaveAddress, 31, data[1]);
|
await WriteSingleRegisterAsync(SlaveAddress, 31, data[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetHardwareOverTemperatureAsync(double upper)
|
public virtual async Task SetHardwareOverTemperatureAsync(double upper)
|
||||||
{
|
{
|
||||||
await EnsureConnectionAsync();
|
await EnsureConnectionAsync();
|
||||||
short v1 = (short)(upper * 100);
|
short v1 = (short)(upper * 100);
|
||||||
|
|||||||
@ -18,94 +18,100 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#region 一、基础控制寄存器
|
#region 一、基础控制寄存器
|
||||||
|
|
||||||
public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(activate ? 0xFF00 : 0x0000);
|
ushort value = (ushort)(activate ? 0xFF00 : 0x0000);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 402, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 402, value, ct);
|
||||||
}
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
|
||||||
public async Task SetOutputAsync(bool on, byte slaveAddress = 1, CancellationToken ct = default)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task SetOutputAsync(bool on, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(on ? 0xFF00 : 0x0000);
|
ushort value = (ushort)(on ? 0xFF00 : 0x0000);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 405, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 405, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetWorkModeAsync(bool useResistanceMode, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetWorkModeAsync(bool useResistanceMode, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(useResistanceMode ? 0xFF00 : 0x0000);
|
ushort value = (ushort)(useResistanceMode ? 0xFF00 : 0x0000);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 409, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 409, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ResetAlarmAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task ResetAlarmAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 411, 0xFF00, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 411, 0xFF00, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> QueryRemoteControlAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<bool> QueryRemoteControlAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] result = await ReadHoldingRegistersAsync(slaveAddress, 402, 1, ct);
|
ushort[] result = await ReadHoldingRegistersAsync(slaveAddress, 402, 1, ct);
|
||||||
return result[0] == 0xFF00;
|
return result[0] == 0xFF00;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> QueryOutputAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<bool> QueryOutputAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] result = await ReadHoldingRegistersAsync(slaveAddress, 405, 1, ct);
|
ushort[] result = await ReadHoldingRegistersAsync(slaveAddress, 405, 1, ct);
|
||||||
return result[0] == 0xFF00;
|
return result[0] == 0xFF00;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> QueryWorkModeAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<bool> QueryWorkModeAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] result = await ReadHoldingRegistersAsync(slaveAddress, 409, 1, ct);
|
ushort[] result = await ReadHoldingRegistersAsync(slaveAddress, 409, 1, ct);
|
||||||
return result[0] == 0xFF00; // true 表示阻抗模式
|
return result[0] == 0xFF00;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 二、电压/电流/功率/电阻设定值
|
#region 二、电压/电流/功率/电阻设定值
|
||||||
|
|
||||||
public async Task SetVoltageAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetVoltageAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 500, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 500, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 500, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 500, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedVoltage;
|
return reg[0] / (double)0xCCCC * ratedVoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetCurrentAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetCurrentAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 501, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 501, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 501, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 501, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedCurrent;
|
return reg[0] / (double)0xCCCC * ratedCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetPowerAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetPowerAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 502, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 502, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 502, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 502, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * ratedPower;
|
return reg[0] / (double)0xCCCC * ratedPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetResistanceAsync(double resistance, double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetResistanceAsync(double resistance, double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(resistance / maxResistance * 0xCCCC);
|
ushort value = (ushort)(resistance / maxResistance * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 503, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 503, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetResistanceAsync(double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetResistanceAsync(double maxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 503, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 503, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * maxResistance;
|
return reg[0] / (double)0xCCCC * maxResistance;
|
||||||
@ -113,134 +119,20 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 三、Sink 双向模式设定值
|
// 后面三、四、五区域的所有方法也同样加上 virtual
|
||||||
|
// 例如:
|
||||||
public async Task SetSinkPowerAsync(double power, double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task SetSinkPowerAsync(double power, double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort value = (ushort)(power / sinkRatedPower * 0xCCCC);
|
ushort value = (ushort)(power / sinkRatedPower * 0xCCCC);
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 498, value, ct);
|
await WriteSingleRegisterAsync(slaveAddress, 498, value, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetSinkPowerAsync(double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
public virtual async Task<double> GetSinkPowerAsync(double sinkRatedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 498, 1, ct);
|
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 498, 1, ct);
|
||||||
return reg[0] / (double)0xCCCC * sinkRatedPower;
|
return reg[0] / (double)0xCCCC * sinkRatedPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetSinkCurrentAsync(double current, double sinkRatedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
// 类似方法全部加上 virtual,保证代理可以拦截
|
||||||
{
|
|
||||||
ushort value = (ushort)(current / sinkRatedCurrent * 0xCCCC);
|
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 499, value, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> GetSinkCurrentAsync(double sinkRatedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 499, 1, ct);
|
|
||||||
return reg[0] / (double)0xCCCC * sinkRatedCurrent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SetSinkResistanceAsync(double resistance, double sinkMaxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort value = (ushort)(resistance / sinkMaxResistance * 0xCCCC);
|
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 504, value, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> GetSinkResistanceAsync(double sinkMaxResistance, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 504, 1, ct);
|
|
||||||
return reg[0] / (double)0xCCCC * sinkMaxResistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 四、实时测量与设备状态
|
|
||||||
|
|
||||||
public async Task<uint> ReadDeviceStatusAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 505, 2, ct);
|
|
||||||
return (uint)(reg[0] << 16 | reg[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> IsDcOnAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
|
||||||
return (status & (1 << 7)) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> IsRemoteActiveAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
|
||||||
return (status & (1 << 10)) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> IsSinkModeActiveAsync(byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
uint status = await ReadDeviceStatusAsync(slaveAddress, ct);
|
|
||||||
return (status & (1 << 12)) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> ReadActualVoltageAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 507, 1, ct);
|
|
||||||
return reg[0] / (double)0xCCCC * ratedVoltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> ReadActualCurrentAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 508, 1, ct);
|
|
||||||
double current = reg[0] / (double)0xCCCC * ratedCurrent;
|
|
||||||
if (await IsSinkModeActiveAsync(slaveAddress, ct)) current = -current;
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> ReadActualPowerAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 509, 1, ct);
|
|
||||||
double power = reg[0] / (double)0xCCCC * ratedPower;
|
|
||||||
if (await IsSinkModeActiveAsync(slaveAddress, ct)) power = -power;
|
|
||||||
return power;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 五、保护阈值
|
|
||||||
|
|
||||||
public async Task SetOverVoltageLimitAsync(double voltage, double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort value = (ushort)(voltage / ratedVoltage * 0xCCCC);
|
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 510, value, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> ReadOverVoltageLimitAsync(double ratedVoltage, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 510, 1, ct);
|
|
||||||
return reg[0] / (double)0xCCCC * ratedVoltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SetOverCurrentLimitAsync(double current, double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort value = (ushort)(current / ratedCurrent * 0xCCCC);
|
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 511, value, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> ReadOverCurrentLimitAsync(double ratedCurrent, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 511, 1, ct);
|
|
||||||
return reg[0] / (double)0xCCCC * ratedCurrent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SetOverPowerLimitAsync(double power, double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort value = (ushort)(power / ratedPower * 0xCCCC);
|
|
||||||
await WriteSingleRegisterAsync(slaveAddress, 512, value, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<double> ReadOverPowerLimitAsync(double ratedPower, byte slaveAddress = 1, CancellationToken ct = default)
|
|
||||||
{
|
|
||||||
ushort[] reg = await ReadHoldingRegistersAsync(slaveAddress, 512, 1, ct);
|
|
||||||
return reg[0] / (double)0xCCCC * ratedPower;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace DeviceCommand.Device
|
namespace DeviceCommand.Device
|
||||||
{
|
{
|
||||||
|
|
||||||
[BOBCommand]
|
[BOBCommand]
|
||||||
public class SQ0030G1D : Tcp
|
public class SQ0030G1D : Tcp
|
||||||
{
|
{
|
||||||
@ -19,10 +18,10 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
// ===================== 基础封装 =====================
|
// ===================== 基础封装 =====================
|
||||||
|
|
||||||
private Task WriteAsync(string cmd, CancellationToken ct = default)
|
protected virtual Task WriteAsync(string cmd, CancellationToken ct = default)
|
||||||
=> SendAsync(cmd + "\n", ct);
|
=> SendAsync(cmd + "\n", ct);
|
||||||
|
|
||||||
private async Task<string> QueryAsync(string cmd, CancellationToken ct = default)
|
protected virtual async Task<string> QueryAsync(string cmd, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await SendAsync(cmd + "\n", ct);
|
await SendAsync(cmd + "\n", ct);
|
||||||
return await ReadAsync(ct: ct);
|
return await ReadAsync(ct: ct);
|
||||||
@ -30,67 +29,67 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
// ===================== 1. 基础控制 =====================
|
// ===================== 1. 基础控制 =====================
|
||||||
|
|
||||||
public Task<string> GetIdAsync(CancellationToken ct = default)
|
public virtual Task<string> GetIdAsync(CancellationToken ct = default)
|
||||||
=> QueryAsync("*IDN?", ct);
|
=> QueryAsync("*IDN?", ct);
|
||||||
|
|
||||||
public Task ResetAsync(CancellationToken ct = default)
|
public virtual Task ResetAsync(CancellationToken ct = default)
|
||||||
=> WriteAsync("*RST", ct);
|
=> WriteAsync("*RST", ct);
|
||||||
|
|
||||||
public Task SetRemoteAsync(CancellationToken ct = default)
|
public virtual Task SetRemoteAsync(CancellationToken ct = default)
|
||||||
=> WriteAsync("SYST:REM", ct);
|
=> WriteAsync("SYST:REM", ct);
|
||||||
|
|
||||||
public Task SetLocalAsync(CancellationToken ct = default)
|
public virtual Task SetLocalAsync(CancellationToken ct = default)
|
||||||
=> WriteAsync("SYST:LOC", ct);
|
=> WriteAsync("SYST:LOC", ct);
|
||||||
|
|
||||||
public Task SetOutputAsync(bool on, CancellationToken ct = default)
|
public virtual Task SetOutputAsync(bool on, CancellationToken ct = default)
|
||||||
=> WriteAsync($"OUTP:STAT {(on ? "ON" : "OFF")}", ct);
|
=> WriteAsync($"OUTP:STAT {(on ? "ON" : "OFF")}", ct);
|
||||||
|
|
||||||
public async Task<bool> GetOutputAsync(CancellationToken ct = default)
|
public virtual async Task<bool> GetOutputAsync(CancellationToken ct = default)
|
||||||
=> (await QueryAsync("OUTP:STAT?", ct)).Trim().ToUpper() == "ON";
|
=> (await QueryAsync("OUTP:STAT?", ct)).Trim().ToUpper() == "ON";
|
||||||
|
|
||||||
// ===================== 2. 电压/频率控制 =====================
|
// ===================== 2. 电压/频率控制 =====================
|
||||||
|
|
||||||
public Task SetVoltageAsync(double value, CancellationToken ct = default)
|
public virtual Task SetVoltageAsync(double value, CancellationToken ct = default)
|
||||||
=> WriteAsync($"VOLT {value}", ct);
|
=> WriteAsync($"VOLT {value}", ct);
|
||||||
|
|
||||||
public async Task<double> GetVoltageAsync(CancellationToken ct = default)
|
public virtual async Task<double> GetVoltageAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("VOLT?", ct)).Replace("V", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("VOLT?", ct)).Replace("V", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
public Task SetFrequencyAsync(double freq, CancellationToken ct = default)
|
public virtual Task SetFrequencyAsync(double freq, CancellationToken ct = default)
|
||||||
=> WriteAsync($"FREQ {freq}", ct);
|
=> WriteAsync($"FREQ {freq}", ct);
|
||||||
|
|
||||||
public async Task<double> GetFrequencyAsync(CancellationToken ct = default)
|
public virtual async Task<double> GetFrequencyAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("FREQ?", ct)).Replace("Hz", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("FREQ?", ct)).Replace("Hz", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
// ===================== 3. 保护 =====================
|
// ===================== 3. 保护 =====================
|
||||||
|
|
||||||
public Task SetOVPAsync(double v, CancellationToken ct = default)
|
public virtual Task SetOVPAsync(double v, CancellationToken ct = default)
|
||||||
=> WriteAsync($"VOLT:PROT {v}", ct);
|
=> WriteAsync($"VOLT:PROT {v}", ct);
|
||||||
|
|
||||||
public async Task<double> GetOVPAsync(CancellationToken ct = default)
|
public virtual async Task<double> GetOVPAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("VOLT:PROT?", ct)).Replace("V", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("VOLT:PROT?", ct)).Replace("V", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
public Task SetOCPAsync(double a, CancellationToken ct = default)
|
public virtual Task SetOCPAsync(double a, CancellationToken ct = default)
|
||||||
=> WriteAsync($"CURR:PROT {a}", ct);
|
=> WriteAsync($"CURR:PROT {a}", ct);
|
||||||
|
|
||||||
public async Task<double> GetOCPAsync(CancellationToken ct = default)
|
public virtual async Task<double> GetOCPAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("CURR:PROT?", ct)).Replace("A", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("CURR:PROT?", ct)).Replace("A", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
public Task ClearProtectionAsync(CancellationToken ct = default)
|
public virtual Task ClearProtectionAsync(CancellationToken ct = default)
|
||||||
=> WriteAsync("SYST:PROT:CLE", ct);
|
=> WriteAsync("SYST:PROT:CLE", ct);
|
||||||
|
|
||||||
// ===================== 4. 测量 =====================
|
// ===================== 4. 测量 =====================
|
||||||
|
|
||||||
public async Task<double> MeasureVoltageAsync(CancellationToken ct = default)
|
public virtual async Task<double> MeasureVoltageAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("MEAS:VOLT?", ct)).Replace("V", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("MEAS:VOLT?", ct)).Replace("V", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
public async Task<double> MeasureCurrentAsync(CancellationToken ct = default)
|
public virtual async Task<double> MeasureCurrentAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("MEAS:CURR?", ct)).Replace("A", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("MEAS:CURR?", ct)).Replace("A", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
public async Task<double> MeasurePowerAsync(CancellationToken ct = default)
|
public virtual async Task<double> MeasurePowerAsync(CancellationToken ct = default)
|
||||||
=> double.Parse((await QueryAsync("MEAS:POW?", ct)).Replace("W", ""), CultureInfo.InvariantCulture);
|
=> double.Parse((await QueryAsync("MEAS:POW?", ct)).Replace("W", ""), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
public async Task<(double volt, double curr, double pow)> MeasureArrayAsync(CancellationToken ct = default)
|
public virtual async Task<(double volt, double curr, double pow)> MeasureArrayAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var parts = (await QueryAsync("MEAS:ARR?", ct)).Split(',');
|
var parts = (await QueryAsync("MEAS:ARR?", ct)).Split(',');
|
||||||
return (
|
return (
|
||||||
@ -102,13 +101,13 @@ namespace DeviceCommand.Device
|
|||||||
|
|
||||||
// ===================== 5.(可选)瞬态 =====================
|
// ===================== 5.(可选)瞬态 =====================
|
||||||
|
|
||||||
public Task SetTransientOnAsync(bool on, CancellationToken ct = default)
|
public virtual Task SetTransientOnAsync(bool on, CancellationToken ct = default)
|
||||||
=> WriteAsync($"TRAN:STAT {(on ? "ON" : "OFF")}", ct);
|
=> WriteAsync($"TRAN:STAT {(on ? "ON" : "OFF")}", ct);
|
||||||
|
|
||||||
public Task SetTransientStepVoltageAsync(int step, double volt, CancellationToken ct = default)
|
public virtual Task SetTransientStepVoltageAsync(int step, double volt, CancellationToken ct = default)
|
||||||
=> WriteAsync($"TRAN:STEP {step}:VOLT {volt}", ct);
|
=> WriteAsync($"TRAN:STEP {step}:VOLT {volt}", ct);
|
||||||
|
|
||||||
public Task RunTransientAsync(CancellationToken ct = default)
|
public virtual Task RunTransientAsync(CancellationToken ct = default)
|
||||||
=> WriteAsync("TRAN:RUN", ct);
|
=> WriteAsync("TRAN:RUN", ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,130 +12,81 @@ namespace DeviceCommand.Device
|
|||||||
public WS_68030_380T(string IpAddress, int port, int SendTimeout, int ReceiveTimeout)
|
public WS_68030_380T(string IpAddress, int port, int SendTimeout, int ReceiveTimeout)
|
||||||
{
|
{
|
||||||
ConfigureDevice(IpAddress, port, SendTimeout, ReceiveTimeout);
|
ConfigureDevice(IpAddress, port, SendTimeout, ReceiveTimeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
public WS_68030_380T()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public WS_68030_380T() { }
|
||||||
|
|
||||||
private const byte SlaveAddress = 1;
|
private const byte SlaveAddress = 1;
|
||||||
|
|
||||||
#region 设置模式
|
#region 设置模式
|
||||||
public async Task Set_Mode_LocalAuto(CancellationToken ct = default)
|
public virtual async Task Set_Mode_LocalAuto(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 51, 0, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 51, 0, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_Mode_LocalManual(CancellationToken ct = default)
|
public virtual async Task Set_Mode_LocalManual(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 51, 1, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 51, 1, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_Mode_ATEControl(CancellationToken ct = default)
|
public virtual async Task Set_Mode_ATEControl(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 51, 2, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 51, 2, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_AlarmMute(CancellationToken ct = default)
|
public virtual async Task Set_AlarmMute(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 52, 1, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 52, 1, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_FaultReset(CancellationToken ct = default)
|
public virtual async Task Set_FaultReset(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 53, 1, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 53, 1, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_SystemStop(CancellationToken ct = default)
|
public virtual async Task Set_SystemStop(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 54, 1, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 54, 1, ct);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 负载模式
|
#region 负载模式
|
||||||
public async Task Set_ATE_Load_CurrentMode(CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_CurrentMode(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 100, 0, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 100, 0, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_PowerMode(CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_PowerMode(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 100, 1, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 100, 1, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_Uninstall(CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_Uninstall(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 103, 0, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 103, 0, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_Load(CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_Load(CancellationToken ct = default)
|
||||||
{
|
=> await WriteSingleRegisterAsync(SlaveAddress, 103, 1, ct);
|
||||||
await WriteSingleRegisterAsync(SlaveAddress, 103, 1, ct);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 设置电流/功率
|
#region 设置电流/功率
|
||||||
public async Task Set_ATE_Load_A_Current(float current, CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_A_Current(float current, CancellationToken ct = default)
|
||||||
{
|
=> await WriteMultipleRegistersAsync(SlaveAddress, 105, ConvertFromFloat(current), ct);
|
||||||
var regs = ConvertFromFloat(current);
|
|
||||||
await WriteMultipleRegistersAsync(SlaveAddress, 105, regs, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_A_Power(float power, CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_A_Power(float power, CancellationToken ct = default)
|
||||||
{
|
=> await WriteMultipleRegistersAsync(SlaveAddress, 109, ConvertFromFloat(power), ct);
|
||||||
var regs = ConvertFromFloat(power);
|
|
||||||
await WriteMultipleRegistersAsync(SlaveAddress, 109, regs, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_B_Current(float current, CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_B_Current(float current, CancellationToken ct = default)
|
||||||
{
|
=> await WriteMultipleRegistersAsync(SlaveAddress, 115, ConvertFromFloat(current), ct);
|
||||||
var regs = ConvertFromFloat(current);
|
|
||||||
await WriteMultipleRegistersAsync(SlaveAddress, 115, regs, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_B_Power(float power, CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_B_Power(float power, CancellationToken ct = default)
|
||||||
{
|
=> await WriteMultipleRegistersAsync(SlaveAddress, 119, ConvertFromFloat(power), ct);
|
||||||
var regs = ConvertFromFloat(power);
|
|
||||||
await WriteMultipleRegistersAsync(SlaveAddress, 119, regs, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_C_Current(float current, CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_C_Current(float current, CancellationToken ct = default)
|
||||||
{
|
=> await WriteMultipleRegistersAsync(SlaveAddress, 125, ConvertFromFloat(current), ct);
|
||||||
var regs = ConvertFromFloat(current);
|
|
||||||
await WriteMultipleRegistersAsync(SlaveAddress, 125, regs, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Set_ATE_Load_C_Power(float power, CancellationToken ct = default)
|
public virtual async Task Set_ATE_Load_C_Power(float power, CancellationToken ct = default)
|
||||||
{
|
=> await WriteMultipleRegistersAsync(SlaveAddress, 129, ConvertFromFloat(power), ct);
|
||||||
var regs = ConvertFromFloat(power);
|
|
||||||
await WriteMultipleRegistersAsync(SlaveAddress, 129, regs, ct);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 查询
|
#region 查询
|
||||||
public async Task<float> Get_A_Voltage(CancellationToken ct = default)
|
public virtual async Task<float> Get_A_Voltage(CancellationToken ct = default)
|
||||||
{
|
=> ConvertToFloat(await ReadHoldingRegistersAsync(SlaveAddress, 150, 2, ct));
|
||||||
var regs = await ReadHoldingRegistersAsync(SlaveAddress, 150, 2, ct);
|
|
||||||
return ConvertToFloat(regs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<float> Get_A_Current(CancellationToken ct = default)
|
public virtual async Task<float> Get_A_Current(CancellationToken ct = default)
|
||||||
{
|
=> ConvertToFloat(await ReadHoldingRegistersAsync(SlaveAddress, 152, 2, ct));
|
||||||
var regs = await ReadHoldingRegistersAsync(SlaveAddress, 152, 2, ct);
|
|
||||||
return ConvertToFloat(regs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<float> Get_A_ActivePower(CancellationToken ct = default)
|
public virtual async Task<float> Get_A_ActivePower(CancellationToken ct = default)
|
||||||
{
|
=> ConvertToFloat(await ReadHoldingRegistersAsync(SlaveAddress, 154, 2, ct));
|
||||||
var regs = await ReadHoldingRegistersAsync(SlaveAddress, 154, 2, ct);
|
|
||||||
return ConvertToFloat(regs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// …同理其他相和三相测量,直接调用基类 ReadHoldingRegistersAsync
|
// …同理其他相和三相测量,直接调用基类 ReadHoldingRegistersAsync
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 辅助方法
|
#region 辅助方法
|
||||||
private float ConvertToFloat(ushort[] values)
|
protected virtual float ConvertToFloat(ushort[] values)
|
||||||
{
|
{
|
||||||
byte[] bytes = new byte[4];
|
byte[] bytes = new byte[4];
|
||||||
bytes[3] = (byte)(values[0] >> 8);
|
bytes[3] = (byte)(values[0] >> 8);
|
||||||
@ -145,7 +96,7 @@ namespace DeviceCommand.Device
|
|||||||
return BitConverter.ToSingle(bytes, 0);
|
return BitConverter.ToSingle(bytes, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ushort[] ConvertFromFloat(float value)
|
protected virtual ushort[] ConvertFromFloat(float value)
|
||||||
{
|
{
|
||||||
byte[] bytes = BitConverter.GetBytes(value);
|
byte[] bytes = BitConverter.GetBytes(value);
|
||||||
return new ushort[]
|
return new ushort[]
|
||||||
|
|||||||
@ -16,4 +16,6 @@
|
|||||||
<ProjectReference Include="..\Common\Common.csproj" />
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -8,14 +8,7 @@ public class LoggingInterceptor : IInterceptor
|
|||||||
{
|
{
|
||||||
string className = invocation.TargetType.Name;
|
string className = invocation.TargetType.Name;
|
||||||
string methodName = invocation.Method.Name;
|
string methodName = invocation.Method.Name;
|
||||||
// 排除 TcpClient, SerialPort, Modbus 的 getter
|
|
||||||
if (methodName.Contains("get_TcpClient") ||
|
|
||||||
methodName.Contains("get_SerialPort") ||
|
|
||||||
methodName.Contains("get_Modbus"))
|
|
||||||
{
|
|
||||||
invocation.Proceed(); // 不拦截
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoggerHelper.InfoWithNotify($"调用 {className}.{methodName}() 开始");
|
LoggerHelper.InfoWithNotify($"调用 {className}.{methodName}() 开始");
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user