Pt100_modbus, itscreen v99
This commit is contained in:
parent
a0cfc13d01
commit
cb7aa966e4
Binary file not shown.
|
|
@ -39,7 +39,7 @@ APP_DIR = "/opt/iomatex-console"
|
||||||
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
||||||
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
||||||
CONFIG_PATH = "/etc/iomatex/console.json"
|
CONFIG_PATH = "/etc/iomatex/console.json"
|
||||||
UI_VERSION = "V 2.2.32"
|
UI_VERSION = "V 2.2.36"
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
"bind": "0.0.0.0",
|
"bind": "0.0.0.0",
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,16 @@ EXBD_WRITE_FAST_TIMEOUT = 2.0
|
||||||
EXBD_WRITE_POST_SLEEP = 0.2
|
EXBD_WRITE_POST_SLEEP = 0.2
|
||||||
EXBD_COMM_PROFILE_REGISTER = 0x00FF
|
EXBD_COMM_PROFILE_REGISTER = 0x00FF
|
||||||
EXBD_BAUD_WRITE_POST_SLEEP = 0.3
|
EXBD_BAUD_WRITE_POST_SLEEP = 0.3
|
||||||
|
PT100_FAMILY = "rs485_pt100_tzt"
|
||||||
|
PT100_DISPLAY_NAME = "RS485 PT100 Temperature Sensor"
|
||||||
|
PT100_BAUD_CODE_MAP = {1: 2400, 2: 4800, 3: 9600}
|
||||||
|
PT100_BAUD_TO_CODE = {value: key for key, value in PT100_BAUD_CODE_MAP.items()}
|
||||||
|
PT100_FINGERPRINT_REGISTER = {
|
||||||
|
"address": 0,
|
||||||
|
"count": 4,
|
||||||
|
"type": "holding",
|
||||||
|
"label": "reg0..3 (holding)",
|
||||||
|
}
|
||||||
|
|
||||||
PORT_GLOBS = (
|
PORT_GLOBS = (
|
||||||
"/dev/ttyS*",
|
"/dev/ttyS*",
|
||||||
|
|
@ -288,6 +298,152 @@ def format_firmware_version(registers: List[Any]) -> Dict[str, Any]:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def first_register_word(result: Optional[Dict[str, Any]]) -> Optional[int]:
|
||||||
|
words = decode_register_words((result or {}).get("values") or [])
|
||||||
|
return words[0] if words else None
|
||||||
|
|
||||||
|
|
||||||
|
def pt100_status_from_registers(reg0: Optional[int], reg1: Optional[int]) -> str:
|
||||||
|
if reg0 is None or reg1 is None:
|
||||||
|
return "invalid_or_unknown"
|
||||||
|
if int(reg0) > 3000 or int(reg1) > 2000:
|
||||||
|
return "open_circuit"
|
||||||
|
if -500 <= int(reg0) <= 2000 and 800 <= int(reg1) <= 1800:
|
||||||
|
expected = 1000 + (0.385 * float(reg0))
|
||||||
|
if abs(float(reg1) - expected) <= 50.0:
|
||||||
|
return "connected"
|
||||||
|
return "invalid_or_unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def pt100_values_from_registers(reg0: Optional[int], reg1: Optional[int]) -> Dict[str, Optional[float]]:
|
||||||
|
return {
|
||||||
|
"temperature": None if reg0 is None else round(int(reg0) / 10.0, 1),
|
||||||
|
"resistance": None if reg1 is None else round(int(reg1) / 10.0, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def pt100_detection_from_words(*, slave: int, baud: int, parity: str, registers: List[int]) -> Optional[Dict[str, Any]]:
|
||||||
|
if len(registers) < 4:
|
||||||
|
return None
|
||||||
|
reg0, reg1, reg2, reg3 = (int(registers[0]), int(registers[1]), int(registers[2]), int(registers[3]))
|
||||||
|
if reg2 != int(slave):
|
||||||
|
return None
|
||||||
|
if reg3 not in PT100_BAUD_CODE_MAP:
|
||||||
|
return None
|
||||||
|
sensor_status = pt100_status_from_registers(reg0, reg1)
|
||||||
|
if sensor_status not in ("connected", "open_circuit"):
|
||||||
|
return None
|
||||||
|
values = pt100_values_from_registers(reg0, reg1)
|
||||||
|
warning = "PT100 sensor is disconnected or wiring is incorrect" if sensor_status == "open_circuit" else ""
|
||||||
|
confidence = "high" if sensor_status == "connected" else "medium"
|
||||||
|
model_string = (
|
||||||
|
f"T={values['temperature']:.1f} C / R={values['resistance']:.1f} Ohm"
|
||||||
|
if values["temperature"] is not None and values["resistance"] is not None and sensor_status == "connected"
|
||||||
|
else "PT100 sensor is disconnected or wiring is incorrect"
|
||||||
|
)
|
||||||
|
raw_value = f"reg0={reg0}, reg1={reg1}, reg2={reg2}, reg3={reg3}"
|
||||||
|
return {
|
||||||
|
"state": "recognized",
|
||||||
|
"familyKey": PT100_FAMILY,
|
||||||
|
"familyLabel": PT100_DISPLAY_NAME,
|
||||||
|
"modelString": model_string,
|
||||||
|
"rawValue": raw_value,
|
||||||
|
"rawString": raw_value,
|
||||||
|
"rawRegisters": [reg0, reg1, reg2, reg3],
|
||||||
|
"rawBytesHex": "",
|
||||||
|
"register": dict(PT100_FINGERPRINT_REGISTER),
|
||||||
|
"detectionRegisters": [dict(PT100_FINGERPRINT_REGISTER)],
|
||||||
|
"matched": True,
|
||||||
|
"protocol": "modbus_rtu",
|
||||||
|
"addressing": "zero_based",
|
||||||
|
"sensorStatus": sensor_status,
|
||||||
|
"confidence": confidence,
|
||||||
|
"values": values,
|
||||||
|
"warning": warning,
|
||||||
|
"baudCode": reg3,
|
||||||
|
"baudMapped": PT100_BAUD_CODE_MAP.get(reg3),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def detect_pt100_oem_candidate(
|
||||||
|
*,
|
||||||
|
port: str,
|
||||||
|
slave: int,
|
||||||
|
baud: int,
|
||||||
|
parity: str,
|
||||||
|
timeout: float,
|
||||||
|
retries: int,
|
||||||
|
log_collector=None,
|
||||||
|
) -> Optional[Dict[str, Any]]:
|
||||||
|
read_result = mbpoll_read(
|
||||||
|
port=port,
|
||||||
|
slave=int(slave),
|
||||||
|
address=0,
|
||||||
|
count=4,
|
||||||
|
baud=int(baud),
|
||||||
|
parity=str(parity),
|
||||||
|
register_type="holding",
|
||||||
|
data_bits=8,
|
||||||
|
stop_bits=1,
|
||||||
|
zero_based=True,
|
||||||
|
timeout=timeout,
|
||||||
|
decode_mode="uint16",
|
||||||
|
retries=retries,
|
||||||
|
)
|
||||||
|
if not read_result.get("ok"):
|
||||||
|
return None
|
||||||
|
raw_registers = decode_register_words(read_result.get("values") or [])
|
||||||
|
detection = pt100_detection_from_words(
|
||||||
|
slave=int(slave),
|
||||||
|
baud=int(baud),
|
||||||
|
parity=str(parity),
|
||||||
|
registers=raw_registers,
|
||||||
|
)
|
||||||
|
if not detection:
|
||||||
|
return None
|
||||||
|
if log_collector:
|
||||||
|
log_collector(
|
||||||
|
"info",
|
||||||
|
f"Slave {slave}: OEM PT100 fingerprint raw registers: {raw_registers}",
|
||||||
|
slave=slave,
|
||||||
|
baud=int(baud),
|
||||||
|
parity=str(parity),
|
||||||
|
raw_value=",".join(str(item) for item in raw_registers),
|
||||||
|
result="pt100_fingerprint",
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"port": port,
|
||||||
|
"slave": int(slave),
|
||||||
|
"baud": int(baud),
|
||||||
|
"parity": str(parity),
|
||||||
|
"status": "ok",
|
||||||
|
"confidence": str(detection.get("confidence") or "medium"),
|
||||||
|
"action": "Select",
|
||||||
|
"test_register": {
|
||||||
|
"address": 0,
|
||||||
|
"count": 4,
|
||||||
|
"type": "holding",
|
||||||
|
"value": raw_registers[0] if raw_registers else None,
|
||||||
|
},
|
||||||
|
"familyDetection": detection,
|
||||||
|
"family": PT100_FAMILY,
|
||||||
|
"family_display_name": PT100_DISPLAY_NAME,
|
||||||
|
"raw_family_value": detection.get("rawValue", ""),
|
||||||
|
"configReadable": True,
|
||||||
|
"sensor_status": detection.get("sensorStatus"),
|
||||||
|
"values": dict(detection.get("values") or {}),
|
||||||
|
"raw": {
|
||||||
|
"reg0": raw_registers[0] if len(raw_registers) > 0 else None,
|
||||||
|
"reg1": raw_registers[1] if len(raw_registers) > 1 else None,
|
||||||
|
"reg2": raw_registers[2] if len(raw_registers) > 2 else None,
|
||||||
|
"reg3": raw_registers[3] if len(raw_registers) > 3 else None,
|
||||||
|
},
|
||||||
|
"warning": detection.get("warning", ""),
|
||||||
|
"protocol": "modbus_rtu",
|
||||||
|
"addressing": "zero_based",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def transport_defaults(family: str = "") -> Dict[str, Any]:
|
def transport_defaults(family: str = "") -> Dict[str, Any]:
|
||||||
if str(family or "").strip():
|
if str(family or "").strip():
|
||||||
profile = get_profile(family)
|
profile = get_profile(family)
|
||||||
|
|
@ -1382,6 +1538,7 @@ def evaluate_family_detection(profile: Dict[str, Any], read_result: Dict[str, An
|
||||||
decoded_values = normalized["decoded_values"]
|
decoded_values = normalized["decoded_values"]
|
||||||
model_string = normalized["model_string"]
|
model_string = normalized["model_string"]
|
||||||
data_type = str(register.get("data_type") or register.get("value_format") or "").strip().lower()
|
data_type = str(register.get("data_type") or register.get("value_format") or "").strip().lower()
|
||||||
|
has_match_patterns = bool(register.get("match") or [])
|
||||||
if match_detection_pattern(register.get("match") or [], normalized.get("normalized") or str(raw_value or "").strip().lower(), decoded_values, data_type):
|
if match_detection_pattern(register.get("match") or [], normalized.get("normalized") or str(raw_value or "").strip().lower(), decoded_values, data_type):
|
||||||
return {
|
return {
|
||||||
"state": "recognized",
|
"state": "recognized",
|
||||||
|
|
@ -1411,9 +1568,9 @@ def evaluate_family_detection(profile: Dict[str, Any], read_result: Dict[str, An
|
||||||
"matched": False,
|
"matched": False,
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
"state": "recognized" if not (register.get("match") or []) else "unrecognized_data",
|
"state": "unrecognized_data",
|
||||||
"familyKey": profile["family"] if not (register.get("match") or []) else "",
|
"familyKey": "",
|
||||||
"familyLabel": profile["display_name"] if not (register.get("match") or []) else "Family register has unknown data",
|
"familyLabel": "Family register has unknown data" if has_match_patterns else "Detection signature is not configured for this family",
|
||||||
"modelString": model_string or raw_value,
|
"modelString": model_string or raw_value,
|
||||||
"rawValue": raw_value,
|
"rawValue": raw_value,
|
||||||
"rawString": normalized.get("raw_text") or raw_value,
|
"rawString": normalized.get("raw_text") or raw_value,
|
||||||
|
|
@ -1421,7 +1578,7 @@ def evaluate_family_detection(profile: Dict[str, Any], read_result: Dict[str, An
|
||||||
"rawBytesHex": normalized.get("raw_bytes_hex") or "",
|
"rawBytesHex": normalized.get("raw_bytes_hex") or "",
|
||||||
"register": dict(register),
|
"register": dict(register),
|
||||||
"detectionRegisters": [dict(item) for item in profile["detection"].get("rules") or [register]],
|
"detectionRegisters": [dict(item) for item in profile["detection"].get("rules") or [register]],
|
||||||
"matched": not (register.get("match") or []),
|
"matched": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1792,10 +1949,39 @@ def build_current_config_summary(
|
||||||
relationship_result = summarize_register_value(summary_registers.get("relationship") or {}, summary_results.get("relationship"))
|
relationship_result = summarize_register_value(summary_registers.get("relationship") or {}, summary_results.get("relationship"))
|
||||||
baud_code = current_config.get("comm_profile_register")
|
baud_code = current_config.get("comm_profile_register")
|
||||||
baud_meta = map_baud_code(profile, baud_code)
|
baud_meta = map_baud_code(profile, baud_code)
|
||||||
|
extra_rows = []
|
||||||
|
warning = ""
|
||||||
|
model_string = model_result.get("cleaned") or model_result.get("raw") or ""
|
||||||
|
if profile.get("family") == PT100_FAMILY:
|
||||||
|
reg0 = first_register_word(summary_results.get("temperature"))
|
||||||
|
reg1 = first_register_word(summary_results.get("resistance"))
|
||||||
|
reg2 = first_register_word(summary_results.get("slave_id"))
|
||||||
|
reg3 = first_register_word(summary_results.get("baud_code"))
|
||||||
|
reg4 = first_register_word(summary_results.get("unknown_parameter"))
|
||||||
|
reg5 = first_register_word(summary_results.get("reserved"))
|
||||||
|
reg6 = first_register_word(summary_results.get("unknown_mode"))
|
||||||
|
values = pt100_values_from_registers(reg0, reg1)
|
||||||
|
sensor_status = pt100_status_from_registers(reg0, reg1)
|
||||||
|
warning = "PT100 sensor is disconnected or wiring is incorrect" if sensor_status == "open_circuit" else ""
|
||||||
|
if sensor_status == "connected" and values["temperature"] is not None and values["resistance"] is not None:
|
||||||
|
model_string = f"T={values['temperature']:.1f} C / R={values['resistance']:.1f} Ohm"
|
||||||
|
elif sensor_status == "open_circuit":
|
||||||
|
model_string = "PT100 sensor is disconnected or wiring is incorrect"
|
||||||
|
elif not model_string:
|
||||||
|
model_string = "PT100 sensor state is invalid or unknown"
|
||||||
|
extra_rows = [
|
||||||
|
{"label": "Temperature", "value": "—" if values["temperature"] is None else f"{values['temperature']:.1f} °C"},
|
||||||
|
{"label": "Resistance", "value": "—" if values["resistance"] is None else f"{values['resistance']:.1f} Ohm"},
|
||||||
|
{"label": "Sensor status", "value": sensor_status.replace("_", " ") if sensor_status else "invalid_or_unknown"},
|
||||||
|
{"label": "Unknown parameter", "value": "—" if reg4 is None else str(reg4)},
|
||||||
|
{"label": "Reserved", "value": "—" if reg5 is None else str(reg5)},
|
||||||
|
{"label": "Unknown mode", "value": "—" if reg6 is None else str(reg6)},
|
||||||
|
{"label": "Raw reg0..3", "value": ", ".join(str(item) for item in [reg0, reg1, reg2, reg3] if item is not None)},
|
||||||
|
]
|
||||||
return {
|
return {
|
||||||
"familyKey": profile.get("family"),
|
"familyKey": profile.get("family"),
|
||||||
"familyLabel": profile.get("display_name"),
|
"familyLabel": profile.get("display_name"),
|
||||||
"modelString": model_result.get("cleaned") or model_result.get("raw") or "",
|
"modelString": model_string,
|
||||||
"modelRaw": model_result.get("raw") or "",
|
"modelRaw": model_result.get("raw") or "",
|
||||||
"firmwareString": firmware_result.get("cleaned") or firmware_result.get("raw") or "",
|
"firmwareString": firmware_result.get("cleaned") or firmware_result.get("raw") or "",
|
||||||
"firmwareRaw": firmware_result.get("raw") or "",
|
"firmwareRaw": firmware_result.get("raw") or "",
|
||||||
|
|
@ -1825,6 +2011,8 @@ def build_current_config_summary(
|
||||||
name: result.get("values") if result and result.get("ok") else []
|
name: result.get("values") if result and result.get("ok") else []
|
||||||
for name, result in summary_results.items()
|
for name, result in summary_results.items()
|
||||||
},
|
},
|
||||||
|
"extraRows": extra_rows,
|
||||||
|
"warning": warning,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2040,6 +2228,18 @@ def discover_devices(
|
||||||
break
|
break
|
||||||
if best_candidate and best_candidate.get("familyDetection", {}).get("state") == "recognized":
|
if best_candidate and best_candidate.get("familyDetection", {}).get("state") == "recognized":
|
||||||
break
|
break
|
||||||
|
if not (best_candidate and best_candidate.get("familyDetection", {}).get("state") == "recognized"):
|
||||||
|
pt100_candidate = detect_pt100_oem_candidate(
|
||||||
|
port=port,
|
||||||
|
slave=int(slave),
|
||||||
|
baud=int(baud),
|
||||||
|
parity=str(parity),
|
||||||
|
timeout=DEFAULT_DISCOVERY_DEEP_TIMEOUT if deep else DEFAULT_DISCOVERY_QUICK_TIMEOUT,
|
||||||
|
retries=2,
|
||||||
|
log_collector=log_collector,
|
||||||
|
)
|
||||||
|
if pt100_candidate:
|
||||||
|
best_candidate = pt100_candidate
|
||||||
if best_candidate:
|
if best_candidate:
|
||||||
found = best_candidate
|
found = best_candidate
|
||||||
results.append(best_candidate)
|
results.append(best_candidate)
|
||||||
|
|
@ -2488,6 +2688,11 @@ def write_device_config(
|
||||||
"Baud rate is not changeable on EM-01. Register 0x62 updates, but actual UART speed remains 9600.",
|
"Baud rate is not changeable on EM-01. Register 0x62 updates, but actual UART speed remains 9600.",
|
||||||
400,
|
400,
|
||||||
)
|
)
|
||||||
|
if family == PT100_FAMILY and id_changed and serial_changed:
|
||||||
|
raise ApiError(
|
||||||
|
"Change Slave ID and Baud Rate separately for RS485 PT100 Temperature Sensor.",
|
||||||
|
400,
|
||||||
|
)
|
||||||
|
|
||||||
write_debug: Dict[str, Any] = {"precheck": precheck["debug"]}
|
write_debug: Dict[str, Any] = {"precheck": precheck["debug"]}
|
||||||
write_sent = False
|
write_sent = False
|
||||||
|
|
@ -2908,6 +3113,48 @@ def write_device_config(
|
||||||
else:
|
else:
|
||||||
operations.append({"level": "success", "message": "Communication profile write command completed"})
|
operations.append({"level": "success", "message": "Communication profile write command completed"})
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
|
if family == PT100_FAMILY:
|
||||||
|
message = "Power cycle is required for baud rate change to take effect"
|
||||||
|
payload = {
|
||||||
|
"ok": True,
|
||||||
|
"stage": "write",
|
||||||
|
"status": "power_cycle_required",
|
||||||
|
"message": message,
|
||||||
|
"write_baudrate": int(write_baud),
|
||||||
|
"current_requested": current,
|
||||||
|
"target_requested": target,
|
||||||
|
"write_sent": bool(write_sent),
|
||||||
|
"target_verified": False,
|
||||||
|
"rediscovery_attempted": False,
|
||||||
|
"rediscovery_found": False,
|
||||||
|
"found": True,
|
||||||
|
"final_detected_config": {
|
||||||
|
"slave": current_slave,
|
||||||
|
"baud": current_baud,
|
||||||
|
"parity": current_parity,
|
||||||
|
},
|
||||||
|
"pending_config": {
|
||||||
|
"slave": current_slave,
|
||||||
|
"baud": target_baud,
|
||||||
|
"parity": target_parity,
|
||||||
|
},
|
||||||
|
"requires_power_cycle": True,
|
||||||
|
"recommended_next_step": message,
|
||||||
|
"operation_log": operations + [{"level": "warn", "message": message}],
|
||||||
|
"debug": write_debug,
|
||||||
|
}
|
||||||
|
append_audit({
|
||||||
|
"action": "write_config",
|
||||||
|
"port": port,
|
||||||
|
"family": family,
|
||||||
|
"current": current,
|
||||||
|
"target": target,
|
||||||
|
"strategy": strategy_value,
|
||||||
|
"status": "power_cycle_required",
|
||||||
|
"success": True,
|
||||||
|
"source": source,
|
||||||
|
})
|
||||||
|
return payload
|
||||||
|
|
||||||
immediate_verify = device_probe(
|
immediate_verify = device_probe(
|
||||||
port=port,
|
port=port,
|
||||||
|
|
@ -2969,6 +3216,28 @@ def write_device_config(
|
||||||
"baud": immediate_verify["current"]["baud"],
|
"baud": immediate_verify["current"]["baud"],
|
||||||
"parity": immediate_verify["current"]["parity"],
|
"parity": immediate_verify["current"]["parity"],
|
||||||
}
|
}
|
||||||
|
if family == PT100_FAMILY and id_changed:
|
||||||
|
old_slave_verify = device_probe(
|
||||||
|
port=port,
|
||||||
|
family=family,
|
||||||
|
slave=int(current_slave),
|
||||||
|
baud=int(write_baud),
|
||||||
|
parity=str(current_parity),
|
||||||
|
timeout=DEFAULT_DISCOVER_TIMEOUT,
|
||||||
|
retries=0,
|
||||||
|
include_summary=False,
|
||||||
|
)
|
||||||
|
write_debug["old_slave_verify_after_id_change"] = old_slave_verify["debug"]
|
||||||
|
if old_slave_verify["ok"]:
|
||||||
|
operations.append({
|
||||||
|
"level": "warn",
|
||||||
|
"message": f"Old Slave ID {current_slave} still responds after write; verify device addressing before further changes",
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
operations.append({
|
||||||
|
"level": "info",
|
||||||
|
"message": f"Old Slave ID {current_slave} no longer responds after write",
|
||||||
|
})
|
||||||
success_message = f"Write verified. Device is now reachable at slave {final_detected['slave']}"
|
success_message = f"Write verified. Device is now reachable at slave {final_detected['slave']}"
|
||||||
if id_write_ack_timed_out and id_changed:
|
if id_write_ack_timed_out and id_changed:
|
||||||
operations.append({
|
operations.append({
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
{ mode: "test_by", label: "TEST BY", host: "rest.test.it-screen.by" },
|
{ mode: "test_by", label: "TEST BY", host: "rest.test.it-screen.by" },
|
||||||
{ mode: "custom", label: "Custom", host: "" }
|
{ mode: "custom", label: "Custom", host: "" }
|
||||||
];
|
];
|
||||||
const UI_VERSION = "V 2.2.32";
|
const UI_VERSION = "V 2.2.36";
|
||||||
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
||||||
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
||||||
const ITSCREEN_LOG_BATCH_MS = 250;
|
const ITSCREEN_LOG_BATCH_MS = 250;
|
||||||
|
|
@ -3075,7 +3075,7 @@
|
||||||
function modbusWriteBaudOptions() {
|
function modbusWriteBaudOptions() {
|
||||||
const profile = modbusSelectedProfile() || {};
|
const profile = modbusSelectedProfile() || {};
|
||||||
const profileOptions = Array.isArray(profile.comm_profiles) ? profile.comm_profiles : [];
|
const profileOptions = Array.isArray(profile.comm_profiles) ? profile.comm_profiles : [];
|
||||||
if (profile.family === "exbd_nano" && profileOptions.length) {
|
if (profileOptions.length) {
|
||||||
return profileOptions.map((item) => ({
|
return profileOptions.map((item) => ({
|
||||||
value: String(textValue(item.ui_value, item.baud)),
|
value: String(textValue(item.ui_value, item.baud)),
|
||||||
label: String(textValue(item.label, item.baud)),
|
label: String(textValue(item.label, item.baud)),
|
||||||
|
|
@ -3102,7 +3102,7 @@
|
||||||
if (strategy === "id") {
|
if (strategy === "id") {
|
||||||
return { target: { slave: Number(log.writeForm.slave) }, strategy };
|
return { target: { slave: Number(log.writeForm.slave) }, strategy };
|
||||||
}
|
}
|
||||||
if (profile.family === "exbd_nano") {
|
if (Array.isArray(profile.comm_profiles) && profile.comm_profiles.length) {
|
||||||
const selected = modbusWriteBaudOptions().find((item) => String(item.value) === String(log.writeForm.baud));
|
const selected = modbusWriteBaudOptions().find((item) => String(item.value) === String(log.writeForm.baud));
|
||||||
if (!selected || !Number.isInteger(selected.registerValue)) {
|
if (!selected || !Number.isInteger(selected.registerValue)) {
|
||||||
return { target: { baud: Number(current.baud) }, strategy };
|
return { target: { baud: Number(current.baud) }, strategy };
|
||||||
|
|
@ -3131,6 +3131,9 @@
|
||||||
if (modbusExbdFamilySelected()) {
|
if (modbusExbdFamilySelected()) {
|
||||||
log.writeForm.parity = "none";
|
log.writeForm.parity = "none";
|
||||||
}
|
}
|
||||||
|
if (modbusEditorFamily() === "rs485_pt100_tzt") {
|
||||||
|
log.writeForm.parity = "none";
|
||||||
|
}
|
||||||
if (modbusEm01FamilySelected()) {
|
if (modbusEm01FamilySelected()) {
|
||||||
log.writeForm.baud = "9600";
|
log.writeForm.baud = "9600";
|
||||||
log.writeForm.parity = "none";
|
log.writeForm.parity = "none";
|
||||||
|
|
@ -3290,6 +3293,13 @@
|
||||||
|
|
||||||
function modbusDeviceStatusMeta(item) {
|
function modbusDeviceStatusMeta(item) {
|
||||||
const detection = modbusSelectedDetection(item);
|
const detection = modbusSelectedDetection(item);
|
||||||
|
if (modbusIsPt100Detection(detection) && detection.state === "recognized") {
|
||||||
|
return {
|
||||||
|
label: modbusPt100StatusLabel(detection.sensorStatus),
|
||||||
|
tone: modbusPt100StatusTone(detection.sensorStatus),
|
||||||
|
family: textValue(detection.familyLabel, t("Unknown device"))
|
||||||
|
};
|
||||||
|
}
|
||||||
const family = textValue(detection.familyLabel, t("Unknown device"));
|
const family = textValue(detection.familyLabel, t("Unknown device"));
|
||||||
const model = textValue(detection.modelString, "");
|
const model = textValue(detection.modelString, "");
|
||||||
if (detection.state === "recognized") {
|
if (detection.state === "recognized") {
|
||||||
|
|
@ -3313,6 +3323,53 @@
|
||||||
return { ...(fallback || {}), ...((summary && typeof summary === "object") ? summary : {}) };
|
return { ...(fallback || {}), ...((summary && typeof summary === "object") ? summary : {}) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function modbusIsPt100Detection(detection) {
|
||||||
|
return textValue(detection && detection.familyKey, "") === "rs485_pt100_tzt";
|
||||||
|
}
|
||||||
|
|
||||||
|
function modbusPt100StatusLabel(status) {
|
||||||
|
const normalized = textValue(status, "").toLowerCase();
|
||||||
|
if (normalized === "connected") return t("Connected");
|
||||||
|
if (normalized === "open_circuit") return t("Open circuit");
|
||||||
|
if (normalized === "invalid_or_unknown") return t("Invalid or unknown");
|
||||||
|
return t("Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
function modbusPt100StatusTone(status) {
|
||||||
|
const normalized = textValue(status, "").toLowerCase();
|
||||||
|
if (normalized === "connected") return "ok";
|
||||||
|
if (normalized === "open_circuit") return "warn";
|
||||||
|
return "warn";
|
||||||
|
}
|
||||||
|
|
||||||
|
function modbusPt100MetricText(value, unit) {
|
||||||
|
const number = Number(value);
|
||||||
|
if (!Number.isFinite(number)) return t("Not available");
|
||||||
|
return `${number.toFixed(1)} ${unit}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function modbusPt100RegisterText(detection) {
|
||||||
|
const rawRegisters = Array.isArray(detection && detection.rawRegisters) ? detection.rawRegisters : [];
|
||||||
|
if (rawRegisters.length < 4) return rawRegisters.length ? `[${rawRegisters.join(", ")}]` : "-";
|
||||||
|
return `reg0=${rawRegisters[0]}, reg1=${rawRegisters[1]}, reg2=${rawRegisters[2]}, reg3=${rawRegisters[3]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderModbusDetectedFamilyCell(item) {
|
||||||
|
const detection = modbusSelectedDetection(item);
|
||||||
|
const status = modbusDeviceStatusMeta(item);
|
||||||
|
if (!modbusIsPt100Detection(detection)) return esc(status.family);
|
||||||
|
const values = detection && detection.values || {};
|
||||||
|
const warning = textValue(detection && detection.warning, "");
|
||||||
|
return `
|
||||||
|
<div>${esc(textValue(detection.familyLabel, status.family))}</div>
|
||||||
|
<div class="formHint">${esc(t("Confidence"))}: ${esc(textValue(detection.confidence, textValue(item.confidence, "medium")))}</div>
|
||||||
|
<div class="formHint">${esc(t("Temperature"))}: ${esc(modbusPt100MetricText(values.temperature, "°C"))}</div>
|
||||||
|
<div class="formHint">${esc(t("Resistance"))}: ${esc(modbusPt100MetricText(values.resistance, "Ohm"))}</div>
|
||||||
|
<div class="formHint">${esc(t("Sensor status"))}: ${esc(modbusPt100StatusLabel(detection.sensorStatus))}</div>
|
||||||
|
${warning ? `<div class="formHint">${esc(warning)}</div>` : ""}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
function modbusDetectionRegisterSource(detection) {
|
function modbusDetectionRegisterSource(detection) {
|
||||||
const registers = Array.isArray(detection && detection.detectionRegisters) ? detection.detectionRegisters : [];
|
const registers = Array.isArray(detection && detection.detectionRegisters) ? detection.detectionRegisters : [];
|
||||||
if (registers.length) {
|
if (registers.length) {
|
||||||
|
|
@ -3323,6 +3380,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function modbusDetectionDebugValue(detection) {
|
function modbusDetectionDebugValue(detection) {
|
||||||
|
if (modbusIsPt100Detection(detection)) {
|
||||||
|
return modbusPt100RegisterText(detection);
|
||||||
|
}
|
||||||
const decoded = textValue(detection && (detection.modelString || detection.rawValue || detection.rawString), "");
|
const decoded = textValue(detection && (detection.modelString || detection.rawValue || detection.rawString), "");
|
||||||
const rawRegisters = Array.isArray(detection && detection.rawRegisters) ? detection.rawRegisters : [];
|
const rawRegisters = Array.isArray(detection && detection.rawRegisters) ? detection.rawRegisters : [];
|
||||||
if (decoded && rawRegisters.length) return `${decoded} [${rawRegisters.join(", ")}]`;
|
if (decoded && rawRegisters.length) return `${decoded} [${rawRegisters.join(", ")}]`;
|
||||||
|
|
@ -3365,7 +3425,7 @@
|
||||||
<td>${esc(item.parity)}</td>
|
<td>${esc(item.parity)}</td>
|
||||||
<td>${esc(modbusDetectionRegisterSource(detection))}</td>
|
<td>${esc(modbusDetectionRegisterSource(detection))}</td>
|
||||||
<td><span class="statusBadge is-${esc(status.tone)}">${esc(status.label)}</span></td>
|
<td><span class="statusBadge is-${esc(status.tone)}">${esc(status.label)}</span></td>
|
||||||
<td>${esc(status.family)}</td>
|
<td>${renderModbusDetectedFamilyCell(item)}</td>
|
||||||
<td>${esc(modbusDetectionDebugValue(detection))}</td>
|
<td>${esc(modbusDetectionDebugValue(detection))}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="actionRow compactActionRow">
|
<div class="actionRow compactActionRow">
|
||||||
|
|
@ -3427,8 +3487,13 @@
|
||||||
{ label: t("Last successful read"), value: formatTimestamp(currentConfig.last_successful_read) },
|
{ label: t("Last successful read"), value: formatTimestamp(currentConfig.last_successful_read) },
|
||||||
{ label: t("Last communication timestamp"), value: formatTimestamp(currentConfig.last_communication_timestamp) }
|
{ label: t("Last communication timestamp"), value: formatTimestamp(currentConfig.last_communication_timestamp) }
|
||||||
];
|
];
|
||||||
|
const extraRows = Array.isArray(summary.extraRows) ? summary.extraRows.map((item) => ({
|
||||||
|
label: textValue(item && item.label, "-"),
|
||||||
|
value: textValue(item && item.value, "-")
|
||||||
|
})) : [];
|
||||||
return `
|
return `
|
||||||
<div class="meta compactMeta">${renderKeyValueRows(rows)}</div>
|
${summary.warning ? `<div class="banner warn">${esc(summary.warning)}</div>` : ""}
|
||||||
|
<div class="meta compactMeta">${renderKeyValueRows(rows.concat(extraRows))}</div>
|
||||||
<details class="technicalDetails">
|
<details class="technicalDetails">
|
||||||
<summary>${esc(t("Raw register details"))}</summary>
|
<summary>${esc(t("Raw register details"))}</summary>
|
||||||
<pre class="diagBlock">${esc(JSON.stringify(currentConfig.raw_values || {}, null, 2))}</pre>
|
<pre class="diagBlock">${esc(JSON.stringify(currentConfig.raw_values || {}, null, 2))}</pre>
|
||||||
|
|
@ -3452,7 +3517,7 @@
|
||||||
if (!result) return "";
|
if (!result) return "";
|
||||||
const status = textValue(result.status, "");
|
const status = textValue(result.status, "");
|
||||||
const isSuccess = result.ok === true && status === "verified_target";
|
const isSuccess = result.ok === true && status === "verified_target";
|
||||||
const level = isSuccess ? "success" : (status === "found_elsewhere" || status === "write_unconfirmed" ? "warn" : "error");
|
const level = isSuccess ? "success" : (status === "found_elsewhere" || status === "write_unconfirmed" || status === "power_cycle_required" ? "warn" : "error");
|
||||||
const message = textValue(result.message || result.recommended_next_step, status || t("Unknown"));
|
const message = textValue(result.message || result.recommended_next_step, status || t("Unknown"));
|
||||||
const summaryRows = [];
|
const summaryRows = [];
|
||||||
const finalConfig = result.final_detected_config || {};
|
const finalConfig = result.final_detected_config || {};
|
||||||
|
|
@ -3735,12 +3800,12 @@
|
||||||
</select>`
|
</select>`
|
||||||
}
|
}
|
||||||
</label>
|
</label>
|
||||||
${modbusEm01FamilySelected() ? `<div class="formHint">${esc(modbusEm01BaudComment())}</div>` : (modbusExbdFamilySelected() ? `
|
${modbusEm01FamilySelected() ? `<div class="formHint">${esc(modbusEm01BaudComment())}</div>` : ((modbusExbdFamilySelected() || modbusEditorFamily() === "rs485_pt100_tzt") ? `
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span>${esc(t("New Parity"))}</span>
|
<span>${esc(t("New Parity"))}</span>
|
||||||
<input type="text" value="none" disabled readonly>
|
<input type="text" value="none" disabled readonly>
|
||||||
</label>
|
</label>
|
||||||
<div class="formHint">${esc(modbusExbdParityComment())}</div>
|
<div class="formHint">${esc(modbusEditorFamily() === "rs485_pt100_tzt" ? t("Parity is fixed to none on this PT100 sensor.") : modbusExbdParityComment())}</div>
|
||||||
` : `
|
` : `
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span>${esc(t("New Parity"))}</span>
|
<span>${esc(t("New Parity"))}</span>
|
||||||
|
|
@ -5245,7 +5310,7 @@
|
||||||
const status = textValue(payload.status, "");
|
const status = textValue(payload.status, "");
|
||||||
const level = payload.ok === true && status === "verified_target"
|
const level = payload.ok === true && status === "verified_target"
|
||||||
? "success"
|
? "success"
|
||||||
: (status === "found_elsewhere" || status === "write_unconfirmed" ? "warn" : "error");
|
: (status === "found_elsewhere" || status === "write_unconfirmed" || status === "power_cycle_required" ? "warn" : "error");
|
||||||
const message = payload.message || payload.recommended_next_step || t("Configuration write completed");
|
const message = payload.message || payload.recommended_next_step || t("Configuration write completed");
|
||||||
appendModbusWriteLog(message, level);
|
appendModbusWriteLog(message, level);
|
||||||
appendModbusLog(message, level);
|
appendModbusLog(message, level);
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
{
|
|
||||||
"family": "ultrasonic_water_meter",
|
|
||||||
"title": "Ultrasonic Water Flow Meter IOMX WM 214C",
|
|
||||||
"display_name": "Ultrasonic Water Flow Meter IOMX WM 214C",
|
|
||||||
"transport": {
|
|
||||||
"protocol": "modbus_rtu",
|
|
||||||
"default_port": "/dev/ttyS3",
|
|
||||||
"default_baud": 9600,
|
|
||||||
"default_parity": "none",
|
|
||||||
"default_databits": 8,
|
|
||||||
"default_stopbits": 1,
|
|
||||||
"scan_baud": [2400, 4800, 9600],
|
|
||||||
"scan_parity": ["none", "even", "odd"],
|
|
||||||
"zero_based": true
|
|
||||||
},
|
|
||||||
"detection": {
|
|
||||||
"family_register": {
|
|
||||||
"address": 0,
|
|
||||||
"count": 1,
|
|
||||||
"type": "holding",
|
|
||||||
"decode_mode": "uint16"
|
|
||||||
},
|
|
||||||
"empty_values": ["", "0", "65535"],
|
|
||||||
"timeout_quick": 1.8,
|
|
||||||
"timeout_deep": 3.2
|
|
||||||
},
|
|
||||||
"registers": {
|
|
||||||
"test_read": {
|
|
||||||
"address": 0,
|
|
||||||
"count": 1,
|
|
||||||
"type": "holding"
|
|
||||||
},
|
|
||||||
"slave_id": {
|
|
||||||
"address": 1543,
|
|
||||||
"count": 1,
|
|
||||||
"type": "holding",
|
|
||||||
"rw": true
|
|
||||||
},
|
|
||||||
"comm_profile": {
|
|
||||||
"address": 1544,
|
|
||||||
"count": 1,
|
|
||||||
"type": "holding",
|
|
||||||
"rw": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"comm_profiles": []
|
|
||||||
}
|
|
||||||
|
|
@ -191,7 +191,7 @@ for path in \
|
||||||
"$SRC_ROOT/backend/app.py" \
|
"$SRC_ROOT/backend/app.py" \
|
||||||
"$SRC_ROOT/backend/itscreen_registration.py" \
|
"$SRC_ROOT/backend/itscreen_registration.py" \
|
||||||
"$SRC_ROOT/backend/modbus_backend.py" \
|
"$SRC_ROOT/backend/modbus_backend.py" \
|
||||||
"$SRC_ROOT/modbus_profiles/ultrasonic_water_meter.json" \
|
"$SRC_ROOT/modbus_profiles/rs485_pt100_tzt.json" \
|
||||||
"$SRC_ROOT/modbus_profiles/iomx_nano_exbd_08_16_12.json" \
|
"$SRC_ROOT/modbus_profiles/iomx_nano_exbd_08_16_12.json" \
|
||||||
"$SRC_ROOT/modbus_profiles/iomx_em_01.json" \
|
"$SRC_ROOT/modbus_profiles/iomx_em_01.json" \
|
||||||
"$SRC_ROOT/frontend/index.html" \
|
"$SRC_ROOT/frontend/index.html" \
|
||||||
|
|
@ -251,7 +251,7 @@ require_file "$STAGE_FRONTEND_DIR/console.i18n.js"
|
||||||
require_file "$STAGE_FRONTEND_DIR/console.js"
|
require_file "$STAGE_FRONTEND_DIR/console.js"
|
||||||
require_file "$STAGE_FRONTEND_DIR/console.css"
|
require_file "$STAGE_FRONTEND_DIR/console.css"
|
||||||
require_file "$STAGE_PROVIDERS_DIR/00_core_services.py"
|
require_file "$STAGE_PROVIDERS_DIR/00_core_services.py"
|
||||||
require_file "$STAGE_MODBUS_PROFILES_DIR/ultrasonic_water_meter.json"
|
require_file "$STAGE_MODBUS_PROFILES_DIR/rs485_pt100_tzt.json"
|
||||||
require_file "$STAGE_MODBUS_PROFILES_DIR/iomx_nano_exbd_08_16_12.json"
|
require_file "$STAGE_MODBUS_PROFILES_DIR/iomx_nano_exbd_08_16_12.json"
|
||||||
require_file "$SRC_GBOX"
|
require_file "$SRC_GBOX"
|
||||||
|
|
||||||
|
|
@ -320,7 +320,7 @@ require_file "$FRONTEND_DIR/index.html"
|
||||||
require_file "$FRONTEND_DIR/console.js"
|
require_file "$FRONTEND_DIR/console.js"
|
||||||
require_file "$FRONTEND_DIR/console.css"
|
require_file "$FRONTEND_DIR/console.css"
|
||||||
require_file "$PROVIDERS_DIR/00_core_services.py"
|
require_file "$PROVIDERS_DIR/00_core_services.py"
|
||||||
require_file "$MODBUS_PROFILES_DIR/ultrasonic_water_meter.json"
|
require_file "$MODBUS_PROFILES_DIR/rs485_pt100_tzt.json"
|
||||||
require_file "$MODBUS_PROFILES_DIR/iomx_nano_exbd_08_16_12.json"
|
require_file "$MODBUS_PROFILES_DIR/iomx_nano_exbd_08_16_12.json"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl_try disable --now iomatex-mdns-alias.service
|
systemctl_try disable --now iomatex-mdns-alias.service
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue