Exemple #1
0
def set_unique_id(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default):		# Saves the unique ID of the QIE card in crate, slot to IGLOO registers.
	#Arguments:
	## Parse "crate" and "slot"
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe")
	if fe:
		unique_ids = get_unique_id(ts=ts, crate=crate, slot=slot, control_hub=control_hub, port=port)
		if unique_ids:
			cmds = []
			for crate_slot, unique_id in unique_ids.iteritems():
				if unique_id:
					cmds.extend([
						"put HF{0}-{1}-iTop_UniqueID {2} {3}".format(crate_slot[0], crate_slot[1], unique_id[0], unique_id[1]),
						"put HF{0}-{1}-iBot_UniqueID {2} {3}".format(crate_slot[0], crate_slot[1], unique_id[0], unique_id[1])
					])
				else:
					print "ERROR (set_unique_id): The unique ID for the card in FE Crate {0}, Slot {1} could not be fetched. Therefore, it can't be set.".format(crate_slot[0], crate_slot[1])
					return False
			output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port)
			if output:
				return unique_ids
			else:
				return False
		else:
			return False
	else:
		return False
Exemple #2
0
def set_ci(ts=None, crate=None, slot=None, enable=False, control_hub=None, script=False):
	# Parse "crate" and "slot":
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot)
	if fe:
		# Parse enable:
		if enable:
			enable_cmd = 1
		else:
			enable_cmd = 0
		
		# Build command list:
		cmds = []
		for crate, slots in fe.iteritems():
			for slot in slots:
				cmds.extend([
					"put HF{0}-{1}-iTop_CntrReg_CImode 0x{2}".format(crate, slot, enable_cmd),
					"put HF{0}-{1}-iBot_CntrReg_CImode 0x{2}".format(crate, slot, enable_cmd),
				])
		
		# Send commands:
		output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, script=script)
		results = ["ERROR" not in j for j in [i["result"] for i in output]]
		if sum(results) == len(results):
			return output
		else:
			print "ERROR (qie.set_ci): Setting the mode resulted in the following:"
			for thing in output:
				print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
			return False
	else:
		print "ERROR (qie.set_ci): The crate, slot arguments were not good."
		return False
Exemple #3
0
def get_unique_id(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default, script=False):		# Reads the unique ID of a given set of crates and slots.
	# INFO: "get HF1-1-UniqueID # '1 0x5f000000 0x9b46ce70'"
	# Arguments:
	## Parse "crate" and "slot"
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe")
	if fe:
#		cmds = []
		results = {}
		# Get the unique ID for each crate, slot
		for crate, slots in fe.iteritems():
			for slot in slots:
#				cmds=.append("get HF{0}-{1}-UniqueID".format(crate, slot))
				output = ngfec.send_commands(ts=ts, cmds=["get HF{0}-{1}-UniqueID".format(crate, slot)], control_hub=control_hub, port=port, script=script)
				if output:
					crate_slot = (crate, slot)
					result = output[0]["result"]
					if "ERROR" not in result:
						results[crate_slot] = result.split()[1:3]		# The first element doesn't matter.
					else:
						results[crate_slot] = False
				else:
					return False
		return results
	else:
		return False
Exemple #4
0
def set_mode(ts=None, crate=None, slot=None, mode=0, control_hub=None, port=ngfec.port_default, verbose=False):		# 0: normal mode, 1: link test mode A (test mode string), 2: link test mode B (IGLOO register)
	# Parse "crate" and "slot":
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot)
	if fe:
		# Parse "mode":
		if mode == 0:
			n = 0
		elif mode == 1:
			n = 1
		elif mode == 2:
			n = 7
		else:
			print "ERROR (qie.set_mode): I don't understand mode = {0}.".format(mode)
			return False
		
		# Build command list:
		cmds = []
		for crate, slots in fe.iteritems():
			for slot in slots:
				cmds.extend([
					"put HF{0}-{1}-iTop_LinkTestMode 0x{2}".format(crate, slot, n),
					"put HF{0}-{1}-iBot_LinkTestMode 0x{2}".format(crate, slot, n),
					"get HF{0}-{1}-iTop_LinkTestMode".format(crate, slot),
					"get HF{0}-{1}-iBot_LinkTestMode".format(crate, slot),
				])
		
		# Send commands:
		output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port)
		results = ["ERROR" not in j for j in [i["result"] for i in output]]
		if sum(results) == len(results):
			if verbose:
				for thing in output:
					print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
			if uhtr.setup(ts=ts):		# This initializes all uHTRs' links. This is necessary after changing modes.
				return True
			else:
				print "ERROR (qie.set_mode): Reinitializing the uHTR links failed."
				return False
		else:
			print "ERROR (qie.set_mode): Setting the mode resulted in the following:"
			for thing in output:
				print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
			return False
	else:
		print "ERROR (qie.set_mode): The crate, slot arguments were not good."
		return False
