【问题标题】:OpenOPC tag activation?OpenOPC 标签激活?
【发布时间】:2015-02-06 13:06:50
【问题描述】:

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

非常感谢您的帮助。

【问题讨论】:

  • 我在 OpenOPC 方面没有经验,但我只想解释一件引起我注意的事情:您的评论“似乎无法访问。质量很差”可能是一种误解。当 OPC 服务器确实知道请求的项目时,它会返回一个错误。当它确实知道该项目时,它会返回一个值-时间戳-质量结构(其中质量可能是例如好或坏)。因此,如果您没有收到错误,而是收到了质量差的东西,那么问题不在您这边 - 它只是服务器为该项目返回的数据。它可能会向任何其他 OPC 客户端返回相同的结果。

标签: python opc dymola


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多