spaw7000设备命令修改

This commit is contained in:
hsc
2026-07-14 13:22:15 +08:00
parent 3318c720b7
commit 2fe307c142
8 changed files with 214 additions and 127 deletions

View File

@@ -58,108 +58,142 @@ namespace DeviceCommand.Device
#endregion
#region 2. MEASure / NUMeric ()
#region 2. NUMeric ()
/// <summary>
/// 查询指定通道的实时 RMS 电压值 (单位: V)
/// </summary>
/// <param name="channel">通道号 (例如: 1, 2, 3...)</param>
public virtual async Task<string> (int channel, CancellationToken ct = default)
{
string query = string.Format(CultureInfo.InvariantCulture, ":MEASure:NUMeric:VALue? U,{0}{1}", channel, ScpiDelimiter);
// 1. 先配置 ITEM1 为指定通道的电压有效值 (URMS)
string setItem = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:ITEM1 URMS,{0}{1}", channel, ScpiDelimiter);
await SendAsync(setItem, ct);
// 2. 再读取 ITEM1 的值
string query = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:VALue? 1{0}", ScpiDelimiter);
return await WriteReadAsync(query, ScpiDelimiter, ct);
}
/// <summary>
/// 查询指定通道的实时 RMS 电流值 (单位: A)
/// </summary>
/// <param name="channel">通道号 (例如: 1, 2, 3...)</param>
public virtual async Task<string> (int channel, CancellationToken ct = default)
{
string query = string.Format(CultureInfo.InvariantCulture, ":MEASure:NUMeric:VALue? I,{0}{1}", channel, ScpiDelimiter);
// 1. 配置 ITEM1 为指定通道的电流有效值 (IRMS)
string setItem = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:ITEM1 IRMS,{0}{1}", channel, ScpiDelimiter);
await SendAsync(setItem, ct);
// 2. 读取 ITEM1 的值
string query = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:VALue? 1{0}", ScpiDelimiter);
return await WriteReadAsync(query, ScpiDelimiter, ct);
}
/// <summary>
/// 查询指定通道的实时有功功率值 (单位: W)
/// </summary>
/// <param name="channel">通道号 (例如: 1, 2, 3...)</param>
public virtual async Task<string> (int channel, CancellationToken ct = default)
{
string query = string.Format(CultureInfo.InvariantCulture, ":MEASure:NUMeric:VALue? P,{0}{1}", channel, ScpiDelimiter);
// 1. 配置 ITEM1 为指定通道的有功功率 (P)
string setItem = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:ITEM1 P,{0}{1}", channel, ScpiDelimiter);
await SendAsync(setItem, ct);
// 2. 读取 ITEM1 的值
string query = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:VALue? 1{0}", ScpiDelimiter);
return await WriteReadAsync(query, ScpiDelimiter, ct);
}
/// <summary>
/// 查询指定通道的实时频率值 (单位: Hz)
/// </summary>
/// <param name="channel">通道号 (例如: 1, 2, 3...)</param>
public virtual async Task<string> (int channel, CancellationToken ct = default)
{
string query = string.Format(CultureInfo.InvariantCulture, ":MEASure:NUMeric:VALue? FREQuency,{0}{1}", channel, ScpiDelimiter);
// 1. 配置 ITEM1 为指定通道的电压频率 (FU)
string setItem = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:ITEM1 FU,{0}{1}", channel, ScpiDelimiter);
await SendAsync(setItem, ct);
// 2. 读取 ITEM1 的值
string query = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:VALue? 1{0}", ScpiDelimiter);
return await WriteReadAsync(query, ScpiDelimiter, ct);
}
/// <summary>
/// 查询指定通道的功率因数 (Power Factor)
/// </summary>
/// <param name="channel">通道号 (例如: 1, 2, 3...)</param>
public virtual async Task<string> (int channel, CancellationToken ct = default)
{
string query = string.Format(CultureInfo.InvariantCulture, ":MEASure:NUMeric:VALue? PF,{0}{1}", channel, ScpiDelimiter);
return await WriteReadAsync(query, ScpiDelimiter, ct);
}
// 1. 配置 ITEM1 为指定通道的功率因数 (LAMBda)
string setItem = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:ITEM1 LAMBda,{0}{1}", channel, ScpiDelimiter);
await SendAsync(setItem, ct);
/// <summary>
/// 自定义组合参数批量读取接口
/// </summary>
/// <param name="parameter">参数助记符 (如 "U,I,P" 或 "S,Q,LAMBda")</param>
/// <param name="channel">通道号</param>
public virtual async Task<string> (string parameter, int channel, CancellationToken ct = default)
{
string query = string.Format(CultureInfo.InvariantCulture, ":MEASure:NUMeric:VALue? {0},{1}{2}", parameter, channel, ScpiDelimiter);
// 2. 读取 ITEM1 的值
string query = string.Format(CultureInfo.InvariantCulture, ":NUMeric:NORMal:VALue? 1{0}", ScpiDelimiter);
return await WriteReadAsync(query, ScpiDelimiter, ct);
}
#endregion
#region 3. INPut
/// <summary>
/// SPAW7000 电压量程枚举 (单位: V)
/// </summary>
public enum VoltageRange
{
V_15 = 15,
V_30 = 30,
V_60 = 60,
V_100 = 100,
V_150 = 150,
V_300 = 300,
V_600 = 600,
V_1000 = 1000
}
/// <summary>
/// 设置指定通道的电压量程 (例如: 15, 30, 60, 150, 300, 600, 1000)
/// SPAW7000 电流量程枚举 (单位: A)
/// </summary>
public virtual async Task (int channel, double range, CancellationToken ct = default)
public enum CurrentRange
{
string cmd = string.Format(CultureInfo.InvariantCulture, ":INPut:VOLTage:RANGe {0},{1:F1}{2}", channel, range, ScpiDelimiter);
A_1 = 1,
A_2 = 2,
A_5 = 5,
A_10 = 10,
A_20 = 20,
A_50 = 50
}
/// <summary>
/// 设置指定通道的电压量程
/// </summary>
/// <param name="channel">通道号/单元号 (1 - 7)</param>
/// <param name="range">电压量程枚举</param>
/// <param name="ct">取消令牌</param>
public virtual async Task (int channel, VoltageRange range, CancellationToken ct = default)
{
// 正确格式例如: :INPut:VOLTage:RANGe:ELEMent1 300\n
string cmd = string.Format(CultureInfo.InvariantCulture,
":INPut:VOLTage:RANGe:ELEMent{0} {1}{2}",
channel, (int)range, ScpiDelimiter);
await SendAsync(cmd, ct);
}
/// <summary>
/// 设置指定通道的电流量程 (取决于接线单元或传感器输入类型)
/// 设置指定通道的电流量程
/// </summary>
public virtual async Task (int channel, double range, CancellationToken ct = default)
/// <param name="channel">通道号/单元号 (1 - 7)</param>
/// <param name="range">电流量程枚举</param>
/// <param name="ct">取消令牌</param>
public virtual async Task (int channel, CurrentRange range, CancellationToken ct = default)
{
string cmd = string.Format(CultureInfo.InvariantCulture, ":INPut:CURRent:RANGe {0},{1:F3}{2}", channel, range, ScpiDelimiter);
// 正确格式例如: :INPut:CURRent:RANGe:ELEMent1 5\n
string cmd = string.Format(CultureInfo.InvariantCulture,
":INPut:CURRent:RANGe:ELEMent{0} {1}{2}",
channel, (int)range, ScpiDelimiter);
await SendAsync(cmd, ct);
}
/// <summary>
/// 设置通道的耦合模式 (AC, DC, ACDC)
/// </summary>
public virtual async Task (int channel, string mode, CancellationToken ct = default)
{
string modeUpper = mode.ToUpper();
if (modeUpper != "AC" && modeUpper != "DC" && modeUpper != "ACDC")
throw new ArgumentException("耦合模式只能为 AC, DC, 或 ACDC");
string cmd = string.Format(CultureInfo.InvariantCulture, ":INPut:COUPling {0},{1}{2}", channel, modeUpper, ScpiDelimiter);
await SendAsync(cmd, ct);
}
#endregion
#region 4. SYSTem
/// <summary>
/// 14. 查询仪器型号名称
/// </summary>

