1

我正在尝试使用 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))

非常感谢您的帮助。

4

1 回答 1

1

我已经能够通过使用propertiesOpenOPC 的方法找到解决方法。

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

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

于 2015-02-11T10:57:05.730 回答