Merge branch 'master' of https://gitlab.com/openflexure/openflexure-microscope-server
This commit is contained in:
commit
e3359be025
2 changed files with 19 additions and 9 deletions
|
|
@ -6,6 +6,11 @@ monkey.patch_all()
|
||||||
import time
|
import time
|
||||||
import atexit
|
import atexit
|
||||||
import logging, logging.handlers
|
import logging, logging.handlers
|
||||||
|
|
||||||
|
# Set root logger level
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
|
|
@ -42,16 +47,12 @@ formatter = logging.Formatter(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Get root logger
|
|
||||||
logger = logging.getLogger()
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
# Create file handler
|
# Create file handler
|
||||||
fh = logging.handlers.RotatingFileHandler(
|
fh = logging.handlers.RotatingFileHandler(
|
||||||
ROOT_LOGFILE, maxBytes=1_000_000, backupCount=5
|
ROOT_LOGFILE, maxBytes=1_000_000, backupCount=5
|
||||||
)
|
)
|
||||||
fh.setFormatter(formatter)
|
fh.setFormatter(formatter)
|
||||||
fh.setLevel(logging.INFO)
|
fh.setLevel(logging.DEBUG)
|
||||||
fh.propagate = False
|
fh.propagate = False
|
||||||
|
|
||||||
# Create access log file handler
|
# Create access log file handler
|
||||||
|
|
@ -59,7 +60,7 @@ afh = logging.handlers.RotatingFileHandler(
|
||||||
ACCESS_LOGFILE, maxBytes=1_000_000, backupCount=5
|
ACCESS_LOGFILE, maxBytes=1_000_000, backupCount=5
|
||||||
)
|
)
|
||||||
afh.setFormatter(formatter)
|
afh.setFormatter(formatter)
|
||||||
afh.setLevel(logging.INFO)
|
afh.setLevel(logging.DEBUG)
|
||||||
afh.propagate = False
|
afh.propagate = False
|
||||||
|
|
||||||
# Add file handler to root logger
|
# Add file handler to root logger
|
||||||
|
|
@ -157,10 +158,12 @@ def err_log():
|
||||||
attachment_filename="openflexure_microscope_{}.log".format(timestamp),
|
attachment_filename="openflexure_microscope_{}.log".format(timestamp),
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route('/api/v1/', defaults={'path': ''})
|
|
||||||
@app.route('/api/v1/<path:path>')
|
@app.route("/api/v1/", defaults={"path": ""})
|
||||||
|
@app.route("/api/v1/<path:path>")
|
||||||
def api_v1_catch_all(path):
|
def api_v1_catch_all(path):
|
||||||
abort(410, 'API v1 is no longer in use. Please upgrade your client.')
|
abort(410, "API v1 is no longer in use. Please upgrade your client.")
|
||||||
|
|
||||||
|
|
||||||
# Automatically clean up microscope at exit
|
# Automatically clean up microscope at exit
|
||||||
def cleanup():
|
def cleanup():
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class ExtensibleSerialInstrument(object):
|
||||||
then we don't warn when ports are opened multiple times.
|
then we don't warn when ports are opened multiple times.
|
||||||
"""
|
"""
|
||||||
with self.communications_lock:
|
with self.communications_lock:
|
||||||
|
logging.debug(f"Opening port {port}")
|
||||||
if hasattr(self, "_ser") and self._ser.isOpen():
|
if hasattr(self, "_ser") and self._ser.isOpen():
|
||||||
if not quiet:
|
if not quiet:
|
||||||
logging.warning("Attempted to open an already-open port!")
|
logging.warning("Attempted to open an already-open port!")
|
||||||
|
|
@ -133,9 +134,12 @@ class ExtensibleSerialInstrument(object):
|
||||||
assert (
|
assert (
|
||||||
self._ser.isOpen()
|
self._ser.isOpen()
|
||||||
), "Attempted to write to the serial port before it was opened. Perhaps you need to call the 'open' method first?"
|
), "Attempted to write to the serial port before it was opened. Perhaps you need to call the 'open' method first?"
|
||||||
|
logging.debug("Encoding message...")
|
||||||
data = query_string + self.termination_character
|
data = query_string + self.termination_character
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
logging.debug(f"Writing message: {data}")
|
||||||
self._ser.write(data)
|
self._ser.write(data)
|
||||||
|
logging.debug("Write successful")
|
||||||
|
|
||||||
def flush_input_buffer(self):
|
def flush_input_buffer(self):
|
||||||
"""Make sure there's nothing waiting to be read, and clear the buffer if there is."""
|
"""Make sure there's nothing waiting to be read, and clear the buffer if there is."""
|
||||||
|
|
@ -145,6 +149,7 @@ class ExtensibleSerialInstrument(object):
|
||||||
|
|
||||||
def readline(self, timeout=None):
|
def readline(self, timeout=None):
|
||||||
"""Read one line from the serial port."""
|
"""Read one line from the serial port."""
|
||||||
|
self._ser.timeout = timeout
|
||||||
with self.communications_lock:
|
with self.communications_lock:
|
||||||
return (
|
return (
|
||||||
self._ser.readline()
|
self._ser.readline()
|
||||||
|
|
@ -192,7 +197,9 @@ class ExtensibleSerialInstrument(object):
|
||||||
"""
|
"""
|
||||||
with self.communications_lock:
|
with self.communications_lock:
|
||||||
self.flush_input_buffer()
|
self.flush_input_buffer()
|
||||||
|
logging.debug(f"Writing query: {queryString}")
|
||||||
self.write(queryString)
|
self.write(queryString)
|
||||||
|
logging.debug("Waiting for query response...")
|
||||||
if self.ignore_echo == True: # Needs Implementing for a multiline read!
|
if self.ignore_echo == True: # Needs Implementing for a multiline read!
|
||||||
first_line = self.readline(timeout).strip()
|
first_line = self.readline(timeout).strip()
|
||||||
if first_line == queryString:
|
if first_line == queryString:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue