Skip to content

Commit

Permalink
UE9: Show a friendlier error when SPIMode is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaberez committed Jan 25, 2016
1 parent 8f87988 commit cc2fbf4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ue9.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,6 @@ def watchdogRead(self):
result = self._writeRead(command, 16, [0xF8, 0x05, 0x09], checksum = False)
return { 'UpdateDAC0onTimeout' : bool(result[7]& 1), 'UpdateDAC1onTimeout' : bool((result[7] >> 1) & 1), 'UpdateDigitalIOAonTimeout' : bool((result[7] >> 3) & 1), 'UpdateDigitalIOBonTimeout' : bool((result[7] >> 4) & 1), 'ResetControlOnTimeout' : bool((result[7] >> 5) & 1), 'ResetCommOnTimeout' : bool((result[7] >> 6) & 1), 'TimeoutPeriod' : struct.unpack('<H', struct.pack("BB", *result[8:10]))[0], 'DIOConfigA' : result[10], 'DIOConfigB' : result[11], 'DAC0' : struct.unpack('<H', struct.pack("BB", *result[12:14]))[0], 'DAC1' : struct.unpack('<H', struct.pack("BB", *result[14:16]))[0] }

SPIModes = { 'A' : 0, 'B' : 1, 'C' : 2, 'D' : 3 }
def spi(self, SPIBytes, AutoCS=True, DisableDirConfig = False, SPIMode = 'A', SPIClockFactor = 0, CSPinNum = 1, CLKPinNum = 0, MISOPinNum = 3, MOSIPinNum = 2, CSPINNum = None):
"""
Name: UE9.spi(SPIBytes, AutoCS=True, DisableDirConfig = False,
Expand Down Expand Up @@ -1335,7 +1334,11 @@ def spi(self, SPIBytes, AutoCS=True, DisableDirConfig = False, SPIMode = 'A', SP
if DisableDirConfig:
command[6] |= (1 << 6)

command[6] |= ( self.SPIModes[SPIMode] & 3 )
spiModes = ('A', 'B', 'C', 'D')
try:
command[6] |= ( spiModes.index(SPIMode) & 3 )
except ValueError:
raise LabJackException("Invalid SPIMode %r, valid modes are: %r" % (SPIMode, spiModes))

command[7] = SPIClockFactor
#command[8] = Reserved
Expand Down

0 comments on commit cc2fbf4

Please sign in to comment.