OpenOPC标签激活?

时间:2015-02-06 13:06:51

标签: python opc dymola

我正在尝试使用OpenOPC作为客户端连接到由Dymola生成的OPC服务器。

我无法弄清楚的是从特定标签中读取的方式。

某些标签可用('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 个答案:

答案 0 :(得分:1)

我已经能够使用OpenOPC的properties方法找到解决方法。

方法properties的价值和质量回报与read方法不一致。

似乎properties方法返回正确的值(质量好),而read方法则没有。