View File

@@ -2,7 +2,9 @@ using DeviceCommand.Device;
using Prism.Commands;
using Prism.Ioc;
using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using UIShare.GlobalVariable;
using UIShare.ViewModelBase;
@@ -57,29 +59,27 @@ namespace DeviceEditModule.ViewModels
set => SetProperty(ref _channel, value);
}
private double _voltageRange = 300.0;
/// <summary>电压量程V。</summary>
public double VoltageRange
private SPAW7000.VoltageRange _voltageRange = SPAW7000.VoltageRange.V_300;
/// <summary>电压量程枚举。</summary>
public SPAW7000.VoltageRange VoltageRange
{
get => _voltageRange;
set => SetProperty(ref _voltageRange, value);
}
private double _currentRange = 5.0;
/// <summary>电流量程A。</summary>
public double CurrentRange
private SPAW7000.CurrentRange _currentRange = SPAW7000.CurrentRange.A_5;
/// <summary>电流量程枚举。</summary>
public SPAW7000.CurrentRange CurrentRange
{
get => _currentRange;
set => SetProperty(ref _currentRange, value);
}
private string _couplingMode = "DC";
/// <summary>耦合模式AC / DC / ACDC。</summary>
public string CouplingMode
{
get => _couplingMode;
set => SetProperty(ref _couplingMode, value);
}
public SPAW7000.VoltageRange[] VoltageRangeOptions { get; } =
(SPAW7000.VoltageRange[])Enum.GetValues(typeof(SPAW7000.VoltageRange));
public SPAW7000.CurrentRange[] CurrentRangeOptions { get; } =
(SPAW7000.CurrentRange[])Enum.GetValues(typeof(SPAW7000.CurrentRange));
private int _resolution = 6;
/// <summary>显示分辨率5 或 6。</summary>
@@ -162,19 +162,18 @@ namespace DeviceEditModule.ViewModels
#region
public ICommand QueryIdentityCommand { get; }
public ICommand ResetDeviceCommand { get; }
public ICommand QueryAllMeasureCommand { get; }
public ICommand SetVoltageRangeCommand { get; }
public ICommand SetCurrentRangeCommand { get; }
public ICommand SetCouplingModeCommand { get; }
public ICommand SetResolutionCommand { get; }
public ICommand SetBrightnessCommand { get; }
public ICommand SetTouchLockOnCommand { get; }
public ICommand SetTouchLockOffCommand { get; }
public ICommand QueryModelCommand { get; }
public ICommand QuerySerialCommand { get; }
public ICommand QueryStatusByteCommand { get; }
public ICommand QueryIdentityCommand { get; }
public ICommand ResetDeviceCommand { get; }
public ICommand QueryAllMeasureCommand { get; }
public ICommand SetVoltageRangeCommand { get; }
public ICommand SetCurrentRangeCommand { get; }
public ICommand SetResolutionCommand { get; }
public ICommand SetBrightnessCommand { get; }
public ICommand SetTouchLockOnCommand { get; }
public ICommand SetTouchLockOffCommand { get; }
public ICommand QueryModelCommand { get; }
public ICommand QuerySerialCommand { get; }
public ICommand QueryStatusByteCommand { get; }
#endregion
@@ -182,26 +181,34 @@ namespace DeviceEditModule.ViewModels
{
_deviceManager = containerProvider.Resolve<DeviceManager>();
QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.(Ct()))));
ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Ct()); AppendLog("设备已重置"); }));
SetVoltageRangeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Channel, VoltageRange, Ct()); AppendLog($"通道 {Channel} 电压量程已设为 {VoltageRange} V"); }));
SetCurrentRangeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Channel, CurrentRange, Ct()); AppendLog($"通道 {Channel} 电流量程已设为 {CurrentRange} A"); }));
SetCouplingModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Channel, CouplingMode, Ct()); AppendLog($"通道 {Channel} 耦合模式已设为 {CouplingMode}"); }));
SetResolutionCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Resolution, Ct()); AppendLog($"显示分辨率已设为 {Resolution} 位"); }));
SetBrightnessCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Brightness, Ct()); AppendLog($"屏幕亮度已设为 {Brightness}"); }));
SetTouchLockOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(true, Ct()); AppendLog("屏幕触摸已锁定"); }));
QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.(Ct()))));
ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Ct()); AppendLog("设备已重置"); }));
SetVoltageRangeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Channel, VoltageRange, Ct()); AppendLog($"通道 {Channel} 电压量程已设为 {(int)VoltageRange} V"); }));
SetCurrentRangeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Channel, CurrentRange, Ct()); AppendLog($"通道 {Channel} 电流量程已设为 {(int)CurrentRange} A"); }));
SetResolutionCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Resolution, Ct()); AppendLog($"显示分辨率已设为 {Resolution} 位"); }));
SetBrightnessCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(Brightness, Ct()); AppendLog($"屏幕亮度已设为 {Brightness}"); }));
SetTouchLockOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(true, Ct()); AppendLog("屏幕触摸已锁定"); }));
SetTouchLockOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.(false, Ct()); AppendLog("屏幕触摸已解锁"); }));
QueryModelCommand = new DelegateCommand(async () => await Exec(async () => { DeviceModel = await _device!.(Ct()); AppendLog($"型号: {DeviceModel}"); }));
QuerySerialCommand = new DelegateCommand(async () => await Exec(async () => { DeviceSerial = await _device!.(Ct()); AppendLog($"序列号: {DeviceSerial}"); }));
QueryModelCommand = new DelegateCommand(async () => await Exec(async () => { DeviceModel = await _device!.(Ct()); AppendLog($"型号: {DeviceModel}"); }));
QuerySerialCommand = new DelegateCommand(async () => await Exec(async () => { DeviceSerial = await _device!.(Ct()); AppendLog($"序列号: {DeviceSerial}"); }));
QueryStatusByteCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("STB: " + await _device!.(Ct()))));
// 只修改这里:保持你原本的 5 次驱动查询调用不变,仅对读回来的科学计数法进行两位小数格式化
QueryAllMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
{
MeasuredVoltage = await _device!.(Channel, Ct());
MeasuredCurrent = await _device!.(Channel, Ct());
MeasuredPower = await _device!.(Channel, Ct());
MeasuredFrequency = await _device!.(Channel, Ct());
MeasuredPowerFactor = await _device!.(Channel, Ct());
string rawU = await _device!.(Channel, Ct());
string rawI = await _device!.(Channel, Ct());
string rawP = await _device!.(Channel, Ct());
string rawF = await _device!.(Channel, Ct());
string rawPF = await _device!.(Channel, Ct());
// 转换科学计数法格式,如果失败会自动保持原样
MeasuredVoltage = FormatToDecimal(rawU, "F2"); // 电压两位小数
MeasuredCurrent = FormatToDecimal(rawI, "F3"); // 电流通常较小建议保留3位小数
MeasuredPower = FormatToDecimal(rawP, "F2"); // 功率两位小数
MeasuredFrequency = FormatToDecimal(rawF, "F2"); // 频率两位小数
MeasuredPowerFactor = FormatToDecimal(rawPF, "F3"); // 功率因数保留3位小数
AppendLog($"CH{Channel} 测量 → U:{MeasuredVoltage}V I:{MeasuredCurrent}A P:{MeasuredPower}W F:{MeasuredFrequency}Hz PF:{MeasuredPowerFactor}");
}));
@@ -235,8 +242,8 @@ namespace DeviceEditModule.ViewModels
}
}
_device = found;
DeviceName = foundName ?? "SPAW7000 (未找到)";
_device = found;
DeviceName = foundName ?? "SPAW7000 (未找到)";
IsConnected = _device?.IsConnected ?? false;
AppendLog(found != null
@@ -256,6 +263,41 @@ namespace DeviceEditModule.ViewModels
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
/// <summary>
/// 将科学计数法字符串转换为标准小数格式
/// </summary>
private string FormatToDecimal(string rawInput, string decimalFormat = "F2")
{
if (string.IsNullOrWhiteSpace(rawInput))
return "—";
// 去除可能夹杂的命令头,保留数据部分
string cleanInput = CleanResponseHeader(rawInput);
// 解析科学计数法NumberStyles.Any 和 InvariantCulture 是关键)
if (double.TryParse(cleanInput, NumberStyles.Any, CultureInfo.InvariantCulture, out double value))
{
return value.ToString(decimalFormat, CultureInfo.InvariantCulture);
}
return cleanInput;
}
/// <summary>
/// 辅助清洗:剥离可能伴随吐回的命令头或双引号
/// </summary>
private string CleanResponseHeader(string response)
{
if (string.IsNullOrWhiteSpace(response)) return string.Empty;
string result = response.Trim();
if (result.Contains(" "))
{
int lastSpaceIndex = result.LastIndexOf(' ');
result = result.Substring(lastSpaceIndex + 1).Trim();
}
return result.Replace("\"", "").Replace("'", "").Trim();
}
private async Task Exec(Func<Task> action)
{
if (_device == null)
@@ -300,4 +342,4 @@ namespace DeviceEditModule.ViewModels
_cts?.Dispose();
}
}
}
}

