|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
""" |
|
3
|
|
|
A module to control the QO Raspberry Pi based H-Bridge hardware. |
|
4
|
|
|
|
|
5
|
|
|
Qudi is free software: you can redistribute it and/or modify |
|
6
|
|
|
it under the terms of the GNU General Public License as published by |
|
7
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
(at your option) any later version. |
|
9
|
|
|
|
|
10
|
|
|
Qudi is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
GNU General Public License for more details. |
|
14
|
|
|
|
|
15
|
|
|
You should have received a copy of the GNU General Public License |
|
16
|
|
|
along with Qudi. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
|
|
18
|
|
|
Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the |
|
19
|
|
|
top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/> |
|
20
|
|
|
""" |
|
21
|
|
|
|
|
22
|
|
|
from core.base import Base |
|
23
|
|
|
from interface.data_logger_interface import DataLoggerInterface |
|
24
|
|
|
|
|
25
|
|
|
from influxdb import InfluxDBClient |
|
26
|
|
|
|
|
27
|
|
|
class InfluxLogger(Base, DataLoggerInterface): |
|
28
|
|
|
_modclass = 'InfluxLogger' |
|
29
|
|
|
_modtype = 'hardware' |
|
30
|
|
|
|
|
31
|
|
|
## declare connectors |
|
32
|
|
|
_out = {'data': 'ProcessInterface'} |
|
33
|
|
|
|
|
34
|
|
|
def __init__(self, **kwargs): |
|
35
|
|
|
super().__init__(**kwargs) |
|
36
|
|
|
self.log_channels = {} |
|
37
|
|
|
|
|
38
|
|
|
def on_activate(self, e): |
|
39
|
|
|
config = self.getConfiguration() |
|
40
|
|
|
|
|
41
|
|
|
if 'user' in config: |
|
42
|
|
|
self.user = config['user'] |
|
43
|
|
|
|
|
44
|
|
|
if 'password' in config: |
|
45
|
|
|
self.pw = config['password'] |
|
46
|
|
|
|
|
47
|
|
|
if 'dbname' in config: |
|
48
|
|
|
self.dbname = config['dbname'] |
|
49
|
|
|
|
|
50
|
|
|
if 'host' in config: |
|
51
|
|
|
self.host = config['host'] |
|
52
|
|
|
|
|
53
|
|
|
if 'port' in config: |
|
54
|
|
|
self.port = config['port'] |
|
55
|
|
|
else: |
|
56
|
|
|
self.port = 8086 |
|
57
|
|
|
|
|
58
|
|
|
if 'dataseries' in config: |
|
59
|
|
|
self.series = config['dataseries'] |
|
60
|
|
|
|
|
61
|
|
|
if 'field' in config: |
|
62
|
|
|
self.field = config['field'] |
|
63
|
|
|
|
|
64
|
|
|
if 'criterion' in config: |
|
65
|
|
|
self.cr = config['criterion'] |
|
66
|
|
|
|
|
67
|
|
|
self.connect_db() |
|
68
|
|
|
|
|
69
|
|
|
def on_deactivate(self, e): |
|
70
|
|
|
del self.conn |
|
71
|
|
|
|
|
72
|
|
|
def connect_db(self): |
|
73
|
|
|
self.conn = InfluxDBClient(self.host, self.port, self.user, self.pw, self.dbname) |
|
74
|
|
|
|
|
75
|
|
|
def get_log_channels(self): |
|
76
|
|
|
return self.log_channels |
|
77
|
|
|
|
|
78
|
|
|
def set_log_channels(self, channelspec): |
|
79
|
|
|
for name, spec in channelspec.items(): |
|
80
|
|
|
if spec is None and name in self.log_channels: |
|
81
|
|
|
self.log_channels.pop(name) |
|
82
|
|
|
elif name in self.log_channels: |
|
83
|
|
|
pass |
|
84
|
|
|
else: |
|
85
|
|
|
pass |
|
86
|
|
|
if True: |
|
87
|
|
|
pass |
|
88
|
|
|
|
|
89
|
|
|
def log_to_channel(self, channel, values): |
|
90
|
|
|
if channel in self.log_channels.keys() and len(values) == len(self.log_channels[channel][values]): |
|
91
|
|
|
conn.write_points(format_data(channel, values, channeltags)) |
|
92
|
|
|
|
|
93
|
|
|
def format_data(self, channel_name, values, tags): |
|
94
|
|
|
return [{ |
|
95
|
|
|
'measurement': channel_name, |
|
96
|
|
|
'fields': values, |
|
97
|
|
|
'tags': tags |
|
98
|
|
|
}] |
|
99
|
|
|
|
|
100
|
|
|
|