#NEWLINE# def _open( self , devpath , mode , max_speed , bit_order , bits_per_word , extra_flags ) : #NEWLINE# #INDENT# if ( not isinstance ( devpath , str ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Invalid devpath type, should be string.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( mode , int ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Invalid mode type, should be integer.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not isinstance ( max_speed , int ) ) and ( not isinstance ( max_speed , float ) ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Invalid max_speed type, should be integer or float.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( bit_order , str ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Invalid bit_order type, should be string.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( bits_per_word , int ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Invalid bits_per_word type, should be integer.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( extra_flags , int ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Invalid extra_flags type, should be integer.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( mode not in [ 0 , 1 , 2 , 3 ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid mode, can be 0, 1, 2, 3.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( bit_order . lower ( ) not in [ 'msb' , 'lsb' ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid bit_order, can be "msb" or "lsb".' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( bits_per_word < 0 ) or ( bits_per_word > 255 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid bits_per_word, must be 0-255.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( extra_flags < 0 ) or ( extra_flags > 255 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid extra_flags, must be 0-255.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# self . _fd = os . open ( devpath , os . O_RDWR ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# raise SPIError ( e . errno , ( 'Opening SPI device: ' + e . strerror ) ) #NEWLINE# #UNINDENT# self . _devpath = devpath #NEWLINE# bit_order = bit_order . lower ( ) #NEWLINE# buf = array . array ( 'B' , [ ( ( mode | ( SPI . _SPI_LSB_FIRST if ( bit_order == 'lsb' ) else 0 ) ) | extra_flags ) ] ) #NEWLINE# try : #NEWLINE# #INDENT# fcntl . ioctl ( self . _fd , SPI . _SPI_IOC_WR_MODE , buf , False ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# raise SPIError ( e . errno , ( 'Setting SPI mode: ' + e . strerror ) ) #NEWLINE# #UNINDENT# buf = array . array ( 'I' , [ int ( max_speed ) ] ) #NEWLINE# try : #NEWLINE# #INDENT# fcntl . ioctl ( buf . _fd , SPI . _SPI_IOC_WR_MAX_SPEED_HZ , buf , False ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# raise SPIError ( e . errno , ( 'Setting SPI max speed: ' + e . strerror ) ) #NEWLINE# #UNINDENT# buf = array . array ( 'B' , [ bits_per_word ] ) #NEWLINE# try : #NEWLINE# #INDENT# fcntl . ioctl ( self . _fd , SPI . _SPI_IOC_WR_BITS_PER_WORD , buf , False ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# raise SPIError ( e . errno , ( 'Setting SPI bits per word: ' + e . strerror ) )