View File

@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
mc:Ignorable="d"
prism:ViewModelLocator.AutoWireViewModel="True"
@@ -92,38 +93,44 @@
<ComboBox Width="80" Height="32" Margin="4,0"
SelectedItem="{Binding Channel}"
VerticalContentAlignment="Center" FontSize="12">
<ComboBoxItem Content="1"/>
<ComboBoxItem Content="2"/>
<ComboBoxItem Content="3"/>
<ComboBoxItem Content="4"/>
<sys:Int32>1</sys:Int32>
<sys:Int32>2</sys:Int32>
<sys:Int32>3</sys:Int32>
<sys:Int32>4</sys:Int32>
<sys:Int32>5</sys:Int32>
<sys:Int32>6</sys:Int32>
<sys:Int32>7</sys:Int32>
<sys:Int32>8</sys:Int32>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,4">
<TextBlock Text="电压量程 (V)" Style="{StaticResource ParamLabel}"/>
<TextBox Style="{StaticResource NumInput}"
Text="{Binding VoltageRange, UpdateSourceTrigger=PropertyChanged}"/>
<ComboBox Width="100" Height="32" Margin="4,0"
ItemsSource="{Binding VoltageRangeOptions}"
SelectedItem="{Binding VoltageRange}"
VerticalContentAlignment="Center" FontSize="12"/>
<Button Content="设置" Command="{Binding SetVoltageRangeCommand}"
Style="{StaticResource CmdBtn}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,4">
<TextBlock Text="电流量程 (A)" Style="{StaticResource ParamLabel}"/>
<TextBox Style="{StaticResource NumInput}"
Text="{Binding CurrentRange, UpdateSourceTrigger=PropertyChanged}"/>
<ComboBox Width="100" Height="32" Margin="4,0"
ItemsSource="{Binding CurrentRangeOptions}"
SelectedItem="{Binding CurrentRange}"
VerticalContentAlignment="Center" FontSize="12"/>
<Button Content="设置" Command="{Binding SetCurrentRangeCommand}"
Style="{StaticResource CmdBtn}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,4">
<!--<StackPanel Orientation="Horizontal" Margin="0,4">
<TextBlock Text="耦合模式" Style="{StaticResource ParamLabel}"/>
<ComboBox Width="90" Height="32" Margin="4,0"
SelectedItem="{Binding CouplingMode}"
ItemsSource="{Binding InputMeasureModeOptions}"
VerticalContentAlignment="Center" FontSize="12">
<ComboBoxItem Content="AC"/>
<ComboBoxItem Content="DC"/>
<ComboBoxItem Content="ACDC"/>
</ComboBox>
<Button Content="设置" Command="{Binding SetCouplingModeCommand}"
Style="{StaticResource CmdBtn}"/>
</StackPanel>
</StackPanel>-->
</StackPanel>
</GroupBox>
@@ -136,8 +143,8 @@
<ComboBox Width="80" Height="32" Margin="4,0"
SelectedItem="{Binding Resolution}"
VerticalContentAlignment="Center" FontSize="12">
<ComboBoxItem Content="5"/>
<ComboBoxItem Content="6"/>
<sys:Int32>5</sys:Int32>
<sys:Int32>6</sys:Int32>
</ComboBox>
<Button Content="设置" Command="{Binding SetResolutionCommand}"
Style="{StaticResource CmdBtn}"/>
@@ -179,12 +186,12 @@
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,4">
<TextBlock Text="型号" Style="{StaticResource ParamLabel}"/>
<TextBox Style="{StaticResource MeasureBox}" Width="120"
<TextBox Style="{StaticResource MeasureBox}" Width="281"
Text="{Binding DeviceModel, Mode=OneWay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,4">
<TextBlock Text="序列号" Style="{StaticResource ParamLabel}"/>
<TextBox Style="{StaticResource MeasureBox}" Width="160"
<TextBox Style="{StaticResource MeasureBox}" Width="281"
Text="{Binding DeviceSerial, Mode=OneWay}"/>
</StackPanel>
</StackPanel>

View File

@@ -110,10 +110,6 @@ namespace TestingModule.ViewModels
SubscribeStepCollections();
Program.PropertyChanged += Program_PropertyChanged;
Admin = _globalInfo.IsAdmin;
_eventAggregator.GetEvent<AlarmEvent>().Subscribe(() =>
{
SelectedTabIndex = 1;
});
}
private void SelectionChanged(object parameter)

View File

@@ -96,7 +96,11 @@ namespace UIShare.GlobalVariable
Time = now
});
ValueLimitAlarmHelper.CheckAlarm(scope, signalFingerprint, methodName, physicalValue, _globalInfo);
string MonitorSatus = ValueLimitAlarmHelper.CheckAlarm(scope, signalFingerprint, methodName, physicalValue, _globalInfo);
if(MonitorSatus!=""|| MonitorSatus != "未报警")
{
//_eventAggregator.GetEvent<AlarmEvent>().Publish(canFingerprint, MonitorSatus);
}
}
}
}

View File

@@ -181,7 +181,11 @@ namespace UIShare.GlobalVariable
});
// 同步检查该作用域 ValueLimitList 是否超限
ValueLimitAlarmHelper.CheckAlarm(scope, entry.Fingerprint, entry.MethodName, value, _globalInfo);
string MonitorSatus= ValueLimitAlarmHelper.CheckAlarm(scope, entry.Fingerprint, entry.MethodName, value, _globalInfo);
if (MonitorSatus != "" || MonitorSatus != "未报警")
{
// _eventAggregator.GetEvent<AlarmEvent>().Publish(entry.Fingerprint, MonitorSatus);
}
}
}
catch

