コード例 #1
0
def sweepSource(statusMessageQueue, ctrlNs, printQueue, ringBuf):



	from SignalHound import SignalHound

	logSetup.initLogging(printQ = printQueue)
	loop_timer = time.time()
	print "Starting sweep-logger!"
	log = logging.getLogger("Main.AcqProcess")

	loop_timer = time.time()
	seq_num = 0

	sh = SignalHound()
	startAcquisition(sh, statusMessageQueue)


	temperature = sh.getDeviceDiagnostics()["temperature"]

	while ctrlNs.run:
		bufPtr, lock = ringBuf.getAddPointer()
		try:
			sh.fetchRaw_s(ctDataBufPtr=bufPtr)
		except Exception:
			log.error("IOError in Acquisition Thread!")
			log.error(traceback.format_exc())

			statusMessageQueue.put({"status" : (time.time(), "Error: Device interface crashed. Reinitializing")})
			log.error("Resetting hardware!")
			# sh.preset()
			sh.forceClose()
			try:
				while 1:
					log.warning("Freeing python device handle")
					del(sh)
			except UnboundLocalError:
				pass

			log.error("Hardware shut down, completely re-initializing device interface!")
			# sys.exit()
			sh = SignalHound()
			startAcquisition(sh, statusMessageQueue)
		finally:
			lock.release()

		if seq_num % PRINT_LOOP_CNT == 0:
			now = time.time()
			delta = now-loop_timer
			updateInterval = delta / PRINT_LOOP_CNT
			freq = 1 / updateInterval
			log.info("Elapsed Time = %0.5f, Frequency = %s. Items in buffer = %s", delta, freq, ringBuf.getItemsNum())
			loop_timer = now

			# print

		if seq_num % CAL_CHK_LOOP_CNT == 0:
			diags = sh.getDeviceDiagnostics()
			statusMessageQueue.put({"status" : (time.time(), diags)})

			temptmp = diags["temperature"]
			if abs(temperature - temptmp) > 2.0:    # Temperature deviations of > 2° cause IF shifts. Therefore, we do a re-cal if they're detected
				statusMessageQueue.put({"status" : (time.time(), "Recalibrating IF due to temperature change")})
				sh.selfCal()
				startAcquisition(sh, statusMessageQueue)
				log.warning("Temperature changed > 2.0 C. Delta is %f. Recalibrated!", abs(temperature - temptmp))
				temperature = temptmp
			else:
				log.info("Temperature deviation = %f. Not doing recal, since drift < 2C", abs(temperature - temptmp))

		seq_num += 1



	sh.abort()
	sh.closeDevice()

	del(sh)

	ctrlNs.acqRunning = False


	log.info("Acquisition-thread exiting!")