You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.IO.Ports;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace HBLConsole.Model
  9. {
  10. public class ModbusRtu : SerialDeviceBase
  11. {
  12. public ModbusRtu()
  13. {
  14. Init();
  15. }
  16. public ObservableCollection<string> Ports { get; set; } = new ObservableCollection<string>();
  17. public ObservableCollection<string> BaudRates { get; set; } = new ObservableCollection<string>();
  18. public ObservableCollection<string> Paritys { get; set; } = new ObservableCollection<string>();
  19. private void Init()
  20. {
  21. Ports.Clear();
  22. foreach (var item in SerialPort.GetPortNames())
  23. {
  24. Ports.Add(item);
  25. }
  26. BaudRates.Clear();
  27. BaudRates.Add("110");
  28. int initValue = 300;
  29. for (int i = 0; i < 17; i++)
  30. {
  31. BaudRates.Add(initValue.ToString());
  32. initValue *= 2;
  33. }
  34. Paritys.Clear();
  35. foreach (var item in Enum.GetNames(typeof(EParity)))
  36. {
  37. Paritys.Add(item);
  38. }
  39. }
  40. }
  41. }