Exemple #5
0
def check_unique_id(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default, verbose=False):
	#Arguments:
	## Parse "crate" and "slot"
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe")
	if fe:
		# Get the unique ID values:
		cmds = []
		for fe_crate, fe_slots in fe.iteritems():
			for fe_slot in fe_slots:
				cmds.extend([
					"get HF{0}-{1}-iTop_UniqueID".format(fe_crate, fe_slot),
					"get HF{0}-{1}-iBot_UniqueID".format(fe_crate, fe_slot),
				])
		results = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port)
		
		# Check the unique ID values:
		if results:
			good = []
			values_previous = []
			for i, result in enumerate(results):
				values = [int(j, 16) for j in result["result"].split()]
#				values = [int(j, 16) for j in "0 0xbad".split()]
#				print values
				if len(values) == 2 and 0 not in values:
					if i%2 == 1:
						if values == values_previous:
							good.append(True)
						else:
#							print values, values_previous
							good.append(False)
					else:
						good.append(True)
				else:
					good.append(False)
				values_previous = values
			if sum(good) == len(good) and len(good) > 0:
				if verbose: print "[OK] The unique IDs were all set properly:\n{0}".format(results)
				return True
			else:
				if verbose: print "[!!] The unique IDs were not all set properly:\n{0}".format(results)
				return False
		else:
			return False
	else:
		return False
Exemple #6
0
def set_clk_phase(ts=False, crate=None, slot=None, i_qie=None, phase=0, control_hub=None, port=ngfec.port_default, script=True):
	# Parse "crate" and "slot":
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot)
	if fe:
		# Parse "i_qie":
		i_qie = meta.parse_args_qie(i_qie=i_qie)		# The default is range(1, 25)
		if i_qie:
			# Parse "phase":
			if isinstance(phase, int):
				phase = int(phase)
				if phase not in range(16):
					print "ERROR (qie.set_clk_phase): The clock phase you selected with \"phase\" must be an element of [0, 1, ..., 15]."
					return False
			else:
				print "ERROR (qie.set_clk_phase): The clock phase you selected with \"phase\" must be an integer (between 0 and 15)."
				return False
			
			# Build list of commands:
			cmds = []
			for crate, slots in fe.iteritems():
				for slot in slots:
					for i in i_qie:
						cmds.extend([
							"put HF{0}-{1}-Qie{2}_ck_ph {3}".format(crate, slot, i, phase),
							"get HF{0}-{1}-Qie{2}_ck_ph".format(crate, slot, i),
						])
			
			# Send commands:
			output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port, script=script)
			results = ["ERROR" not in j for j in [i["result"] for i in output]]
			if sum(results) == len(results):
#				for thing in output:
#					print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
				return True
			else:
				print "ERROR (qie.set_clk_phase): Setting QIE clock phase mode resulted in the following:"
				for thing in output:
					print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
				return False
		else:
			print "ERROR (qie.set_clk_phase): The \"i_qie\" argument was not good."
			return False
	else:
		print "ERROR (qie.set_clk_phase): The crate, slot arguments were not good."
		return False
