Pleki
Pleki

Reputation: 108

OpenOPC tag activation?

I'm trying to use OpenOPC as a client to connect to an OPC server generated thanks to Dymola.

What I can't figure out is the way to read from a particular tag.

Some tags are available ('SimControl') and others are not ('ModelVariables') whereas those tags should be available after server Initialization.

Is there a way to activate tags in the same way that what is it done in Matrikon Explorer.

Here is the code that I used :

# -*- 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))

Many thanks for any help.

Upvotes: 1

Views: 1443

Answers (1)

Pleki
Pleki

Reputation: 108

I've been able to find a workaround by using the properties method of OpenOPC.

The value and quality return by the method properties are not consistent with the read method.

It seems that the properties method return the right value (with good quality) whereas the read method does not.

Upvotes: 1

Related Questions