UC2-REST 0.2.0.19__tar.gz → 0.2.0.20__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.19 → uc2_rest-0.2.0.20}/PKG-INFO +1 -1
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/UC2_REST.egg-info/PKG-INFO +1 -1
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/UC2_REST.egg-info/SOURCES.txt +1 -0
- uc2_rest-0.2.0.20/uc2rest/MockSerial.py +74 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/UC2Client.py +1 -1
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/__version__.py +1 -1
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/laser.py +0 -1
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/ledmatrix.py +4 -4
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/message.py +13 -8
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/motor.py +21 -2
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/mserial.py +33 -24
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/state.py +12 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/LICENSE +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/README.md +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/UC2_REST.egg-info/dependency_links.txt +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/UC2_REST.egg-info/not-zip-safe +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/UC2_REST.egg-info/requires.txt +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/UC2_REST.egg-info/top_level.txt +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/setup.cfg +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/setup.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/__init__.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/analog.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/camera.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/cmdrecorder.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/config.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/config_.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/digitalout.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/galvo.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/home.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/logger.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/modules.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/pid.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/rotator.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/slm.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/temperature.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/updater.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/utils.py +0 -0
- {uc2_rest-0.2.0.19 → uc2_rest-0.2.0.20}/uc2rest/wifi.py +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from threading import Thread
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
class MockSerial:
|
|
6
|
+
def __init__(self, port, baudrate, timeout=1):
|
|
7
|
+
self.port = port
|
|
8
|
+
self.baudrate = baudrate
|
|
9
|
+
self.timeout = timeout
|
|
10
|
+
self.is_open = False
|
|
11
|
+
self.data_buffer = []
|
|
12
|
+
self.thread = Thread(target=self._simulate_data)
|
|
13
|
+
self.thread.daemon = True
|
|
14
|
+
self.thread.start()
|
|
15
|
+
self.is_open = True
|
|
16
|
+
self.manufacturer = "UC2Mock"
|
|
17
|
+
self.BAUDRATES = -1
|
|
18
|
+
|
|
19
|
+
def flush(self):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
def isOpen(self):
|
|
23
|
+
return self.is_open
|
|
24
|
+
|
|
25
|
+
def open(self):
|
|
26
|
+
self.is_open = True
|
|
27
|
+
|
|
28
|
+
def close(self):
|
|
29
|
+
self.is_open = False
|
|
30
|
+
|
|
31
|
+
def readline(self, timeout=1):
|
|
32
|
+
if not self.is_open:
|
|
33
|
+
raise Exception("Device not connected")
|
|
34
|
+
if len(self.data_buffer) == 0:
|
|
35
|
+
return b''
|
|
36
|
+
data = self.data_buffer
|
|
37
|
+
self.data_buffer = self.data_buffer
|
|
38
|
+
time.sleep(.05)
|
|
39
|
+
return bytes(data)
|
|
40
|
+
|
|
41
|
+
def read(self, num_bytes):
|
|
42
|
+
if not self.is_open:
|
|
43
|
+
raise Exception("Device not connected")
|
|
44
|
+
if len(self.data_buffer) == 0:
|
|
45
|
+
return b''
|
|
46
|
+
data = self.data_buffer[:num_bytes]
|
|
47
|
+
self.data_buffer = self.data_buffer[num_bytes:]
|
|
48
|
+
return bytes(data)
|
|
49
|
+
|
|
50
|
+
def write(self, data):
|
|
51
|
+
if not self.is_open:
|
|
52
|
+
raise Exception("Device not connected")
|
|
53
|
+
pass # Do nothing, as it's a mock
|
|
54
|
+
|
|
55
|
+
def _simulate_data(self):
|
|
56
|
+
while self.is_open:
|
|
57
|
+
if random.random() < 0.2: # Simulate occasional data availability
|
|
58
|
+
self.data_buffer.extend([random.randint(0, 255) for _ in range(10)])
|
|
59
|
+
time.sleep(0.1)
|
|
60
|
+
|
|
61
|
+
def __enter__(self):
|
|
62
|
+
self.open()
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
66
|
+
self.close()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == '__main__':
|
|
70
|
+
with MockSerial("COM1", 9600) as ser:
|
|
71
|
+
while True:
|
|
72
|
+
data = ser.readline()
|
|
73
|
+
print(data)
|
|
74
|
+
time.sleep(1)
|
|
@@ -39,7 +39,7 @@ class UC2Client(object):
|
|
|
39
39
|
is_serial = False
|
|
40
40
|
|
|
41
41
|
# BAUDRATE = 500000
|
|
42
|
-
BAUDRATE =
|
|
42
|
+
BAUDRATE = 500000
|
|
43
43
|
|
|
44
44
|
def __init__(self, host=None, port=31950, serialport=None, identity="UC2_Feather", baudrate=BAUDRATE, NLeds=64, SerialManager=None, DEBUG=False, logger=None):
|
|
45
45
|
'''
|
|
@@ -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.20"
|
|
10
10
|
__author__ = 'Benedict Diederich'
|
|
11
11
|
__author_email__ = 'benedictdied@gmail.com'
|
|
12
12
|
__license__ = 'GPL v3'
|
|
@@ -6,7 +6,6 @@ class Laser(object):
|
|
|
6
6
|
self.filter_pos_2 = 0
|
|
7
7
|
self.filter_pos_3 = 0
|
|
8
8
|
self.filter_pos_LED = 0
|
|
9
|
-
self._parent.logger.debug("Attention, lasers are on channels 1,2,3")
|
|
10
9
|
|
|
11
10
|
def set_laser(self, channel=1, value=0, auto_filterswitch=False,
|
|
12
11
|
filter_axis=-1, filter_position = None,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import json
|
|
3
3
|
import time
|
|
4
|
-
gTimeout =
|
|
4
|
+
gTimeout = 2
|
|
5
5
|
class LedMatrix(object):
|
|
6
6
|
def __init__(self, parent, NLeds=64):
|
|
7
7
|
#TOOD: This is for the LED matrix only!
|
|
@@ -73,7 +73,7 @@ class LedMatrix(object):
|
|
|
73
73
|
self.currentLedArrayMode = "array"
|
|
74
74
|
return r
|
|
75
75
|
|
|
76
|
-
def send_LEDMatrix_full(self, intensity = (255,255,255), getReturn=
|
|
76
|
+
def send_LEDMatrix_full(self, intensity = (255,255,255), getReturn=True, timeout=gTimeout):
|
|
77
77
|
'''
|
|
78
78
|
set all LEDs with te same RGB value: intensity=(255,255,255)
|
|
79
79
|
'''
|
|
@@ -168,7 +168,7 @@ class LedMatrix(object):
|
|
|
168
168
|
|
|
169
169
|
return self.ledpattern
|
|
170
170
|
|
|
171
|
-
def setAll(self, state, intensity=None, getReturn=
|
|
171
|
+
def setAll(self, state, intensity=None, getReturn=True):
|
|
172
172
|
# fast addressing
|
|
173
173
|
# turns on all LEDs at a certain intensity
|
|
174
174
|
state = np.sum(state)>0
|
|
@@ -179,7 +179,7 @@ class LedMatrix(object):
|
|
|
179
179
|
self.ledpattern = state*np.ones((self.NLeds, 3))
|
|
180
180
|
return self.ledpattern
|
|
181
181
|
|
|
182
|
-
def setIntensity(self, intensity, getReturn=
|
|
182
|
+
def setIntensity(self, intensity, getReturn=True):
|
|
183
183
|
self.intensity = intensity
|
|
184
184
|
self.setPattern(getReturn=getReturn)
|
|
185
185
|
|
|
@@ -9,19 +9,17 @@ class Message(object):
|
|
|
9
9
|
This class only parses incoming messages from the ESP32 that can be used e.g. for triggering events such as taking an image
|
|
10
10
|
or converting hardware inputs such as button presses to software events
|
|
11
11
|
'''
|
|
12
|
-
def __init__(self, parent=None):
|
|
12
|
+
def __init__(self, parent=None, nCallbacks = 10):
|
|
13
13
|
self._parent = parent
|
|
14
|
+
self.nCallbacks = nCallbacks
|
|
15
|
+
# initialize the callback functions
|
|
16
|
+
self.init_callback_functions(self.nCallbacks)
|
|
14
17
|
|
|
15
|
-
# create a dictionary of callback functions that can be triggered by incoming messages
|
|
16
|
-
self._callbackPerKey = {}
|
|
17
|
-
self.NCallBacks = 10
|
|
18
|
-
for i in range(self.NCallBacks):
|
|
19
|
-
self._callbackPerKey[i] = None
|
|
20
|
-
|
|
21
18
|
# register a callback function for the motor status on the serial loop
|
|
22
19
|
if hasattr(self._parent, "serial"):
|
|
23
20
|
self._parent.serial.register_callback(self._callback_message, pattern="message")
|
|
24
21
|
|
|
22
|
+
|
|
25
23
|
def _callback_message(self, data):
|
|
26
24
|
''' cast the json in the form:
|
|
27
25
|
{
|
|
@@ -69,13 +67,20 @@ class Message(object):
|
|
|
69
67
|
except Exception as e:
|
|
70
68
|
print("Error in _callback_message: ", e)
|
|
71
69
|
|
|
70
|
+
def init_callback_functions(self, nCallbacks=10):
|
|
71
|
+
''' initialize the callback functions '''
|
|
72
|
+
self._callbackPerKey = {}
|
|
73
|
+
self.nCallbacks = nCallbacks
|
|
74
|
+
for i in range(nCallbacks):
|
|
75
|
+
self._callbackPerKey[i] = None
|
|
76
|
+
|
|
72
77
|
def register_callback(self, key, callback):
|
|
73
78
|
''' register a callback function for a specific key '''
|
|
74
79
|
self._callbackPerKey[key] = callback
|
|
75
80
|
|
|
76
81
|
def trigger_message(self, key:int=1, value:int=1):
|
|
77
82
|
# {"task": "/message_act", "message": 1, "key":1, "value":1}
|
|
78
|
-
path = "/
|
|
83
|
+
path = "/message_act"
|
|
79
84
|
payload = {
|
|
80
85
|
"task": path,
|
|
81
86
|
"key": key,
|
|
@@ -45,11 +45,23 @@ class Motor(object):
|
|
|
45
45
|
# register a callback function for the motor status on the serial loop
|
|
46
46
|
if hasattr(self._parent, "serial"):
|
|
47
47
|
self._parent.serial.register_callback(self._callback_motor_status, pattern="steppers")
|
|
48
|
-
|
|
48
|
+
# announce a function that is called when we receive a position update through the callback
|
|
49
|
+
self._callbackPerKey = {}
|
|
50
|
+
self.nCallbacks = 10
|
|
51
|
+
self._callbackPerKey = self.init_callback_functions(nCallbacks=self.nCallbacks) # only one is used for now
|
|
52
|
+
print(self._callbackPerKey)
|
|
49
53
|
# move motor to wake them up #FIXME: Should not be necessary!
|
|
50
54
|
#self.move_stepper(steps=(1,1,1,1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False))
|
|
51
55
|
#self.move_stepper(steps=(-1,-1,-1,-1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False))
|
|
52
56
|
|
|
57
|
+
def init_callback_functions(self, nCallbacks=10):
|
|
58
|
+
''' initialize the callback functions '''
|
|
59
|
+
_callbackPerKey = {}
|
|
60
|
+
self.nCallbacks = nCallbacks
|
|
61
|
+
for i in range(nCallbacks):
|
|
62
|
+
_callbackPerKey[i] = []
|
|
63
|
+
return _callbackPerKey
|
|
64
|
+
|
|
53
65
|
def _callback_motor_status(self, data):
|
|
54
66
|
''' cast the json in the form:
|
|
55
67
|
{
|
|
@@ -67,9 +79,16 @@ class Motor(object):
|
|
|
67
79
|
stepperID = data["steppers"][iMotor]["stepperid"]
|
|
68
80
|
# smart to re-update this variable? Will be updated by motor-sender too
|
|
69
81
|
self._position[stepperID] = data["steppers"][iMotor]["position"]
|
|
82
|
+
if callable(self._callbackPerKey[0]):
|
|
83
|
+
self._callbackPerKey[0](self._position) # we call the function with the value
|
|
70
84
|
except Exception as e:
|
|
71
85
|
print("Error in _callback_motor_status: ", e)
|
|
72
86
|
|
|
87
|
+
def register_callback(self, key, callbackfct):
|
|
88
|
+
''' register a callback function for a specific key '''
|
|
89
|
+
self._callbackPerKey[key] = callbackfct
|
|
90
|
+
|
|
91
|
+
|
|
73
92
|
def setTrigger(self, axis="X", pin=1, offset=0, period=1):
|
|
74
93
|
# {"task": "/motor_act", "setTrig": {"steppers": [{"stepperid": 1, "trigPin": 1, "trigOff":0, "trigPer":1}]}}
|
|
75
94
|
if type(axis) is not int:
|
|
@@ -512,7 +531,7 @@ class Motor(object):
|
|
|
512
531
|
r = self._parent.post_json(path, payload)
|
|
513
532
|
return r
|
|
514
533
|
|
|
515
|
-
def get_position(self, axis=None, timeout
|
|
534
|
+
def get_position(self, axis=None, timeout=1):
|
|
516
535
|
# pulls all current positions from the stepper controller
|
|
517
536
|
path = "/motor_get"
|
|
518
537
|
payload = {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import serial
|
|
2
|
+
from serial.tools import list_ports
|
|
2
3
|
import json
|
|
3
4
|
import queue
|
|
4
5
|
import threading
|
|
5
6
|
import time
|
|
6
7
|
|
|
7
|
-
T_SERIAL_WARMUP =
|
|
8
|
+
T_SERIAL_WARMUP = 2.5
|
|
8
9
|
class Serial:
|
|
9
10
|
def __init__(self, port, baudrate=115200, timeout=5,
|
|
10
11
|
identity="UC2_Feather", parent=None, DEBUG=False):
|
|
@@ -26,7 +27,7 @@ class Serial:
|
|
|
26
27
|
self.identity = identity
|
|
27
28
|
self.DEBUG = DEBUG
|
|
28
29
|
self.is_connected = False
|
|
29
|
-
self.write_timeout =
|
|
30
|
+
self.write_timeout = 1
|
|
30
31
|
self.read_timeout = 0.02
|
|
31
32
|
|
|
32
33
|
self.cmdCallBackFct = None
|
|
@@ -37,6 +38,7 @@ class Serial:
|
|
|
37
38
|
self.responses = {}
|
|
38
39
|
self.commands = {}
|
|
39
40
|
self.lock = threading.Lock()
|
|
41
|
+
self.serialLock = threading.Lock()
|
|
40
42
|
|
|
41
43
|
# setup callback list for parent modules
|
|
42
44
|
self.callBackList = []
|
|
@@ -53,8 +55,10 @@ class Serial:
|
|
|
53
55
|
# free up any old data
|
|
54
56
|
while True:
|
|
55
57
|
try:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
readLineRaw = ser.readline()
|
|
59
|
+
readLine = readLineRaw.decode('utf-8').strip()
|
|
60
|
+
if self.DEBUG and readLine != "":
|
|
61
|
+
self._logger.debug(readLine)
|
|
58
62
|
if readLine == "" and time.time()-t0 > timeMinimum:
|
|
59
63
|
break
|
|
60
64
|
except Exception as e:
|
|
@@ -116,7 +120,7 @@ class Serial:
|
|
|
116
120
|
It may be that - depending on the OS - the response may be corrupted
|
|
117
121
|
If this is the case try to hard-code the COM port into the config JSON file
|
|
118
122
|
'''
|
|
119
|
-
_available_ports =
|
|
123
|
+
_available_ports = list_ports.comports(include_links=False)
|
|
120
124
|
ports_to_check = ["COM", "/dev/tt", "/dev/a", "/dev/cu.SLA", "/dev/cu.wchusb"]
|
|
121
125
|
descriptions_to_check = ["CH340", "CP2102"]
|
|
122
126
|
|
|
@@ -165,7 +169,8 @@ class Serial:
|
|
|
165
169
|
for i in range(500):
|
|
166
170
|
# if we just want to send but not even wait for a response
|
|
167
171
|
mReadline = ser.readline()
|
|
168
|
-
if self.DEBUG
|
|
172
|
+
if self.DEBUG and mReadline != "" and mReadline != "\n" and mReadline != b'' and mReadline != b'\n':
|
|
173
|
+
self._logger.debug("[checkFirmware]: "+str(mReadline))
|
|
169
174
|
if mReadline.decode('utf-8').strip() == "++":
|
|
170
175
|
self._freeSerialBuffer(ser)
|
|
171
176
|
return True
|
|
@@ -188,14 +193,17 @@ class Serial:
|
|
|
188
193
|
json_command = self.sender_queue.get()
|
|
189
194
|
|
|
190
195
|
# Process the command
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
with self.serialLock:
|
|
197
|
+
try:
|
|
198
|
+
if self.DEBUG and json_command!="": self._logger.debug("[SendingCommands]:"+str(json_command))
|
|
199
|
+
self.serialdevice.write(json_command.encode('utf-8'))
|
|
200
|
+
except Exception as e:
|
|
201
|
+
self._logger.error("Failed to write the line in serial: "+str(e))
|
|
195
202
|
|
|
196
203
|
# Signal that the command has been processed
|
|
197
204
|
self.sender_queue.task_done()
|
|
198
|
-
|
|
205
|
+
if self.DEBUG: self._logger.debug("[SendingCommands]: Task done")
|
|
206
|
+
|
|
199
207
|
# Wait for .05 second before processing the next command
|
|
200
208
|
time.sleep(0.05)
|
|
201
209
|
|
|
@@ -206,7 +214,6 @@ class Serial:
|
|
|
206
214
|
nLineCountTimeout = 50 # maximum number of lines read before timeout
|
|
207
215
|
lineCounter = 0
|
|
208
216
|
while self.running:
|
|
209
|
-
|
|
210
217
|
if self.manufacturer == "UC2Mock":
|
|
211
218
|
self.running = False
|
|
212
219
|
return
|
|
@@ -219,15 +226,13 @@ class Serial:
|
|
|
219
226
|
self.is_connected = True
|
|
220
227
|
|
|
221
228
|
# if we just want to send but not even wait for a response
|
|
222
|
-
|
|
223
229
|
try:
|
|
224
|
-
|
|
230
|
+
with self.serialLock:
|
|
231
|
+
mReadline = self.serialdevice.readline()
|
|
232
|
+
line = mReadline.decode('utf-8').strip()
|
|
233
|
+
if self.DEBUG and line!="": self._logger.debug("[ProcessLines]:"+str(line))
|
|
225
234
|
except Exception as e:
|
|
226
235
|
self._logger.error("Failed to read the line in serial: "+str(e))
|
|
227
|
-
try:
|
|
228
|
-
line = mReadline.decode('utf-8').strip()
|
|
229
|
-
if self.DEBUG and line!="": self._logger.debug("[ProcessLines]:"+str(line))
|
|
230
|
-
except:
|
|
231
236
|
line = ""
|
|
232
237
|
if line == "++":
|
|
233
238
|
reading_json = True
|
|
@@ -334,16 +339,19 @@ class Serial:
|
|
|
334
339
|
command["qid"] = identifier
|
|
335
340
|
try:
|
|
336
341
|
json_command = json.dumps(command)+"\n"
|
|
337
|
-
self.serialdevice.flush()
|
|
338
|
-
if self.DEBUG: self._logger.debug("[
|
|
342
|
+
#self.serialdevice.flush()
|
|
343
|
+
if self.DEBUG and json_command!="": self._logger.debug("[SendingCommands]:"+str(json_command))
|
|
344
|
+
self.serialdevice.write(json_command.encode('utf-8'))
|
|
345
|
+
#time.sleep(1)
|
|
339
346
|
# we have to queue the commands and give it some time to process
|
|
340
|
-
self._enqueue_command(json_command)
|
|
347
|
+
#self._enqueue_command(json_command)
|
|
341
348
|
|
|
342
349
|
except Exception as e:
|
|
343
350
|
if self.DEBUG: self._logger.error(e)
|
|
344
351
|
return "Failed to Send"
|
|
345
352
|
self.commands[identifier]=command # FIXME: Need to clear this after the response is received
|
|
346
353
|
if nResponses <= 0 or not self.is_connected or self.manufacturer=="UC2Mock":
|
|
354
|
+
time.sleep(0.1)
|
|
347
355
|
return identifier
|
|
348
356
|
t0 = time.time()
|
|
349
357
|
timeReturnReceived = 0.3
|
|
@@ -351,7 +359,7 @@ class Serial:
|
|
|
351
359
|
time.sleep(0.002)
|
|
352
360
|
if self.resetLastCommand or time.time()-t0>timeout or not self.is_connected:
|
|
353
361
|
self.resetLastCommand = False
|
|
354
|
-
return "communication interrupted"
|
|
362
|
+
return "communication interrupted by timeout or reset: "+str(identifier) + " and code:"+str(self.commands[identifier])
|
|
355
363
|
with self.lock:
|
|
356
364
|
if identifier in self.responses:
|
|
357
365
|
if len(self.responses[identifier])==nResponses:
|
|
@@ -362,7 +370,6 @@ class Serial:
|
|
|
362
370
|
if time.time()-t0>timeReturnReceived and not (identifier in self.responses and len(self.responses[identifier]) > 0):
|
|
363
371
|
self._logger.debug("It takes too long to get a response, we will resend the last command")
|
|
364
372
|
try:
|
|
365
|
-
self.DEBUG=1
|
|
366
373
|
self.serialdevice.write(json.dumps(self.commands[identifier]).encode('utf-8'))
|
|
367
374
|
time.sleep(0.1)
|
|
368
375
|
except Exception as e:
|
|
@@ -381,8 +388,10 @@ class Serial:
|
|
|
381
388
|
self.stop()
|
|
382
389
|
self.running = False
|
|
383
390
|
|
|
384
|
-
def reconnect(self):
|
|
391
|
+
def reconnect(self, baudrate=None):
|
|
385
392
|
self.running = False
|
|
393
|
+
if baudrate is not None:
|
|
394
|
+
self.baudrate = baudrate
|
|
386
395
|
try:
|
|
387
396
|
self.serialdevice.close()
|
|
388
397
|
except:
|
|
@@ -84,3 +84,15 @@ class State(object):
|
|
|
84
84
|
except:
|
|
85
85
|
return r
|
|
86
86
|
|
|
87
|
+
|
|
88
|
+
def getHeap(self, timeout=1):
|
|
89
|
+
path = "/state_get"
|
|
90
|
+
payload = {
|
|
91
|
+
"task":path,
|
|
92
|
+
"heap": 1
|
|
93
|
+
}
|
|
94
|
+
r = self._parent.post_json(path, payload, timeout=timeout)
|
|
95
|
+
try:
|
|
96
|
+
return r["heap"]
|
|
97
|
+
except:
|
|
98
|
+
return r
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|