设备列表
This commit is contained in:
27
DeviceCommand/Base/SerialPortConfig.cs
Normal file
27
DeviceCommand/Base/SerialPortConfig.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace DeviceCommand.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// 串口通信参数(DeviceCommand 内部纯数据类,供设备类构造函数使用)。
|
||||
/// 与 UIShare.UIViewModel.SerialPortConfigVM 字段一一对应,
|
||||
/// StopBits / Parity 在此处使用 System.IO.Ports 强类型枚举,
|
||||
/// 由 DeviceManager 从字符串解析后填入。
|
||||
/// </summary>
|
||||
public class SerialPortConfig
|
||||
{
|
||||
public string PortName { get; set; } = "COM1";
|
||||
|
||||
public int BaudRate { get; set; } = 9600;
|
||||
|
||||
public int DataBits { get; set; } = 8;
|
||||
|
||||
public StopBits StopBits { get; set; } = StopBits.One;
|
||||
|
||||
public Parity Parity { get; set; } = Parity.None;
|
||||
|
||||
public int ReadTimeout { get; set; } = 3000;
|
||||
|
||||
public int WriteTimeout { get; set; } = 3000;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,15 @@ namespace DeviceCommand.Base
|
||||
_serialPort = new SerialPort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 <see cref="SerialPortConfig"/> 一次性配置串口通信参数。
|
||||
/// </summary>
|
||||
public Serial_Port(SerialPortConfig config) : this()
|
||||
{
|
||||
if (config == null) return;
|
||||
ConfigureDevice(config.PortName, config.BaudRate, config.DataBits, config.StopBits, config.Parity, config.ReadTimeout, config.WriteTimeout);
|
||||
}
|
||||
|
||||
public void ConfigureDevice(string portName, int baudRate, int dataBits = 8, StopBits stopBits = StopBits.One, Parity parity = Parity.None, int readTimeout = 3000, int writeTimeout = 3000)
|
||||
{
|
||||
PortName = portName;
|
||||
|
||||
@@ -23,6 +23,15 @@ namespace DeviceCommand.Base
|
||||
_tcpClient = new TcpClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 <see cref="TcpConfig"/> 一次性配置 TCP 通信参数。
|
||||
/// </summary>
|
||||
public Tcp(TcpConfig config) : this()
|
||||
{
|
||||
if (config == null) return;
|
||||
ConfigureDevice(config.IPAddress, config.Port, config.SendTimeout, config.ReceiveTimeout);
|
||||
}
|
||||
|
||||
public void ConfigureDevice(string ipAddress, int port, int sendTimeout = 3000, int receiveTimeout = 3000)
|
||||
{
|
||||
IPAddress = ipAddress;
|
||||
|
||||
17
DeviceCommand/Base/TcpConfig.cs
Normal file
17
DeviceCommand/Base/TcpConfig.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace DeviceCommand.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// TCP 通信参数(DeviceCommand 内部纯数据类,供设备类构造函数使用)。
|
||||
/// 与 UIShare.UIViewModel.TcpConfigVM 字段一一对应,由 DeviceManager 在实例化时填充。
|
||||
/// </summary>
|
||||
public class TcpConfig
|
||||
{
|
||||
public string IPAddress { get; set; } = "127.0.0.1";
|
||||
|
||||
public int Port { get; set; } = 502;
|
||||
|
||||
public int SendTimeout { get; set; } = 3000;
|
||||
|
||||
public int ReceiveTimeout { get; set; } = 3000;
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,10 @@ namespace DeviceCommand.Device
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:初始化 IT7800E 交直流电源通信参数
|
||||
/// 构造函数:传入 <see cref="TcpConfig"/> 一次性初始化 IT7800E 交直流电源通信参数。
|
||||
/// </summary>
|
||||
public IT7800E(string ipAddress, int port, int sendTimeout, int receiveTimeout)
|
||||
public IT7800E(TcpConfig config) : base(config)
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
}
|
||||
|
||||
#region 1. IEEE 488.2 公共命令
|
||||
|
||||
@@ -14,11 +14,10 @@ namespace DeviceCommand.Device
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:初始化 N36200/N36300 设备通信参数
|
||||
/// 构造函数:传入 <see cref="TcpConfig"/> 一次性初始化 N36200/N36300 设备通信参数。
|
||||
/// </summary>
|
||||
public N36200(string ipAddress, int port, int sendTimeout, int receiveTimeout)
|
||||
public N36200(TcpConfig config) : base(config)
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
}
|
||||
|
||||
#region 3.1. IEEE 488.2 公共命令
|
||||
|
||||
@@ -22,9 +22,8 @@ namespace DeviceCommand.Device
|
||||
// 手册第 4 页明确规定:每条命令后面都要加结束符 0x0A (\n)
|
||||
private const string SCPIDelimiter = "\n";
|
||||
|
||||
public N36600(string ipAddress, int port, int sendTimeout, int receiveTimeout)
|
||||
public N36600(TcpConfig config) : base(config)
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -14,11 +14,10 @@ namespace DeviceCommand.Device
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:初始化 N69200 电子负载通信参数
|
||||
/// 构造函数:传入 <see cref="TcpConfig"/> 一次性初始化 N69200 电子负载通信参数。
|
||||
/// </summary>
|
||||
public N69200(string ipAddress, int port, int sendTimeout, int receiveTimeout)
|
||||
public N69200(TcpConfig config) : base(config)
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
}
|
||||
|
||||
#region 3.1. IEEE 488.2 公共命令
|
||||
|
||||
@@ -14,11 +14,11 @@ namespace DeviceCommand.Device
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:初始化示波器通信参数 (鼎阳示波器网口 Socket 默认端口通常为 5025)
|
||||
/// 构造函数:传入 <see cref="TcpConfig"/> 一次性初始化示波器通信参数。
|
||||
/// 鼎阳示波器网口 Socket 默认端口通常为 5025,请在配置中设置。
|
||||
/// </summary>
|
||||
public SDS2000X_HD(string ipAddress, int port = 5025, int sendTimeout = 3000, int receiveTimeout = 3000)
|
||||
public SDS2000X_HD(TcpConfig config) : base(config)
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
}
|
||||
|
||||
#region 1. IEEE 488.2 公共命令
|
||||
|
||||
@@ -14,11 +14,10 @@ namespace DeviceCommand.Device
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数:初始化 SPAW7000 功率分析记录仪通信参数
|
||||
/// 构造函数:传入 <see cref="TcpConfig"/> 一次性初始化 SPAW7000 功率分析记录仪通信参数。
|
||||
/// </summary>
|
||||
public SPAW7000(string ipAddress, int port, int sendTimeout, int receiveTimeout)
|
||||
public SPAW7000(TcpConfig config) : base(config)
|
||||
{
|
||||
ConfigureDevice(ipAddress, port, sendTimeout, receiveTimeout);
|
||||
}
|
||||
|
||||
#region 1. IEEE 488.2 公共命令
|
||||
|
||||
Reference in New Issue
Block a user