using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.IO.Ports; using System.Text; using System.Threading.Tasks; namespace HBLConsole.Model { public class ModbusRtu : SerialDeviceBase { public ModbusRtu() { Init(); } public ObservableCollection Ports { get; set; } = new ObservableCollection(); public ObservableCollection BaudRates { get; set; } = new ObservableCollection(); public ObservableCollection Paritys { get; set; } = new ObservableCollection(); private void Init() { Ports.Clear(); foreach (var item in SerialPort.GetPortNames()) { Ports.Add(item); } BaudRates.Clear(); BaudRates.Add("110"); int initValue = 300; for (int i = 0; i < 17; i++) { BaudRates.Add(initValue.ToString()); initValue *= 2; } Paritys.Clear(); foreach (var item in Enum.GetNames(typeof(EParity))) { Paritys.Add(item); } } } }