def rawSPI(self, Data, AddMsDelay = False, AddHundredUsDelay = False, SPIMode = 'A', NumberOfBytesToWriteRead = 0, ControlCS = False, StateOfActiveCS = False, CSLineNumber = 0):
        """
        Name: U12.rawSPI( Data, AddMsDelay = False, AddHundredUsDelay = False,
                          SPIMode = 'A', NumberOfBytesToWriteRead = 0,
                          ControlCS = False, StateOfActiveCS = False,
                          CSLineNumber = 0)
        
        Args: Data, A list of four bytes to write using SPI
              AddMsDelay, If True, a 1 ms delay is added between each bit
              AddHundredUsDelay, if True, 100us delay is added
              SPIMode, 'A', 'B', 'C', or 'D'
              NumberOfBytesToWriteRead, number of bytes to write and read.
              ControlCS, D0-D7 is automatically controlled as CS. The state and
                         direction of CS is only tested if control is enabled.
              StateOfActiveCS, Active state for CS line.
              CSLineNumber, D line to use as CS if enabled (0-7).
        
        Desc: This function performs SPI communication. See Section 5.14 of the
              User's Guide.
              
        Returns: A dictionary with the following keys,
            DataByte0-3, the first four data bytes read
            ErrorFlags, a BitField representing the error flags.
            
        Example:
        >>> import u12
        >>> d = u12.U12()
        >>> d.rawSPI([1,2,3,4], NumberOfBytesToWriteRead = 4)
        {
         'DataByte3': 4,
         'DataByte2': 3,
         'DataByte1': 2,
         'DataByte0': 1,
         'ErrorFlags':
          <BitField object: [ CSStateTris Error Flag = 0 (0), ... ] >
        }
        
        """
        command = [ 0 ] * 8
        
        if not isinstance(Data, list) or len(Data) > 4:
            raise U12Exception("Data wasn't a list, or was too long.")
        
        NumberOfBytesToWriteRead = NumberOfBytesToWriteRead & 0xff
        
        if NumberOfBytesToWriteRead == 0:
            NumberOfBytesToWriteRead = len(Data)
            
        if NumberOfBytesToWriteRead > 18 or NumberOfBytesToWriteRead < 1:
            raise U12Exception("Can only read/write 1 to 18 bytes at a time.")
        
        Data.reverse()
        command[:len(Data)] = Data
        
        bf = BitField()
        bf.bit7 = int(bool(AddMsDelay))
        bf.bit6 = int(bool(AddHundredUsDelay))
        
        modeIndex = self.SPIModes.index(SPIMode)
        bf[7-modeIndex] = 1
        
        command[4] = int(bf)
        
        # 01100010 (SPI)
        bf2 = BitField()
        bf2.bit6 = 1
        bf2.bit5 = 1
        bf2.bit1 = 1
        
        command[5] = int(bf2)
        command[6] = NumberOfBytesToWriteRead
        
        bf3 = BitField(rawByte = CSLineNumber)
        bf3.bit7 = int(bool(ControlCS))
        bf3.bit6 = int(bool(StateOfActiveCS))
        
        command[7] = int(bf3)
        
        self.write(command)
        results = self.read()
        
        if results[5] != command[5]:
            raise U12Exception(results[5] % "Expected SPI response, got %s instead.")
        
        returnDict = dict()
        returnDict['DataByte3'] = results[0]
        returnDict['DataByte2'] = results[1]
        returnDict['DataByte1'] = results[2]
        returnDict['DataByte0'] = results[3]
        
        bfLabels = ["CSStateTris Error Flag", "SCKTris Error Flag", "MISOTris Error Flag", "MOSITris Error Flag"]
        bf = BitField( rawByte = results[4], labelPrefix = "", labelList = bfLabels )
        
        returnDict["ErrorFlags"] = bf
        
        return returnDict
dataset/ETHPy150Open LabPy/lantz/lantz/drivers/labjack/_internal/u12.py/U12.rawSPI/swapped operands of `%`