Files
ACP/DeviceCommand/Devices/TektronixMSO.cs
2026-07-29 16:23:43 +08:00

198 lines
7.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Common.Attributes;
using DeviceCommand.Base;
using Model.Models;
using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceCommand.Devices
{
#region
/// <summary>
/// Tektronix MSO 采集模式
/// </summary>
public enum TekAcquisitionMode
{
/// <summary> 采样模式 </summary>
SAMple,
/// <summary> 峰值检测模式 </summary>
PEAKdetect,
/// <summary> 高分辨率模式 </summary>
HIRes,
/// <summary> 平均模式 </summary>
AVErage,
/// <summary> 包络模式 </summary>
ENVelope
}
/// <summary>
/// Tektronix MSO 测量类型 (部分常用)
/// </summary>
public enum TekMeasurementType
{
AMPLitude,
FREQuency,
MEAN,
PK2PK,
MAXimum,
MINimum
}
#endregion
[ACPCommand]
public class TektronixMSO : Tcp
{
// SCPI 指令结束符 (文档中提到消息终止符需使用 LF)[cite: 1]
private const string ScpiDelimiter = "\n";
public TektronixMSO(TcpConfig config) : base(config)
{
}
#region 1.
public virtual async Task<string> (CancellationToken ct = default)
{
// 返回仪器的标识代码[cite: 1]
return await WriteReadAsync($"*IDN?{ScpiDelimiter}", ScpiDelimiter, ct);
}
public virtual async Task<string> (CancellationToken ct = default)
{
// 查询仪器是否处于忙碌状态,常用于同步操作[cite: 1]
return await WriteReadAsync($"BUSY?{ScpiDelimiter}", ScpiDelimiter, ct);
}
public virtual async Task (CancellationToken ct = default)
{
// 指示仪器执行信号路径校准 (SPC),需要几分钟时间[cite: 1]
await SendAsync($"*CAL?{ScpiDelimiter}", ct);
}
#endregion
#region 2. (Acquisition)
/// <summary>
/// 启动或停止采集
/// </summary>
public virtual async Task (bool , CancellationToken ct = default)
{
// 启动、停止或返回采集状态[cite: 1]
string = ? "RUN" : "STOP";
await SendAsync($"ACQuire:STATE {参数}{ScpiDelimiter}", ct);
}
public virtual async Task<string> (CancellationToken ct = default)
{
return await WriteReadAsync($"ACQuire:STATE?{ScpiDelimiter}", ScpiDelimiter, ct); //[cite: 1]
}
public virtual async Task (TekAcquisitionMode , CancellationToken ct = default)
{
// 设置或查询采集模式[cite: 1]
await SendAsync($"ACQuire:MODe {模式}{ScpiDelimiter}", ct);
}
#endregion
#region 3. (Horizontal)
public virtual async Task (double , CancellationToken ct = default)
{
// 设置或查询水平刻度 (Scale)[cite: 1]
string cmd = string.Format(CultureInfo.InvariantCulture, "HORizontal:SCAle {0:E}{1}", , ScpiDelimiter);
await SendAsync(cmd, ct);
}
public virtual async Task (long , CancellationToken ct = default)
{
// 设置或查询记录长度[cite: 1]
await SendAsync($"HORizontal:RECOrdlength {长度}{ScpiDelimiter}", ct);
}
public virtual async Task (double , CancellationToken ct = default)
{
// 设置或查询水平采样率[cite: 1]
string cmd = string.Format(CultureInfo.InvariantCulture, "HORizontal:SAMPLERate {0:E}{1}", , ScpiDelimiter);
await SendAsync(cmd, ct);
}
#endregion
#region 4. (Display & Vertical)
/// <summary>
/// 全局启用或关闭某通道的显示
/// </summary>
public virtual async Task (int , bool , CancellationToken ct = default)
{
// 设置或查询指定通道的显示模式(开或关)[cite: 1]
string = ? "ON" : "OFF";
await SendAsync($"DISplay:GLObal:CH{通道号}:STATE {参数}{ScpiDelimiter}", ct);
}
/// <summary>
/// 设置指定通道的垂直缩放比例 (Volts/Div)
/// </summary>
public virtual async Task (int , double , CancellationToken ct = default)
{
// 设置或查询指定Waveform View内指定通道的垂直缩放比例WaveView<x> 通常为1[cite: 1]
string cmd = string.Format(CultureInfo.InvariantCulture, "DISplay:WAVEView1:CH{0}:VERTical:SCAle {1:E}{2}", , , ScpiDelimiter);
await SendAsync(cmd, ct);
}
/// <summary>
/// 设置指定通道的垂直位置 (Divisions)
/// </summary>
public virtual async Task (int , double , CancellationToken ct = default)
{
// 设置或查询指定Waveform View内指定通道的垂直位置以格为单位[cite: 1]
string cmd = string.Format(CultureInfo.InvariantCulture, "DISplay:WAVEView1:CH{0}:VERTical:POSition {1:F2}{2}", , , ScpiDelimiter);
await SendAsync(cmd, ct);
}
#endregion
#region 5. (Measurement)
/// <summary>
/// 新增一个测量项槽位
/// </summary>
public virtual async Task (CancellationToken ct = default)
{
// 添加一个测量项[cite: 1]
await SendAsync($"MEASUrement:ADDMEAS{ScpiDelimiter}", ct);
}
public virtual async Task (int , TekMeasurementType , CancellationToken ct = default)
{
// 设置或查询测量类型[cite: 1]
await SendAsync($"MEASUrement:MEAS{测量项编号}:TYPe {类型}{ScpiDelimiter}", ct);
}
public virtual async Task (int , string , CancellationToken ct = default)
{
// 设置或查询局部输入源 (例如 CH1, CH2)[cite: 1]
await SendAsync($"MEASUrement:MEAS{测量项编号}:SOURCE {源名称}{ScpiDelimiter}", ct);
}
[Monitorable("测量项当前采集的平均值")]
public virtual async Task<string> (int , CancellationToken ct = default)
{
// 返回当前采集的指定测量的平均值[cite: 1]
return await WriteReadAsync($"MEASUrement:MEAS{测量项编号}:RESUlts:CURRentacq:MEAN?{ScpiDelimiter}", ScpiDelimiter, ct);
}
public virtual async Task<string> (int , CancellationToken ct = default)
{
// 返回自上次统计重置以来指定测量的最大值(当前采集)[cite: 1]
return await WriteReadAsync($"MEASUrement:MEAS{测量项编号}:RESUlts:CURRentacq:MAXimum?{ScpiDelimiter}", ScpiDelimiter, ct);
}
#endregion
}
}