@@ -97,40 +97,28 @@ def __setattr__(self, name, value):
9797
9898 # read commands ----------------------------------------------------------
9999 def readWord (self , address , commandCode ):
100- buffer = bytearray (2 )
101- self .i2cbus .writeto (address , bytes ([commandCode ]), False )
102- self .i2cbus .readfrom_into (address , buffer )
100+ buffer = self .i2cbus .readfrom_mem (address , commandCode , 2 )
103101 return (buffer [1 ] << 8 ) | buffer [0 ]
104102
105103 def readByte (self , address , commandCode ):
106- buffer = bytearray (1 )
107- self .i2cbus .writeto (address , bytes ([commandCode ]), False )
108- self .i2cbus .readfrom_into (address , buffer )
109- return buffer [0 ]
104+ return self .i2cbus .readfrom_mem (address , commandCode , 1 )[0 ]
110105
111106 def readBlock (self , address , commandCode , nBytes ):
112- buffer = bytearray (nBytes )
113- self .i2cbus .writeto (address , bytes ([commandCode ]), False )
114- self .i2cbus .readfrom_into (address , buffer )
115- return buffer
107+ return self .i2cbus .readfrom_mem (address , commandCode , nBytes )
116108
117109
118110 # write commands----------------------------------------------------------
119111 def writeCommand (self , address , commandCode ):
120- self .i2cbus .writeto (address , bytes ([ commandCode ] ))
112+ self .i2cbus .writeto (address , commandCode . to_bytes ( 1 , 'little' ))
121113
122114 def writeWord (self , address , commandCode , value ):
123- buffer = bytearray (2 )
124- buffer [0 ] = value & 0xFF
125- buffer [1 ] = (value >> 8 ) & 0xFF
126- self .i2cbus .writeto (address , bytes (bytes ([commandCode ]) + buffer ), False )
115+ self .i2cbus .writeto_mem (address , commandCode , value .to_bytes (2 , 'little' ))
127116
128117 def writeByte (self , address , commandCode , value ):
129- self .i2cbus .writeto (address , bytes ([ commandCode , value ] ))
118+ self .i2cbus .writeto_mem (address , commandCode , value . to_bytes ( 1 , 'little' ))
130119
131120 def writeBlock (self , address , commandCode , value ):
132- data = [value ] if not isinstance (value , list ) else value
133- self .i2cbus .writeto (address , bytes (bytes ([commandCode ]) + bytes (data )), False )
121+ self .i2cbus .writeto_mem (address , commandCode , bytes (value ))
134122
135123
136124 # scan -------------------------------------------------------------------
0 commit comments