Exemple #7
0
def set_fixed_range(ts=False, crate=None, slot=None, i_qie=None, enable=None, r=None, control_hub=None, port=ngfec.port_default):		# Turn fixed range mode on or off for a given QIE.
	# Parse "crate" and "slot":
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot)
	if fe:
		# Parse "i_qie":
		i_qie = meta.parse_args_qie(i_qie=i_qie)		# The default is range(1, 25)
		if i_qie:
			# Parse "r" and "enable":
			if enable == None:
				if r == None:
					r = 0
					enable = False
				else:
					if isinstance(r, int):
						r = int(r)
						if r in range(4):
							enable = True
						else:
							print "ERROR (qie.set_fixed_range): The range you select with \"r\" must be an element of [0, 1, 2, 3]."
							return False
					else:
						print "ERROR (qie.set_fixed_range): You need to make sure to input an integer value for \"r\"."
						return False
			else:
				enable = bool(enable)
			
			# Build list of commands:
			cmds = []
			for crate, slots in fe.iteritems():
				for slot in slots:
					for i in i_qie:
						if enable:
							cmds.extend([
								"put HF{0}-{1}-QIE{2}_FixRange 1".format(crate, slot, i),
								"put HF{0}-{1}-QIE{2}_RangeSet {3}".format(crate, slot, i, r),
								"get HF{0}-{1}-QIE{2}_FixRange".format(crate, slot, i),
								"get HF{0}-{1}-QIE{2}_RangeSet".format(crate, slot, i),
							])
						else :
							cmds.extend([
								"put HF{0}-{1}-QIE{2}_FixRange 0".format(crate, slot, i),
								"put HF{0}-{1}-QIE{2}_RangeSet 0".format(crate, slot, i),
								"get HF{0}-{1}-QIE{2}_FixRange".format(crate, slot, i),
								"get HF{0}-{1}-QIE{2}_RangeSet".format(crate, slot, i),
							])
			
			# Send commands:
			output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port)
			results = ["ERROR" not in j for j in [i["result"] for i in output]]
			if sum(results) == len(results):
#				for thing in output:
#					print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
				return True
			else:
				print "ERROR (qie.set_fixed_range): Setting fixed-range mode resulted in the following:"
				for thing in output:
					print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
				return False
		else:
			print "ERROR (qie.set_fixed_range): The \"i_qie\" argument was not good."
			return False
	else:
		print "ERROR (qie.set_fixed_range): The crate, slot arguments were not good."
		return False
Exemple #8
0
def set_ped(ts=False, crate=None, slot=None, i_qie=None, dac=None, dac_cid=None, i_cid=set(range(4)), control_hub=None, port=ngfec.port_default):		# Set the pedestal of QIE "i_qie" to DAC value "dac" and CID DAC value of "dac_cid".
	# Parse "crate" and "slot":
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot)
	if fe:
		# Parse "i_qie":
		i_qie = meta.parse_args_qie(i_qie=i_qie)		# The default is range(1, 25)
		if i_qie:
			# Parse "i_cid":
			i_cid_original = i_cid
			if isinstance(i_cid, int):
				i_cid = [i_cid]
			elif not (isinstance(i_cid, list) or isinstance(i_cid, set)):
				print "ERROR (qie.set_ped): You must enter an integer or a list of integers for \"i_cid\". The pedestals have not be changed."
				return False
			i_cid = set(i_cid)
			if not i_cid.issubset(set(range(4))):
				print "ERROR (qie.set_ped): \"i_cid\" can only contain elements of [0, 1, 2, 3], but you tried to set it to {0}. The pedestals have not be changed.".format(i_cid_original)
				return False
		
			# Parse "dac" and "dac_cid":
			if dac == None and dac_cid == None:
				print "WARNING (qie.set_ped): You didn't supply a \"dac\" or \"dac_cid\", so \"dac\" will be set to 6, the default, and \"dac_cid\" will be set to 0, the default, for all \"i_cid\" in {0} and all \"i_qie\" in {1}.".format(i_cid, i_qie)
				dac = 6
				dac_cid = 0
		
			## Parse "dac":
			if dac != None:
				if abs(dac) > 31:
					print "ERROR (qie.set_ped): You must enter a decimal integer for \"dac\" between -31 and 31. You tried to set it to {0}. The pedestals have not been changed.".format(dac)
					return False
				else:
					if dac <= 0:
						dac = abs(dac)
					else:
						dac = dac + 32
					dac_str = "{0:#04x}".format(dac)		# The "#" prints the "0x". The number of digits to pad with 0s must include these "0x", hence "4" instead of "2".
			else:
				dac_str = False
		
			## Parse "dac_cid":
			if dac_cid != None:
				if abs(dac_cid) > 7:
					print "ERROR (qie.set_ped): You must enter a decimal integer for \"dac_cid\" between -7 and 7. You tried to set it to {0}. The pedestals have not been changed.".format(dac_cid)
					return False
				else:
					if dac_cid <= 0:
						dac_cid = abs(dac_cid)
					else:
						dac_cid = dac_cid + 8
					dac_cid_str = "{0:#04x}".format(dac_cid)		# The "#" prints the "0x". The number of digits to pad with 0s must include these "0x", hence "4" instead of "2".
			else:
				dac_cid_str = False
		
			# See where things stand:
			if not dac_str and not dac_cid_str:
				print "ERROR (qie.set_ped): You intended to set pedestals, but it turns out none will be changed."
				return False
			if not fe:
				print "ERROR (qie.set_ped): The crate/slot configuration is all jacked up."
				return False
		
			# Build command list:
			cmds = []
			for crate, slots in fe.iteritems():
				for slot in slots:
					for i in i_qie:
						if dac_str:
							cmds.extend([
								"put HF{0}-{1}-QIE{2}_PedestalDAC {3}".format(crate, slot, i, dac_str),
								"get HF{0}-{1}-QIE{2}_PedestalDAC".format(crate, slot, i),
							])
						if dac_cid_str:
							for j in i_cid:
								cmds.extend([
									"put HF{0}-{1}-QIE{2}_CapID{3}pedestal {4}".format(crate, slot, i, j, dac_cid_str),
									"get HF{0}-{1}-QIE{2}_CapID{3}pedestal".format(crate, slot, i, j),
								])
	
			# Send commands:
			output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port)
			results = ["ERROR" not in j for j in [i["result"] for i in output]]
			if sum(results) == len(results):
		#		for thing in output:
		#			print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
				return True
			else:
				print "ERROR (qie.set_ped): Setting pedestals resulted in the following:"
				for thing in output:
					print "\t{0} -> {1}".format(thing["cmd"], thing["result"])
				return False
		else:
			print "ERROR (qie.set_ped): The \"i_qie\" argument was not good."
			return False
	else:
		print "ERROR (qie.set_ped): The crate, slot arguments were not good."
		return False
