Skip to content

Instantly share code, notes, and snippets.

@hgrecco
Forked from ColinBrosseau/code
Last active December 22, 2015 14:39
Show Gist options
  • Save hgrecco/6486889 to your computer and use it in GitHub Desktop.
Save hgrecco/6486889 to your computer and use it in GitHub Desktop.
SampleRateUnit = {'Seconds': '0', 'Minutes': '1', 'Hours': '2',
'Days': '3', '%': '4'}
SamplePeriodUnit = {'Seconds': '0', 'Minutes': '1', 'Hours': '2',
'Days': '3', 'Weeks': '4', 'Pulses': '5'}
TotalDurationUnit = {'Period': '0', 'Seconds': '1', 'Minutes': '2',
'Hours': '3', 'Days': '4', 'Weeks': '5', 'Continuous': '6',
'predefinded': '7'}
TimeStampEnabled = {False: 0, True: 1}
@Feat(values=(None, SampleRateUnit, None, SamplePeriodUnit, None,
TotalDurationUnit, TimeStampEnabled,))
def sampling(self):
"""This command is used to read the current data sampling settings.
(rds)
"""
return self.parse_query('*rds', format='Sample Rate: {:f} / {}\t'
'Sample Period: {:f} / {}\t'
'Total Duration: {:f} {}\t'
'Time Stamp: {}')
@sampling.setter
def sampling(self, value):
"""This command provides the data sampling parameters for the logging
and statistics environments. (dsu)
"""
self.query('*dsu {} {} {} {} {} {} {}'.format(*value))
@hgrecco
Copy link
Author

hgrecco commented Sep 8, 2013

I see now. Sorry for the confusion. In this cases where the instrument programming code is not designed in a simmetrical way, you can still use getter and setter but just avoid the automatic conversion using values.

SampleRateUnit = {'Seconds': '0', 'Minutes': '1', 'Hours': '2',
                  'Days': '3', '%': '4'}
SamplePeriodUnit = {'Seconds': '0', 'Minutes': '1', 'Hours': '2',
                    'Days': '3', 'Weeks': '4', 'Pulses': '5'}
TotalDurationUnit = {'Period': '0', 'Seconds': '1', 'Minutes': '2',
                     'Hours': '3', 'Days': '4', 'Weeks': '5', 'Continuous': '6',
                     'predefinded': '7'}
TimeStampEnabled = {False: 0, True: 1}

@Feat(values=(None, SampleRateUnit, None, SamplePeriodUnit, None,
              TotalDurationUnit, TimeStampEnabled,))
def sampling(self):
    """This command is used to read the current data sampling settings.
    (rds)
    """
    out = self.parse_query('*rds', format='Sample Rate: {} / {}\t'
                           'Sample Period: {} / {}\t'
                           'Total Duration: {} {}\t'
                           'Time Stamp: {}')
    out[0] = int(out[0])
    out[2] = int(out[2])
    out[4] = int(out[4])
    out[6] = True if value[6] == 'ON' else False
    return out

@sampling.setter
def sampling(self, value):
    """This command provides the data sampling parameters for the logging
    and statistics environments. (dsu)
    """
    value[1] = self.SamplePeriodUnit[value[1]]
    value[3] = self.SamplePeriodUnit[value[3]]
    value[5] = self.TotalDurationUnit[value[5]]
    value[6] = 1 if value[6] else 0
    self.query('*dsu {} {} {} {} {} {} {}'.format(*value))

By the way, are you sure that the numbers are always integers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment