BOB/DeviceCommand/Device/Backfeed.cs

181 lines
7.2 KiB
C#

using Common.Attributes;
using Model;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceCommand.Device
{
[BOBCommand]
public class Backfeed
{
public string CurrentDevice { get; set; }
private E36233A _E36233A { get; set; }
private IT6724CReverse _IT6724CReverse { get; set; }
public object CurrentInstance
{
get
{
if (CurrentDevice == "E36233A")
return _E36233A;
else if (CurrentDevice == "IT6724CReverse")
return _IT6724CReverse;
else
throw new InvalidOperationException("还没初始化实例");
}
}
public Backfeed(ICommunicationConfig config)
{
if (config is TcpConfig tcpConfig)
{
_E36233A = new E36233A(tcpConfig.IPAddress, tcpConfig.Port, tcpConfig.WriteTimeout, tcpConfig.ReadTimeout);
CurrentDevice = "E36233A";
}
else if (config is SerialPortConfig serialPortConfig)
{
_IT6724CReverse = new IT6724CReverse(serialPortConfig.COMPort, serialPortConfig.BaudRate, serialPortConfig.DataBit, serialPortConfig.StopBit, serialPortConfig.ParityBit, serialPortConfig.ReadTimeout, serialPortConfig.WriteTimeout);
CurrentDevice = "IT6724CReverse";
}
}
#region -
// 清除输出保护
public virtual async Task (CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(ct);
}
// 设置电源输出
public virtual async Task (bool , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, ct);
}
// 设置为远程模式
public virtual async Task (CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(ct);
}
// 蜂鸣器测试
public virtual async Task (CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(ct);
}
// 设置电流
public virtual async Task (double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, ct);
}
// 设置电流保护OCP电流
public virtual async Task OCP电流(double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.OCP电流(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.OCP电流(, ct);
}
// 设置OCP开关
public virtual async Task OCP开关(bool , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.OCP开关(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.OCP开关(, ct);
}
// 设置电压
public virtual async Task (double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, ct);
}
// 设置电压保护OVP电压
public virtual async Task OVP电压(double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.OVP电压(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.OVP电压(, ct);
}
// 设置OVP开关
public virtual async Task OVP开关(bool , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.OVP开关(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.OVP开关(, ct);
}
// 设置功率保护功率
public virtual async Task (double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, ct);
}
// 设置功率保护开关
public virtual async Task (bool , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, ct);
}
// 设置电流斜率
public virtual async Task (double , double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, , ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, , ct);
}
// 设置电压斜率
public virtual async Task (double , double , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, , ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, , ct);
}
// 发送自定义命令
public virtual async Task (string , CancellationToken ct = default)
{
if (CurrentDevice == "E36233A")
await _E36233A.(, ct);
else if (CurrentDevice == "IT6724CReverse")
await _IT6724CReverse.(, ct);
}
#endregion
}
}