View File

@@ -16,26 +16,16 @@ namespace UIShare.GlobalVariable
/// <param name="methodName">方法名/信号标识</param>
/// <param name="value">当前采样值</param>
/// <param name="globalInfo">全局信息</param>
public static void CheckAlarm(string scope, string fingerprint, string methodName, double value, GlobalInfo globalInfo)
public static string CheckAlarm(string scope, string fingerprint, string methodName, double value, GlobalInfo globalInfo)
{
if (globalInfo?.ConfigDic == null) return;
if (!globalInfo.ConfigDic.TryGetValue(scope, out var systemConfig)) return;
if (systemConfig.ValueLimitList == null) return;
if (globalInfo?.ConfigDic == null) return "";
if (!globalInfo.ConfigDic.TryGetValue(scope, out var systemConfig)) return "";
if (systemConfig.ValueLimitList == null) return "";
var limit = systemConfig.ValueLimitList.FirstOrDefault(x =>
x.Fingerprint == fingerprint && x.MethodName == methodName);
if (limit == null) return;
if (value > limit.Upper)
{
limit.IsAlarm = true;
limit.AlarmSatus = AlarmStatus.;
}
else if (value < limit.Lower)
{
limit.IsAlarm = true;
limit.AlarmSatus = AlarmStatus.;
}
else if(value > limit.UpperExtreme)
if (limit == null) return "";
if (value > limit.UpperExtreme)
{
limit.IsAlarm = true;
limit.AlarmSatus = AlarmStatus.;
@@ -45,12 +35,22 @@ namespace UIShare.GlobalVariable
limit.IsAlarm = true;
limit.AlarmSatus = AlarmStatus.;
}
else if (value > limit.Upper)
{
limit.IsAlarm = true;
limit.AlarmSatus = AlarmStatus.;
}
else if (value < limit.Lower)
{
limit.IsAlarm = true;
limit.AlarmSatus = AlarmStatus.;
}
else
{
limit.IsAlarm = false;
limit.AlarmSatus = AlarmStatus.;
}
return limit.AlarmSatus.ToString();
}
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace UIShare.PubEvent
{
public class AlarmEvent :PubSubEvent
public class AlarmEvent :PubSubEvent<Tuple<string,string>>
{
}
}