1
我試圖使用OpenOPC作爲客戶端連接到Dymola生成的OPC服務器。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))
非常感謝任何幫助。
我在OpenOPC沒有經歷過,但我只是想說明一兩件事,引起我的注意:您的評論。「似乎無法訪問質量差」可能是一種誤解。當OPC服務器知道所請求的項目時,它會返回一個錯誤。當它知道該項目時,它會返回一個值 - 時間戳質量結構(質量可能是好或壞)。因此,如果你沒有得到一個錯誤,但得到質量差的東西,那麼問題就不在你身邊 - 它只是服務器爲該項目返回的數據。它可能會返回給任何其他OPC客戶端。 – ZbynekZ 2015-02-07 09:51:10