def startFilm(self, film_settings=None): # Disable live mode check box self.ui.liveModeCheckBox.setEnabled(False) # Pause live view mode (if running) if self.ui.liveModeCheckBox.isChecked(): self.stopCamera() self.stopLiveView() self.filming = True self.film_name = os.path.join(self.parameters.get("film.directory"), str(self.ui.filenameLabel.text())) self.film_name = self.film_name[:-len(self.ui.filetypeComboBox. currentText())] if film_settings is None: film_settings = filmSettings.FilmSettings( self.parameters.get("film.acq_mode"), self.parameters.get("film.frames")) save_film = self.ui.saveMovieCheckBox.isChecked() else: save_film = True self.writer = None self.ui.recordButton.setText("Stop") try: # Film file prep if save_film: self.writer = writers.createFileWriter( self.ui.filetypeComboBox.currentText(), self.film_name, self.parameters, self.camera.getFeedNamesToSave()) self.camera.startFilm(self.writer, film_settings) self.ui.recordButton.setStyleSheet( "QPushButton { color: red }") else: self.camera.startFilm(None, film_settings) self.ui.recordButton.setStyleSheet( "QPushButton { color: orange }") self.film_name = False # Modules. for module in self.modules: module.startFilm(self.film_name, self.ui.autoShuttersCheckBox.isChecked()) except halModule.StartFilmException as error: # Handle any start Film errors error_message = "startFilm() in HAL encountered an error: \n" + str( error) hdebug.logText(error_message) # Handle error returning to Dave. The subsequent call to stopFilm() will handle sending this message if self.tcp_requested_movie: message = self.tcp_message message.setError(True, error_message) # Disable parameters radio buttons. self.parameters_box.startFilm() # go... self.startCamera()
def initCamera(self, pci_card=0): if not self.camera: hdebug.logText("Initializing Andor Camera", False) if (platform.architecture()[0] == "32bit"): path = "c:/Program Files/Andor iXon/Drivers/" driver = "atmcd32d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver, pci_card) return path = "c:/Program Files/Andor Solis/" driver = "atmcd32d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver, pci_card) return else: path = "c:/Program Files/Andor Solis/Drivers/" driver = "atmcd64d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver, pci_card) return path = "c:/Program Files (x86)/Andor Solis/Drivers/" driver = "atmcd64d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver, pci_card) return hdebug.logText("Can't find Andor Camera drivers")
def initCamera(self): if not self.cameras[0]: hdebug.logText(" Initializing Andor Cameras", False) if (platform.architecture()[0] == "32bit"): path = "c:/Program Files/Andor iXon/Drivers/" driver = "atmcd32d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver) return path = "c:/Program Files/Andor Solis/" driver = "atmcd32d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver) return else: path = "c:/Program Files/Andor Solis/Drivers/" driver = "atmcd64d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver) return path = "c:/Program Files (x86)/Andor Solis/Drivers/" driver = "atmcd64d.dll" if os.path.exists(path + driver): self.initCameraHelperFn(path, driver) return print "Can't find Andor Camera drivers"
def dropEvent(self, event): # Initialize filenames variable filenames = [] # Tranfer urls to filenames for url in event.mimeData().urls(): filenames.append(str(url.toLocalFile())) # Sort file names filenames = sorted(filenames) # Identify first type name, firstType = os.path.splitext(filenames[0]) # Check to see if all types are the same sameType = [] for filename in filenames: name, fileType = os.path.splitext(filename) sameType.append(fileType == firstType) # If not, raise an error and abort load if not all(sameType): hdebug.logText(" Loaded mixed file types") QtGui.QMessageBox.information(self, "Too many file types", "") return # Load files if firstType == ".dax": # Load dax files self.loadMovie(filenames) elif firstType == ".msc": # Load mosaics for filename in sorted(filenames): self.loadMosaic(filename) else: hdebug.logText(" " + firstType + " is not recognized") QtGui.QMessageBox.information(self, "File type not recognized", "")
def dropEvent(self, event): if self.filming: return filenames = [] for url in event.mimeData().urls(): #filenames.append(str(url.encodedPath())[1:]) filenames.append(str(url.toLocalFile())) for filename in sorted(filenames): [file_type, error_text] = params.fileType(filename) if (file_type == "parameters"): self.newSettings(filename) elif (file_type == "shutters"): self.newShutters(filename) else: if error_text: hdebug.logText(" " + filename + " is not a valid XML file.") QtGui.QMessageBox.information(self, "XML file parsing error", error_text) else: hdebug.logText(" " + filename + " is of unknown type") QtGui.QMessageBox.information(self, "File type not recognized", "")
def readyRead(self): while self.socket.canReadLine(): message = str(self.socket.readLine())[:-1] if hdebug.getDebug(): hdebug.logText("Got: " + message) # Send an acknowledgement that the command was recieved. self.socket.write(QtCore.QByteArray("Ack\n")) self.socket.flush() # Parse the message to generate the command. message_split = message.split(",") # Get command type. command_type = message_split[0] # Parse command data. i = 0 command_data = [] message_data = message_split[1:] while(i < len(message_data)): m_type = message_data[i] m_value = message_data[i+1] if (m_type == "string"): command_data.append(m_value) elif (m_type == "int"): command_data.append(int(m_value)) elif (m_type == "float"): command_data.append(float(m_value)) else: print "Unknown type:", m_type i += 2 self.commMessage.emit(TCPMessage(command_type, command_data))
def startFilm(self, film_name, run_shutters): # Recording the power. if film_name: self.fp = open(film_name + ".power", "w") frame_base = "frame" for channel in self.channels: frame_base = frame_base + " " + channel.getName() self.fp.write(frame_base + "\n") # Running the shutters. if run_shutters: self.running_shutters = True # Setup channels. for channel in self.channels: channel.setupFilm() try: # Start hardware. for name, instance in self.hardware_modules.iteritems(): if (instance.getStatus() == True): instance.startFilm(self.parameters.get("seconds_per_frame"), self.parameters.get("illumination.shutter_oversampling")) # Start channels. for channel in self.channels: channel.startFilm() except halExceptions.HardwareException as error: error_message = "startFilm in illumination control encountered an error: \n" + str(error) hdebug.logText(error_message) raise halModule.StartFilmException(error_message)
def dropEvent(self, event): # Initialize filenames variable filenames = [] # Tranfer urls to filenames for url in event.mimeData().urls(): filenames.append(str(url.toLocalFile())) # Sort file names filenames = sorted(filenames) # Identify first type name, firstType = os.path.splitext(filenames[0]) # Check to see if all types are the same sameType = [] for filename in filenames: name, fileType = os.path.splitext(filename) sameType.append(fileType == firstType) # If not, raise an error and abort load if not all(sameType): hdebug.logText(" Loaded mixed file types") QtGui.QMessageBox.information(self, "Too many file types", "") return # Load files if (firstType == '.dax'): # Load dax files self.loadMovie(filenames) elif (firstType == '.msc'): # Load mosaics for filename in sorted(filenames): self.loadMosaic(filename) else: hdebug.logText(" " + firstType + " is not recognized") QtGui.QMessageBox.information(self, "File type not recognized", "")
def disconnected(self): if hdebug.getDebug(): hdebug.logText(" TCPControl lost connection. " + str(self.isConnected())) self.socket.disconnectFromHost() self.socket.close() self.socket = None self.commLostConnection.emit()
def sendComplete(self, a_string): if self.isConnected(): hdebug.logText("sendComplete " + a_string) self.socket.write(QtCore.QByteArray("Complete," + a_string + "\n")) self.socket.flush() else: hdebug.logText("sendComplete: not connected")
def newParameters(self, parameters): p = parameters.get("camera1") try: # Set binning. Some cameras might support x_bin != y_bin to # for now we are requiring these to be equal. x_bin = p.get("x_bin") if (x_bin != p.get("y_bin")): raise AssertionError("unequal binning is not supported.") if (x_bin == 1): self.camera.setProperty("AOIBinning", "enum", "1x1") elif (x_bin == 2): self.camera.setProperty("AOIBinning", "enum", "2x2") elif (x_bin == 3): self.camera.setProperty("AOIBinning", "enum", "3x3") elif (x_bin == 4): self.camera.setProperty("AOIBinning", "enum", "4x4") elif (x_bin == 8): self.camera.setProperty("AOIBinning", "enum", "8x8") else: raise andor.AndorException("unsupported bin size " + str(p.get("x_bin"))) # Set ROI location and size. if ((p.get("x_pixels") % x_bin) != 0) or ((p.get("y_pixels") % x_bin) != 0): raise andor.AndorException("image size must be a multiple of the bin size.") self.camera.setProperty("AOIWidth", "int", p.get("x_pixels")/x_bin) self.camera.setProperty("AOIHeight", "int", p.get("y_pixels")/x_bin) self.camera.setProperty("AOILeft", "int", p.get("x_start")) self.camera.setProperty("AOITop", "int", p.get("y_start")) # Set the rest of the camera properties. # # Note: These could overwrite the above. For example, if you # have both "x_start" and "AOILeft" in the parameters # file then "AOILeft" will overwrite "x_start". Trouble # may follow if they are not set to the same value. # for key, value in p.__dict__.iteritems(): if self.camera.hasFeature(key): value_type = str(type(value).__name__) self.camera.setProperty(key, value_type, value) self.got_camera = True except andor.AndorException: hdebug.logText("QCameraThread: Bad camera settings") print traceback.format_exc() self.got_camera = False if not p.has("bytes_per_frame"): p.set("bytes_per_frame", 2 * p.get("x_pixels") * p.get("y_pixels")) # Get the target temperature for the camera. On some # cameras this cannot be set. if not p.has("temperature"): p.set("temperature", self.camera.getProperty("TemperatureControl", "enum")) self.parameters = p
def newParameters(self, parameters): if self.spinning_disk: try: self.spinning_disk.newParameters(parameters) # Pass all parameters except halExceptions.HardwareException as error: error_message = "newParameters error in spinning disk control: \n" + str(error) hdebug.logText(error_message) raise halModule.NewParametersException(error_message)
def stopFilm(self): illuminationHardware.DaqModulation.stopFilm(self) for task in [self.ct_task, self.ao_task, self.do_task]: if task: try: task.stopTask() task.clearTask() except nicontrol.NIException as e: hdebug.logText("stop / clear failed for task " + str(task) + " with " + str(e))
def getPosition(self): if not self.tcp_client.isConnected(): hdebug.logText("getPosition: not connected to HAL.") return message = getPositionMessage() self.messages.append(message) self.sendFirstMessage()
def getSettings(self): if not self.tcp_client.isConnected(): hdebug.logText("getSettings: not connected to HAL.") return self.messages.append(mosaicSettingsMessage()) self.messages.append(objectiveMessage(True)) self.sendFirstMessage()
def toggleSettings(self): self.parameters = self.parameters_box.getCurrentParameters() self.stopCamera() try: self.newParameters() except: hdebug.logText("bad parameters") QtGui.QMessageBox.information(self, "Bad parameters", traceback.format_exc()) self.startCamera()
def sendCommand(self, command): if self.isConnected(): hdebug.logText(" sending: " + command) self.unacknowledged += 1 self.socket.sendCommand(command) self.socket.flush() time.sleep(0.05) else: hdebug.logText(" Not connected?!?")
def position(self): if self.live: try: [self.x, self.y] = map(lambda x: float(x)*self.unit_to_um, self.commWithResp("W X Y").split(" ")[1:3]) except: hdebug.logText(" Warning: Bad position from ASI stage.") return [self.x, self.y, 0.0] else: return [0.0, 0.0, 0.0]
def newParameters(self, parameters): if self.spinning_disk: try: self.spinning_disk.newParameters( parameters) # Pass all parameters except halExceptions.HardwareException as error: error_message = "newParameters error in spinning disk control: \n" + str( error) hdebug.logText(error_message) raise halModule.NewParametersException(error_message)
def setDirectory(self, directory): self.directory = directory if not self.tcp_client.isConnected(): hdebug.logText("setDirectory: not connected to HAL.") return False self.messages.append(directoryMessage(self.directory)) self.sendFirstMessage() return True
def position(self): if self.live: try: [self.x, self.y] = map(lambda x: float(x)*self.unit_to_um, self.commWithResp("?pos")[:-2].split(" ")) except: hdebug.logText(" Warning: Bad position from Marzhauser stage.") return [self.x, self.y, 0.0] else: return [0.0, 0.0, 0.0]
def getPosition(self): if not self.tcp_client.isConnected(): hdebug.logText("getPosition: not connected to HAL.") return if not self.got_settings: self.messages.append(mosaicSettingsMessage()) self.messages.append(objectiveMessage()) self.messages.append(getPositionMessage()) self.sendFirstMessage()
def gotoPosition(self, stagex, stagey): if not self.tcp_client.isConnected(): hdebug.logText("gotoPosition: not connected to HAL.") return if not self.got_settings: self.messages.append(mosaicSettingsMessage()) self.messages.append(objectiveMessage()) self.messages.append(moveStageMessage(stagex, stagey, True)) self.sendFirstMessage()
def startFilm(self, film_settings): try: if (film_settings.acq_mode == "fixed_length"): self.camera.setProperty("CycleMode", "enum", "Fixed") self.camera.setProperty("FrameCount", "int", film_settings.frames_to_take) else: self.camera.setProperty("CycleMode", "enum", "Continuous") except andor.AndorException as error: error_message = "startFilm error in AndorSDK3: \n" + str(error) hdebug.logText(error_message) raise halModule.StartFilmException(error_message)
def newParameters(self, parameters): p = parameters.get("camera1") size_x = (p.get("x_end") - p.get("x_start") + 1)/p.get("x_bin") size_y = (p.get("y_end") - p.get("y_start") + 1)/p.get("y_bin") p.set("x_pixels", size_x) p.set("y_pixels", size_y) try: # Set ROI location and size. self.camera.setPropertyValue("subarray_hpos", p.get("x_start")) self.camera.setPropertyValue("subarray_hsize", p.get("x_pixels")) self.camera.setPropertyValue("subarray_vpos", p.get("y_start")) self.camera.setPropertyValue("subarray_vsize", p.get("y_pixels")) # Set binning. if (p.get("x_bin") != p.get("y_bin")): raise AssertionError("unequal binning is not supported.") if (p.get("x_bin") == 1): self.camera.setPropertyValue("binning", "1x1") elif (p.get("x_bin") == 2): self.camera.setPropertyValue("binning", "2x2") elif (p.get("x_bin") == 4): self.camera.setPropertyValue("binning", "4x4") else: raise AssertionError("unsupported bin size", p.get("x_bin")) # Set the rest of the hamamatsu properties. # # Note: These could overwrite the above. For example, if you # have both "x_start" and "subarray_hpos" in the parameters # file then "subarray_hpos" will overwrite "x_start". Trouble # may follow if they are not set to the same value. # for key in p.getAttrs(): if (key == "binning"): # sigh.. continue if self.camera.isCameraProperty(key): self.camera.setPropertyValue(key, p.get(key)) # Set camera sub-array mode so that it will return the correct frame rate. self.camera.setSubArrayMode() p.set("bytes_per_frame", 2 * p.get("x_pixels") * p.get("y_pixels") / (p.get("x_bin") * p.get("y_bin"))) self.got_camera = True except hcam.DCAMException: hdebug.logText("QCameraThread: Bad camera settings") print traceback.format_exc() self.got_camera = False self.parameters = p
def newSettings(self, parameters_filename): # parse parameters file is_valid_xml = True try: parameters = params.Parameters(parameters_filename, is_HAL = True) except: is_valid_xml = False hdebug.logText("failed to parse parameters file " + parameters_filename) QtGui.QMessageBox.information(self, "Parameter file parsing error", traceback.format_exc()) if is_valid_xml: self.parameters_box.addParameters(parameters)
def toggleSettings(self): self.parameters = self.parameters_box.getCurrentParameters() self.stopCamera() try: self.newParameters() # FIXME: This should not catch all errors. except: hdebug.logText("bad parameters") QtGui.QMessageBox.information(self, "Bad parameters", traceback.format_exc()) self.parameters_box.updateParameters() self.startCamera()
def fitAFunctionLS(data, params, fn): result = params errorfunction = lambda p: numpy.ravel( fn(*p)(*numpy.indices(data.shape)) - data) good = True [result, cov_x, infodict, mesg, success] = scipy.optimize.leastsq(errorfunction, params, full_output=1, maxfev=500) if (success < 1) or (success > 4): hdebug.logText("Fitting problem: " + mesg) #print "Fitting problem:", mesg good = False return [result, good]
def getAcquisitionTimings(self, which_camera): # The camera frame rate seems to be max(exposure time, readout time). # This number may not be good accurate enough for shutter synchronization? exposure_time = self.camera.getPropertyValue("exposure_time")[0] readout_time = self.camera.getPropertyValue("timing_readout_time")[0] if (exposure_time < readout_time): frame_rate = 1.0/readout_time # Print a warning since the user probably does not want this to be true. hdebug.logText("Camera exposure time (" + str(exposure_time) + ") is less than the readout time (" + str(readout_time), True) else: frame_rate = 1.0/exposure_time temp = 1.0/frame_rate return [temp, temp]
def captureStart(self, stagex, stagey): print stagex, stagey if os.path.exists(self.fullname()): os.remove(self.fullname()) if not self.tcp_client.isConnected(): hdebug.logText("captureStart: not connected to HAL.") return False if not self.got_settings: self.messages.append(mosaicSettingsMessage()) self.messages.append(objectiveMessage()) self.messages.append(moveStageMessage(stagex, stagey)) self.messages.append(movieMessage(self.filename)) self.sendFirstMessage()
def handleMessageReceived(self, message): if message.hasError(): hdebug.logText("tcp error: " + message.getErrorMessage()) self.messages = [] self.waiting_for_response = False return # # If the message does not involve taking a movie and there are no more # messages then emit the otherComplete signal. # if (message.getData("is_other") == True) and (len(self.messages) == 0): self.otherComplete.emit() if (message.getType() == "Get Mosaic Settings"): self.got_settings = True #coord.Point.pixels_to_um = message.getResponse("pixels_to_um") i = 1 while message.getResponse("obj" + str(i)) is not None: self.newObjectiveData.emit( message.getResponse("obj" + str(i)).split(",")) i += 1 if (message.getType() == "Get Objective"): if self.curr_objective is None or ( self.curr_objective != message.getResponse("objective")): self.curr_objective = message.getResponse("objective") self.changeObjective.emit(self.curr_objective) if (message.getType() == "Get Stage Position"): a_point = coord.Point(message.getResponse("stage_x"), message.getResponse("stage_y"), "um") self.getPositionComplete.emit(a_point) # # self.loadImage() will emit the captureComplete signal. # if (message.getType() == "Take Movie"): self.loadImage(self.directory + message.getData("name") + ".dax") if (len(self.messages) > 0): self.tcp_client.sendMessage(self.messages.pop(0)) else: self.waiting_for_response = False
def newParameters(self, parameters): # Get the camera parameters p = parameters.get("camera1") # Try setting the parameters try: # Loop over parameters for key in p.getAttrs(): # Check for a difference from the current configuration if not (key in self.parameters.getAttrs()) or not (self.parameters.get(key) == p.get(key)): if self.camera.hasFeature(key): value = p.get(key) value_type = str(type(value).__name__) self.camera.setProperty(key, value_type, value) self.got_camera = True except andor.AndorException as error: self.got_camera = False error_message = "newParameters error in AndorSDK3: \n" + str(error) hdebug.logText(error_message) raise halModule.NewParametersException(error_message) # Get the target temperature for the camera. On some # cameras this cannot be set. p.set("temperature", self.camera.getProperty("TemperatureControl", "enum")) # Update frame size p.set("bytes_per_frame", 2 * p.get("AOIHeight") * p.get("AOIWidth")) # Translate AOI information to values used by other hal modules p.set("x_bin", int(p.get("AOIBinning")[0])) p.set("y_bin", int(p.get("AOIBinning")[0])) p.set("x_start", p.get("AOILeft")) p.set("y_start", p.get("AOITop")) p.set("x_end", p.get("AOILeft") + p.get("AOIWidth") - 1) p.set("y_end", p.get("AOITop") + p.get("AOIHeight") - 1) p.set("x_pixels", p.get("AOIWidth")) p.set("y_pixels", p.get("AOIHeight")) # Record the current camera configuration self.parameters = copy.deepcopy(p)
def newShutters(self, shutters_filename): if self.filming: return new_shutters = False try: for module in self.modules: module.newShutters(shutters_filename) new_shutters = True except: QtGui.QMessageBox.information(self, "Shutter file parsing error", traceback.format_exc()) hdebug.logText("failed to parse shutter file " + shutters_filename) for module in self.modules: module.newShutters(self.old_shutters_file) self.parameters.set("shutters", self.old_shutters_file) if new_shutters: self.parameters.set("shutters", shutters_filename) self.old_shutters_file = shutters_filename self.ui.shuttersText.setText(getFileName(self.parameters.get("shutters"))) params.setDefaultShutter(shutters_filename)
def __init__(self, camera_id, ini_file="uc480_settings.ini"): Handle.__init__(self, camera_id) # Initialize camera. check(uc480.is_InitCamera(ctypes.byref(self), ctypes.wintypes.HWND(0)), "is_InitCamera") #check(uc480.is_SetErrorReport(self, IS_ENABLE_ERR_REP)) # Get some information about the camera. self.info = CameraProperties() check(uc480.is_GetSensorInfo(self, ctypes.byref(self.info)), "is_GetSensorInfo") self.im_width = self.info.nMaxWidth self.im_height = self.info.nMaxHeight # Initialize some general camera settings. if (os.path.exists(ini_file)): self.loadParameters(ini_file) hdebug.logText("uc480 loaded parameters file " + ini_file, to_console=False) else: check(uc480.is_SetColorMode(self, IS_SET_CM_Y8), "is_SetColorMode") check(uc480.is_SetGainBoost(self, IS_SET_GAINBOOST_OFF), "is_SetGainBoost") check(uc480.is_SetGamma(self, 1), "is_SetGamma") check( uc480.is_SetHardwareGain(self, 0, IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER), "is_SetHardwareGain") hdebug.logText("uc480 used default settings.", to_console=False) # Setup capture parameters. self.bitpixel = 8 # This is correct for a BW camera anyway.. self.cur_frame = 0 self.data = False self.id = 0 self.image = False self.running = False self.setBuffers()
def __init__(self, nodes): for node in nodes: if (len(node) == 0): if node.attrib.get("type", False): node_type = node.attrib["type"] if (node_type == "boolean"): if (node.text.lower() == "true"): setattr(self, node.tag, True) else: setattr(self, node.tag, False) elif (node_type == "int"): setattr(self, node.tag, int(node.text)) elif (node_type == "float"): setattr(self, node.tag, float(node.text)) elif (node_type == "rgb"): setattr(self, node.tag, node.text) else: hdebug.logText( "HardwareXMLObject, unrecognized type: " + node_type) else: setattr(self, node.tag, node.text)
def startFilm(self, film_name, run_shutters): # Recording the power. if film_name: self.fp = open(film_name + ".power", "w") frame_base = "frame" for channel in self.channels: frame_base = frame_base + " " + channel.getName() self.fp.write(frame_base + "\n") # Running the shutters. if run_shutters: self.running_shutters = True # Setup channels. for channel in self.channels: channel.setupFilm() try: # Start hardware. for name, instance in self.hardware_modules.iteritems(): # print name # print instance if (instance.getStatus() == True): instance.startFilm( self.parameters.get("seconds_per_frame"), self.parameters.get( "illumination.shutter_oversampling")) # Start channels. for channel in self.channels: channel.startFilm() except halExceptions.HardwareException as error: error_message = "startFilm in illumination control encountered an error: \n" + str( error) hdebug.logText(error_message) raise halModule.StartFilmException(error_message)
def toggleSettings(self): self.parameters = self.parameters_box.getCurrentParameters() # Stop live view if self.ui.liveModeCheckBox.isChecked(): self.stopCamera() self.stopLiveView() # Try setting the parametersc try: self.newParameters() # FIXME: This should not catch all errors. except: hdebug.logText("bad parameters") QtGui.QMessageBox.information(self, "Bad parameters", traceback.format_exc()) self.parameters_box.updateParameters() # Restart live view if self.ui.liveModeCheckBox.isChecked(): self.startCamera() self.startLiveView()
def run(self): while True: # Block here waiting for a connection. [client_sock, client_info] = self.server_sock.accept() # Initialization of a new connection. hdebug.logText("Bluetooth: Connected.") self.mutex.lock() self.client_sock = client_sock connected = True self.connected = True self.images_sent = 0 self.start_time = time.time() # Send initial configuration information. if self.filming: self.messages.append("startfilm") else: self.messages.append("stopfilm") self.mutex.unlock() while connected: # Block here waiting for a string from the paired device. data = self.client_sock.recv(1024) if (len(data) == 0): self.mutex.lock() connect = False self.connected = False self.drag_gain = 1.0 self.messages = [] self.show_camera = True images_per_second = float( self.images_sent) / float(time.time() - self.start_time) hdebug.logText("Bluetooth: Disconnected") hdebug.logText( "Bluetooth: Sent {0:.2f} images per second.".format( images_per_second)) self.mutex.unlock() else: for datum in data.split("<>"): if (len(datum) > 0): self.newData.emit(datum) self.mutex.lock() connected = self.connected self.mutex.unlock()
def newParameters(self, parameters): #self.initCamera() p = parameters self.reversed_shutter = p.get("reversed_shutter") try: hdebug.logText("Setting Read Mode", False) self.camera.setReadMode(4) hdebug.logText("Setting Temperature", False) self.camera.setTemperature(p.get("temperature")) hdebug.logText("Setting Trigger Mode", False) self.camera.setTriggerMode(0) hdebug.logText("Setting ROI and Binning", False) self.camera.setROIAndBinning(p.get("ROI"), p.get("binning")) hdebug.logText("Setting Horizontal Shift Speed", False) self.camera.setHSSpeed(p.get("hsspeed")) hdebug.logText("Setting Vertical Shift Amplitude", False) self.camera.setVSAmplitude(p.get("vsamplitude")) hdebug.logText("Setting Vertical Shift Speed", False) self.camera.setVSSpeed(p.get("vsspeed")) hdebug.logText("Setting EM Gain Mode", False) self.camera.setEMGainMode(p.get("emgainmode")) hdebug.logText("Setting EM Gain", False) self.camera.setEMCCDGain(p.get("emccd_gain")) hdebug.logText("Setting Baseline Clamp", False) self.camera.setBaselineClamp(p.get("baselineclamp")) hdebug.logText("Setting Preamp Gain", False) self.camera.setPreAmpGain(p.get("preampgain")) hdebug.logText("Setting Acquisition Mode", False) self.camera.setACQMode("run_till_abort") hdebug.logText("Setting Frame Transfer Mode", False) self.camera.setFrameTransferMode(p.get("frame_transfer_mode")) hdebug.logText("Setting Exposure Time", False) self.camera.setExposureTime(p.get("exposure_time")) hdebug.logText("Setting Kinetic Cycle Time", False) self.camera.setKineticCycleTime(p.get("kinetic_cycle_time")) hdebug.logText("Setting ADChannel", False) self.camera.setADChannel(p.get("adchannel")) p.head_model = self.camera.getHeadModel() hdebug.logText("Camera Initialized", False) self.got_camera = True except: hdebug.logText("andorCameraControl: Bad camera settings") print traceback.format_exc() self.got_camera = False self.newFilmSettings(parameters, None) self.parameters = parameters
def newParameters(self, parameters): p = parameters.get("camera1") size_x = (p.get("x_end") - p.get("x_start") + 1)/p.get("x_bin") size_y = (p.get("y_end") - p.get("y_start") + 1)/p.get("y_bin") p.set("x_pixels", size_x) p.set("y_pixels", size_y) self.reversed_shutter = p.get("reversed_shutter") try: self.camera.setACQMode("run_till_abort") hdebug.logText("Setting Read Mode", False) self.camera.setReadMode(4) hdebug.logText("Setting Temperature", False) self.camera.setTemperature(p.get("temperature")) hdebug.logText("Setting Trigger Mode", False) self.camera.setTriggerMode(0) hdebug.logText("Setting ROI and Binning", False) cam_roi = [p.get("x_start"), p.get("x_end"), p.get("y_start"), p.get("y_end")] cam_binning = [p.get("x_bin"), p.get("y_bin")] if p.get("isolated_cropmode", False): self.camera.setIsolatedCropMode(True, cam_roi[3] - cam_roi[2], cam_roi[1] - cam_roi[0], cam_binning[1], cam_binning[0]) else: self.camera.setIsolatedCropMode(False, cam_roi[3] - cam_roi[2], cam_roi[1] - cam_roi[0], cam_binning[1], cam_binning[0]) self.camera.setROIAndBinning(cam_roi, cam_binning) hdebug.logText("Setting Horizontal Shift Speed", False) p.set("hsspeed", self.camera.setHSSpeed(p.get("hsspeed"))) hdebug.logText("Setting Vertical Shift Amplitude", False) self.camera.setVSAmplitude(p.get("vsamplitude")) hdebug.logText("Setting Vertical Shift Speed", False) p.set("vsspeed", self.camera.setVSSpeed(p.get("vsspeed"))) hdebug.logText("Setting EM Gain Mode", False) self.camera.setEMGainMode(p.get("emgainmode")) hdebug.logText("Setting Advanced EM Gain Control", False) self.camera.setEMAdvanced(p.get("emccd_advanced", False)) hdebug.logText("Setting EM Gain", False) self.camera.setEMCCDGain(p.get("emccd_gain")) hdebug.logText("Setting Baseline Clamp", False) self.camera.setBaselineClamp(p.get("baselineclamp")) hdebug.logText("Setting Preamp Gain", False) p.set("preampgain", self.camera.setPreAmpGain(p.get("preampgain"))) hdebug.logText("Setting Acquisition Mode", False) self.camera.setACQMode("run_till_abort") hdebug.logText("Setting Frame Transfer Mode", False) self.camera.setFrameTransferMode(p.get("frame_transfer_mode")) hdebug.logText("Setting Exposure Time", False) self.camera.setExposureTime(p.get("exposure_time")) hdebug.logText("Setting Kinetic Cycle Time", False) self.camera.setKineticCycleTime(p.get("kinetic_cycle_time")) hdebug.logText("Setting ADChannel", False) self.camera.setADChannel(p.get("adchannel")) p.set("head_model", self.camera.getHeadModel()) # Update parameters as necessary based on settings. [gain_low, gain_high] = self.camera.getEMGainRange() prop = p.getp("emccd_gain") prop.setMinimum(gain_low) prop.setMaximum(gain_high) p.set(["em_gain_low", "em_gain_high"], [gain_low, gain_high]) hs_speeds = self.camera.getHSSpeeds()[p.get("adchannel")] prop = p.getp("hsspeed") prop.setAllowed(hs_speeds) hdebug.logText("Camera Initialized", False) self.got_camera = True except: hdebug.logText("andorCameraControl: Bad camera settings") print traceback.format_exc() self.got_camera = False if not p.has("bytes_per_frame"): p.set("bytes_per_frame", 2 * p.get("x_pixels") * p.get("y_pixels") / (p.get("x_bin") * p.get("y_bin"))) self.parameters = p