Skip to content
6 changes: 2 additions & 4 deletions hardwarelibrary/communication/debugport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/devicemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/motion/rotationdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/motion/sutterdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/physicaldevice.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions hardwarelibrary/powermeters/powermeterdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
15 changes: 9 additions & 6 deletions hardwarelibrary/sources/cobolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import time
from threading import Thread, RLock

globalLock = RLock()

class CoboltCantTurnOnWithAutostartOn(Exception):
pass

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/spectrometers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/spectrometers/oceaninsight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down