You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
6.9 KiB
Python
267 lines
6.9 KiB
Python
from . import tools
|
|
|
|
TRANSFER_FUNCTION_CODE = {
|
|
0: "线性 (Linear)",
|
|
1: "平方根 (Square Root)",
|
|
2: "平方根三次方 (Square Root 3rd Power)",
|
|
3: "平方根五次方 (Square Root 5th Power)",
|
|
4: "特殊曲线 (Special Curve) - 不推荐使用",
|
|
5: "平方 (Square)",
|
|
6: "带截止的平方根 (Square root with cut-off)",
|
|
10: "等百分比 1:25 (Equal Percentage 1:25)",
|
|
11: "等百分比 1:33 (Equal Percentage 1:33)",
|
|
12: "等百分比 1:50 (Equal Percentage 1:50)",
|
|
15: "快开 1:25 (Quick Open 1:25)",
|
|
16: "快开 1:33 (Quick Open 1:33)",
|
|
17: "快开 1:50 (Quick Open 1:50)",
|
|
30: "双曲线 (Hyperbolic) - Shape Factor 0.10",
|
|
31: "双曲线 (Hyperbolic) - Shape Factor 0.20",
|
|
32: "双曲线 (Hyperbolic) - Shape Factor 0.30",
|
|
34: "双曲线 (Hyperbolic) - Shape Factor 0.50",
|
|
37: "双曲线 (Hyperbolic) - Shape Factor 0.70",
|
|
40: "双曲线 (Hyperbolic) - Shape Factor 1.00",
|
|
41: "双曲线 (Hyperbolic) - Shape Factor 1.50",
|
|
42: "双曲线 (Hyperbolic) - Shape Factor 2.00",
|
|
43: "双曲线 (Hyperbolic) - Shape Factor 3.00",
|
|
44: "双曲线 (Hyperbolic) - Shape Factor 4.00",
|
|
45: "双曲线 (Hyperbolic) - Shape Factor 5.00",
|
|
100: "平底罐 (Flat bottom tank)",
|
|
101: "锥形或金字塔形底罐 (Conical or pyramidal bottom tank)",
|
|
102: "抛物线形底罐 (Parabolic bottom tank)",
|
|
103: "球形底罐 (Spherical bottom tank)",
|
|
104: "斜底罐 (Angled bottom tank)",
|
|
105: "平端圆柱罐 (Flat end cylinder tank)",
|
|
106: "抛物线端圆柱罐 (Parabolic end cylinder tank)",
|
|
107: "球形罐 (Spherical tank)",
|
|
230: "离散/开关 (Discrete/Switch)",
|
|
250: "未使用 (Not Used)",
|
|
251: "无 (None)",
|
|
252: "未知 (Unknown)",
|
|
253: "特殊 (Special)"
|
|
}
|
|
REVERSE_TRANSFER_FUNCTION_CODE = {v: k for k, v in TRANSFER_FUNCTION_CODE.items()}
|
|
|
|
UNITS_CODE = {
|
|
# Pressure
|
|
1: "inH2O @ 68 F",
|
|
2: "inHg @ 0 C",
|
|
3: "ftH2O @ 68 F",
|
|
4: "mmH2O @ 68 F",
|
|
5: "mmHg @ 0 C",
|
|
6: "psi",
|
|
7: "bar",
|
|
8: "mbar",
|
|
9: "g/cm2",
|
|
10: "kg/cm2",
|
|
11: "Pa",
|
|
12: "kPa",
|
|
13: "torr",
|
|
14: "atm",
|
|
145: "inH2O @ 60F",
|
|
237: "MPa",
|
|
238: "inH2O @ 4C",
|
|
239: "mmH2O @ 4C",
|
|
# Temperature
|
|
32: "deg C",
|
|
33: "deg F",
|
|
34: "deg R",
|
|
35: "K",
|
|
# Volumetric Flow
|
|
15: "cu ft/min",
|
|
16: "gal/min",
|
|
17: "liter/min",
|
|
18: "imp gal/min",
|
|
19: "cu m/hr",
|
|
22: "gal/sec",
|
|
23: "Mgal/day",
|
|
24: "liter/sec",
|
|
25: "Ml/day",
|
|
26: "cu ft/sec",
|
|
27: "cu ft/day",
|
|
28: "cu m/sec",
|
|
29: "cu m/day",
|
|
30: "imp gal/hr",
|
|
31: "imp gal/day",
|
|
121: "std cu m/hr",
|
|
122: "std liter/hr",
|
|
123: "std cu ft/min",
|
|
130: "cu ft/hr",
|
|
131: "cu m/min",
|
|
132: "bbl/sec",
|
|
133: "bbl/min",
|
|
134: "bbl/hr",
|
|
135: "bbl/day",
|
|
136: "gal/hr",
|
|
137: "imp gal/sec",
|
|
235: "gal/day",
|
|
# Velocity
|
|
20: "ft/sec",
|
|
21: "m/sec",
|
|
114: "in/sec",
|
|
115: "in/min",
|
|
116: "ft/min",
|
|
120: "m/hr",
|
|
# Volume
|
|
40: "gal",
|
|
41: "liter",
|
|
42: "imp gal",
|
|
43: "cu m",
|
|
46: "bbl",
|
|
110: "bushel",
|
|
111: "cu yd",
|
|
112: "cu ft",
|
|
113: "cu in",
|
|
134: "bbl liq",
|
|
166: "std cu m",
|
|
167: "std l",
|
|
168: "std cu ft",
|
|
236: "hectoliter",
|
|
# Mass
|
|
60: "g",
|
|
61: "kg",
|
|
62: "metric ton",
|
|
63: "lb",
|
|
64: "short ton",
|
|
65: "long ton",
|
|
125: "oz",
|
|
# Mass Flow
|
|
70: "g/sec",
|
|
71: "g/min",
|
|
72: "g/hr",
|
|
73: "kg/sec",
|
|
74: "kg/min",
|
|
75: "kg/hr",
|
|
76: "kg/day",
|
|
77: "metric ton/min",
|
|
78: "metric ton/hr",
|
|
79: "metric ton/day",
|
|
80: "lb/sec",
|
|
81: "lb/min",
|
|
82: "lb/hr",
|
|
83: "lb/day",
|
|
84: "short ton/min",
|
|
85: "short ton/hr",
|
|
86: "short ton/day",
|
|
87: "long ton/hr",
|
|
88: "long ton/day",
|
|
# Mass per Volume
|
|
90: "SGU",
|
|
91: "g/cu cm",
|
|
92: "kg/cu m",
|
|
93: "lb/gal",
|
|
94: "lb/cu ft",
|
|
95: "g/ml",
|
|
96: "kg/liter",
|
|
97: "g/liter",
|
|
98: "lb/cu in",
|
|
99: "short ton/cu yd",
|
|
100: "deg Twaddell",
|
|
102: "deg Baume",
|
|
103: "deg API",
|
|
104: "deg API",
|
|
146: "ug/liter",
|
|
147: "ug/cu m",
|
|
# Viscosity
|
|
54: "cSt",
|
|
55: "cP",
|
|
# Electric Potential
|
|
36: "mV",
|
|
58: "V",
|
|
# Electric Current
|
|
39: "mA",
|
|
# Electric Resistance
|
|
37: "ohm",
|
|
163: "kohm",
|
|
# Energy (includes Work)
|
|
69: "J",
|
|
89: "dtherm",
|
|
126: "kWh",
|
|
128: "MWh",
|
|
162: "kcal",
|
|
164: "MJ",
|
|
165: "Btu",
|
|
# Power
|
|
127: "kW",
|
|
129: "hp",
|
|
140: "Mcal/hr",
|
|
141: "MJ/hr",
|
|
142: "Btu/hr",
|
|
# Radial Velocity
|
|
117: "deg/sec",
|
|
118: "rev/sec",
|
|
119: "rpm",
|
|
# Miscellaneous
|
|
38: "Hz",
|
|
57: "percent",
|
|
59: "pH",
|
|
101: "deg Balling",
|
|
105: "percent solids/wt",
|
|
106: "percent solids/vol",
|
|
107: "deg Plato",
|
|
108: "proof/vol",
|
|
109: "proof/mass",
|
|
139: "ppm",
|
|
148: "percent consistency",
|
|
149: "vol percent",
|
|
150: "percent steam qual",
|
|
152: "cu ft/lb",
|
|
153: "pF",
|
|
154: "ml/liter",
|
|
155: "ul/liter",
|
|
156: "dB",
|
|
160: "deg Brix",
|
|
161: "percent LEL",
|
|
169: "ppb",
|
|
# Generic & Reserved
|
|
240: "Manufacturer specific",
|
|
241: "Manufacturer specific",
|
|
242: "Manufacturer specific",
|
|
243: "Manufacturer specific",
|
|
244: "Manufacturer specific",
|
|
245: "Manufacturer specific",
|
|
246: "Manufacturer specific",
|
|
247: "Manufacturer specific",
|
|
248: "Manufacturer specific",
|
|
249: "Manufacturer specific",
|
|
250: "Not Used",
|
|
251: "Unknown",
|
|
252: "Unknown",
|
|
253: "Special"
|
|
}
|
|
REVERSE_UNITS_CODE = {v: k for k, v in UNITS_CODE.items()}
|
|
|
|
def get_unit_description(code):
|
|
"""根据代码获取单位描述"""
|
|
return UNITS_CODE.get(code, f"未知代码({code})")
|
|
|
|
def set_primary_variable_lower_range_value(address: bytes, value) -> bytes:
|
|
return tools.pack_command(address, command_id=37)
|
|
|
|
def reset_configuration_changed_flag(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=38)
|
|
|
|
def perform_master_reset(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=42)
|
|
|
|
def read_additional_transmitter_status(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=48)
|
|
|
|
def read_dynamic_variable_assignments(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=50)
|
|
|
|
def write_number_of_response_preambles(address: bytes, number: int) -> bytes:
|
|
data = number.to_bytes(1, "big")
|
|
return tools.pack_command(address, command_id=59, data=data)
|
|
|
|
def toggle_analog_output_mode(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=66)
|
|
|
|
def trim_analog_output_zero(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=67)
|
|
|
|
def trim_analog_output_span(address: bytes) -> bytes:
|
|
return tools.pack_command(address, command_id=68)
|
|
|
|
def select_baud_rate(address: bytes, rate: int) -> bytes:
|
|
data = rate.to_bytes(1, "big")
|
|
return tools.pack_command(address, command_id=123, data=data) |