2015-02-06 5 views
1

나는 Dymola 덕분에 생성 된 OPC 서버에 연결하기 위해 클라이언트로 OpenOPC를 사용하려고합니다.OpenOPC 태그 활성화?

내가 알 수없는 것은 특정 태그에서 읽는 방법입니다.

일부 태그 ('SimControl')와 다른 태그 ('ModelVariables')는 사용할 수 없지만 서버 초기화 후 사용할 수있는 태그가 있습니다.

Matrikon Explorer에서 수행되는 것과 동일한 방식으로 태그를 활성화하는 방법이 있습니까?

# -*- coding: utf-8 -*- 
""" 
Created on Fri Feb 06 09:48:09 2015 
Simple test to connect to the Dymosim server generated with Dymola 
""" 

import os,sys 
import time,OpenOPC 

#%% Connexion to server 
opcserv='Dymosim.OPCServer' 

opc = OpenOPC.client() 
opc.connect(opcserv) 

#%% Tags description in a dictionnary form 

# Following tags are for simulation control 
# and are available as soon as the client is connected to the server 
root1='SimControl.' 
l1=['Realtime','tScale', 
'Initialize','Pause','Run','Stop', 
'Delay','Initialized','Time','Status'] 
Sim={t:root1+t for t in l1} 

# Following tags are for variables display during simulation. 
# They should be available after the simulation was "Initialize" 
root2='ModelVariables.' # Available once the model has been initialized 
v1=['heatCapacitor.port.T','heatCapacitor.port.Q_flow'] 
l2=['T','Q'] 
Var={k:root2+v for (k,v) in zip(l2,v1)} 


#%% Simulation 
# Initialization of the simulation 
opc.write((Sim['Initialize'],True)) 

#%% Run the simulation 
opc.write((Sim['Run'],True)) 

# Pause simulation after 2 s 
time.sleep(2) 
opc.write((Sim['Pause'],True)) 

#%% Read variables 
opc.read(Sim['Time']) # OK 
opc.read(Var['T'])  # Seems not accessible. Quality is bad 
opc.list() # The 2 tags appear (SimControl and ModelVariables) 

#%% Run the simulation until the end 
opc.write((Sim['Run'],True)) 

많은 감사를 어떤 도움 : 여기

은 내가 사용하는 코드입니다.

+1

OpenOPC에 익숙하지 않지만 내 눈을 사로 잡은 한 가지를 설명하고자합니다. "귀하의 의견에 접근 할 수 없습니다. 품질이 좋지 않습니다"는 오해 일 수 있습니다. OPC 서버가 요청한 항목을 알고 있으면 오류를 리턴합니다. 항목을 알고있을 때 값 - 타임 스탬프 품질 구조를 반환합니다 (예 : 품질이 좋음 또는 나쁨). 따라서 오류가 발생하지 않고 품질이 나쁜 것을 얻는다면 문제는 당신 편이 아닙니다. 단순히 서버가 해당 항목에 대해 반환 한 데이터입니다. 다른 OPC 클라이언트에 동일한 값을 반환 할 가능성이 높습니다. – ZbynekZ

답변

1

OpenOPC의 properties 방법을 사용하여 해결 방법을 찾을 수있었습니다.

properties 메서드에 의한 값 및 품질 반환 값은 read 메서드와 일치하지 않습니다.

read 메서드는 그렇지 않은 반면 properties 메서드는 올바른 값 (좋은 품질)을 반환하는 것으로 보입니다.