终端一体化运控平台
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.
 
 
 

87 line
3.3 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace BPASmartClient.MorkCL
  10. {
  11. /// <summary>
  12. /// 地址转换类
  13. /// </summary>
  14. internal static class ExtensionMethod
  15. {
  16. /// <summary>
  17. /// Modbus 地址转换
  18. /// </summary>
  19. /// <param name="address"></param>
  20. /// <returns></returns>
  21. public static string ToModbusAdd(this string address)
  22. {
  23. if (address == null) return "";
  24. if (address.Length > 0)
  25. {
  26. address = address.Trim();
  27. if (address.ToUpper().Contains("GM") && address.Length >= 3)
  28. {
  29. var res = address.Remove(0, 2);
  30. if (res != null && res.Length > 0) return (int.Parse(res) + 4096).ToString();
  31. }
  32. else if (address.ToUpper().Contains("M") && address.Length >= 4)
  33. {
  34. var res = address.Substring(1).Split('.');
  35. if (res != null && res.Length == 2)
  36. {
  37. if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
  38. {
  39. if (ExitAddress >= 0 && ExitAddress <= 7)
  40. {
  41. return ((firstAddress * 8) + 320 + ExitAddress).ToString();
  42. }
  43. }
  44. }
  45. }
  46. else if (address.ToUpper().Contains("GI") && address.Length >= 3)
  47. {
  48. var res = address.Remove(0, 2);
  49. if (res != null && res.Length > 0) return res;
  50. }
  51. else if (address.ToUpper().Contains("LB") && address.Length >= 3)
  52. {
  53. var res = address.Substring(2);
  54. if (res != null && res.Length > 0)
  55. {
  56. if (int.TryParse(res, out int firstAddress)) return firstAddress.ToString();
  57. }
  58. }
  59. else if ((address.ToUpper().Contains("VW") || address.ToUpper().Contains("VD")) && address.Length >= 3)
  60. {
  61. var res = address.Substring(2);
  62. if (res != null && int.TryParse(res, out int tempAddress))
  63. {
  64. return ((tempAddress / 2) + 100).ToString();
  65. }
  66. }
  67. else if (address.ToUpper().Contains("LW") && address.Length >= 3)
  68. {
  69. var res = address.Substring(2);
  70. if (res != null && int.TryParse(res, out int LwAddress))
  71. {
  72. return LwAddress.ToString();
  73. }
  74. }
  75. }
  76. return "";
  77. }
  78. public static void ShowNotify(this MessageNotify notify, string title, string info,EnumPromptType promptType= EnumPromptType.Success)
  79. {
  80. NoticeDemoViewModel.OpenMsg(promptType, Application.Current.MainWindow, title, info);
  81. }
  82. }
  83. }