160 lines
5.3 KiB
C#
160 lines
5.3 KiB
C#
using Common.Attributes;
|
||
using DeviceCommand.Base;
|
||
using System;
|
||
using System.IO.Ports;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace DeviceCommand.Device
|
||
{
|
||
[BOBCommand]
|
||
public class IT6724C : Serial_Port
|
||
{
|
||
public IT6724C()
|
||
{
|
||
ConfigureDevice("COM1", 9600, 8, StopBits.One, Parity.None, 3000, 3000);
|
||
ConnectAsync();
|
||
}
|
||
|
||
#region 设置命令
|
||
|
||
/// <summary>
|
||
/// 设置输出状态,true 为开,false 为关
|
||
/// </summary>
|
||
public Task SetOutputAsync(bool state, CancellationToken ct = default)
|
||
=> SendAsync($"OUTPut {(state ? 1 : 0)}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 切换到远程控制模式
|
||
/// </summary>
|
||
public Task SetRemoteModeAsync(CancellationToken ct = default)
|
||
=> SendAsync("SYSTem:REMote\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 蜂鸣器测试
|
||
/// </summary>
|
||
public Task BeeperTestAsync(CancellationToken ct = default)
|
||
=> SendAsync("SYSTem:BEEPer\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 设置输出电流(单位:A)
|
||
/// </summary>
|
||
public Task SetCurrentAsync(double current, CancellationToken ct = default)
|
||
=> SendAsync($"CURRent {current}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 设置过流保护电流(OCP,单位:A)
|
||
/// </summary>
|
||
public Task SetOCPCurrentAsync(double current, CancellationToken ct = default)
|
||
=> SendAsync($"CURRent:PROTection {current}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 设置过流保护状态,true 为启用,false 为禁用
|
||
/// </summary>
|
||
public Task SetOCPStateAsync(bool state, CancellationToken ct = default)
|
||
=> SendAsync($"CURRent:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 清除过流保护触发状态
|
||
/// </summary>
|
||
public Task ClearOCPAsync(CancellationToken ct = default)
|
||
=> SendAsync("CURRent:PROTection:CLEar\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 设置输出电压(单位:V)
|
||
/// </summary>
|
||
public Task SetVoltageAsync(double voltage, CancellationToken ct = default)
|
||
=> SendAsync($"VOLTage {voltage}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 设置过压保护电压(OVP,单位:V)
|
||
/// </summary>
|
||
public Task SetOVPVoltageAsync(double voltage, CancellationToken ct = default)
|
||
=> SendAsync($"VOLT:PROTection {voltage}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 设置过压保护状态,true 为启用,false 为禁用
|
||
/// </summary>
|
||
public Task SetOVPStateAsync(bool state, CancellationToken ct = default)
|
||
=> SendAsync($"VOLT:PROTection:STATe {(state ? 1 : 0)}\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 清除过压保护触发状态
|
||
/// </summary>
|
||
public Task ClearOVPAsync(CancellationToken ct = default)
|
||
=> SendAsync("VOLT:PROTection:CLEar\r\n", ct);
|
||
|
||
/// <summary>
|
||
/// 发送自定义命令
|
||
/// </summary>
|
||
public Task SendCustomCommandAsync(string command, CancellationToken ct = default)
|
||
=> SendAsync($"{command}\r\n", ct);
|
||
|
||
#endregion
|
||
|
||
#region 查询命令
|
||
|
||
/// <summary>
|
||
/// 查询仪器标识,返回制造商、型号、序列号、固件版本
|
||
/// </summary>
|
||
public async Task<string> QueryIDAsync(CancellationToken ct = default)
|
||
{
|
||
await SendAsync("*IDN?\r\n", ct);
|
||
return await ReadAsync(ct: ct);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询过流保护是否触发,返回 true 表示触发
|
||
/// </summary>
|
||
public async Task<bool> QueryOCPTrippedAsync(CancellationToken ct = default)
|
||
{
|
||
await SendAsync("CURRent:PROTection:TRIPed?\r\n", ct);
|
||
var result = await ReadAsync(ct: ct);
|
||
return result == "1";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询过压保护是否触发,返回 true 表示触发
|
||
/// </summary>
|
||
public async Task<bool> QueryOVPTrippedAsync(CancellationToken ct = default)
|
||
{
|
||
await SendAsync("VOLT:PROTection:TRIPed?\r\n", ct);
|
||
var result = await ReadAsync(ct: ct);
|
||
return result == "1";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询实际输出电流(单位:A)
|
||
/// </summary>
|
||
public async Task<double> QueryCurrentAsync(CancellationToken ct = default)
|
||
{
|
||
await SendAsync("MEASure:CURRent?\r\n", ct);
|
||
var result = await ReadAsync(ct: ct);
|
||
return Convert.ToDouble(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询实际输出电压(单位:V)
|
||
/// </summary>
|
||
public async Task<double> QueryVoltageAsync(CancellationToken ct = default)
|
||
{
|
||
await SendAsync("MEASure:VOLTage?\r\n", ct);
|
||
var result = await ReadAsync(ct: ct);
|
||
return Convert.ToDouble(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询实际输出功率(单位:W)
|
||
/// </summary>
|
||
public async Task<double> QueryPowerAsync(CancellationToken ct = default)
|
||
{
|
||
await SendAsync("MEASure:POWer?\r\n", ct);
|
||
var result = await ReadAsync(ct: ct);
|
||
return Convert.ToDouble(result);
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
}
|