Saltar al contenido principal

Información del servidor

Resumen​

El nodo estándar de OPC UA i=2256 (Server.ServerStatus) muestra la información de ejecución del servidor. La SDK no descubre el ExtensionObject de ServerStatusDataType, sino que lee por separado los 11 subnodos estándar y a continuación entrega un ServerStatus de tipo fuerte (11 Read RPC en total: i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993).

Apartado correspondiente de la norma: Parte 5, §6.3 (ServerStatusDataType).

API​

MétodoCategoríaLectura y escrituraExplicación
ua.read_server_status()DiagnósticoLeerDevuelve ServerStatus (11 visitas RPC)
ua.read_server_state()DiagnósticoLeerDevuelve ServerState Enumeración (única RPC)
ua.read_current_time()DiagnósticoLeerDevuelve Optional[datetime] (UTC, único RPC; si la lectura falla, devuelve None)

Firma auténtica:

def read_server_status(self) -> ServerStatus: ...
def read_server_state(self) -> ServerState: ...
def read_current_time(self) -> Optional[datetime]: ...

@dataclass(frozen=True)
class BuildInfo:
product_uri: Optional[str] = None
manufacturer_name: Optional[str] = None
product_name: Optional[str] = None
software_version: Optional[str] = None
build_number: Optional[str] = None
build_date: Optional[datetime] = None

@dataclass(frozen=True)
class ServerStatus:
start_time: Optional[datetime] = None # i=2257
current_time: Optional[datetime] = None # i=2258
state: ServerState = ServerState.UNKNOWN # i=2259
build: Optional[BuildInfo] = None # i=2261..i=2266 Montaje
seconds_till_shutdown: int = 0 # i=2992
shutdown_reason: Optional[str] = None # i=2993

class ServerState(IntEnum):
RUNNING = 0 # Normal
FAILED = 1 # Fallo fatal
NO_CONFIGURATION = 2 # Falta la configuración
SUSPENDED = 3 # Suspendido por el equipo de operaciones y mantenimiento
SHUTDOWN = 4 # Se está cerrando
TEST = 5 # Modo de prueba
COMMUNICATION_FAULT = 6 # Fallo en el enlace
UNKNOWN = 7 # SDK Casuística (se lee «fallo» / valor distinto de 0..6)

Si falla la lectura de cualquier subcampo, se utilizará el valor por defecto (None / 0 / UNKNOWN) y no se lanzará ninguna excepción.

Ejemplo de código​

from darra_opcua import DarraOpcUa, ServerState   # Nombre del módulo darra_opcua

with DarraOpcUa("opc.tcp://localhost:4840") as ua:
ua.connect()

# 1) De un solo uso
status = ua.read_server_status()
print(f"Start = {status.start_time}")
print(f"Now = {status.current_time}")
print(f"State = {status.state.name}")
if status.build is not None:
print(f"Build = {status.build.product_name} {status.build.software_version}")

if status.state != ServerState.RUNNING:
print(f"服务端非 Running, 距关停 {status.seconds_till_shutdown}s")

# 2) Comprobación de estado ligera
if ua.read_server_state() == ServerState.RUNNING:
print("在线")

# 3) Desviación del reloj
server_now = ua.read_current_time()
if server_now is not None:
from datetime import datetime, timezone
drift = (datetime.now(timezone.utc) - server_now).total_seconds() * 1000
print(f"时钟差 = {drift:.1f} ms")

Comparación entre idiomas​

C#PythonJavaC++RustC
ReadServerStatusread_server_statusreadServerStatusReadServerStatusread_server_statusDarraUa_Session_ReadServerStatus
ReadServerStateread_server_statereadServerStateReadServerStateread_server_stateDarraUa_Session_ReadServerState

Siguiente paso​