using Prism.Mvvm; namespace UIShare.UIViewModel { /// /// TCP 连接配置(与 DeviceCommand.Base.Tcp 保持字段一致)。 /// public class TcpConnectionConfig : BindableBase { private string _ipAddress = "127.0.0.1"; public string IPAddress { get => _ipAddress; set => SetProperty(ref _ipAddress, value); } private int _port = 502; public int Port { get => _port; set => SetProperty(ref _port, value); } private int _sendTimeout = 3000; public int SendTimeout { get => _sendTimeout; set => SetProperty(ref _sendTimeout, value); } private int _receiveTimeout = 3000; public int ReceiveTimeout { get => _receiveTimeout; set => SetProperty(ref _receiveTimeout, value); } public TcpConnectionConfig() { } /// 拷贝构造,用于对话框编辑副本。 public TcpConnectionConfig(TcpConnectionConfig? src) { if (src == null) return; IPAddress = src.IPAddress; Port = src.Port; SendTimeout = src.SendTimeout; ReceiveTimeout = src.ReceiveTimeout; } /// 把字段拷回目标对象(保存时用)。 public void CopyTo(TcpConnectionConfig? dst) { if (dst == null) return; dst.IPAddress = IPAddress; dst.Port = Port; dst.SendTimeout = SendTimeout; dst.ReceiveTimeout = ReceiveTimeout; } } /// /// 串口连接配置(与 DeviceCommand.Base.Serial_Port 保持字段一致)。 /// StopBits / Parity 用字符串保存,避免 UIShare 引入 System.IO.Ports 依赖。 /// public class SerialPortConnectionConfig : BindableBase { private string _portName = "COM1"; public string PortName { get => _portName; set => SetProperty(ref _portName, value); } private int _baudRate = 9600; public int BaudRate { get => _baudRate; set => SetProperty(ref _baudRate, value); } private int _dataBits = 8; public int DataBits { get => _dataBits; set => SetProperty(ref _dataBits, value); } // 取值:"One" / "OnePointFive" / "Two" / "None" private string _stopBits = "One"; public string StopBits { get => _stopBits; set => SetProperty(ref _stopBits, value); } // 取值:"None" / "Odd" / "Even" / "Mark" / "Space" private string _parity = "None"; public string Parity { get => _parity; set => SetProperty(ref _parity, value); } private int _readTimeout = 3000; public int ReadTimeout { get => _readTimeout; set => SetProperty(ref _readTimeout, value); } private int _writeTimeout = 3000; public int WriteTimeout { get => _writeTimeout; set => SetProperty(ref _writeTimeout, value); } public SerialPortConnectionConfig() { } public SerialPortConnectionConfig(SerialPortConnectionConfig? src) { if (src == null) return; PortName = src.PortName; BaudRate = src.BaudRate; DataBits = src.DataBits; StopBits = src.StopBits; Parity = src.Parity; ReadTimeout = src.ReadTimeout; WriteTimeout = src.WriteTimeout; } public void CopyTo(SerialPortConnectionConfig? dst) { if (dst == null) return; dst.PortName = PortName; dst.BaudRate = BaudRate; dst.DataBits = DataBits; dst.StopBits = StopBits; dst.Parity = Parity; dst.ReadTimeout = ReadTimeout; dst.WriteTimeout = WriteTimeout; } } }