diff --git a/stage_ui/console_core/backend/modbus_backend.py b/stage_ui/console_core/backend/modbus_backend.py index fb64369..1da722f 100644 --- a/stage_ui/console_core/backend/modbus_backend.py +++ b/stage_ui/console_core/backend/modbus_backend.py @@ -3,9 +3,11 @@ import glob import json import os import re +import select import shutil import subprocess import sys +import termios import threading import time import uuid @@ -22,6 +24,14 @@ DEFAULT_DISCOVERY_DEEP_TIMEOUT = 3.2 DISCOVERY_JOBS: Dict[str, Dict[str, Any]] = {} DISCOVERY_JOBS_LOCK = threading.Lock() SID_WRITE_ACK_OPTIONAL_FAMILIES = {"exbd_nano"} +EM01_FAMILY = "iomx_em_01" +EM01_FIXED_BAUD = 9600 +EM01_BAUD_REGISTER = 0x62 +EXBD_FAMILY = "exbd_nano" +EXBD_WRITE_FAST_TIMEOUT = 2.0 +EXBD_WRITE_POST_SLEEP = 0.2 +EXBD_COMM_PROFILE_REGISTER = 0x00FF +EXBD_BAUD_WRITE_POST_SLEEP = 0.3 PORT_GLOBS = ( "/dev/ttyS*", @@ -504,6 +514,197 @@ def mbpoll_write_register( return payload +def calcModbusCrc(data: bytes) -> int: + crc = 0xFFFF + for byte in data: + crc ^= int(byte) & 0xFF + for _ in range(8): + if crc & 0x0001: + crc = (crc >> 1) ^ 0xA001 + else: + crc >>= 1 + return crc & 0xFFFF + + +def buildEm01SlaveIdWriteFrame(currentSid: int, newSid: int) -> bytes: + payload = bytes([ + int(currentSid) & 0xFF, + 0x10, + 0x00, + 0x61, + 0x00, + 0x01, + 0x02, + 0x00, + int(newSid) & 0xFF, + ]) + crc = calcModbusCrc(payload) + return payload + bytes([crc & 0xFF, (crc >> 8) & 0xFF]) + + +def termios_baud_constant(baud: int) -> int: + mapping = { + 1200: termios.B1200, + 2400: termios.B2400, + 4800: termios.B4800, + 9600: termios.B9600, + 19200: termios.B19200, + 38400: termios.B38400, + 57600: termios.B57600, + 115200: termios.B115200, + } + speed = mapping.get(int(baud)) + if speed is None: + raise ApiError(f"Unsupported serial baud rate: {baud}", 400) + return speed + + +def serial_write_raw_frame( + *, + port: str, + baud: int, + frame: bytes, + timeout: float = 1.0, +) -> Dict[str, Any]: + fd = None + started = time.monotonic() + ack = bytearray() + try: + speed = termios_baud_constant(baud) + fd = os.open(port, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) + attrs = termios.tcgetattr(fd) + attrs[0] = 0 + attrs[1] = 0 + attrs[2] = termios.CLOCAL | termios.CREAD | termios.CS8 + attrs[3] = 0 + attrs[4] = speed + attrs[5] = speed + attrs[6][termios.VMIN] = 0 + attrs[6][termios.VTIME] = 0 + termios.tcflush(fd, termios.TCIOFLUSH) + termios.tcsetattr(fd, termios.TCSANOW, attrs) + total_sent = 0 + while total_sent < len(frame): + sent = os.write(fd, frame[total_sent:]) + if sent <= 0: + raise OSError("Serial write returned 0 bytes") + total_sent += sent + termios.tcdrain(fd) + + deadline = time.monotonic() + max(float(timeout), 0.1) + while time.monotonic() < deadline: + ready, _, _ = select.select([fd], [], [], 0.05) + if not ready: + continue + chunk = os.read(fd, 256) + if not chunk: + continue + ack.extend(chunk) + + elapsed_ms = int((time.monotonic() - started) * 1000) + payload = { + "ok": True, + "write_sent": True, + "bytes_sent": len(frame), + "frame_hex": " ".join(f"{byte:02X}" for byte in frame), + "ack_hex": " ".join(f"{byte:02X}" for byte in ack), + "ack_bytes": len(ack), + "elapsed_ms": elapsed_ms, + } + backend_log( + "modbus_raw_serial_write", + port=port, + baud=int(baud), + frame_hex=payload["frame_hex"], + ack_hex=payload["ack_hex"], + ack_bytes=payload["ack_bytes"], + elapsed_ms=elapsed_ms, + ok=True, + ) + return payload + except ApiError: + raise + except Exception as exc: + elapsed_ms = int((time.monotonic() - started) * 1000) + payload = { + "ok": False, + "write_sent": False, + "bytes_sent": 0, + "frame_hex": " ".join(f"{byte:02X}" for byte in frame), + "ack_hex": " ".join(f"{byte:02X}" for byte in ack), + "ack_bytes": len(ack), + "elapsed_ms": elapsed_ms, + "error_type": "serial_write_failed", + "error": str(exc), + } + backend_log( + "modbus_raw_serial_write", + port=port, + baud=int(baud), + frame_hex=payload["frame_hex"], + ack_hex=payload["ack_hex"], + ack_bytes=payload["ack_bytes"], + elapsed_ms=elapsed_ms, + ok=False, + error=str(exc), + ) + return payload + finally: + if fd is not None: + try: + os.close(fd) + except Exception: + pass + + +def write_em01_slave_id( + *, + port: str, + current_sid: int, + new_sid: int, +) -> Dict[str, Any]: + frame = buildEm01SlaveIdWriteFrame(current_sid, new_sid) + result = serial_write_raw_frame( + port=port, + baud=EM01_FIXED_BAUD, + frame=frame, + ) + result["current_sid"] = int(current_sid) + result["new_sid"] = int(new_sid) + return result + + +def buildExbdCommProfileWriteFrame(currentSid: int, registerValue: int) -> bytes: + payload = bytes([ + int(currentSid) & 0xFF, + 0x06, + 0x00, + 0xFF, + 0x00, + int(registerValue) & 0xFF, + ]) + crc = calcModbusCrc(payload) + return payload + bytes([crc & 0xFF, (crc >> 8) & 0xFF]) + + +def write_exbd_comm_profile( + *, + port: str, + current_sid: int, + register_value: int, + baud: int, +) -> Dict[str, Any]: + frame = buildExbdCommProfileWriteFrame(current_sid, register_value) + result = serial_write_raw_frame( + port=port, + baud=int(baud), + frame=frame, + ) + result["current_sid"] = int(current_sid) + result["register_value"] = int(register_value) + return result + + def read_profile_register( *, profile: Dict[str, Any], @@ -657,6 +858,7 @@ def build_probe_diagnostics( "parity": current_parity_value, }, "expected_current": None, + "advisory_reasons": [], "mismatch_reasons": [], "result": "pending", } @@ -669,11 +871,14 @@ def build_probe_diagnostics( "baud": expected_baud, "parity": expected_parity, } + advisory_reasons: List[str] = [] mismatch_reasons: List[str] = [] if current_slave_value != expected_slave: - mismatch_reasons.append( - f"decoded slave_id mismatch: expected {expected_slave}, got {current_slave_value}" - ) + reason = f"decoded slave_id mismatch: expected {expected_slave}, got {current_slave_value}" + if family == EM01_FAMILY: + advisory_reasons.append(reason) + else: + mismatch_reasons.append(reason) if comm_result is not None and bool(comm_result.get("ok")): if decoded_comm.get("decoded"): if current_baud_value != expected_baud: @@ -685,9 +890,12 @@ def build_probe_diagnostics( f"decoded parity mismatch: expected {expected_parity}, got {current_parity_value}" ) else: - mismatch_reasons.append( - "comm_profile read succeeded but could not be decoded to baud/parity business values" - ) + reason = "comm_profile read succeeded but could not be decoded to baud/parity business values" + if family == EM01_FAMILY: + advisory_reasons.append(reason) + else: + mismatch_reasons.append(reason) + diagnostics["advisory_reasons"] = advisory_reasons diagnostics["mismatch_reasons"] = mismatch_reasons return diagnostics @@ -702,6 +910,7 @@ def device_probe( timeout: float = DEFAULT_DISCOVER_TIMEOUT, retries: int = 1, expected_current: Optional[Dict[str, Any]] = None, + include_summary: bool = True, ) -> Dict[str, Any]: profile = get_profile(family) requested_slave = int(slave) @@ -745,15 +954,20 @@ def device_probe( parity=parity, timeout=timeout, retries=retries, - ) + ) if include_summary else {} test_value = test_result["values"][0]["value"] if test_result.get("ok") and test_result.get("values") else None slave_value = slave_result["values"][0]["value"] if slave_result and slave_result.get("ok") and slave_result.get("values") else None comm_value = comm_result["values"][0]["value"] if comm_result and comm_result.get("ok") and comm_result.get("values") else None decoded_comm = decode_comm_profile(profile, comm_value) - current_slave_value = int(slave_value) if slave_value is not None else requested_slave - current_baud_value = decoded_comm["baud"] if decoded_comm["decoded"] else requested_baud - current_parity_value = decoded_comm["parity"] if decoded_comm["decoded"] else requested_parity + if family == EM01_FAMILY: + current_slave_value = requested_slave + current_baud_value = EM01_FIXED_BAUD + current_parity_value = "none" + else: + current_slave_value = int(slave_value) if slave_value is not None else requested_slave + current_baud_value = decoded_comm["baud"] if decoded_comm["decoded"] else requested_baud + current_parity_value = decoded_comm["parity"] if decoded_comm["decoded"] else requested_parity diagnostics = build_probe_diagnostics( profile=profile, family=family, @@ -785,6 +999,7 @@ def device_probe( decoded_current=diagnostics.get("decoded_current"), registers=diagnostics.get("registers"), reads=diagnostics.get("reads"), + include_summary=bool(include_summary), mismatch_reasons=mismatch_reasons, ok=ok, result=diagnostics.get("result"), @@ -1244,6 +1459,7 @@ def validate_profile(data: Dict[str, Any], source_path: str) -> Dict[str, Any]: "family": family, "title": title or family, "display_name": display_name or title or family, + "discovery_enabled": bool(data.get("discovery_enabled", True)), "transport": { "protocol": str(transport.get("protocol", "modbus_rtu")), "default_port": str(transport.get("default_port", "/dev/ttyS3")), @@ -1623,7 +1839,7 @@ def discover_devices( log_collector=None, ) -> Dict[str, Any]: ensure_port_locked(port) - profiles = load_profiles() + profiles = [profile for profile in load_profiles() if bool(profile.get("discovery_enabled", True))] start_slave = max(1, int(slave_range[0])) end_slave = max(start_slave, int(slave_range[1])) baud_candidates = [int(item) for item in (baudrates or [9600]) if int(item) > 0] @@ -2176,6 +2392,8 @@ def write_device_config( target_slave = int(target.get("slave", current_slave)) target_baud = int(target.get("baud", current_baud)) target_parity = str(target.get("parity", current_parity)) + exbd_fast_id_write = family == EXBD_FAMILY and strategy_value == "id_only" and target_slave != current_slave + exbd_fast_baud_write = family == EXBD_FAMILY and strategy_value == "serial_only" and target_baud != current_baud and target_parity == current_parity == "none" precheck = device_probe( port=port, @@ -2183,13 +2401,14 @@ def write_device_config( slave=int(current_slave), baud=int(write_baud), parity=str(current_parity), - timeout=DEFAULT_DISCOVER_TIMEOUT, - retries=1, + timeout=EXBD_WRITE_FAST_TIMEOUT if (exbd_fast_id_write or exbd_fast_baud_write) else DEFAULT_DISCOVER_TIMEOUT, + retries=0 if (exbd_fast_id_write or exbd_fast_baud_write) else 1, expected_current={ "slave": current_slave, "baud": current_baud, "parity": current_parity, }, + include_summary=not (exbd_fast_id_write or exbd_fast_baud_write), ) operations = [{"level": "info", "message": "Pre-check started before write"}] if not precheck["ok"]: @@ -2226,9 +2445,14 @@ def write_device_config( }) return payload operations.append({"level": "success", "message": "Pre-check passed; current device communication is confirmed"}) + diagnostics = ((precheck.get("debug") or {}).get("precheck_diagnostics") or {}) + for reason in diagnostics.get("advisory_reasons") or []: + operations.append({"level": "warn", "message": f"Pre-check advisory: {reason}"}) id_changed = target_slave != int(precheck["current_config"]["slave_id"]) serial_changed = target_baud != current_baud or target_parity != current_parity + if family == EM01_FAMILY: + id_changed = target_slave != int(current_slave) if strategy_value == "id_only": serial_changed = False @@ -2259,10 +2483,301 @@ def write_device_config( 400, ) + if family == EM01_FAMILY and serial_changed: + raise ApiError( + "Baud rate is not changeable on EM-01. Register 0x62 updates, but actual UART speed remains 9600.", + 400, + ) + write_debug: Dict[str, Any] = {"precheck": precheck["debug"]} write_sent = False id_write_ack_timed_out = False serial_write_ack_timed_out = False + if family == EM01_FAMILY and id_changed: + operations.append({ + "level": "info", + "message": "EM-01 uses a raw FC10 frame for Slave ID write on register 0x61", + }) + write_id = write_em01_slave_id( + port=port, + current_sid=current_slave, + new_sid=target_slave, + ) + write_debug["slave_id_write"] = write_id + write_sent = bool(write_id.get("write_sent")) + if not write_id["ok"]: + payload = { + "ok": False, + "stage": "write", + "status": "write_failed", + "message": "Slave ID write command failed", + "write_baudrate": int(EM01_FIXED_BAUD), + "current_requested": current, + "target_requested": target, + "write_sent": write_sent, + "target_verified": False, + "rediscovery_attempted": False, + "rediscovery_found": False, + "final_detected_config": None, + "recommended_next_step": "Check serial port access and EM-01 communication state", + "operation_log": operations + [{"level": "error", "message": "EM-01 raw Slave ID write failed"}], + "debug": write_debug, + } + append_audit({ + "action": "write_config", + "port": port, + "family": family, + "current": current, + "target": target, + "strategy": strategy_value, + "status": "write_failed", + "success": False, + "debug": {"slave_id_write": write_id}, + "source": source, + }) + return payload + operations.append({"level": "success", "message": "EM-01 raw Slave ID write frame sent"}) + operations.append({"level": "info", "message": f"Readback started on new Slave ID {target_slave} at 9600 baud"}) + time.sleep(0.2) + immediate_verify = device_probe( + port=port, + family=family, + slave=int(target_slave), + baud=int(EM01_FIXED_BAUD), + parity=str(current_parity), + timeout=DEFAULT_DISCOVER_TIMEOUT, + retries=1, + ) + write_debug["immediate_target_verify"] = immediate_verify["debug"] + if immediate_verify["ok"]: + final_detected = { + "slave": immediate_verify["current"]["slave"], + "baud": immediate_verify["current"]["baud"], + "parity": immediate_verify["current"]["parity"], + } + success_message = f"Write verified. Device is now reachable at slave {final_detected['slave']}" + payload = { + "ok": True, + "stage": "post_write_validation", + "status": "verified_target", + "message": success_message, + "write_baudrate": int(EM01_FIXED_BAUD), + "current_requested": current, + "target_requested": target, + "write_sent": True, + "target_verified": True, + "rediscovery_attempted": False, + "rediscovery_found": True, + "found": True, + "final_detected_config": final_detected, + "recommended_next_step": success_message, + "operation_log": operations + [{"level": "success", "message": f"Readback confirmed new Slave ID {final_detected['slave']}"}], + "debug": write_debug, + } + append_audit({ + "action": "write_config", + "port": port, + "family": family, + "current": current, + "target": target, + "strategy": strategy_value, + "status": "verified_target", + "success": True, + "final_detected_config": final_detected, + "source": source, + }) + return payload + + payload = { + "ok": False, + "stage": "post_write_validation", + "status": "write_unconfirmed", + "message": "Slave ID write was sent, but readback on the new Slave ID did not confirm the change", + "write_baudrate": int(EM01_FIXED_BAUD), + "current_requested": current, + "target_requested": target, + "write_sent": True, + "target_verified": False, + "rediscovery_attempted": False, + "rediscovery_found": False, + "found": False, + "final_detected_config": None, + "recommended_next_step": f"Re-read EM-01 on slave {target_slave} at 9600 baud", + "operation_log": operations + [{"level": "error", "message": f"Readback on new Slave ID {target_slave} failed"}], + "debug": write_debug, + } + append_audit({ + "action": "write_config", + "port": port, + "family": family, + "current": current, + "target": target, + "strategy": strategy_value, + "status": "write_unconfirmed", + "success": False, + "write_sent": True, + "target_verified": False, + "source": source, + }) + return payload + + if exbd_fast_baud_write and serial_changed: + comm_value = int(target_comm_profile_value) if target_comm_profile_value is not None else encode_comm_profile(profile, target_baud, target_parity) + if comm_value is None: + raise ApiError("Requested baud/parity is not supported by profile mapping", 400) + operations.append({ + "level": "info", + "message": f"ExBd uses mbpoll FC06 for baud profile write on holding register {int(registers['comm_profile']['address'])}", + }) + write_comm = mbpoll_write_register( + port=port, + slave=int(current_slave), + address=int(registers["comm_profile"]["address"]), + value=comm_value, + baud=write_baud, + parity=current_parity, + data_bits=int(transport["default_databits"]), + stop_bits=int(transport["default_stopbits"]), + zero_based=bool(transport.get("zero_based", True)), + ) + write_debug["comm_profile_write"] = write_comm + write_sent = bool(write_comm.get("write_sent")) + if not write_comm["ok"]: + error_type = str(write_comm.get("error_type") or "") + ack_optional = family in SID_WRITE_ACK_OPTIONAL_FAMILIES and error_type == "timeout" + if ack_optional: + serial_write_ack_timed_out = True + write_sent = True + operations.append({"level": "warn", "message": "Baud write response timed out"}) + operations.append({"level": "info", "message": "Post-write verification started after missing baud write ACK"}) + time.sleep(EXBD_BAUD_WRITE_POST_SLEEP) + else: + payload = { + "ok": False, + "stage": "write", + "status": "write_failed", + "message": "Communication profile write command failed", + "write_baudrate": int(write_baud), + "current_requested": current, + "target_requested": target, + "write_sent": write_sent, + "target_verified": False, + "rediscovery_attempted": False, + "rediscovery_found": False, + "final_detected_config": None, + "recommended_next_step": "Check serial port access and ExBd communication state", + "operation_log": operations + [{"level": "error", "message": "ExBd baud write command failed"}], + "debug": write_debug, + } + append_audit({ + "action": "write_config", + "port": port, + "family": family, + "current": current, + "target": target, + "strategy": strategy_value, + "status": "write_failed", + "success": False, + "debug": {"comm_profile_write": write_comm}, + "source": source, + }) + return payload + else: + operations.append({"level": "success", "message": "ExBd baud write command completed"}) + operations.append({"level": "info", "message": f"Readback started on baud {target_baud}"}) + time.sleep(EXBD_BAUD_WRITE_POST_SLEEP) + immediate_verify = device_probe( + port=port, + family=family, + slave=int(current_slave), + baud=int(target_baud), + parity=str(target_parity), + timeout=EXBD_WRITE_FAST_TIMEOUT, + retries=0, + include_summary=False, + ) + write_debug["immediate_target_verify"] = immediate_verify["debug"] + if immediate_verify["ok"]: + final_detected = { + "slave": immediate_verify["current"]["slave"], + "baud": immediate_verify["current"]["baud"], + "parity": immediate_verify["current"]["parity"], + } + success_message = f"Write verified. Device is now reachable at slave {final_detected['slave']} with baud {final_detected['baud']}" + if serial_write_ack_timed_out: + operations.append({ + "level": "success", + "message": f"New baud {final_detected['baud']} responds; register {int(registers['comm_profile']['address'])} matches requested profile value {comm_value}", + }) + operations.append({ + "level": "success", + "message": "Final result: SUCCESS (write applied despite missing ACK)", + }) + success_message = f"Write verified after missing ACK. Device is now reachable at slave {final_detected['slave']} with baud {final_detected['baud']}" + payload = { + "ok": True, + "stage": "post_write_validation", + "status": "verified_target", + "message": success_message, + "write_baudrate": int(write_baud), + "current_requested": current, + "target_requested": target, + "write_sent": True, + "target_verified": True, + "rediscovery_attempted": False, + "rediscovery_found": True, + "found": True, + "final_detected_config": final_detected, + "recommended_next_step": success_message, + "operation_log": operations + [{"level": "success", "message": f"Readback confirmed new baud {final_detected['baud']}"}], + "debug": write_debug, + } + append_audit({ + "action": "write_config", + "port": port, + "family": family, + "current": current, + "target": target, + "strategy": strategy_value, + "status": "verified_target", + "success": True, + "final_detected_config": final_detected, + "source": source, + }) + return payload + payload = { + "ok": False, + "stage": "post_write_validation", + "status": "write_unconfirmed", + "message": "Baud write was sent, but readback on the new baud rate did not confirm the change", + "write_baudrate": int(write_baud), + "current_requested": current, + "target_requested": target, + "write_sent": True, + "target_verified": False, + "rediscovery_attempted": False, + "rediscovery_found": False, + "found": False, + "final_detected_config": None, + "recommended_next_step": f"Re-read ExBd on slave {current_slave} at baud {target_baud}", + "operation_log": operations + [{"level": "error", "message": f"Readback on new baud {target_baud} failed"}], + "debug": write_debug, + } + append_audit({ + "action": "write_config", + "port": port, + "family": family, + "current": current, + "target": target, + "strategy": strategy_value, + "status": "write_unconfirmed", + "success": False, + "write_sent": True, + "target_verified": False, + "source": source, + }) + return payload + if id_changed: operations.append({ "level": "info", @@ -2289,7 +2804,7 @@ def write_device_config( write_sent = True operations.append({"level": "warn", "message": "Slave ID write response timed out"}) operations.append({"level": "info", "message": "Post-write verification started after missing Slave ID write ACK"}) - time.sleep(0.8) + time.sleep(EXBD_WRITE_POST_SLEEP if exbd_fast_id_write else 0.8) else: payload = { "ok": False, @@ -2323,7 +2838,7 @@ def write_device_config( return payload else: operations.append({"level": "success", "message": "Slave ID write command completed"}) - time.sleep(0.8) + time.sleep(EXBD_WRITE_POST_SLEEP if exbd_fast_id_write else 0.8) if serial_changed: comm_value = int(target_comm_profile_value) if target_comm_profile_value is not None else encode_comm_profile(profile, target_baud, target_parity) @@ -2400,8 +2915,9 @@ def write_device_config( slave=int(target_slave), baud=int(target_baud), parity=str(target_parity), - timeout=DEFAULT_DISCOVER_TIMEOUT, + timeout=EXBD_WRITE_FAST_TIMEOUT if exbd_fast_id_write else DEFAULT_DISCOVER_TIMEOUT, retries=0, + include_summary=not exbd_fast_id_write, ) write_debug["immediate_target_verify"] = immediate_verify["debug"] if id_write_ack_timed_out and id_changed: @@ -2411,8 +2927,9 @@ def write_device_config( slave=int(current_slave), baud=int(write_baud), parity=str(current_parity), - timeout=DEFAULT_DISCOVER_TIMEOUT, + timeout=EXBD_WRITE_FAST_TIMEOUT if exbd_fast_id_write else DEFAULT_DISCOVER_TIMEOUT, retries=0, + include_summary=not exbd_fast_id_write, ) write_debug["old_slave_verify_after_timeout"] = old_slave_verify["debug"] if old_slave_verify["ok"]: @@ -2650,6 +3167,11 @@ def write_register( source: str = "ui", ) -> Dict[str, Any]: ensure_port_locked(port) + if family == EM01_FAMILY and int(address) == EM01_BAUD_REGISTER: + raise ApiError( + "Baud rate is not changeable on EM-01. Register 0x62 updates, but actual UART speed remains 9600.", + 400, + ) transport = transport_defaults(family) result = mbpoll_write_register( port=port, diff --git a/stage_ui/console_core/frontend/console.css b/stage_ui/console_core/frontend/console.css index 515e817..b69a980 100644 --- a/stage_ui/console_core/frontend/console.css +++ b/stage_ui/console_core/frontend/console.css @@ -235,10 +235,17 @@ h1{margin:0;font-size:34px;line-height:1.02;font-weight:650;letter-spacing:-.03e width:100%; border:1px solid var(--line); border-radius:12px; - background:var(--surface-soft); + background-color:var(--surface-soft); + background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 22 22'%3E%3Cpath d='M6 8.5 11 13.5 16 8.5' fill='none' stroke='%2366736d' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); + background-repeat:no-repeat; + background-position:right 14px center; + background-size:22px 22px; color:var(--ink); - padding:10px 12px; + padding:10px 48px 10px 12px; font:inherit; + appearance:none; + -webkit-appearance:none; + -moz-appearance:none; } .menuSelect:focus-visible{ outline:none; @@ -812,12 +819,71 @@ html[dir="rtl"] .itscreenLogsActions{ width:100%;padding:10px 12px;border-radius:12px;border:1px solid var(--line);background:var(--panel);color:var(--ink); } .field select{ - width:100%;padding:10px 12px;border-radius:12px;border:1px solid var(--line);background:var(--panel);color:var(--ink); + width:100%; + padding:10px 48px 10px 12px; + border-radius:12px; + border:1px solid var(--line); + background-color:var(--panel); + background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 22 22'%3E%3Cpath d='M6 8.5 11 13.5 16 8.5' fill='none' stroke='%2366736d' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); + background-repeat:no-repeat; + background-position:right 14px center; + background-size:22px 22px; + color:var(--ink); + appearance:none; + -webkit-appearance:none; + -moz-appearance:none; } .field input:hover{border-color:var(--line)} .field select:hover{border-color:var(--line)} .field input:focus-visible{border-color:var(--accent)} .field select:focus-visible{border-color:var(--accent)} +.numberStepper{ + display:grid; + grid-template-columns:minmax(0,1fr) auto; + gap:8px; + align-items:stretch; +} +.numberStepper input{ + min-width:0; +} +.numberStepper input[type="number"]{ + -moz-appearance:textfield; +} +.numberStepper input[type="number"]::-webkit-outer-spin-button, +.numberStepper input[type="number"]::-webkit-inner-spin-button{ + -webkit-appearance:none; + margin:0; +} +.numberStepperButtons{ + display:grid; + grid-template-columns:repeat(2,minmax(40px,40px)); + gap:6px; +} +.numberStepperBtn{ + border:1px solid var(--line); + border-radius:12px; + background:var(--surface-soft); + color:var(--ink); + font:inherit; + font-size:20px; + font-weight:700; + line-height:1; + cursor:pointer; + min-width:40px; + padding:0; +} +.numberStepperBtn:hover:not(:disabled){ + background:var(--surface-muted); + border-color:var(--line); +} +.numberStepperBtn:focus-visible{ + outline:none; + box-shadow:0 0 0 3px rgba(14,122,83,.18); +} +.numberStepperBtn:disabled{ + opacity:.5; + cursor:not-allowed; +} .wrapValue{ display:flex; align-items:center; @@ -1143,6 +1209,11 @@ html[dir="rtl"] .itscreenLogsActions{ .technicalDetails .diagBlock{ margin-top:10px; max-height:260px; + max-width:100%; + overflow:auto; + white-space:pre; + word-break:normal; + overflow-wrap:normal; } .modbusSummaryMeta{ margin-top:12px; @@ -1162,6 +1233,9 @@ html[dir="rtl"] .itscreenLogsActions{ .writeLogCard{ margin-top:14px; } +.modbusWriteApplyRow{ + margin-top:28px; +} .panel.is-disabled{ opacity:.6; } @@ -1183,6 +1257,12 @@ html[dir="rtl"] .itscreenLogsActions{ font-size:12px; line-height:1.5; } +#modbusWriteApplyBtn{ + background:#0e7a53; +} +#modbusWriteApplyBtn:hover:not(:disabled){ + background:#129866; +} .modalBackdrop{ position:fixed; inset:0; diff --git a/stage_ui/console_core/frontend/console.js b/stage_ui/console_core/frontend/console.js index af4ac4d..8019898 100644 --- a/stage_ui/console_core/frontend/console.js +++ b/stage_ui/console_core/frontend/console.js @@ -314,6 +314,28 @@ return encodeURIComponent((value ?? "").toString()); } + function renderNumberStepperInput(options) { + const id = textValue(options && options.id, ""); + const value = options && typeof options.value !== "undefined" ? options.value : ""; + const min = options && typeof options.min !== "undefined" ? ` min="${esc(options.min)}"` : ""; + const max = options && typeof options.max !== "undefined" ? ` max="${esc(options.max)}"` : ""; + const step = options && typeof options.step !== "undefined" ? ` step="${esc(options.step)}"` : ""; + const inputMode = textValue(options && options.inputMode, ""); + const oninput = textValue(options && options.oninput, ""); + const onkeydown = textValue(options && options.onkeydown, ""); + const onblur = textValue(options && options.onblur, ""); + const disabled = options && options.disabled ? " disabled" : ""; + return ` +