using Common.Attributes;
using DeviceCommand.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Common.Attributes.ATSCommandAttribute;
namespace DeviceCommand.Device
{
///
/// 直流电源——三通道可编程直流电源设备(型号:IT-N6322B)
///
[ATSCommand]
[DeviceCategory("三通道可编程直流电源")]
public class IT_N6322B : Tcp
{
public SemaphoreSlim semaphoreSlimLock { get; set; } = new(1, 1);
public enum ChannelList_Enum
{
CH1 = 1, CH2 = 2, CH3 = 3
}
///
/// 切换为远程模式 三通道可编程直流电源
///
/// 设备
///
///
public async Task Set_RemoteMode(Tcp client, CancellationToken ct = default)
{
try
{
await SendAsync(client, $"SYST:REM\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 切换为本地模式
///
/// 设备
///
///
public async Task Set_LocalMode(Tcp client, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"SYST:LOC\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道对应通道输出电压
///
/// 设备
/// 通道
/// 电压
/// 支持中途取消发送指令
///
public async Task Set_OutputVoltage(Tcp client, ChannelList_Enum channel, float voltage, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"VOLT {voltage},(@{channel} )\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道过电压保护电平
///
/// 设备
/// 通道
/// 输出频率
/// 支持中途取消发送指令
///
public async Task Set_MaxVoltage(Tcp client, ChannelList_Enum channel, float voltage, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"VOLT:OVER:PROT {voltage},(@{channel})\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道的输出电流
///
/// 设备
/// 通道
/// 输出频率
/// 支持中途取消发送指令
///
public async Task Set_OutputCurrent(Tcp client, ChannelList_Enum channel, float current, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"CURR {current},(@{channel})\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道输出过电流保护电平
///
/// 设备
/// 通道
/// 电压
/// 支持中途取消发送指令
///
public async Task Set_MaxCurrent(Tcp client, ChannelList_Enum channel, float current, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"CURR:OVER:PROT {current},(@{channel})\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道输出的电压和电流值
///
/// 设备
/// 通道
/// 电压
/// 电流
/// 支持中途取消发送指令
///
public async Task Set_MaxCurrent(Tcp client, ChannelList_Enum channel, float voltage, float current, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"APPL {voltage},{current},(@{channel})\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 返回指定通道电源输出的实际电压值
///
/// 设备
/// 通道
/// 取消令牌
/// 返回值是:定通道电源输出的实际电压值 (Amps)
public async Task QueryVoltage(Tcp client, ChannelList_Enum channel, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
return await WriteRead(client, $"MEAS:VOLT?,(@{channel})\r\n", "\n", ct: ct);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 返回指定通道电源输出的实际电流值
///
/// 设备
/// 通道
/// 取消令牌
/// 返回值是:设置的电流值 (Amps)
public async Task QueryCurrent(Tcp client, ChannelList_Enum channel, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
return await WriteRead(client, $"MEAS:CURR?,(@{channel})\r\n", "\n", ct: ct); // 使用缩写
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 返回指定通道电源输出的实际功率值
///
/// 设备
/// 通道
/// 取消令牌
/// 返回值是:指定通道电源输出的实际功率值 (Amps)
public async Task QueryPower(Tcp client, ChannelList_Enum channel, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
return await WriteRead(client, $"MEAS:POW?,(@{channel})\r\n", "\n", ct: ct);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道的开启
///
/// 设备
/// 通道
/// 支持中途取消发送指令
///
public async Task Set_Power_ON(Tcp client, ChannelList_Enum channel, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
//1/0 或 ON/OFF都可以
await SendAsync(client, $"OUTP ON,(@{channel})\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
///
/// 设置源指定通道的关闭
///
/// 设备
/// 通道
/// 支持中途取消发送指令
///
public async Task Set_Power_OFF(Tcp client, ChannelList_Enum channel, CancellationToken ct = default)
{
await semaphoreSlimLock.WaitAsync(ct);
try
{
await SendAsync(client, $"OUTP OFF,(@{channel})\n", ct);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
semaphoreSlimLock.Release();
}
}
}
}