Exemple #9
0
def get_status(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default):		# Perform basic checks of the QIE cards:
	# Arguments and variables:
	log =""
	## Parse "crate" and "slot"
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe")
	if fe:
		statuses = {}
		qie_info = get_info(ts=ts, crate=crate, slot=slot, control_hub=control_hub, port=port)
		for crate, slots in fe.iteritems():
			for slot in slots:
				crate_slot = (crate, slot)
				s = status(ts=ts, crate=crate, slot=slot)
				# IGLOO top status:
				s.id_top = qie_info[crate_slot]["id_igloo_top"]
				s.fw_top = [
					qie_info[crate_slot]["fw_igloo_top_major"],
					qie_info[crate_slot]["fw_igloo_top_minor"],
				]
				if sum(s.fw_top) >= 2 and sum([i !="0" for i in s.id_top]) == 2:
					s.status.append(1)
				else:
					s.status.append(0)
				
				# IGLOO bottom status:
				s.id_bot = qie_info[crate_slot]["id_igloo_bot"]
				s.fw_bot = [
					qie_info[crate_slot]["fw_igloo_bot_major"],
					qie_info[crate_slot]["fw_igloo_bot_minor"],
				]
				if sum(s.fw_bot) >= 2 and sum([i !="0" for i in s.id_bot]) == 2:
					s.status.append(1)
				else:
					s.status.append(0)
				
				# Bridge status:
				s.fw_b = [
					qie_info[crate_slot]["fw_bridge_major"],
					qie_info[crate_slot]["fw_bridge_minor"],
					qie_info[crate_slot]["fw_bridge_svn"],
				]
				if sum(s.fw_b) >= 3:
					s.status.append(1)
				else:
					s.status.append(0)
				
		#		# Check QIE resets in the BRIDGE (1) and the IGLOO2s (2):
		#		orbit_temp = []
		#		f_orbit_bridge = f_orbit["bridge"][i_qie]
		#		f_orbit_igloo = f_orbit["igloo"][i_qie]
		#		## (1) Check the BRIDGE:
		#		if (f_orbit_bridge["f"] < 13000 and f_orbit_bridge["f"] > 10000 and f_orbit_bridge["f_e"] < 500):
		#			status["status"].append(1)
		#		else:
		#			status["status"].append(0)
		#		orbit_temp.append([f_orbit_bridge["f"], f_orbit_bridge["f_e"]])
		#		## (2) Check the IGLOO2s:
		#		for i in range(2):
		#			if (f_orbit_igloo["f"][i] < 13000 and f_orbit_igloo["f"][i] > 10000 and f_orbit_igloo["f_e"][i] < 600):
		#				status["status"].append(1)
		#			else:
		#				status["status"].append(0)
		#			orbit_temp.append([f_orbit_igloo["f"][i], f_orbit_igloo["f_e"][i]])
		#		status["orbit"].append(orbit_temp)
				
				s.update()
				statuses[crate_slot] = s
		return statuses
	else:
		return False
