SerialDeviceConverter.cs 944 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using TeamAAS.Core;
  6. namespace Plugins.Standard.Core
  7. {
  8. public class SerialDeviceConverter : StringConverter
  9. {
  10. public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
  11. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  12. {
  13. var names = new List<string>();
  14. try
  15. {
  16. var comm = CoreManager.Communication;
  17. if (comm != null)
  18. {
  19. names = comm.GetSerials().Select(d => d.Name).Where(n => !string.IsNullOrEmpty(n)).ToList();
  20. }
  21. }
  22. catch { }
  23. return new StandardValuesCollection(names);
  24. }
  25. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => false;
  26. }
  27. }