Skip to content

Commit

Permalink
adding abilitz to select port for esp32cam
Browse files Browse the repository at this point in the history
  • Loading branch information
ranranking committed Jul 17, 2023
1 parent c6cd10a commit 961f0d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions imswitch/imcontrol/controller/controllers/MCTController.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ def takeTimelapseThread(self, tperiod = 1):

image1 = image2.copy()

save values
make sure not to have too large travelrange after last (e.g. initial position + 2*shift))
#save values
#make sure not to have too large travelrange after last (e.g. initial position + 2*shift))

#increase iterator
self.nImagesTaken += 1
Expand Down
12 changes: 11 additions & 1 deletion imswitch/imcontrol/model/interfaces/CameraESP32CamSerial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import io

class CameraESP32CamSerial:
def __init__(self):
def __init__(self, port=None):
super().__init__()
self.__logger = initLogger(self, tryInheritParent=True)

# many to be purged
self.port = port
self.model = "ESP32Camera"
self.shape = (0, 0)

Expand All @@ -39,6 +40,15 @@ def __init__(self):
self.serialdevice = self.connect_to_usb_device()

def connect_to_usb_device(self):
if self.port is not None:
try:
ser = serial.Serial(port.device, baudrate=2000000, timeout=1)
print("Succesfully connected to previously set port")
return ser
except:
pass


ports = serial.tools.list_ports.comports()
for port in ports:
if port.manufacturer == self.manufacturer or port.manufacturer=="Microsoft":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def __init__(self, detectorInfo, name, **_lowLevelManagers):
self._running = False
self._adjustingParameters = False
fullShape = (320,240)
try:
self.port = detectorInfo.managerProperties['port']
except:
self.port = None

# Prepare actions
actions = {}
Expand All @@ -29,7 +33,7 @@ def __init__(self, detectorInfo, name, **_lowLevelManagers):
}
# initialize camera

self._camera = self._getESP32CamObj()
self._camera = self._getESP32CamObj(self.port)

# init super-class
super().__init__(detectorInfo, name, fullShape=fullShape, supportedBinnings=[1],
Expand Down Expand Up @@ -112,11 +116,11 @@ def openPropertiesDialog(self):
self._camera.openPropertiesGUI()


def _getESP32CamObj(self):
def _getESP32CamObj(self, port ):
try:
from imswitch.imcontrol.model.interfaces.CameraESP32CamSerial import CameraESP32CamSerial
self.__logger.debug(f'Trying to initialize ESP32Camera')
camera = CameraESP32CamSerial()
camera = CameraESP32CamSerial(port)
except Exception as e:
self.__logger.warning(f'Failed to initialize PiCamera {e}, loading TIS mocker')
from imswitch.imcontrol.model.interfaces.tiscamera_mock import MockCameraTIS
Expand Down

0 comments on commit 961f0d2

Please sign in to comment.