#! /usr/env/python #-------------------------------------------------------------------------------- """ Application: Dialog_Rio for DAQ_96_Gui Register IO Dialog for the Graphical User Interface to the DAQ_96 Control Program """ #-------------------------------------------------------------------------------- # This includes the member function: # # Rio_ProbeCrateSlots ( MasterNum, SlaveNum, PopResult = "Yes" ) # # This function probes all slots in a given crate and returns an array # showing which slots were found to have an ADF-2 Card plugged in. # By default this function will pop a result window with a list # of all slots and whether each is populated. # Pass argument PopResult = "No" (or =0) to skip the pop up window. # # Note: Slot #0 is not a real physical slot, but is still probed to # verify that the geographic addressing is working correctly. # # Created : 09-Jun-2005 #------------------------------------------------------------------------ # Can be used with DAQ_96_Gui command files. # # usage example: # # from Misc_Constants import SlotNumMax # from Site_Dependent import BitStreamDir, T7_FirmwareName # # SlotHasAdf = ProbeCrateSlots ( MasterNum = MasterNum, # SlaveNum = SlaveNum ) # # for SlotNum in range(SlotNumMax+1) : # i.e. slots 0,1,2,...21 # if ( SlotHasAdf [SlotNum] == "Yes" ) : # Config_Fpga ( MasterNum = MasterNum, # SlaveNum = SlaveNum, # SlotNum = SlotNum, # FpgaMask = 0x3, # 1: fpga#0, 2: fpga#1, 3: both # BitStream = BitStreamDir + T7_FirmwareName ) # #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- import string from Tkinter import * import Pmw from MultiShell import updateComboBox from MultiShell import updateIntVar from Print_Utils import printLine from Misc_Constants import SlotNumMax from Misc_Constants import BcPalProbeReg from Misc_Utils import RegAddrString from Xml_Utils import CreateXmlCommand from Xml_Utils import AppendCommentField from Xml_Utils import RetrieveXmlAttr from Misc_Constants import eOk, eError from tkMessageBox import showinfo #-------------------------------------------------------------------------------- #------------------------------------------------------------------------ class Dialog_Rio : def __init__ ( self, MShell, FrameNum ) : self.MShell = MShell self.RioFrame = FrameNum # printLine ( "Dialog", 'Frame #%d is "%s"' % ( FrameNum, MShell.frameName[FrameNum] ) ) #-------------------------------------------------------------------------------- def createInterface(self): MShell = self.MShell MShell.addFieldLabel ( nFrame = self.RioFrame, labelName = 'Access: Register IO to ADF Cards', column = 1, columnspan = 4, height = 3, width = 35, row = MShell.nextFieldRow() ) # MShell.addFieldLabel ( nFrame = self.RioFrame, # labelName = "VI Mst/Slv", # column = 1, # row = MShell.nextFieldRow() ) # RioCrateMasterFrame = \ # MShell.addFieldFrame ( nFrame = self.RioFrame, # labelName = "VI Frame for Rio", # column = 2, # columnspan = 3, # row = MShell.currentFieldRow() ) self.RioMasterNum_var = IntVar() self.RioMasterNum_var.set(0) # MShell.addFieldRadioB ( frame = RioCrateMasterFrame, # labelName ="M#0", # value = 0, # variable = self.RioMasterNum_var ) # MShell.addFieldRadioB ( frame = RioCrateMasterFrame, # labelName ="#1", # value = 1, # variable = self.RioMasterNum_var ) self.RioSlaveNum_var = IntVar() self.RioSlaveNum_var.set(0) # MShell.addFieldRadioB ( frame = RioCrateMasterFrame, # labelName ="S#0", # value = 0, # variable = self.RioSlaveNum_var ) # MShell.addFieldRadioB ( frame = RioCrateMasterFrame, # labelName ="#1", # value = 1, # variable = self.RioSlaveNum_var ) # MShell.addFieldRadioB ( frame = RioCrateMasterFrame, # labelName ="#2", # value = 2, # variable = self.RioSlaveNum_var ) # MShell.addFieldRadioB ( frame = RioCrateMasterFrame, # labelName ="#3", # value = 3, # variable = self.RioSlaveNum_var ) self.RioSlotNum_box = \ MShell.addFieldCombo ( nFrame = self.RioFrame, labelName ="Slot Num", helpMessage ="Slot Num", statusMessage="Slot Num", initValue ="0", width = 10 ) MShell.addFieldLabel ( nFrame = self.RioFrame, labelName = "Chip Num", column = 1, row = MShell.nextFieldRow() ) RioChipNumFrame = \ MShell.addFieldFrame ( nFrame = self.RioFrame, labelName = "Chip Num Rio", column = 2, columnspan = 3, row = MShell.currentFieldRow() ) self.RioChipNum_var = IntVar() self.RioChipNum_var.set(0) MShell.addFieldRadioB ( frame = RioChipNumFrame, labelName ="Pal/Fpga#0", value = 0, variable = self.RioChipNum_var) MShell.addFieldRadioB ( frame = RioChipNumFrame, labelName ="Fpga#1", value = 1, variable = self.RioChipNum_var) self.RioRegAddr_box = \ MShell.addFieldCombo ( nFrame = self.RioFrame, labelName ="Reg Addr", helpMessage ="Reg Addr", statusMessage="Reg Addr", initValue ="1", width = 10 ) self.RioDataOut_box = \ MShell.addFieldCombo ( nFrame = self.RioFrame, labelName ="Data Out", helpMessage ="Data Out", statusMessage="Data Out", initValue ="0", width = 10 ) self.RioDataIn_box = \ MShell.addFieldEntry ( nFrame = self.RioFrame, labelName ="Data In", helpMessage ="Data In", statusMessage="Data In", column = 3, row = MShell.currentFieldRow(), initValue ="-", bg = 'gray80', width = 10 ) MShell.addFieldButton ( nFrame = self.RioFrame, labelName = "Write Reg", helpMessage = "Write ADF Register", statusMessage= "Write ADF Register", column = 2, row = MShell.nextFieldRow(), command = self.Rio_Reg_Write, width = 10 ) MShell.addFieldButton ( nFrame = self.RioFrame, labelName ="Read Reg", helpMessage ="Read ADF Register", statusMessage="Read ADF Register", column = 4, row = MShell.currentFieldRow(), command = self.Rio_Reg_Read, width = 10 ) self.RioReply_box = \ MShell.addFieldEntry ( nFrame = self.RioFrame, labelName ="Reply", helpMessage ="Reply", statusMessage="Reply", initValue ="-", bg = 'gray80', columnspan = 4, font = ('Verdana',7), width = 43 ) MShell.addFieldLabel ( nFrame = self.RioFrame, labelName = '---------------------------------------------', column = 1, columnspan = 5, row = MShell.nextFieldRow() ) MShell.addFieldButton ( nFrame = self.RioFrame, labelName = 'Probe Slots', helpMessage = 'Probe All Slots In Crate', statusMessage= 'Probe All Slots In Crate', column = 2, row = MShell.nextFieldRow(), command = self.Rio_ProbeCrateSlots, width = 10 ) MShell.addFieldButton ( nFrame = self.RioFrame, labelName = 'MultiRead...', helpMessage = 'Multiple Register Read Tools', statusMessage= 'Multiple Register Read Tools', column = 3, row = MShell.currentFieldRow(), command = lambda: MShell.selectFrame(MShell.MioFrame), width = 10 ) MShell.addFieldButton ( nFrame = self.RioFrame, labelName = 'Histogram...', helpMessage = 'Register Histogram', statusMessage= 'Register Histogram', column = 4, row = MShell.currentFieldRow(), command = lambda: MShell.selectFrame(MShell.HstFrame), width = 10 ) #-------------------------------------------------------------------------------- def Rio_Reg_Read ( self, MasterNum = None, SlaveNum = None, SlotNum = None, ChipNum = None, RegAddr = None, Comment = None ) : MasterNum_int = updateIntVar ( self.RioMasterNum_var, MasterNum ) SlaveNum_int = updateIntVar ( self.RioSlaveNum_var, SlaveNum ) SlotNum_int = updateComboBox ( self.RioSlotNum_box, SlotNum ) ChipNum_int = updateIntVar ( self.RioChipNum_var, ChipNum ) RegAddr_int = updateComboBox ( self.RioRegAddr_box, RegAddr ) guiCmdName = "Rio_ReadReg" xmlCmdDoc = CreateXmlCommand ( guiCmdName, { "ADF" : { "MASTER": str(MasterNum_int), "SLAVE" : str(SlaveNum_int), "SLOT" : str(SlotNum_int) }, "CHIP" : { "NUM" : str(ChipNum_int) }, "REG" : { "ADDR" : str(RegAddr_int) } } ) AppendCommentField ( xmlCmdDoc, Comment ) guiCmdReply = self.MShell.sendGuiComand ( xmlCmdDoc ) DataIn_str, \ Reply_Status = RetrieveXmlAttr ( CmdReply = guiCmdReply, CmdName = guiCmdName, EltAttrList = [ [ "DATA", "IN", self.RioDataIn_box ] ], ReplyBox = self.RioReply_box ) try : DataIn_int = eval ( DataIn_str ) except : DataIn_int = 0 if ( Reply_Status == eOk ) : printLine ( "Rio_Read", "Read %#06x = %5d %s" % ( DataIn_int, DataIn_int, RegAddrString ( MasterNum_int, SlaveNum_int, SlotNum_int, ChipNum_int, RegAddr_int ) ) ) else : printLine ( "Rio_Read", "*** Error Detected ***" ) return DataIn_int, Reply_Status #-------------------------------------------------------------------------------- def Rio_Reg_Write( self, MasterNum = None, SlaveNum = None, SlotNum = None, ChipNum = None, RegAddr = None, DataOut = None, Comment = None ) : MasterNum_int = updateIntVar ( self.RioMasterNum_var, MasterNum ) SlaveNum_int = updateIntVar ( self.RioSlaveNum_var, SlaveNum ) SlotNum_int = updateComboBox ( self.RioSlotNum_box, SlotNum ) ChipNum_int = updateIntVar ( self.RioChipNum_var, ChipNum ) RegAddr_int = updateComboBox ( self.RioRegAddr_box, RegAddr ) DataOut_int = updateComboBox ( self.RioDataOut_box, DataOut ) printLine ( "Rio_Write", "Write %#06x = %5d %s" % ( DataOut_int, DataOut_int, RegAddrString ( MasterNum_int, SlaveNum_int, SlotNum_int, ChipNum_int, RegAddr_int ) ) ) guiCmdName = "Rio_WriteReg" xmlCmdDoc = CreateXmlCommand ( guiCmdName, { "ADF" : { "MASTER": str(MasterNum_int), "SLAVE" : str(SlaveNum_int), "SLOT" : str(SlotNum_int) }, "CHIP" : { "NUM" : str(ChipNum_int) }, "REG" : { "ADDR" : str(RegAddr_int) }, "DATA" : { "OUT" : str(DataOut_int) } } ) AppendCommentField ( xmlCmdDoc, Comment ) guiCmdReply = self.MShell.sendGuiComand ( xmlCmdDoc ) DataIn_str, \ Reply_Status = RetrieveXmlAttr ( CmdReply = guiCmdReply, CmdName = guiCmdName, EltAttrList = [ [ "DATA", "IN", self.RioDataIn_box ] ], ReplyBox = self.RioReply_box ) try : DataIn_int = eval ( DataIn_str ) except : DataIn_int = 0 if ( Reply_Status == eOk ) : printLine ( "Rio_Write", "Read %#06x = %5d %s" % ( DataIn_int, DataIn_int, RegAddrString ( MasterNum_int, SlaveNum_int, SlotNum_int, ChipNum_int, RegAddr_int ) ) ) else : printLine ( "Rio_Write", "*** Error Detected ***" ) return DataIn_int, Reply_Status #------------------------------------------------------------------------ def Rio_ProbeCrateSlots ( self, MasterNum = None, SlaveNum = None, PopResult = "Yes" ) : MasterNum_int = updateIntVar ( self.RioMasterNum_var, MasterNum ) SlaveNum_int = updateIntVar ( self.RioSlaveNum_var, SlaveNum ) # initialize return value to no card anywhere SlotHasAdf = (SlotNumMax+1) * ["No"] # Address each Slot in turn, and see if we had an IO error for SlotNum in range(SlotNumMax+1) : # i.e. slots 0,1,2,...21 SlotHasAdf [SlotNum] = \ self.Rio_ProbeSlot( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum ) # Show a pop-up window with the summary of which slots are populated if ( PopResult == "Yes" ) : Summary = "" for SlotNum in range(SlotNumMax+1) : # i.e. slots 0,1,2,...21 if ( SlotHasAdf[SlotNum] == "Yes" ) : Summary = Summary + "\nSlot #%02d = Adf" % SlotNum else : Summary = Summary + "\nSlot #%02d = No Adf Card" % SlotNum # force a little window onto the user with the summary showinfo ( "Summary", Summary ) return SlotHasAdf #------------------------------------------------------------------------ def Rio_ProbeSlot ( self, MasterNum = None, SlaveNum = None, SlotNum = None ) : MasterNum_int = updateIntVar ( self.RioMasterNum_var, MasterNum ) SlaveNum_int = updateIntVar ( self.RioSlaveNum_var, SlaveNum ) SlotNum_int = updateComboBox ( self.RioSlotNum_box, SlotNum ) # initialize return value to asuming there is a card SlotHasAdf = "Yes" # read the initial value to restore it later Data_Previous, IO_Status = \ self.Rio_Reg_Read( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum, ChipNum = 0, RegAddr = BcPalProbeReg ) # First try setting LSBit low Data_In, IO_Status = \ self.Rio_Reg_Write( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum, ChipNum = 0, RegAddr = BcPalProbeReg, DataOut = Data_Previous & 0xf0 ) # force the lowest 4 bits to 0x0 # Now explicitely read it back Data_In, IO_Status = \ self.Rio_Reg_Read( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum, ChipNum = 0, RegAddr = BcPalProbeReg ) # and verify the lowest nibble if ( ( Data_In & 0x000f ) != 0x00 ) : SlotHasAdf = "No" else : # now try setting the LSBit high Data_In, IO_Status = \ self.Rio_Reg_Write( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum, ChipNum = 0, RegAddr = BcPalProbeReg, DataOut = Data_Previous | 0x0f ) # force the lowest 4 bits to 0xf # Now explicitely read it back Data_In, IO_Status = \ self.Rio_Reg_Read( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum, ChipNum = 0, RegAddr = BcPalProbeReg ) # and verify the lowest nibble if ( ( Data_In & 0x000f ) != 0x0f ) : SlotHasAdf = "No" # Last: restore the previous control value if ( SlotHasAdf == "Yes" ) : Data_In, IO_Status = \ self.Rio_Reg_Write( MasterNum = MasterNum_int, SlaveNum = SlaveNum_int, SlotNum = SlotNum, ChipNum = 0, RegAddr = BcPalProbeReg, DataOut = Data_Previous ) return SlotHasAdf