Read an ADC, return the result

The following Macro reads an ADC, displays the value and returns the result. It makes use of the fact that the adc object is derived from a DeviceProxy which allows the user to access the device commands and attributes directly.

#!/usr/bin/env python
# 
# file name: /home/pXXuser/sardanaMacros/ReadAdc_class.py 
"""this module contains some demo code"""

__all__ = ["ReadAdc_class"]

from sardana.macroserver.macro import Macro, Type

class ReadAdc_class(Macro):
    """reads an ADC values, displays the result and returns it"""
    param_def = [[ "adc", Type.ZeroDExpChannel, None, "an ADC" ]]
    result_def = [[ "result", Type.Float, None, "the ADC reading" ]]
    def run(self, adc):
        result = float(adc.CurrentValue)
        self.output( "%s reading %g " % (adc.name, result))
        return result

This macros can be invoked from Spock in two ways:

p09/door/exp.01 [24]: ReadAdc exp_adc01
exp_adc01 reading 9 
         Result [24]: 9.0

p09/door/exp.01 [25]: a = %ReadAdc exp_adc01
exp_adc01 reading -8 

p09/door/exp.01 [26]: a
         Result [26]: -8.0



2019-11-13