From 24c2d6449c8692a92251e5f33746f1ca39e48234 Mon Sep 17 00:00:00 2001 From: Benedict Diederich Date: Thu, 7 Dec 2023 09:59:24 +0100 Subject: [PATCH 1/5] Fixing reconnection issue --- uc2rest/mserial.py | 6 ++---- uc2rest/temperature.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/uc2rest/mserial.py b/uc2rest/mserial.py index 6474d6e..9b57184 100644 --- a/uc2rest/mserial.py +++ b/uc2rest/mserial.py @@ -9,7 +9,7 @@ class Serial: def __init__(self, port, baudrate=115200, timeout=5, identity="UC2_Feather", parent=None, DEBUG=False): - self.serialdevice= None + self.serialdevice = None self.serialport = port self.baudrate = baudrate self.timeout = timeout @@ -175,7 +175,7 @@ def _process_commands(self): # currentIdentifier, command = self.command_queue.get() # device not ready yet - if self.serialdeviceis None: + if self.serialdevice is None: self.is_connected = False continue else: @@ -288,11 +288,9 @@ def sendMessage(self, command, nResponses=1, timeout = 20): try: json_command = json.dumps(command)+"\n" with self.lock: - t0 = time.time() self.serialdevice.flush() self._logger.debug("[SendMessage]: "+str(json_command)) self.serialdevice.write(json_command.encode('utf-8') ) - self._logger.debug("[SendMessage] took: "+str(time.time()-t0)) except Exception as e: if self.DEBUG: self._logger.error(e) return "Failed to Send" diff --git a/uc2rest/temperature.py b/uc2rest/temperature.py index 5cb247f..5a21ee0 100644 --- a/uc2rest/temperature.py +++ b/uc2rest/temperature.py @@ -13,7 +13,7 @@ def stop_heating(self): r = self.set_temperature(active=0) return r - def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=600000, updaterate=1000): + def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=60000000, updaterate=1000): # {"task": "/heat_act", "active":1, "Kp":1000, "Ki":0.1, "Kd":0.1, "target":37, "timeout":600000, "updaterate":1000} path = "/heat_act" payload = { From bb9b3460406a3a4c3f37c70b7fb2e64706ddfefd Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Dec 2023 15:57:20 +0100 Subject: [PATCH 2/5] removing motor move on start --- uc2rest/motor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uc2rest/motor.py b/uc2rest/motor.py index 2dc67db..7d8a62c 100644 --- a/uc2rest/motor.py +++ b/uc2rest/motor.py @@ -54,8 +54,8 @@ def __init__(self, parent=None): self._parent.serial.register_callback(self._callback_motor_status, pattern="steppers") # move motor to wake them up #FIXME: Should not be necessary! - self.move_stepper(steps=(1,1,1,1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False)) - self.move_stepper(steps=(-1,-1,-1,-1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False)) + #self.move_stepper(steps=(1,1,1,1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False)) + #self.move_stepper(steps=(-1,-1,-1,-1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False)) def _callback_motor_status(self, data): ''' cast the json in the form: From d1c37f428b04a0b96aae72dcd664957ba986c649 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Dec 2023 17:58:58 +0100 Subject: [PATCH 3/5] Update home.py --- uc2rest/home.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uc2rest/home.py b/uc2rest/home.py index 093cf21..42417c9 100644 --- a/uc2rest/home.py +++ b/uc2rest/home.py @@ -78,7 +78,7 @@ def home(self, axis=None, timeout=None, speed=None, direction=None, endposreleas { "stepperid": axis, "timeout":timeout*1000, - "speed":speed, + "speed":direction*abs(speed), "direction":direction, "endposrelease":endposrelease, "endstoppolarity":endstoppolarity From 9cf526365a503069b3f95804e78d38a18959c396 Mon Sep 17 00:00:00 2001 From: Benedict Diederich Date: Mon, 18 Dec 2023 17:16:01 +0100 Subject: [PATCH 4/5] update laser interface --- uc2rest/laser.py | 32 +------------------------------- uc2rest/temperature.py | 2 +- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/uc2rest/laser.py b/uc2rest/laser.py index d61189b..eb80f42 100644 --- a/uc2rest/laser.py +++ b/uc2rest/laser.py @@ -46,7 +46,7 @@ def set_laser(self, channel=1, value=0, auto_filterswitch=False, } #self._parent.logger.debug("Setting Laser "+str(channel)+", value: "+str(value)) - r = self._parent.post_json(path, payload, getReturn=is_blocking) + r = self._parent.post_json(path, payload, getReturn=is_blocking, timeout=.5) return r def set_laserpin(self, laserid=1, laserpin=0): @@ -61,33 +61,3 @@ def set_laserpin(self, laserid=1, laserpin=0): r = self._parent.post_json(path, payload) return r - def get_laserpins(self): - path = '/laser_get' - - r = self._parent.get_json(path) - - if type(r) is dict: - # cast laser pins - if "LASER1pin" in r: r["LASER1pin"] = int(r["LASER1pin"]) - else: r["LASER1pin"] = 0 - if r.__contains__("LASER2pin"): r["LASER2pin"] = int(r["LASER2pin"]) - else: r["LASER2pin"] = 0 - if r.__contains__("LASER3pin"): r["LASER3pin"] = int(r["LASER3pin"]) - else: r["LASER3pin"] = 0 - else: - r={} - r["LASER1pin"] = 0 - r["LASER2pin"] = 0 - r["LASER3pin"] = 0 - - return r - - def get_laserpin(self, laserid=1): - path = '/laser_get' - - payload = { - "task": path, - } - - r = self._parent.post_json(path, payload,timeout=2) - return r["LASER"+str(laserid)+"pin"] diff --git a/uc2rest/temperature.py b/uc2rest/temperature.py index 8a2e09f..67aeadb 100644 --- a/uc2rest/temperature.py +++ b/uc2rest/temperature.py @@ -13,7 +13,7 @@ def stop_heating(self): r = self.set_temperature(active=0) return r - def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=60000000, updaterate=1000): + def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=600000000, updaterate=1000): # {"task": "/heat_act", "active":1, "Kp":1000, "Ki":0.1, "Kd":0.1, "target":37, "timeout":60000000, "updaterate":1000} path = "/heat_act" payload = { From c3b90deea9ac6c1f69097f7fcff7c89cf3c96904 Mon Sep 17 00:00:00 2001 From: Benedict Diederich Date: Fri, 19 Jan 2024 13:39:32 +0100 Subject: [PATCH 5/5] fixing timeout issue --- uc2rest/UC2Client.py | 2 +- uc2rest/motor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/uc2rest/UC2Client.py b/uc2rest/UC2Client.py index 3887843..70f7a58 100644 --- a/uc2rest/UC2Client.py +++ b/uc2rest/UC2Client.py @@ -172,7 +172,7 @@ def post_json(self, path, payload, getReturn=True, nResponses=1, timeout=1): elif self.is_serial or self.isPyScript: if timeout <=0: getReturn = False - return self.serial.post_json(path, payload, getReturn=getReturn, nResponses=nResponses) + return self.serial.post_json(path, payload, getReturn=getReturn, nResponses=nResponses, timeout=timeout) else: self.logger.error("No ESP32 device is connected - check IP or Serial port!") return None diff --git a/uc2rest/motor.py b/uc2rest/motor.py index 8eae3a6..83b539e 100644 --- a/uc2rest/motor.py +++ b/uc2rest/motor.py @@ -521,7 +521,7 @@ def set_motor_enable(self, enable=None, enableauto=None): r = self._parent.post_json(path, payload) return r - def get_position(self, axis=None, timeout=1): + def get_position(self, axis=None, timeout=.2): # pulls all current positions from the stepper controller path = "/motor_get" payload = { @@ -532,7 +532,7 @@ def get_position(self, axis=None, timeout=1): _physicalStepSizes = np.array((self.stepSizeA, self.stepSizeX, self.stepSizeY, self.stepSizeZ)) # this may be an asynchronous call.. #FIXME! - r = self._parent.post_json(path, payload, getReturn = True, nResponses=1) + r = self._parent.post_json(path, payload, getReturn = True, nResponses=1, timeout=timeout) if "motor" in r: for index, istepper in enumerate(r["motor"]["steppers"]): _position[istepper["stepperid"]]=istepper["position"]*_physicalStepSizes[self.motorAxisOrder[index]]