BOB参数命名优化

This commit is contained in:
hsc 2025-11-17 11:40:12 +08:00
parent b16533be6a
commit b37d1c1056
23 changed files with 98 additions and 83 deletions

View File

@ -275,7 +275,7 @@ namespace BOB.ViewModels
!t.IsNested && !t.IsNested &&
(t.IsClass || t.IsValueType) && (t.IsClass || t.IsValueType) &&
(!t.IsAbstract || t.IsSealed) && (!t.IsAbstract || t.IsSealed) &&
t.GetCustomAttribute<ATSCommandAttribute>() != null); t.GetCustomAttribute<BOBCommandAttribute>() != null);
foreach (var type in types) foreach (var type in types)
{ {

View File

@ -1,19 +1,12 @@
using BOB.Models; using BOB.Models;
using BOB.Views; using BOB.Views;
using Common.PubEvent; using Common.PubEvent;
using Common.PubEvents;
using Logger; using Logger;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using Microsoft.Win32; using Microsoft.Win32;
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
@ -92,6 +85,7 @@ 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; }
#endregion #endregion
private IEventAggregator _eventAggregator; private IEventAggregator _eventAggregator;
@ -102,7 +96,7 @@ namespace BOB.ViewModels
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_globalVariables = globalVariables; _globalVariables = globalVariables;
_stepRunning=stepRunning; _stepRunning =stepRunning;
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen); LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow); MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
MaximizeCommand = new DelegateCommand<Window>(MaximizeWindow); MaximizeCommand = new DelegateCommand<Window>(MaximizeWindow);
@ -120,6 +114,7 @@ namespace BOB.ViewModels
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon); _eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
} }
private void UpdateRunIcon(string obj) private void UpdateRunIcon(string obj)
{ {
RunIcon= obj switch RunIcon= obj switch

View File

@ -38,9 +38,6 @@
Margin="16" Margin="16"
Foreground="{DynamicResource PrimaryHueMidBrush}" /> Foreground="{DynamicResource PrimaryHueMidBrush}" />
<Separator Margin="0,0,0,8" /> <Separator Margin="0,0,0,8" />
<Button Content="首页"
Style="{StaticResource MaterialDesignFlatButton}"
Margin="8" />
<Button Content="系统设置" <Button Content="系统设置"
Style="{StaticResource MaterialDesignFlatButton}" Style="{StaticResource MaterialDesignFlatButton}"
Margin="8" /> Margin="8" />
@ -50,9 +47,6 @@
<Button Content="更新信息" <Button Content="更新信息"
Style="{StaticResource MaterialDesignFlatButton}" Style="{StaticResource MaterialDesignFlatButton}"
Margin="8" /> Margin="8" />
<Button Content="关于"
Style="{StaticResource MaterialDesignFlatButton}"
Margin="8" />
</StackPanel> </StackPanel>
</materialDesign:DrawerHost.LeftDrawerContent> </materialDesign:DrawerHost.LeftDrawerContent>
<Grid> <Grid>
@ -244,18 +238,19 @@
<!-- 主内容区 --> <!-- 主内容区 -->
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="454*" /> <ColumnDefinition Width="29*" />
<ColumnDefinition Width="424*" />
<ColumnDefinition Width="91*" /> <ColumnDefinition Width="91*" />
<ColumnDefinition Width="57*" /> <ColumnDefinition Width="57*" />
<ColumnDefinition Width="1319*" /> <ColumnDefinition Width="1318*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ContentControl prism:RegionManager.RegionName="ShellViewManager" <ContentControl prism:RegionManager.RegionName="ShellViewManager"
Grid.ColumnSpan="4" /> Grid.ColumnSpan="5" />
<Border x:Name="Overlay" <Border x:Name="Overlay"
Background="#40000000" Background="#40000000"
Visibility="Collapsed" Visibility="Collapsed"
Panel.ZIndex="10" Panel.ZIndex="10"
Grid.ColumnSpan="4" /> Grid.ColumnSpan="5" />
</Grid> </Grid>
</materialDesign:DialogHost> </materialDesign:DialogHost>
</Grid> </Grid>

View File

@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class CommandApplication public static class CommandApplication
{ {
/// <summary> /// <summary>

View File

@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class CommandArray public static class CommandArray
{ {
#region #region

View File

@ -18,7 +18,7 @@ namespace Command
NotEqual NotEqual
} }
[ATSCommand] [BOBCommand]
public static class CommandMath public static class CommandMath
{ {
#region Double类型数据 #region Double类型数据

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class CommandRadixChange public static class CommandRadixChange
{ {
#region #region

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class CommandStringProcessing public static class CommandStringProcessing
{ {
///<summary> ///<summary>

View File

@ -9,7 +9,7 @@ using System.Xml.Linq;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class CommandSystem public static class CommandSystem
{ {
#region #region

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class CommandTime public static class CommandTime
{ {
#region #region

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Command namespace Command
{ {
[ATSCommand] [BOBCommand]
public static class Delay public static class Delay
{ {
/// <summary> /// <summary>

View File

@ -10,7 +10,7 @@ namespace Common.Attributes
/// 标记可加载到指令集中的类或方法 /// 标记可加载到指令集中的类或方法
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class ATSCommandAttribute : Attribute public sealed class BOBCommandAttribute : Attribute
{ {
/// <summary> /// <summary>
/// 指令描述(用于工具提示) /// 指令描述(用于工具提示)
@ -22,9 +22,9 @@ namespace Common.Attributes
/// </summary> /// </summary>
public string Category { get; set; } = "默认分类"; public string Category { get; set; } = "默认分类";
public ATSCommandAttribute() { } public BOBCommandAttribute() { }
public ATSCommandAttribute(string description) public BOBCommandAttribute(string description)
{ {
Description = description; Description = description;
} }

View File

@ -22,14 +22,9 @@ namespace DeviceCommand.Base
private readonly SemaphoreSlim _commLock = new(1, 1); private readonly SemaphoreSlim _commLock = new(1, 1);
public void ConfigureDevice( public void ConfigureDevice(string portName, int baudRate, int dataBits = 8,
string portName, StopBits stopBits = StopBits.One, Parity parity = Parity.None,
int baudRate, int readTimeout = 3000, int writeTimeout = 3000)
int dataBits = 8,
StopBits stopBits = StopBits.One,
Parity parity = Parity.None,
int readTimeout = 3000,
int writeTimeout = 3000)
{ {
PortName = portName; PortName = portName;
BaudRate = baudRate; BaudRate = baudRate;

View File

@ -61,11 +61,7 @@ namespace DeviceCommand.Base
await _commLock.WaitAsync(ct); await _commLock.WaitAsync(ct);
try try
{ {
var sendTask = Modbus.WriteSingleRegisterAsync(slaveAddress, registerAddress, value).WaitAsync(ct); await Modbus.WriteSingleRegisterAsync(slaveAddress, registerAddress, value).WaitAsync(TimeSpan.FromMinutes(SendTimeout),ct);
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP写单寄存器超时");
await sendTask;
} }
finally finally
{ {
@ -78,11 +74,7 @@ namespace DeviceCommand.Base
await _commLock.WaitAsync(ct); await _commLock.WaitAsync(ct);
try try
{ {
var sendTask = Modbus.WriteMultipleRegistersAsync(slaveAddress, startAddress, values).WaitAsync(ct); await Modbus.WriteMultipleRegistersAsync(slaveAddress, startAddress, values).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP写多寄存器超时");
await sendTask;
} }
finally finally
{ {
@ -95,11 +87,8 @@ namespace DeviceCommand.Base
await _commLock.WaitAsync(ct); await _commLock.WaitAsync(ct);
try try
{ {
var readTask = Modbus.ReadHoldingRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(ct); var result =await Modbus.ReadHoldingRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
var timeoutTask = Task.Delay(ReceiveTimeout, ct); return result;
var completedTask = await Task.WhenAny(readTask, timeoutTask);
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP读取保持寄存器超时");
return await readTask;
} }
finally finally
{ {
@ -112,11 +101,7 @@ namespace DeviceCommand.Base
await _commLock.WaitAsync(ct); await _commLock.WaitAsync(ct);
try try
{ {
var sendTask = Modbus.WriteSingleCoilAsync(slaveAddress, coilAddress, value).WaitAsync(ct); await Modbus.WriteSingleCoilAsync(slaveAddress, coilAddress, value).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
var timeoutTask = Task.Delay(ReceiveTimeout, ct);
var completedTask = await Task.WhenAny(sendTask, timeoutTask);
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP写单线圈超时");
await sendTask;
} }
finally finally
{ {
@ -129,11 +114,8 @@ namespace DeviceCommand.Base
await _commLock.WaitAsync(ct); await _commLock.WaitAsync(ct);
try try
{ {
var readTask = Modbus.ReadCoilsAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(ct); var result = await Modbus.ReadCoilsAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
var timeoutTask = Task.Delay(ReceiveTimeout, ct); return result;
var completedTask = await Task.WhenAny(readTask, timeoutTask);
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP读取线圈超时");
return await readTask;
} }
finally finally
{ {
@ -146,11 +128,8 @@ namespace DeviceCommand.Base
await _commLock.WaitAsync(ct); await _commLock.WaitAsync(ct);
try try
{ {
var readTask = Modbus.ReadInputRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(ct); var result = await Modbus.ReadInputRegistersAsync(slaveAddress, startAddress, numberOfPoints).WaitAsync(TimeSpan.FromMinutes(SendTimeout), ct);
var timeoutTask = Task.Delay(ReceiveTimeout, ct); return result;
var completedTask = await Task.WhenAny(readTask, timeoutTask);
if (completedTask == timeoutTask) throw new TimeoutException($"ModbusTCP读取输入寄存器超时");
return await readTask;
} }
finally finally
{ {

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,11 +9,13 @@ using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
//是德 //是德
[BOBCommand]
public class E36233A:Tcp 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 #region SCPI

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,8 +8,14 @@ using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
[BOBCommand]
public class EAEL9080:ModbusTcp public class EAEL9080:ModbusTcp
{ {
public EAEL9080()
{
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
ConnectAsync();
}
#region #region
public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default) public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
{ {

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.IO.Ports; using System.IO.Ports;
using System.Threading; using System.Threading;
@ -6,12 +7,13 @@ using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
[BOBCommand]
public class IT6724C : Serial_Port public class IT6724C : Serial_Port
{ {
public IT6724C(string portName, int baudRate, int dataBits = 8, StopBits stopBits = StopBits.One, public IT6724C()
Parity parity = Parity.None, int readTimeout = 3000, int writeTimeout = 3000)
{ {
ConfigureDevice(portName, baudRate, dataBits, stopBits, parity, readTimeout, writeTimeout); ConfigureDevice("COM1", 9600, 8, StopBits.One, Parity.None, 3000, 3000);
ConnectAsync();
} }
#region #region

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -6,8 +7,14 @@ using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
[BOBCommand]
public class LQ7500_D : ModbusRtu public class LQ7500_D : ModbusRtu
{ {
public LQ7500_D()
{
ConfigureDevice("COM1", 9600);
ConnectAsync();
}
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 =

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,8 +8,14 @@ using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
[BOBCommand]
public class PSB11000: ModbusTcp public class PSB11000: ModbusTcp
{ {
public PSB11000()
{
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
ConnectAsync();
}
#region #region
public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default) public async Task SetRemoteControlAsync(bool activate, byte slaveAddress = 1, CancellationToken ct = default)
{ {

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
@ -9,8 +10,14 @@ namespace DeviceCommand.Device
/// <summary> /// <summary>
/// Sequoia SQ0030G1D 控制类SCPI 指令封装) /// Sequoia SQ0030G1D 控制类SCPI 指令封装)
/// </summary> /// </summary>
[BOBCommand]
public class SQ0030G1D : Tcp public class SQ0030G1D : Tcp
{ {
public SQ0030G1D()
{
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
ConnectAsync();
}
#region ========== SCPI ========== #region ========== SCPI ==========
/// <summary> /// <summary>

View File

@ -1,12 +1,19 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
[BOBCommand]
public class WS_68030_380T : ModbusTcp public class WS_68030_380T : ModbusTcp
{ {
public WS_68030_380T()
{
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
ConnectAsync();
}
private const byte SlaveAddress = 1; private const byte SlaveAddress = 1;
#region #region

View File

@ -1,4 +1,5 @@
using DeviceCommand.Base; using Common.Attributes;
using DeviceCommand.Base;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,7 +8,13 @@ using System.Threading.Tasks;
namespace DeviceCommand.Device namespace DeviceCommand.Device
{ {
[BOBCommand]
public class ZXKS:ModbusTcp public class ZXKS:ModbusTcp
{ {
public ZXKS()
{
ConfigureDevice("127.0.0.1", 502, 3000, 3000);
ConnectAsync();
}
} }
} }

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
@ -12,4 +12,8 @@
<PackageReference Include="System.IO.Ports" Version="10.0.0" /> <PackageReference Include="System.IO.Ports" Version="10.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project> </Project>