161 lines
6.1 KiB
C#
161 lines
6.1 KiB
C#
using Common.Attributes;
|
||
using DeviceCommand.Base;
|
||
using System;
|
||
using System.Linq;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace DeviceCommand.Device
|
||
{
|
||
[BOBCommand]
|
||
public class E36233A : Tcp
|
||
{
|
||
public E36233A(string ipAddress, int port, int sendTimeout, int receiveTimeout)
|
||
{
|
||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||
}
|
||
|
||
public E36233A()
|
||
{
|
||
}
|
||
|
||
#region 基础系统命令(必须保留)
|
||
|
||
/// <summary>查询设备身份</summary>
|
||
public Task<string> QueryIDAsync(CancellationToken ct = default)
|
||
=> SendCommandReadAsync("*IDN?", ct);
|
||
|
||
/// <summary>清除错误与状态</summary>
|
||
public Task ClearStatusAsync(CancellationToken ct = default)
|
||
=> SendAsync("*CLS\r\n", ct);
|
||
|
||
/// <summary>系统复位</summary>
|
||
public Task ResetAsync(CancellationToken ct = default)
|
||
=> SendAsync("*RST\r\n", ct);
|
||
|
||
#endregion
|
||
|
||
#region 通道与输出控制
|
||
|
||
/// <summary>选择通道 CH1 或 CH2</summary>
|
||
public Task SelectChannelAsync(int channel, CancellationToken ct = default)
|
||
{
|
||
if (channel < 1 || channel > 2)
|
||
throw new ArgumentOutOfRangeException(nameof(channel));
|
||
|
||
return SendAsync($"INST:SEL CH{channel}\r\n", ct);
|
||
}
|
||
|
||
/// <summary>开关输出</summary>
|
||
public Task SetOutputAsync(bool on, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"OUTP {(on ? "ON" : "OFF")},(@{channels})\r\n", ct);
|
||
|
||
#endregion
|
||
|
||
#region 电压/电流设置
|
||
|
||
/// <summary>设置电压 (0~30.9V)</summary>
|
||
public Task SetVoltageAsync(double volt, string channels = "1", CancellationToken ct = default)
|
||
{
|
||
if (volt < 0 || volt > 30.9) throw new ArgumentOutOfRangeException(nameof(volt));
|
||
return SendAsync($"SOUR:VOLT {volt},(@{channels})\r\n", ct);
|
||
}
|
||
|
||
/// <summary>设置电流限值 (0~20.6A)</summary>
|
||
public Task SetCurrentAsync(double curr, string channels = "1", CancellationToken ct = default)
|
||
{
|
||
if (curr < 0 || curr > 20.6) throw new ArgumentOutOfRangeException(nameof(curr));
|
||
return SendAsync($"SOUR:CURR {curr},(@{channels})\r\n", ct);
|
||
}
|
||
|
||
/// <summary>设置过压保护</summary>
|
||
public Task SetOVPAsync(double ovp, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:VOLT:PROT {ovp},(@{channels})\r\n", ct);
|
||
|
||
/// <summary>设置过流保护</summary>
|
||
public Task SetOCPAsync(double ocp, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:CURR:PROT {ocp},(@{channels})\r\n", ct);
|
||
|
||
/// <summary>清除 OVP/OCP 错误</summary>
|
||
public Task ClearProtectionAsync(string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:VOLT:PROT:CLE (@{channels})\r\n", ct);
|
||
|
||
#endregion
|
||
|
||
#region 斜率设置(用于启动测试)
|
||
|
||
/// <summary>设置电压上升斜率</summary>
|
||
public Task SetRiseSlewAsync(double slew, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:VOLT:SLEW:RIS {slew},(@{channels})\r\n", ct);
|
||
|
||
/// <summary>设置电压下降斜率</summary>
|
||
public Task SetFallSlewAsync(double slew, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:VOLT:SLEW:FALL {slew},(@{channels})\r\n", ct);
|
||
|
||
#endregion
|
||
|
||
#region 测量
|
||
|
||
/// <summary>测量电压(V)</summary>
|
||
public async Task<double> MeasureVoltageAsync(string channels = "1", CancellationToken ct = default)
|
||
{
|
||
string result = await SendCommandReadAsync($"MEAS:VOLT? (@{channels})", ct);
|
||
return double.TryParse(result, out var value) ? value : 0;
|
||
}
|
||
|
||
/// <summary>测量电流(A)</summary>
|
||
public async Task<double> MeasureCurrentAsync(string channels = "1", CancellationToken ct = default)
|
||
{
|
||
string result = await SendCommandReadAsync($"MEAS:CURR? (@{channels})", ct);
|
||
return double.TryParse(result, out var value) ? value : 0;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 保护状态查询
|
||
|
||
public async Task<bool> QueryOVPTrippedAsync(string channels = "1", CancellationToken ct = default)
|
||
{
|
||
string result = await SendCommandReadAsync($"SOUR:VOLT:PROT:TRIP? (@{channels})", ct);
|
||
return result == "1";
|
||
}
|
||
|
||
public async Task<bool> QueryOCPTrippedAsync(string channels = "1", CancellationToken ct = default)
|
||
{
|
||
string result = await SendCommandReadAsync($"SOUR:CURR:PROT:TRIP? (@{channels})", ct);
|
||
return result == "1";
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 序列(用于阶梯电压/耐久测试)
|
||
|
||
public Task SetVoltageListAsync(double[] voltages, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:LIST:VOLT {string.Join(",", voltages)},(@{channels})\r\n", ct);
|
||
|
||
public Task SetCurrentListAsync(double[] currents, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:LIST:CURR {string.Join(",", currents)},(@{channels})\r\n", ct);
|
||
|
||
public Task SetDwellListAsync(double[] times, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:LIST:DWEL {string.Join(",", times)},(@{channels})\r\n", ct);
|
||
|
||
public Task SetSequenceRepeatAsync(string count, string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"SOUR:LIST:COUN {count},(@{channels})\r\n", ct);
|
||
|
||
public Task StartSequenceAsync(string channels = "1", CancellationToken ct = default)
|
||
=> SendAsync($"INIT (@{channels})\r\n", ct);
|
||
|
||
#endregion
|
||
|
||
#region 辅助方法
|
||
|
||
private async Task<string> SendCommandReadAsync(string cmd, CancellationToken ct = default)
|
||
{
|
||
await SendAsync(cmd + "\r\n", ct);
|
||
return await ReadAsync("\n", ct);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|