BOB参数命名优化
This commit is contained in:
parent
b16533be6a
commit
b37d1c1056
@ -275,7 +275,7 @@ namespace BOB.ViewModels
|
||||
!t.IsNested &&
|
||||
(t.IsClass || t.IsValueType) &&
|
||||
(!t.IsAbstract || t.IsSealed) &&
|
||||
t.GetCustomAttribute<ATSCommandAttribute>() != null);
|
||||
t.GetCustomAttribute<BOBCommandAttribute>() != null);
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
|
||||
@ -1,19 +1,12 @@
|
||||
using BOB.Models;
|
||||
using BOB.Views;
|
||||
using Common.PubEvent;
|
||||
using Common.PubEvents;
|
||||
using Logger;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
@ -92,6 +85,7 @@ namespace BOB.ViewModels
|
||||
public ICommand NewCommand { get; set; }
|
||||
public ICommand SetDefaultCommand { get; set; }
|
||||
public ICommand LoadCommand { get; set; }
|
||||
public ICommand NavigateOneCommand { get; set; }
|
||||
#endregion
|
||||
|
||||
private IEventAggregator _eventAggregator;
|
||||
@ -102,7 +96,7 @@ namespace BOB.ViewModels
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
_globalVariables = globalVariables;
|
||||
_stepRunning=stepRunning;
|
||||
_stepRunning =stepRunning;
|
||||
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
|
||||
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
|
||||
MaximizeCommand = new DelegateCommand<Window>(MaximizeWindow);
|
||||
@ -119,6 +113,7 @@ namespace BOB.ViewModels
|
||||
LoadCommand = new DelegateCommand(Load);
|
||||
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
|
||||
}
|
||||
|
||||
|
||||
private void UpdateRunIcon(string obj)
|
||||
{
|
||||
|
||||
@ -38,9 +38,6 @@
|
||||
Margin="16"
|
||||
Foreground="{DynamicResource PrimaryHueMidBrush}" />
|
||||
<Separator Margin="0,0,0,8" />
|
||||
<Button Content="首页"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Margin="8" />
|
||||
<Button Content="系统设置"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Margin="8" />
|
||||
@ -50,9 +47,6 @@
|
||||
<Button Content="更新信息"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Margin="8" />
|
||||
<Button Content="关于"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Margin="8" />
|
||||
</StackPanel>
|
||||
</materialDesign:DrawerHost.LeftDrawerContent>
|
||||
<Grid>
|
||||
@ -244,18 +238,19 @@
|
||||
<!-- 主内容区 -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="454*" />
|
||||
<ColumnDefinition Width="29*" />
|
||||
<ColumnDefinition Width="424*" />
|
||||
<ColumnDefinition Width="91*" />
|
||||
<ColumnDefinition Width="57*" />
|
||||
<ColumnDefinition Width="1319*" />
|
||||
<ColumnDefinition Width="1318*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentControl prism:RegionManager.RegionName="ShellViewManager"
|
||||
Grid.ColumnSpan="4" />
|
||||
Grid.ColumnSpan="5" />
|
||||
<Border x:Name="Overlay"
|
||||
Background="#40000000"
|
||||
Visibility="Collapsed"
|
||||
Panel.ZIndex="10"
|
||||
Grid.ColumnSpan="4" />
|
||||
Grid.ColumnSpan="5" />
|
||||
</Grid>
|
||||
</materialDesign:DialogHost>
|
||||
</Grid>
|
||||
|
||||
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandApplication
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandArray
|
||||
{
|
||||
#region 数组操作
|
||||
|
||||
@ -18,7 +18,7 @@ namespace Command
|
||||
NotEqual
|
||||
}
|
||||
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandMath
|
||||
{
|
||||
#region 返回值是Double类型数据
|
||||
|
||||
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandRadixChange
|
||||
{
|
||||
#region 进制转换
|
||||
|
||||
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandStringProcessing
|
||||
{
|
||||
///<summary>
|
||||
|
||||
@ -9,7 +9,7 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandSystem
|
||||
{
|
||||
#region 类型转换
|
||||
|
||||
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace Command
|
||||
{
|
||||
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class CommandTime
|
||||
{
|
||||
#region 时间处理
|
||||
|
||||
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Command
|
||||
{
|
||||
[ATSCommand]
|
||||
[BOBCommand]
|
||||
public static class Delay
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -10,7 +10,7 @@ namespace Common.Attributes
|
||||
/// 标记可加载到指令集中的类或方法
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class ATSCommandAttribute : Attribute
|
||||
public sealed class BOBCommandAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 指令描述(用于工具提示)
|
||||
@ -22,9 +22,9 @@ namespace Common.Attributes
|
||||
/// </summary>
|
||||
public string Category { get; set; } = "默认分类";
|
||||
|
||||
public ATSCommandAttribute() { }
|
||||
public BOBCommandAttribute() { }
|
||||
|
||||
public ATSCommandAttribute(string description)
|
||||
public BOBCommandAttribute(string description)
|
||||
{
|
||||
Description = description;
|
||||
}
|
||||
@ -22,14 +22,9 @@ namespace DeviceCommand.Base
|
||||
|
||||
private readonly SemaphoreSlim _commLock = new(1, 1);
|
||||
|
||||
public void ConfigureDevice(
|
||||
string portName,
|
||||
int baudRate,
|
||||
int dataBits = 8,
|
||||
StopBits stopBits = StopBits.One,
|
||||
Parity parity = Parity.None,
|
||||
int readTimeout = 3000,
|
||||
int writeTimeout = 3000)
|
||||
public void ConfigureDevice(string portName, int baudRate, int dataBits = 8,
|
||||
StopBits stopBits = StopBits.One, Parity parity = Parity.None,
|
||||
int readTimeout = 3000, int writeTimeout = 3000)
|
||||
{
|
||||
PortName = portName;
|
||||
BaudRate = baudRate;
|
||||
|
||||
@ -61,11 +61,7 @@ namespace DeviceCommand.Base
|
||||
await _commLock.WaitAsync(ct);
|
||||
try
|
||||
{
|
||||
var sendTask = Modbus.WriteSingleRegisterAsync(slaveAddress, registerAddress, value).WaitAsync(ct);
|
||||
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
|
||||
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
|
||||
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP写单寄存器超时");
|
||||
await sendTask;
|
||||
await Modbus.WriteSingleRegisterAsync(slaveAddress, registerAddress, value).WaitAsync(TimeSpan.FromMinutes(SendTimeout),ct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -78,11 +74,7 @@ namespace DeviceCommand.Base
|
||||
await _commLock.WaitAsync(ct);
|
||||
try
|
||||
{
|
||||
var sendTask = Modbus.WriteMultipleRegistersAsync(slaveAddress, startAddress, values).WaitAsync(ct);
|
||||
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
|
||||
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
|
||||
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP写多寄存器超时");
|
||||
await sendTask;
|
||||
await Modbus.WriteMultipleRegistersAsync(slaveAddress, startAddress, values).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -95,11 +87,8 @@ namespace DeviceCommand.Base
|
||||
await _commLock.WaitAsync(ct);
|
||||
try
|
||||
{
|
||||
var readTask = Modbus.ReadHoldingRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(ct);
|
||||
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
|
||||
var completedTask = await Task.WhenAny(readTask, timeoutTask);
|
||||
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP读取保持寄存器超时");
|
||||
return await readTask;
|
||||
var result =await Modbus.ReadHoldingRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -112,11 +101,7 @@ namespace DeviceCommand.Base
|
||||
await _commLock.WaitAsync(ct);
|
||||
try
|
||||
{
|
||||
var sendTask = Modbus.WriteSingleCoilAsync(slaveAddress, coilAddress, value).WaitAsync(ct);
|
||||
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
|
||||
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
|
||||
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP写单线圈超时");
|
||||
await sendTask;
|
||||
await Modbus.WriteSingleCoilAsync(slaveAddress, coilAddress, value).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -126,14 +111,11 @@ namespace DeviceCommand.Base
|
||||
|
||||
public async Task<bool[]> ReadCoilsAsync(byte slaveAddress, ushort startAddress, ushort numberOfPoints, CancellationToken ct = default)
|
||||
{
|
||||
await _commLock.WaitAsync(ct);
|
||||
await _commLock.WaitAsync(ct);
|
||||
try
|
||||
{
|
||||
var readTask = Modbus.ReadCoilsAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(ct);
|
||||
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
|
||||
var completedTask = await Task.WhenAny(readTask, timeoutTask);
|
||||
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP读取线圈超时");
|
||||
return await readTask;
|
||||
var result = await Modbus.ReadCoilsAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -146,11 +128,8 @@ namespace DeviceCommand.Base
|
||||
await _commLock.WaitAsync(ct);
|
||||
try
|
||||
{
|
||||
var readTask = Modbus.ReadInputRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(ct);
|
||||
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
|
||||
var completedTask = await Task.WhenAny(readTask, timeoutTask);
|
||||
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP读取输入寄存器超时");
|
||||
return await readTask;
|
||||
var result = await Modbus.ReadInputRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -8,11 +9,13 @@ using System.Threading.Tasks;
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
//是德
|
||||
[BOBCommand]
|
||||
public class E36233A:Tcp
|
||||
{
|
||||
public E36233A(string ipAddress, int port, int sendTimeout = 3000, int receiveTimeout = 3000)
|
||||
public E36233A()
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
#region SCPI 常用命令方法
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,8 +8,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
[BOBCommand]
|
||||
public class EAEL9080:ModbusTcp
|
||||
{
|
||||
public EAEL9080()
|
||||
{
|
||||
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
#region 一、基础控制与远程模式寄存器
|
||||
public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
using System.Threading;
|
||||
@ -6,12 +7,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
[BOBCommand]
|
||||
public class IT6724C : Serial_Port
|
||||
{
|
||||
public IT6724C(string portName, int baudRate, int dataBits = 8, StopBits stopBits = StopBits.One,
|
||||
Parity parity = Parity.None, int readTimeout = 3000, int writeTimeout = 3000)
|
||||
public IT6724C()
|
||||
{
|
||||
ConfigureDevice(portName, baudRate, dataBits, stopBits, parity, readTimeout, writeTimeout);
|
||||
ConfigureDevice("COM1", 9600, 8, StopBits.One, Parity.None, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
|
||||
#region 设置命令
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -6,8 +7,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
[BOBCommand]
|
||||
public class LQ7500_D : ModbusRtu
|
||||
{
|
||||
public LQ7500_D()
|
||||
{
|
||||
ConfigureDevice("COM1", 9600);
|
||||
ConnectAsync();
|
||||
}
|
||||
public byte SlaveAddress { get; set; } = 1; // default slave address
|
||||
|
||||
private static readonly int[] Pow10Table =
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,8 +8,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
[BOBCommand]
|
||||
public class PSB11000: ModbusTcp
|
||||
{
|
||||
public PSB11000()
|
||||
{
|
||||
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
#region 一、基础控制与远程模式寄存器
|
||||
public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
@ -9,8 +10,14 @@ namespace DeviceCommand.Device
|
||||
/// <summary>
|
||||
/// Sequoia SQ0030G1D 控制类(SCPI 指令封装)
|
||||
/// </summary>
|
||||
[BOBCommand]
|
||||
public class SQ0030G1D : Tcp
|
||||
{
|
||||
public SQ0030G1D()
|
||||
{
|
||||
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
#region ========== 通用 SCPI 封装 ==========
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
[BOBCommand]
|
||||
public class WS_68030_380T : ModbusTcp
|
||||
{
|
||||
public WS_68030_380T()
|
||||
{
|
||||
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
private const byte SlaveAddress = 1;
|
||||
|
||||
#region 设置模式
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DeviceCommand.Base;
|
||||
using Common.Attributes;
|
||||
using DeviceCommand.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,7 +8,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DeviceCommand.Device
|
||||
{
|
||||
[BOBCommand]
|
||||
public class ZXKS:ModbusTcp
|
||||
{
|
||||
public ZXKS()
|
||||
{
|
||||
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
|
||||
ConnectAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
@ -12,4 +12,8 @@
|
||||
<PackageReference Include="System.IO.Ports" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common\Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user