Skip to content

Function to return a SamplingCounter object for any Python descriptor

Jose Tiago Macara Coutinho requested to merge issue-377 into master

This closes #377 (closed).

Example how it looks like:


# Lets start with plain old object (can be a bliss or non bliss object):
 
class Potentiostat:

    def __init__(self, name):
        self.name = name

    @property
    def potential(self):
        return float(self.comm.write_readline('POT?\n'))

    def get_voltage(self):
        return float(self.comm.write_readline('VOL?\n'))

pot = Potentiostat('p1')

from bliss.common.measurement import SoftCounter

# counter from an object property
pot_cnt = SoftCounter(pot, 'potential')

# counter form an object method. The optional apply parameter
# allows you to apply a transformation function to the value
milivol_cnt = SoftCounter(pot, 'get_voltage', name='voltage',
                          apply=lambda v: v*1000)

# Functions can also be made counters. Here is how:

import random
aleat_cnt = SoftCounter(value=random.random, name='aleat')

# Particularly useful might be tango attributes or commands as counters:

from bliss.common.tango import DeviceProxy

fe = DeviceProxy('orion:10000/fe/id/00')
sr_curr_cnt = SoftCounter(fe, value='sr_current')

# now you can use the counters in any scan:
loopscan(10, 0.1, pot_cnt, milivol_cnt, aleat_cnt, sr_curr_cnt)
Edited by Jose Tiago Macara Coutinho

Merge request reports