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 { /// /// 通道1 /// CH1 = 1, /// /// 通道2 /// CH2 = 2, /// /// 通道3 /// CH3 = 3 } /// /// 切换为远程模式 三通道可编程直流电源 /// /// 设备 /// /// public async Task Set_RemoteMode(Tcp client, CancellationToken ct = default) { await semaphoreSlimLock.WaitAsync(ct); 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_OutputITVoltage(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_MaxITVoltage(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_OutputITCurrent(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_MaxITCurrent(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_CurrentAndVoltage(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 Query_ITVoltage(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 Query_ITCurrent(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 Query_ITPower(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_ITPower_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_ITPower_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(); } } } }