Exemple #10
0
def get_info(ts=None, crate=None, slot=None, control_hub=None, port=ngfec.port_default, script=True):
	# Arguments and variables
	output = []
	raw_output = ""
	## Parse crate, slot:
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe")
	if fe:
		# Prepare:
		data = {}
		results = {}
		for crate, slots in fe.iteritems():
			for slot in slots:
				data[(crate, slot)] = []
				## Prepare bridge info:
				data[(crate, slot)].append([
					"fw_bridge_major",
					'get HF{0}-{1}-B_FIRMVERSION_MAJOR'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"fw_bridge_minor",
					'get HF{0}-{1}-B_FIRMVERSION_MINOR'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"fw_bridge_svn",
					'get HF{0}-{1}-B_FIRMVERSION_SVN'.format(crate, slot),
				])
				## Prepare IGLOO info:
				data[(crate, slot)].append([
					"fw_igloo_top_major",
					'get HF{0}-{1}-iTop_FPGA_MAJOR_VERSION'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"fw_igloo_top_minor",
					'get HF{0}-{1}-iTop_FPGA_MINOR_VERSION'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"fw_igloo_bot_major",
					'get HF{0}-{1}-iBot_FPGA_MAJOR_VERSION'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"fw_igloo_bot_minor",
					'get HF{0}-{1}-iBot_FPGA_MINOR_VERSION'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"id_igloo_top",
					'get HF{0}-{1}-iTop_UniqueID'.format(crate, slot),
				])
				data[(crate, slot)].append([
					"id_igloo_bot",
					'get HF{0}-{1}-iBot_UniqueID'.format(crate, slot),
				])
		# Compile list of commands to send:
		cmds = [d[1] for crate_slot, ds in data.iteritems() for d in ds]
#		print cmds
		# Send commands:
		ngfec_out = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port, script=script)
		# Understand results:
		for crate_slot, ds in data.iteritems():
			results[crate_slot] = {}
			for i, d in enumerate(ds):
				key = d[0]
				cmd = d[1]
				for result in ngfec_out:
					if result["cmd"] == cmd:
						if "ERROR" not in result["result"]:
							if "UniqueID" not in cmd:
								results[crate_slot].update({
									key: int(result["result"], 16)
								})
							else:
								results[crate_slot].update({
									key: result["result"].split()
								})
						else:
							results[crate_slot].update({
								key: False
							})
			results[crate_slot]["fws"] = [
				"{0:02d}.{1:02d}".format(results[crate_slot]["fw_igloo_top_major"], results[crate_slot]["fw_igloo_top_minor"]),
				"{0:02d}.{1:02d}".format(results[crate_slot]["fw_igloo_bot_major"], results[crate_slot]["fw_igloo_bot_minor"]),
				"{0:02d}.{1:02d}.{2:04d}".format(results[crate_slot]["fw_bridge_major"], results[crate_slot]["fw_bridge_minor"], results[crate_slot]["fw_bridge_svn"]),
			]
		# Return results:
		return results
	else:
		return False
Exemple #11
0
def setup(ts=None, crate=None, slot=None, i_qie=None, control_hub=None, port=None, verbose=False):
# Set up any number of QIE cards. Specify a group of QIE cards by the crates and slots. If you specify the ts and nothing else, it will set up all of them.
	# Arguments:
	cmds = []
	## Parse "crate" and "slot"
	fe = meta.parse_args_crate_slot(ts=ts, crate=crate, slot=slot, crate_type="fe")
	if fe:
		## Parse "i_qie":
		is_qie = meta.parse_args_qie(i_qie=i_qie)		# The default is range(1, 25)
		if is_qie:
			# Define setup commands:
			for fe_crate, slots in fe.iteritems():
				for fe_slot in slots:
#					print fe_crate, fe_slot
					for i_qie in is_qie:
						## Put all QIE program register values to default:
						cmds.extend([
							"put HF{0}-{1}-QIE{2}_Lvds 0x1".format(fe_crate, fe_slot, i_qie),		# 1 bit
							"put HF{0}-{1}-QIE{2}_Trim 0x2".format(fe_crate, fe_slot, i_qie),		# 2 bits
							"put HF{0}-{1}-QIE{2}_DiscOn 0x0".format(fe_crate, fe_slot, i_qie),		# 1 bit
							"put HF{0}-{1}-QIE{2}_TGain 0x0".format(fe_crate, fe_slot, i_qie),		# 1 bit
							"put HF{0}-{1}-QIE{2}_TimingThresholdDAC 0xff".format(fe_crate, fe_slot, i_qie),		# 8 bits
							"put HF{0}-{1}-QIE{2}_TimingIref 0x0".format(fe_crate, fe_slot, i_qie),		# 3 bits
							"put HF{0}-{1}-QIE{2}_PedestalDAC 0x26".format(fe_crate, fe_slot, i_qie),		# 6 bits
							"put HF{0}-{1}-QIE{2}_CapID0pedestal 0x0".format(fe_crate, fe_slot, i_qie),		# 4 bits
							"put HF{0}-{1}-QIE{2}_CapID1pedestal 0x0".format(fe_crate, fe_slot, i_qie),		# 4 bits
							"put HF{0}-{1}-QIE{2}_CapID2pedestal 0x0".format(fe_crate, fe_slot, i_qie),		# 4 bits
							"put HF{0}-{1}-QIE{2}_CapID3pedestal 0x0".format(fe_crate, fe_slot, i_qie),		# 4 bits
							"put HF{0}-{1}-QIE{2}_FixRange 0x0".format(fe_crate, fe_slot, i_qie),		# 1 bit
							"put HF{0}-{1}-QIE{2}_RangeSet 0x0".format(fe_crate, fe_slot, i_qie),		# 2 bits
							"put HF{0}-{1}-QIE{2}_ChargeInjectDAC 0x0".format(fe_crate, fe_slot, i_qie),		# 3 bits
							"put HF{0}-{1}-QIE{2}_RinSel 0x4".format(fe_crate, fe_slot, i_qie),		# 4 bits
							"put HF{0}-{1}-QIE{2}_Idcset 0x0".format(fe_crate, fe_slot, i_qie),		# 5 bits
							"put HF{0}-{1}-QIE{2}_CalMode 0x0".format(fe_crate, fe_slot, i_qie),		# 1 bit
							"put HF{0}-{1}-QIE{2}_CkOutEn 0x0".format(fe_crate, fe_slot, i_qie),		# 1 bit
							"put HF{0}-{1}-QIE{2}_TDCMode 0x0".format(fe_crate, fe_slot, i_qie),		# 1 bit
						])
						## Other QIE-specific things:
						cmds.extend([
							'put HF{0}-{1}-Qie{2}_ck_ph 0x0'.format(fe_crate, fe_slot, i_qie),		# Set the clock phase to 0.
						])
					## Put all other QIE card values to default values:
					cmds.extend([
						"put HF{0}-{1}-iTop_CntrReg_CImode 0x0".format(fe_crate, fe_slot),
						"put HF{0}-{1}-iBot_CntrReg_CImode 0x0".format(fe_crate, fe_slot),
#						"put HF{0}-{1}-iTop_LinkTestMode 0x0".format(fe_crate, fe_slot),
#						"put HF{0}-{1}-iBot_LinkTestMode 0x0".format(fe_crate, fe_slot),
						"put HF{0}-{1}-iTop_UniqueID 0x0 0x0".format(fe_crate, fe_slot),
						"put HF{0}-{1}-iBot_UniqueID 0x0 0x0".format(fe_crate, fe_slot),
					])
			if verbose: print "\tSetting all QIE chips and cards to default values ..."
			output = ngfec.send_commands(ts=ts, cmds=cmds, control_hub=control_hub, port=port, script=True)
			if output:
				if verbose: print "\tSetting QIE card IDs in the IGLOO registers ..."
				result = set_unique_id(ts=ts, crate=crate, slot=slot, control_hub=control_hub, port=port)
				if result:
					return {
						"output": output,
						"fe": fe,
						"ids": result,
					}
				else:
					if verbose: print "\tERROR (qie.setup): Failed to set up the QIE card IDs."
					return False
			else:
				return False
		else:
			return False
	else:
		return False