设备命令修改
This commit is contained in:
@@ -49,64 +49,102 @@ namespace DeviceCommand.Devices
|
||||
|
||||
#endregion
|
||||
|
||||
#region 3. LIST 步阶参数配置
|
||||
#region 3. LIST 步阶参数配置 (独立发送版 - 三参数固定版)
|
||||
|
||||
/// <summary>
|
||||
/// 配置单相的 LIST 序列参数
|
||||
/// 传入的数组长度必须保持一致,代表 LIST 的每个 Step(SEQ)
|
||||
/// 切换目标相位并设置波形为正弦波
|
||||
/// 建议在发送具体 LIST 参数前调用一次即可
|
||||
/// </summary>
|
||||
/// <param name="phase">相位 (1: L1, 2: L2, 3: L3)</param>
|
||||
/// <param name="degrees">各步起始角度 (如 [0, 0, 0])</param>
|
||||
/// <param name="vacStart">各步交流起始电压 (如 [230, 11.5, 230])</param>
|
||||
/// <param name="vacEnd">各步交流结束电压 (如 [230, 11.5, 230])</param>
|
||||
/// <param name="vdcStart">各步直流起始电压</param>
|
||||
/// <param name="vdcEnd">各步直流结束电压</param>
|
||||
/// <param name="freqStart">各步起始频率</param>
|
||||
/// <param name="freqEnd">各步结束频率</param>
|
||||
/// <param name="dwellTimeMs">各步执行时间(单位: 毫秒)</param>
|
||||
public virtual async Task 配置单相List序列(
|
||||
int phase,
|
||||
double[] degrees,
|
||||
double[] vacStart, double[] vacEnd,
|
||||
double[] vdcStart, double[] vdcEnd,
|
||||
double[] freqStart, double[] freqEnd,
|
||||
double[] dwellTimeMs,
|
||||
CancellationToken ct = default)
|
||||
public virtual async Task 切换相位Async(int phase, CancellationToken ct = default)
|
||||
{
|
||||
if (phase < 1 || phase > 3) throw new ArgumentOutOfRangeException(nameof(phase), "相位必须为 1, 2, 或 3");
|
||||
if (phase < 1 || phase > 3)
|
||||
throw new ArgumentOutOfRangeException(nameof(phase), "相位必须为 1, 2, 或 3");
|
||||
|
||||
// 选择相位并设置为正弦波
|
||||
await SendAsync($"INST:NSEL {phase}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"FUNC:SHAP:A SINE{ScpiDelimiter}", ct);
|
||||
|
||||
// 转换数组为 SCPI 需要的逗号分隔字符串
|
||||
string strDegrees = JoinParameters(degrees);
|
||||
string strVacStart = JoinParameters(vacStart);
|
||||
string strVacEnd = JoinParameters(vacEnd);
|
||||
string strVdcStart = JoinParameters(vdcStart);
|
||||
string strVdcEnd = JoinParameters(vdcEnd);
|
||||
string strFreqStart = JoinParameters(freqStart);
|
||||
string strFreqEnd = JoinParameters(freqEnd);
|
||||
string strDwell = JoinParameters(dwellTimeMs);
|
||||
|
||||
// 下发序列参数
|
||||
// 注意 Chroma 部分指令是 DEGR,部分固件版本是 DEGRee,这里统一使用简写 DEGR,兼容性最好
|
||||
await SendAsync($"LIST:DEGR {strDegrees}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:VOLT:AC:STAR {strVacStart}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:VOLT:AC:END {strVacEnd}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:VOLT:DC:STAR {strVdcStart}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:VOLT:DC:END {strVdcEnd}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:FREQ:STAR {strFreqStart}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:FREQ:END {strFreqEnd}{ScpiDelimiter}", ct);
|
||||
await SendAsync($"LIST:DWEL {strDwell}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 辅助方法:将 double 数组转换为逗号分隔的字符串,确保小数点格式正确
|
||||
/// 配置 LIST 各步起始角度
|
||||
/// </summary>
|
||||
private string JoinParameters(double[] values)
|
||||
public virtual async Task 配置List起始角度Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
return string.Join(",", values.Select(v => v.ToString("0.###", CultureInfo.InvariantCulture)));
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:DEGR {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步交流起始电压
|
||||
/// </summary>
|
||||
public virtual async Task 配置List交流起始电压Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:VOLT:AC:STAR {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步交流结束电压
|
||||
/// </summary>
|
||||
public virtual async Task 配置List交流结束电压Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:VOLT:AC:END {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步直流起始电压
|
||||
/// </summary>
|
||||
public virtual async Task 配置List直流起始电压Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:VOLT:DC:STAR {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步直流结束电压
|
||||
/// </summary>
|
||||
public virtual async Task 配置List直流结束电压Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:VOLT:DC:END {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步起始频率
|
||||
/// </summary>
|
||||
public virtual async Task 配置List起始频率Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:FREQ:STAR {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步结束频率
|
||||
/// </summary>
|
||||
public virtual async Task 配置List结束频率Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:FREQ:END {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置 LIST 各步执行时间 (单位: 毫秒)
|
||||
/// </summary>
|
||||
public virtual async Task 配置List执行时间Async(double step1, double step2, double step3, CancellationToken ct = default)
|
||||
{
|
||||
string strValues = JoinParameters(step1, step2, step3);
|
||||
await SendAsync($"LIST:DWEL {strValues}{ScpiDelimiter}", ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 辅助方法:将三个 double 值转换为逗号分隔的字符串,确保小数点格式正确
|
||||
/// </summary>
|
||||
private string JoinParameters(double val1, double val2, double val3)
|
||||
{
|
||||
return $"{val1.ToString("0.###", CultureInfo.InvariantCulture)}," +
|
||||
$"{val2.ToString("0.###", CultureInfo.InvariantCulture)}," +
|
||||
$"{val3.ToString("0.###", CultureInfo.InvariantCulture)}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user