diff --git a/hardwarelibrary/communication/debugport.py b/hardwarelibrary/communication/debugport.py index b7ebe45f..8839134b 100644 --- a/hardwarelibrary/communication/debugport.py +++ b/hardwarelibrary/communication/debugport.py @@ -59,8 +59,7 @@ def flush(self): self.buffers = [bytearray(),bytearray()] def readData(self, length, endPoint=None): - if endPoint is None: - endPointIndex = 0 + endPointIndex = 0 if endPoint is None else endPoint with self.portLock: time.sleep(self.delay*random.random()) @@ -75,8 +74,7 @@ def readData(self, length, endPoint=None): return data def writeData(self, data, endPoint=None): - if endPoint is None: - endPointIndex = 0 + endPointIndex = 0 if endPoint is None else endPoint with self.portLock: self.inputBuffers[endPointIndex].extend(data) diff --git a/hardwarelibrary/devicemanager.py b/hardwarelibrary/devicemanager.py index 05b3c988..46036ae6 100644 --- a/hardwarelibrary/devicemanager.py +++ b/hardwarelibrary/devicemanager.py @@ -93,7 +93,7 @@ def matchesPhysicalDevice(self, device): return False if self.idVendor != device.idVendor: return False - if re.match(self.serialNumber, device.serialNumber, re.IGNORECASE) is not None: + if re.match(self.serialNumber, device.serialNumber, re.IGNORECASE) is None: return False return True diff --git a/hardwarelibrary/motion/rotationdevice.py b/hardwarelibrary/motion/rotationdevice.py index f7486443..46899568 100644 --- a/hardwarelibrary/motion/rotationdevice.py +++ b/hardwarelibrary/motion/rotationdevice.py @@ -54,7 +54,7 @@ def doMoveTo(self, angle): self._debugOrientation = angle def doMoveBy(self, displacement): - self._debugOrientation += angle + self._debugOrientation += displacement def doHome(self): self._debugOrientation = 0 diff --git a/hardwarelibrary/motion/sutterdevice.py b/hardwarelibrary/motion/sutterdevice.py index 5625bf13..8cb0a47c 100644 --- a/hardwarelibrary/motion/sutterdevice.py +++ b/hardwarelibrary/motion/sutterdevice.py @@ -49,7 +49,7 @@ def doInitializeDevice(self): self.port.open(baudRate=128000, timeout=10) if self.port is None: - raise PhysicalDevice.UnableToInitialize("Cannot allocate port {0}".format(self.portPath)) + raise PhysicalDevice.UnableToInitialize("Cannot allocate port for serial '{0}'".format(self.serialNumber)) self.positionInMicrosteps() diff --git a/hardwarelibrary/physicaldevice.py b/hardwarelibrary/physicaldevice.py index 4fec4c1c..15ad4483 100644 --- a/hardwarelibrary/physicaldevice.py +++ b/hardwarelibrary/physicaldevice.py @@ -1,7 +1,7 @@ from enum import Enum, IntEnum from threading import Thread, RLock -import hardwarelibrary.utils +from hardwarelibrary import utils from hardwarelibrary.notificationcenter import NotificationCenter import typing import time diff --git a/hardwarelibrary/powermeters/powermeterdevice.py b/hardwarelibrary/powermeters/powermeterdevice.py index d118b6a5..5b9208cf 100644 --- a/hardwarelibrary/powermeters/powermeterdevice.py +++ b/hardwarelibrary/powermeters/powermeterdevice.py @@ -28,11 +28,5 @@ def setCalibrationWavelength(self, wavelength): self.doSetCalibrationWavelength(wavelength) self.doGetCalibrationWavelength() - def measureAbsolutePower(self): - self.doGetAbsolutePower() - power = self.absolutePower - NotificationCenter().postNotification(PowerMeterNotification.didMeasure, notifyingObject=self, userInfo=power) - return power - def doGetStatusUserInfo(self): return self.measureAbsolutePower() diff --git a/hardwarelibrary/sources/cobolt.py b/hardwarelibrary/sources/cobolt.py index fa877129..7b6e2255 100644 --- a/hardwarelibrary/sources/cobolt.py +++ b/hardwarelibrary/sources/cobolt.py @@ -6,6 +6,8 @@ import time from threading import Thread, RLock +globalLock = RLock() + class CoboltCantTurnOnWithAutostartOn(Exception): pass @@ -64,13 +66,14 @@ def doInitializeDevice(self): self.doTurnAutostartOn() self.doGetInterlockState() self.doGetPower() - except Exception as error: - if self.port is not None: - if self.port.isOpen: - self.port.close() + except PhysicalDevice.UnableToInitialize: + if self.port is not None and self.port.isOpen: + self.port.close() + raise + except Exception: + if self.port is not None and self.port.isOpen: + self.port.close() raise PhysicalDevice.UnableToInitialize() - except PhysicalDeviceUnableToInitialize as error: - raise error def doShutdownDevice(self): diff --git a/hardwarelibrary/spectrometers/base.py b/hardwarelibrary/spectrometers/base.py index 6ebf95bb..b9429a94 100644 --- a/hardwarelibrary/spectrometers/base.py +++ b/hardwarelibrary/spectrometers/base.py @@ -147,7 +147,7 @@ def showHelp(cls, err=None): speed, etc...). More spectrometers will be supported in the future. Look at the class USB2000 to see what you have to provide to support a new spectrometer (it is not that much work, but you need one to test). -""".format(__file__, ', '.join(Spectrometer.supportedClassNames))) +""".format(__file__, ', '.join(Spectrometer.supportedClassNames()))) # Well, how about that? This does not work in Windows # https://stackoverflow.com/questions/2330245/python-change-text-color-in-shell diff --git a/hardwarelibrary/spectrometers/oceaninsight.py b/hardwarelibrary/spectrometers/oceaninsight.py index b051d94f..7595def4 100644 --- a/hardwarelibrary/spectrometers/oceaninsight.py +++ b/hardwarelibrary/spectrometers/oceaninsight.py @@ -275,7 +275,7 @@ def doInitializeDevice(self): self.epStatus = self.inputEndpoints[self.epStatusIdx] self.flushEndpoints() - self.sendCommand(b'0x01') + self.sendCommand(b'\x01') time.sleep(0.1) self.getCalibration() except Exception as err: