终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

73 lines
2.4 KiB

  1. using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.Device
  8. {
  9. public class VariableMonitorAttribute : Attribute
  10. {
  11. /// <summary>
  12. /// 变量描述
  13. /// </summary>
  14. /// <param name="Notes">描述</param>
  15. /// <param name="PLCAddress">PLC 地址</param>
  16. /// <param name="ModbusTcpAddress">Modbus TCP 地址</param>
  17. public VariableMonitorAttribute(string Notes, string PLCAddress = "", string ModbusTcpAddress = "")
  18. {
  19. this.PLCAddress = PLCAddress;
  20. this.ModbusTcpAddress = GetModbusTcpAdd(PLCAddress);// ModbusTcpAddress;
  21. this.Notes = Notes;
  22. }
  23. private string GetModbusTcpAdd(string address)
  24. {
  25. if (address == null) return "";
  26. if (address.Length > 0)
  27. {
  28. address = address.Trim();
  29. if (address.ToUpper().Contains("M") && address.Length >= 4)
  30. {
  31. var res = address.Substring(1).Split('.');
  32. if (res != null && res.Length == 2)
  33. {
  34. if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
  35. {
  36. if (ExitAddress >= 0 && ExitAddress <= 7)
  37. {
  38. return ((firstAddress * 8) + 320 + ExitAddress).ToString();
  39. }
  40. }
  41. }
  42. }
  43. else if ((address.ToUpper().Contains("VW") || address.ToUpper().Contains("VD")) && address.Length >= 3)
  44. {
  45. var res = address.Substring(2);
  46. if (res != null && int.TryParse(res, out int tempAddress))
  47. {
  48. return ((tempAddress / 2) + 100).ToString();
  49. }
  50. }
  51. }
  52. return "";
  53. }
  54. /// <summary>
  55. /// PLC 地址
  56. /// </summary>
  57. public string PLCAddress { get; set; }
  58. /// <summary>
  59. /// Modbus TCP 地址
  60. /// </summary>
  61. public string ModbusTcpAddress { get; set; }
  62. /// <summary>
  63. /// 描述
  64. /// </summary>
  65. public string Notes { get; set; }
  66. }
  67. }