Commit c9129e72 authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Merge branch 'MQTT' of gitlab-ssh.irstea.fr:reversaal/OhmPi into MQTT

Showing with 18 additions and 11 deletions
+18 -11
...@@ -35,7 +35,7 @@ EXEC_LOGGING_CONFIG = { ...@@ -35,7 +35,7 @@ EXEC_LOGGING_CONFIG = {
# Data logging configuration # Data logging configuration
DATA_LOGGING_CONFIG = { DATA_LOGGING_CONFIG = {
'logging_level': logging.INFO, 'logging_level': logging.INFO,
'logging_to_console': False, 'logging_to_console': True,
'file_name': 'data_log', 'file_name': 'data_log',
'max_bytes': 16777216, 'max_bytes': 16777216,
'backup_count': 1024, 'backup_count': 1024,
......
...@@ -84,21 +84,22 @@ class OhmPi(object): ...@@ -84,21 +84,22 @@ class OhmPi(object):
# default acquisition settings # default acquisition settings
self.settings = { self.settings = {
'injection_duration': 0.2, 'injection_duration': 0.2,
'nbr_meas': 100, 'nbr_meas': 1,
'sequence_delay': 1, 'sequence_delay': 1,
'nb_stack': 1, 'nb_stack': 1,
'export_path': 'data/measurement.csv' 'export_path': 'data/measurement.csv'
} }
print(self.settings)
# read in acquisition settings # read in acquisition settings
if settings is not None: if settings is not None:
self._update_acquisition_settings(settings) self._update_acquisition_settings(settings)
self.exec_logger.debug('Initialized with configuration:' + str(self.settings)) print(self.settings)
self.exec_logger.debug('Initialized with settings:' + str(self.settings))
# read quadrupole sequence # read quadrupole sequence
if sequence is None: if sequence is None:
self.sequence = np.array([[1, 2, 3, 4]]) self.sequence = np.array([[1, 2, 3, 4]], dtype=np.int32)
else: else:
self.read_quad(sequence) self.read_quad(sequence)
...@@ -119,7 +120,7 @@ class OhmPi(object): ...@@ -119,7 +120,7 @@ class OhmPi(object):
# Starts the command processing thread # Starts the command processing thread
self.cmd_thread = threading.Thread(target=self.process_commands) self.cmd_thread = threading.Thread(target=self.process_commands)
self.cmd_thread.start() self.cmd_thread.start()
#self.process_commands()
def _update_acquisition_settings(self, config): def _update_acquisition_settings(self, config):
"""Update acquisition settings from a json file or dictionary. """Update acquisition settings from a json file or dictionary.
...@@ -234,7 +235,7 @@ class OhmPi(object): ...@@ -234,7 +235,7 @@ class OhmPi(object):
sequence : numpy.array sequence : numpy.array
Array of shape (number quadrupoles * 4). Array of shape (number quadrupoles * 4).
""" """
sequence = np.loadtxt(filename, delimiter=" ", dtype=int) # load quadrupole file sequence = np.loadtxt(filename, delimiter=" ", dtype=np.int32) # load quadrupole file
if sequence is not None: if sequence is not None:
self.exec_logger.debug('Sequence of {:d} quadrupoles read.'.format(sequence.shape[0])) self.exec_logger.debug('Sequence of {:d} quadrupoles read.'.format(sequence.shape[0]))
...@@ -498,8 +499,7 @@ class OhmPi(object): ...@@ -498,8 +499,7 @@ class OhmPi(object):
} }
else: # for testing, generate random data else: # for testing, generate random data
d = {'time': datetime.now().isoformat(), 'A': quad[0], 'B': quad[1], 'M': quad[2], 'N': quad[3], d = {'time': datetime.now().isoformat(), 'A': quad[0], 'B': quad[1], 'M': quad[2], 'N': quad[3],
'R [ohm]': np.abs(np.random.randn(1)) 'R [ohm]': np.abs(np.random.randn(1)).tolist()}
}
# round number to two decimal for nicer string output # round number to two decimal for nicer string output
output = [f'{k}\t' for k in d.keys()] output = [f'{k}\t' for k in d.keys()]
...@@ -512,7 +512,14 @@ class OhmPi(object): ...@@ -512,7 +512,14 @@ class OhmPi(object):
output += f'{val}\t' output += f'{val}\t'
output = output[:-1] output = output[:-1]
self.exec_logger.debug(output) self.exec_logger.debug(output)
self.data_logger.info(json.loads(d)) dd = d.copy()
dd.update({'A': str(dd['A'])})
dd.update({'B': str(dd['B'])})
dd.update({'M': str(dd['M'])})
dd.update({'N': str(dd['N'])})
print(np.dtype(d['A']))
print(json.dumps(dd))
self.data_logger.info(json.dumps(dd))
time.sleep(1) # NOTE: why this? time.sleep(1) # NOTE: why this?
return d return d
...@@ -807,4 +814,4 @@ if __name__ == "__main__": ...@@ -807,4 +814,4 @@ if __name__ == "__main__":
ohmpi = OhmPi(settings='ohmpi_param.json') ohmpi = OhmPi(settings='ohmpi_param.json')
\ No newline at end of file
File moved
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment