import spidev
import struct

try:

    spi = spidev.SpiDev() # create spi object
    spi.open(0, 1) # open spi port 0, device (CS) 1
    
except IOError:

    print("Invalid SPI port!")
    exit(1)

# f = float, B = unsigned Char (uint8_t equivalent)

size = struct.calcsize('fBB') # change format to suit data being transmitted
print(size)

def main():

	while True:
        try:
		    data = spi.readbytes(size)

		    #struct.unpack(format, bytestring)
		    tup = struct.unpack('fBB', data) # change format to suit data being transmitted
		    print(tup[0])
		    print(tup[1])
		    print(tup[2])
		    
        except KeyboardInterrupt:
	        spi.close()
	
if __name__ == '__main__':
    main ()