UC2-REST 0.2.0.16__tar.gz → 0.2.0.18__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/PKG-INFO +1 -1
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/UC2_REST.egg-info/PKG-INFO +1 -1
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/UC2_REST.egg-info/SOURCES.txt +1 -2
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/UC2Client.py +201 -196
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/__version__.py +1 -1
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/home.py +1 -1
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/laser.py +1 -31
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/motor.py +72 -21
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/mserial.py +123 -65
- UC2-REST-0.2.0.18/uc2rest/temperature.py +54 -0
- UC2-REST-0.2.0.16/uc2rest/mserial_.py +0 -296
- UC2-REST-0.2.0.16/uc2rest/mserial_old.py +0 -412
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/LICENSE +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/README.md +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/UC2_REST.egg-info/dependency_links.txt +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/UC2_REST.egg-info/not-zip-safe +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/UC2_REST.egg-info/requires.txt +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/UC2_REST.egg-info/top_level.txt +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/setup.cfg +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/setup.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/__init__.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/analog.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/camera.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/cmdrecorder.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/config.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/config_.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/digitalout.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/galvo.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/ledmatrix.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/logger.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/modules.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/pid.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/rotator.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/slm.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/state.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/updater.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/utils.py +0 -0
- {UC2-REST-0.2.0.16 → UC2-REST-0.2.0.18}/uc2rest/wifi.py +0 -0
|
@@ -24,12 +24,11 @@ uc2rest/logger.py
|
|
|
24
24
|
uc2rest/modules.py
|
|
25
25
|
uc2rest/motor.py
|
|
26
26
|
uc2rest/mserial.py
|
|
27
|
-
uc2rest/mserial_.py
|
|
28
|
-
uc2rest/mserial_old.py
|
|
29
27
|
uc2rest/pid.py
|
|
30
28
|
uc2rest/rotator.py
|
|
31
29
|
uc2rest/slm.py
|
|
32
30
|
uc2rest/state.py
|
|
31
|
+
uc2rest/temperature.py
|
|
33
32
|
uc2rest/updater.py
|
|
34
33
|
uc2rest/utils.py
|
|
35
34
|
uc2rest/wifi.py
|
|
@@ -1,197 +1,202 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# coding: utf-8
|
|
3
|
-
#%%
|
|
4
|
-
"""
|
|
5
|
-
Simple client code for the ESP32 in Python
|
|
6
|
-
Copyright 2021 Benedict Diederich, released under LGPL 3.0 or later
|
|
7
|
-
"""
|
|
8
|
-
from .mserial import Serial
|
|
9
|
-
from .mserial import SerialManagerWrapper
|
|
10
|
-
from .galvo import Galvo
|
|
11
|
-
from .config import config
|
|
12
|
-
from .ledmatrix import LedMatrix
|
|
13
|
-
from .motor import Motor
|
|
14
|
-
from .home import Home
|
|
15
|
-
from .state import State
|
|
16
|
-
from .laser import Laser
|
|
17
|
-
from .wifi import Wifi
|
|
18
|
-
from .camera import Camera
|
|
19
|
-
from .analog import Analog
|
|
20
|
-
from .modules import Modules
|
|
21
|
-
from .digitalout import DigitalOut
|
|
22
|
-
from .rotator import Rotator
|
|
23
|
-
from .logger import Logger
|
|
24
|
-
from .cmdrecorder import cmdRecorder
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
headers={
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
BAUDRATE =
|
|
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
|
-
self.
|
|
68
|
-
self.
|
|
69
|
-
self.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
self.
|
|
74
|
-
self.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
self.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
#
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
returnMessage
|
|
166
|
-
returnMessage["success"] =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
#
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
#%%
|
|
4
|
+
"""
|
|
5
|
+
Simple client code for the ESP32 in Python
|
|
6
|
+
Copyright 2021 Benedict Diederich, released under LGPL 3.0 or later
|
|
7
|
+
"""
|
|
8
|
+
from .mserial import Serial
|
|
9
|
+
from .mserial import SerialManagerWrapper
|
|
10
|
+
from .galvo import Galvo
|
|
11
|
+
from .config import config
|
|
12
|
+
from .ledmatrix import LedMatrix
|
|
13
|
+
from .motor import Motor
|
|
14
|
+
from .home import Home
|
|
15
|
+
from .state import State
|
|
16
|
+
from .laser import Laser
|
|
17
|
+
from .wifi import Wifi
|
|
18
|
+
from .camera import Camera
|
|
19
|
+
from .analog import Analog
|
|
20
|
+
from .modules import Modules
|
|
21
|
+
from .digitalout import DigitalOut
|
|
22
|
+
from .rotator import Rotator
|
|
23
|
+
from .logger import Logger
|
|
24
|
+
from .cmdrecorder import cmdRecorder
|
|
25
|
+
from .temperature import Temperature
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
import requests
|
|
29
|
+
except:
|
|
30
|
+
print("No requests available - running on pyscript?")
|
|
31
|
+
|
|
32
|
+
class UC2Client(object):
|
|
33
|
+
# headers = {'ESP32-version': '*'}
|
|
34
|
+
headers={"Content-Type":"application/json"}
|
|
35
|
+
getmessage = ""
|
|
36
|
+
is_connected = False
|
|
37
|
+
|
|
38
|
+
is_wifi = False
|
|
39
|
+
is_serial = False
|
|
40
|
+
|
|
41
|
+
# BAUDRATE = 500000
|
|
42
|
+
BAUDRATE = 115200
|
|
43
|
+
|
|
44
|
+
def __init__(self, host=None, port=31950, serialport=None, identity="UC2_Feather", baudrate=BAUDRATE, NLeds=64, SerialManager=None, DEBUG=False, logger=None):
|
|
45
|
+
'''
|
|
46
|
+
This client connects to the UC2-REST microcontroller that can be found here
|
|
47
|
+
https://github.com/openUC2/UC2-REST
|
|
48
|
+
|
|
49
|
+
generally speaking you send/receive JSON documents that will cause an:
|
|
50
|
+
1. action => "/XXX_act"
|
|
51
|
+
2. getting => "/XXX_get"
|
|
52
|
+
3. setting => "/XXX_set"
|
|
53
|
+
|
|
54
|
+
you can send commands through wifi/http or usb/serial
|
|
55
|
+
'''
|
|
56
|
+
if logger is None:
|
|
57
|
+
self.logger = Logger()
|
|
58
|
+
else:
|
|
59
|
+
self.logger = logger
|
|
60
|
+
|
|
61
|
+
# perhaps we are in the browser?
|
|
62
|
+
self.isPyScript = False
|
|
63
|
+
|
|
64
|
+
# initialize communication channel (# connect to wifi or usb)
|
|
65
|
+
if serialport is not None:
|
|
66
|
+
# use USB connection
|
|
67
|
+
self.serial = Serial(serialport, baudrate, parent=self, identity=identity, DEBUG=DEBUG)
|
|
68
|
+
self.is_serial = True
|
|
69
|
+
self.is_connected = self.serial.is_connected
|
|
70
|
+
self.serial.DEBUG = DEBUG
|
|
71
|
+
elif host is not None:
|
|
72
|
+
# use client in wireless mode
|
|
73
|
+
self.is_wifi = True
|
|
74
|
+
self.host = host
|
|
75
|
+
self.port = port
|
|
76
|
+
|
|
77
|
+
# check if host is up
|
|
78
|
+
self.logger.debug(f"Connecting to microscope {self.host}:{self.port}")
|
|
79
|
+
#self.is_connected = self.isConnected()
|
|
80
|
+
elif SerialManager is not None:
|
|
81
|
+
# we are trying to access the controller from .a web browser
|
|
82
|
+
self.serial = SerialManagerWrapper(SerialManager, parent=self)
|
|
83
|
+
self.isPyScript = True
|
|
84
|
+
else:
|
|
85
|
+
self.logger.error("No ESP32 device is connected - check IP or Serial port!")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if not self.isPyScript: from .updater import updater
|
|
89
|
+
|
|
90
|
+
# import libraries depending on API version
|
|
91
|
+
self.logger.debug("Using API version 2")
|
|
92
|
+
|
|
93
|
+
#FIXME
|
|
94
|
+
#self.set_state(debug=False)
|
|
95
|
+
|
|
96
|
+
# initialize state
|
|
97
|
+
self.state = State(self)
|
|
98
|
+
if not self.isPyScript:
|
|
99
|
+
state = self.state.get_state()
|
|
100
|
+
|
|
101
|
+
# initialize config
|
|
102
|
+
if not self.isPyScript:
|
|
103
|
+
self.config = config(self)
|
|
104
|
+
|
|
105
|
+
# initialize cmdRecorder
|
|
106
|
+
self.cmdRecorder = cmdRecorder(self)
|
|
107
|
+
|
|
108
|
+
# initialize LED matrix
|
|
109
|
+
self.led = LedMatrix(self, NLeds=NLeds)
|
|
110
|
+
|
|
111
|
+
# initilize motor
|
|
112
|
+
self.motor = Motor(self)
|
|
113
|
+
|
|
114
|
+
# initialize rotator
|
|
115
|
+
self.rotator = Rotator(self)
|
|
116
|
+
|
|
117
|
+
# initiliaze homing
|
|
118
|
+
self.home = Home(self)
|
|
119
|
+
|
|
120
|
+
# initialize temperature
|
|
121
|
+
self.temperature = Temperature(self)
|
|
122
|
+
|
|
123
|
+
# initialize laser
|
|
124
|
+
self.state = State(self)
|
|
125
|
+
|
|
126
|
+
# initialize galvo
|
|
127
|
+
self.galvo = Galvo(self)
|
|
128
|
+
|
|
129
|
+
# initialize laser
|
|
130
|
+
self.laser = Laser(self)
|
|
131
|
+
|
|
132
|
+
# initialize wifi
|
|
133
|
+
self.wifi = Wifi(self)
|
|
134
|
+
|
|
135
|
+
# initialize camera
|
|
136
|
+
self.camera = Camera(self)
|
|
137
|
+
|
|
138
|
+
# initialize analog
|
|
139
|
+
self.analog = Analog(self)
|
|
140
|
+
|
|
141
|
+
# initialize digital out
|
|
142
|
+
self.digitalout = DigitalOut(self)
|
|
143
|
+
|
|
144
|
+
# initialize config
|
|
145
|
+
if False: # not self.isPyScript:
|
|
146
|
+
self.config = config(self)
|
|
147
|
+
try: self.pinConfig = self.config.loadConfigDevice()
|
|
148
|
+
except: self.pinConfig = None
|
|
149
|
+
|
|
150
|
+
# initialize updater
|
|
151
|
+
if not self.isPyScript:
|
|
152
|
+
try: self.updater = updater(parent=self)
|
|
153
|
+
except: self.updater = None
|
|
154
|
+
|
|
155
|
+
# initialize module controller
|
|
156
|
+
self.modules = Modules(parent=self)
|
|
157
|
+
|
|
158
|
+
def post_json(self, path, payload, getReturn=True, nResponses=1, timeout=1):
|
|
159
|
+
if self.is_wifi:
|
|
160
|
+
# FIXME: this is not working
|
|
161
|
+
url = f"http://{self.host}:{self.port}{path}"
|
|
162
|
+
try:
|
|
163
|
+
if timeout==0: timeout=.2
|
|
164
|
+
r = requests.post(url, json=payload, headers=self.headers, timeout=timeout)
|
|
165
|
+
returnMessage = r.json()
|
|
166
|
+
returnMessage["success"] = r.status_code==200
|
|
167
|
+
except Exception as e:
|
|
168
|
+
print(e)
|
|
169
|
+
returnMessage = {}
|
|
170
|
+
returnMessage["error"] = str(e)
|
|
171
|
+
returnMessage["success"] = 0
|
|
172
|
+
return returnMessage
|
|
173
|
+
elif self.is_serial or self.isPyScript:
|
|
174
|
+
if timeout <=0:
|
|
175
|
+
getReturn = False
|
|
176
|
+
return self.serial.post_json(path, payload, getReturn=getReturn, timeout=timeout, nResponses=nResponses)
|
|
177
|
+
else:
|
|
178
|
+
self.logger.error("No ESP32 device is connected - check IP or Serial port!")
|
|
179
|
+
return None
|
|
180
|
+
|
|
181
|
+
def get_json(self, path, getReturn=True, timeout=1):
|
|
182
|
+
if self.is_wifi:
|
|
183
|
+
# FIXME: this is not working
|
|
184
|
+
url = f"http://{self.host}:{self.port}{path}"
|
|
185
|
+
r = requests.get(url, headers=self.headers, timeout=timeout)
|
|
186
|
+
return r.json()
|
|
187
|
+
elif self.is_serial or self.isPyScript:
|
|
188
|
+
# timeout is not used anymore
|
|
189
|
+
if timeout <=0:
|
|
190
|
+
getReturn = False
|
|
191
|
+
return self.serial.post_json(path, payload=None, getReturn=getReturn, nResponses=1, timeout=timeout)
|
|
192
|
+
#return self.serial.read_json()
|
|
193
|
+
else:
|
|
194
|
+
self.logger.error("No ESP32 device is connected - check IP or Serial port!")
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
def setDebugging(self, debug=False):
|
|
198
|
+
self.logger.debug(f"Setting debugging to {debug}")
|
|
199
|
+
self.serial.DEBUG = debug
|
|
200
|
+
|
|
201
|
+
def close(self):
|
|
197
202
|
self.serial.closeSerial()
|
|
@@ -6,7 +6,7 @@ __version__.py
|
|
|
6
6
|
|
|
7
7
|
__title__ = 'UC2-REST'
|
|
8
8
|
__description__ = 'This pacage will help you to drive the ESP32-driven microscopy control modules from UC2'
|
|
9
|
-
__version__ = "v0.2.0.
|
|
9
|
+
__version__ = "v0.2.0.18"
|
|
10
10
|
__author__ = 'Benedict Diederich'
|
|
11
11
|
__author_email__ = 'benedictdied@gmail.com'
|
|
12
12
|
__license__ = 'GPL v3'
|
|
@@ -46,7 +46,7 @@ class Laser(object):
|
|
|
46
46
|
|
|
47
47
|
}
|
|
48
48
|
#self._parent.logger.debug("Setting Laser "+str(channel)+", value: "+str(value))
|
|
49
|
-
r = self._parent.post_json(path, payload, getReturn=is_blocking)
|
|
49
|
+
r = self._parent.post_json(path, payload, getReturn=is_blocking, timeout=.5)
|
|
50
50
|
return r
|
|
51
51
|
|
|
52
52
|
def set_laserpin(self, laserid=1, laserpin=0):
|
|
@@ -61,33 +61,3 @@ class Laser(object):
|
|
|
61
61
|
r = self._parent.post_json(path, payload)
|
|
62
62
|
return r
|
|
63
63
|
|
|
64
|
-
def get_laserpins(self):
|
|
65
|
-
path = '/laser_get'
|
|
66
|
-
|
|
67
|
-
r = self._parent.get_json(path)
|
|
68
|
-
|
|
69
|
-
if type(r) is dict:
|
|
70
|
-
# cast laser pins
|
|
71
|
-
if "LASER1pin" in r: r["LASER1pin"] = int(r["LASER1pin"])
|
|
72
|
-
else: r["LASER1pin"] = 0
|
|
73
|
-
if r.__contains__("LASER2pin"): r["LASER2pin"] = int(r["LASER2pin"])
|
|
74
|
-
else: r["LASER2pin"] = 0
|
|
75
|
-
if r.__contains__("LASER3pin"): r["LASER3pin"] = int(r["LASER3pin"])
|
|
76
|
-
else: r["LASER3pin"] = 0
|
|
77
|
-
else:
|
|
78
|
-
r={}
|
|
79
|
-
r["LASER1pin"] = 0
|
|
80
|
-
r["LASER2pin"] = 0
|
|
81
|
-
r["LASER3pin"] = 0
|
|
82
|
-
|
|
83
|
-
return r
|
|
84
|
-
|
|
85
|
-
def get_laserpin(self, laserid=1):
|
|
86
|
-
path = '/laser_get'
|
|
87
|
-
|
|
88
|
-
payload = {
|
|
89
|
-
"task": path,
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
r = self._parent.post_json(path, payload,timeout=2)
|
|
93
|
-
return r["LASER"+str(laserid)+"pin"]
|