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.IsClass || t.IsValueType) &&
(!t.IsAbstract || t.IsSealed) &&
t.GetCustomAttribute<ATSCommandAttribute>() != null);
t.GetCustomAttribute<BOBCommandAttribute>() != null);
foreach (var type in types)
{

View File

@ -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);
@ -120,6 +114,7 @@ namespace BOB.ViewModels
_eventAggregator.GetEvent<UpdateIconEvent>().Subscribe(UpdateRunIcon);
}
private void UpdateRunIcon(string obj)
{
RunIcon= obj switch

View File

@ -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>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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;
}

View File

@ -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;

View File

@ -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
{
@ -129,11 +114,8 @@ namespace DeviceCommand.Base
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
{

View File

@ -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

View File

@ -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)
{

View File

@ -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

View File

@ -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 =

View File

@ -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)
{

View File

@ -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>

View File

@ -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

View File

@ -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();
}
}
}

View File

@ -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>