modbus.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from __future__ import annotations
  2. from .base import ProtocolSpec
  3. MODBUS_POINT_TYPE_ALIASES = {
  4. "bool": "bool",
  5. "boolean": "bool",
  6. "BOOL": "bool",
  7. "short": "int16",
  8. "SHORT": "int16",
  9. "int16": "int16",
  10. "INT16": "int16",
  11. "word": "uint16",
  12. "WORD": "uint16",
  13. "uint16": "uint16",
  14. "UINT16": "uint16",
  15. "long": "int32",
  16. "LONG": "int32",
  17. "int32": "int32",
  18. "INT32": "int32",
  19. "dword": "uint32",
  20. "DWORD": "uint32",
  21. "uint32": "uint32",
  22. "UINT32": "uint32",
  23. "float": "float32",
  24. "FLOAT": "float32",
  25. "real": "float32",
  26. "REAL": "float32",
  27. "float32": "float32",
  28. "FLOAT32": "float32",
  29. "double": "float64",
  30. "DOUBLE": "float64",
  31. "float64": "float64",
  32. "FLOAT64": "float64",
  33. "longlong": "int64",
  34. "LONGLONG": "int64",
  35. "int64": "int64",
  36. "INT64": "int64",
  37. "qword": "uint64",
  38. "QWORD": "uint64",
  39. "uint64": "uint64",
  40. "UINT64": "uint64",
  41. }
  42. MODBUS_REGISTER_TYPE_ALIASES = {
  43. "coil": 1,
  44. "coils": 1,
  45. "read_coils": 1,
  46. "线圈": 1,
  47. "discrete_input": 2,
  48. "discrete_inputs": 2,
  49. "read_discrete_inputs": 2,
  50. "离散输入": 2,
  51. "holding_register": 3,
  52. "holding_registers": 3,
  53. "read_holding_registers": 3,
  54. "保持寄存器": 3,
  55. "input_register": 4,
  56. "input_registers": 4,
  57. "read_input_registers": 4,
  58. "输入寄存器": 4,
  59. }
  60. MODBUS_SPEC = ProtocolSpec(
  61. protocol="modbus",
  62. create_device_path="/api/collector/device",
  63. create_point_path="/api/collector/modbus/point/add_collect_point",
  64. point_test_path="/api/dc-gateway/modbus/read_points",
  65. device_defaults={
  66. "type": "modbus",
  67. "timeout": 3,
  68. "is_persistent": True,
  69. "group_id": 0,
  70. "alarm_interval": 90,
  71. "collect_interval": 5,
  72. "retry_times": 0,
  73. },
  74. point_defaults={
  75. "scale_ratio": 1,
  76. "value_offset": 0,
  77. "group_id": 0,
  78. "invalid_values": "",
  79. "valid_range_start": None,
  80. "valid_range_end": None,
  81. "bit": 0,
  82. },
  83. )