taurus-org / taurus

Moved to https://gitlab.com/taurus-org/taurus
http://taurus-scada.org
43 stars 46 forks source link

TaurusLabel display for a state not refreshed #1099

Closed marouanebj closed 4 years ago

marouanebj commented 4 years ago

Hello,

I do not know if it is the expected behavior but it is the one a would like. I created a Sardana ZeroDController (=model). I display the currentValue with a TaurusLabel. I display the state with a TaurusLabel too.

My currentValue display changes regularly but the state is just read once a start and never updated. Is it normal ? because I want it to update.

So I did this modifications: added onDisplayUpdateTimerTimeout to make the think work as I want (see here after). Do you have advises to make this better ?

Thanks, Marouane

class ZeroDLineWidget(Qt.QWidget):
    def __init__(self, parent, model):
        Qt.QWidget.__init__(self, parent)

        self.model = model

        self.stateTaurusLabel = TaurusLabel(self)
        self.stateTaurusLabel.setModel(model + "/state")
        self.stateTaurusLabel.setBgRole('rvalue')

        self.statusTaurusLabel = TaurusLabel(self)
        self.statusTaurusLabel.setModel(model + "/status")
        self.statusTaurusLabel.setBgRole('parentObj.stateObj.rvalue')

        self.currentvalueTaurusLabel = TaurusLabel(self)
        self.currentvalueTaurusLabel.setModel(model + "/currentvalue")
        self.currentvalueTaurusLabel.setBgRole('parentObj.stateObj.rvalue')
...
       # Display update timer
        self.displayUpdateTimer = Qt.QTimer(self)
        self.displayUpdateTimer.timeout.connect(self.onDisplayUpdateTimerTimout)
        self.displayUpdateTimer.start(300)

    def onDisplayUpdateTimerTimeout(self):
        device = taurushelper.Device(self.model)
        deviceState = device.getChildObj("/state")
        deviceStatus = device.getChildObj("/status")
        deviceCurrentValue = device.getChildObj("/currentValue")
        deviceState.poll()
        deviceStatus.poll()
        deviceCurrentValue.poll()
marouanebj commented 4 years ago

by the way here the taurus I use with QT4 python-taurus/stable,stable,now 4.5.0+dfsg-1 all [installé]

cpascual commented 4 years ago

Hi, I am afraid that what you describe is a known limitation. The problem is that currently, TaurusValueLabel only subscribes to events from its model. Setting the background with .setBgRole('parentObj.stateObj.rvalue') does not automatically subscribe to events of the state.

In the particular case where the model is the state attribute (i.e. you are showing the state in the foreground too) then the background does refresh correctly, but not in the other cases.

This is one of the motivations to implement multi-model support in Taurus, which has been in my TODO list since 5years ago and never got the time...

workaround1

A workaround is to use a TaurusLed to display the state next to the TaurusLabel that displays the value

workaround2

You could try to implement MyLabel(TaurusLabel) and play with the setModel method to add MyLabel as a listener of the state attribute and then handle the two sources of the events in the handleEvent method.

marouanebj commented 4 years ago

Hi, Thanks for the fast reply. You mention

TaurusValueLabel

, I do not know that Widget, do you mean TaurusValue ?

You say:

In the particular case where the model is the state attribute (i.e. you are showing the state in the foreground too) then the background does refresh correctly, but not in the other cases.

But I have a TaurusLabel for the state and one for the current value. I simulate an instrument that get a random number between 0 and 10 and if the number is bigger than 8 I set the state at Alarm. Let's speak only of the value my StateTaurusLabel is not updated while my CurrentPositionTaurusLed is regularly updated. So the problem seems to be the state attribute not automatically updated. Can this be a problem with Sardana ? Thanks.

reszelaz commented 4 years ago

Hi Marouane,

Sorry, currently I have quite limited time to go into detail of your problem - I will be back at work in 2 weeks. Meanwhile I have some ideas which may help you.

Do you run a Sardana acquisition with the 0D channel? Currently 0D are only supported in the measurement group acquisition. We think on implementing the exprimental channel acquisition for 0D - it should be relativelly easy.. If you do not run acquisitions, you would need to do it to provoke the state changes. So, as on today, you will need to define a measurement group, either using expconf, or using defmeas macro e.g. defmeas mntgrp02 ct01 zerod01 and run a ct macro e.g. ct 1 mntgrp02.

If you were not running acquisition, most probably what you have observed with the TaurusLabel widgets are:

Have you read the 0D overview and its API. If you run acquisition the Value attribute may be more interesting to you?

Also, you may be interested in the 0D TaurusValue widget. You can launch it with taurus form zerod01 (or eventually taurusform zerod01 for older versions of taurus). It offers quite poor functionalities since the 0Ds do not work in experimental channel acquisition yet. Then, this widget would work similarly to the one for timerable channels - currently under review/integration process: https://github.com/sardana-org/sardana/pull/1203

Hope this helps!

marouanebj commented 4 years ago

Thanks, I understand now, the non update, It is because I did not launch any acquisition. I will reread and try to understand the 0D overview and look also zerod01. Yes it helped a lot. If you want to close you can, So If I come with other questions it would be properly labeled in another issue. Thanks again.

reszelaz commented 4 years ago

Great! With zerod01 I refer to one channel of the DummyZeroDController controller. This are created with the sar_demo macro and usually (on a clean Tango DB) has this name. But you can also use a custom 0D controllers... Remember, if you find something unclear in the docs, don't hesitate to ask! We will for sure try to help and correct the docs for the future.

cpascual commented 4 years ago

Hi @reszelaz , thanks for the clarification! Closing this.