ASCIIConverter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Uestc.Auto6.Dso.Protocol.RS232
  7. {
  8. static class ASCIIConverter
  9. {
  10. public static string GetASCIIStr(char c)
  11. {
  12. return (int)c switch
  13. {
  14. 0 => "NUL",
  15. 1 => "SOH",
  16. 2 => "STX",
  17. 3 => "ETX",
  18. 4 => "EOT",
  19. 5 => "EBQ",
  20. 6 => "ACK",
  21. 7 => "BEL",
  22. 8 => "BS",
  23. 9 => "HT",
  24. 10 => "LF",
  25. 11 => "VT",
  26. 12 => "FF",
  27. 13 => "CR",
  28. 14 => "SO",
  29. 15 => "SI",
  30. 16 => "DLE",
  31. 17 => "DC1",
  32. 18 => "DC2",
  33. 19 => "DC3",
  34. 20 => "DC4",
  35. 21 => "NAK",
  36. 22 => "SYN",
  37. 23 => "ETB",
  38. 24 => "CAN",
  39. 25 => "EM",
  40. 26 => "SUB",
  41. 27 => "ESC",
  42. 28 => "FS",
  43. 29 => "GS",
  44. 30 => "RS",
  45. 31 => "US",
  46. 32 => "SP",
  47. int ch when (ch >= 33 && ch <= 126) => System.Text.Encoding.ASCII.GetString(new byte[1] { (byte)ch}),
  48. 127 => "DEL",
  49. _=>"",
  50. };
  51. }
  52. }
  53. }