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