forked from jcsombria/py-ripserver
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRIPMatlab.py
More file actions
74 lines (63 loc) · 1.63 KB
/
Copy pathRIPMatlab.py
File metadata and controls
74 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''
@author: jcsombria
'''
import os.path
from rip.RIPGeneric import RIPGeneric
from rip.matlab.MatlabConnector import CommandBuilder, MatlabConnector
import matlab.engine
class RIPMatlab(RIPGeneric):
'''
RIP MATLAB Adapter
'''
def __init__(self, info):
'''
Constructor
'''
super().__init__(info)
self.matlab = matlab.engine.start_matlab('-desktop')
def default_info(self):
'''
Default metadata.
'''
return {
'name': 'Matlab',
'description': 'An implementation of RIP to control MATLAB',
'authors': 'J. Chacon',
'keywords': 'MATLAB, Raspberry PI',
'readables': [],
'writables': [],
}
def set(self, expid, variables, values):
if isinstance(variables, list):
size = len(variables)
for i in range(size):
try:
name, value = variables[i], values[i]
self.matlab.workspace[name] = value
except:
pass
else:
try:
name, value = variables, values
self.matlab.workspace[name] = value
except:
pass
self.matlab.set(variables, values)
def get(self, expid, variables):
readables = self._getReadables()
values = []
for n in variables:
try:
if n in readables:
v = self.matlab.workspace[n]
values.append(v)
except:
values.append('###ERROR###')
return [variables, values]
def preGetValuesToNotify(self):
self.matlab.workspace['time'] = self.sampler.time
def getValuesToNotify(self, expid=None):
values = self.get(expid, self._getReadables())
return values
def postGetValuesToNotify(self):
pass