-
-
Save hgrecco/6486889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
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
As one can see, there is no need for conversion in the getter as the return from the device is already in the correct form (except 'ON' -> True). Maybe it's just easyer to not make a getter/setter for this one.