-
-
Save ColinBrosseau/6481362 to your computer and use it in GitHub Desktop.
How to handle asymetric responce from an instrument
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
global SampleRateUnit | |
SampleRateUnit = {'Seconds': '0', 'Minutes': '1', 'Hours': '2', | |
'Days': '3', '%': '4'} | |
global SamplePeriodUnit | |
SamplePeriodUnit = {'Seconds': '0', 'Minutes': '1', 'Hours': '2', | |
'Days': '3', 'Weeks': '4', 'Pulses': '5'} | |
global TotalDurationUnit | |
TotalDurationUnit = {'Period': '0', 'Seconds': '1', 'Minutes': '2', | |
'Hours': '3', 'Days': '4', 'Weeks': '5', 'Continuous': '6', | |
'predefinded': '7'} | |
global TimeStamp | |
TimeStamp = {'OFF': False, 'ON': True, False: 0, True: 1} | |
@Feat(values=(None, SampleRateUnit, None, SamplePeriodUnit, None, | |
TotalDurationUnit, TimeStamp,)) | |
def sampling(self): | |
"""This command is used to read the current data sampling settings. | |
(rds) | |
""" | |
out = self.parse_query('*rds', format='Sample Rate: {} / {}\tSample Period: {} / {}\tTotal Duration: {} {}\tTime Stamp: {}') | |
print(out) | |
global SampleRateUnit | |
global SamplePeriodUnit | |
global TotalDurationUnit | |
global TimeStamp | |
out[1] = SampleRateUnit[out[1]] | |
out[3] = SamplePeriodUnit[out[3]] | |
out[5] = TotalDurationUnit[out[5]] | |
out[6] = TimeStamp[out[6]] | |
return out | |
#return self.query('*rds') | |
@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)) |
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
1 |
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
print(inst.sampling) | |
gives | |
21:55:07 INFO Getting sampling | |
21:55:07 DEBUG Sending b'*rds\r\n' | |
21:55:07 DEBUG Received 'Sample Rate: 1 / Seconds\tSample Period: 30 / Seconds\tTotal Duration: 1 Period\tTime Stamp: ON\r\n' (len=94) | |
['1', 'Seconds', '30', 'Seconds', '1', 'Period', 'ON'] | |
21:55:07 DEBUG (raw) Got ['1', '0', '30', '0', '1', '0', True] for sampling | |
21:55:07 INFO Got ('1', 'Seconds', '30', 'Seconds', '1', 'Period', 'ON') for sampling | |
('1', 'Seconds', '30', 'Seconds', '1', 'Period', 'ON') |
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
inst.sampling = ('1', 'Seconds', '30', 'Seconds', '1', 'Period', True) | |
gives | |
21:55:07 INFO Setting sampling = ('1', 'Seconds', '30', 'Seconds', '1', 'Period', True) (current=MISSING, force=False) | |
21:55:07 DEBUG (raw) Setting sampling = ('1', '0', '30', '0', '1', '0', 1) | |
21:55:07 DEBUG Sending b'*dsu 1 0 30 0 1 0 1\r\n' | |
21:55:07 DEBUG Received 'ACK\r\n' (len=5) | |
21:55:07 INFO sampling was set to ('1', 'Seconds', '30', 'Seconds', '1', 'Period', True) |
It'd be nice to use units with this function. This is because
'1', 'Seconds', '30', 'Seconds', '1', 'Period', True
in fact means
1 second, 30 seconds, 1 period, True
This is it: there are actually 4 parameters for this device setting.
So I'd like to use units....
But! If we look in the device manual
http://riel.pmc.umontreal.ca/sandbox/groups/leonelli/wiki/5c75f/attachments/a37cb842-PE.Manual.RevB.pdf
section 4.2.3.6 (on pdf page 59)
we see that the 1st parameter unit can be
seconds, minutes, hours, days or percentage of pulses
So it doen't seems to make sence of using a quantity that unit will change over context.
What do you think?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As one can see, for setting the device this one needs to reveive numbers (on a string form).
But when we retrive this parameter from the device, it is in a string (human readable) form.
This is why the Feat is so weird. It there is something wrong about that? Or a better way to do it?