Beispiel #1
0
    else:
        print "WriteSpi OK"

    # Test WriteReadSpi
    c_data = CreateByteBuffer(64)
    (ok, ) = qusb.WriteReadSpi(0, c_data, 64)
    if (not ok):
        print "***WriteReadSpi() failed with error: ", str(
            Error(qusb.LastError()))
    else:
        print "WriteReadSpi OK"

if "i2c" in test:
    # Test ReadI2C
    c_data = CreateByteBuffer(64)
    (ok, data) = qusb.ReadI2C(0x60, c_data, 64)
    if (not ok):
        print "***ReadI2C() failed with error: ", str(Error(qusb.LastError()))
    else:
        print "ReadI2C OK"

    # Test CachedWriteI2C
    c_data = CreateByteBuffer(64)
    (ok, ) = qusb.CachedWriteI2C(0x60, c_data, 64)
    if (not ok):
        print "***CachedWriteI2C() failed with error: ", str(
            Error(qusb.LastError()))
    else:
        print "CachedWriteI2C OK"

    # Test WriteI2C
Beispiel #2
0
# Write the starting address (0x0000)
write_len = 2
i2c_write_data = CreateByteBuffer(write_len)
i2c_write_data[0] = 0
i2c_write_data[1] = 0
(result, ) = qusb.WriteI2C(0x51, i2c_write_data, write_len)
if (result == 0):
    print "Cannot write data to %s" % (devName)
    qusb.Close()
    sys.exit()
print "Set starting I2C memory read address to 0x0000"

# Read I2C bytes
read_len = 8
i2c_read_data = CreateByteBuffer(read_len)
(result, num_read) = qusb.ReadI2C(0x51, i2c_read_data, read_len)
if (result == 0):
    print "Cannot read data from %s" % (devName)
    qusb.Close()
    sys.exit()
print "Read {0} bytes of I2C data starting at 0x0000".format(read_len)

for i in xrange(read_len):
    print "addr: {0}, data: {1:02X}".format(i, i2c_read_data[i])

# Close the port when you're done with it
qusb.Close()

print "Done"