print "ReadData OK" # Test ReadDataEx length = 1024 c_data = CreateByteBuffer(length) (ok, bytesRead) = qusb.ReadDataEx(c_data, length, DataFlags.OutOfOrder) if (not ok): print "***ReadDataEx() failed with error: ", str( Error(qusb.LastError())) else: print "ReadDataEx OK" # Test WriteData length = 1024 c_data = CreateByteBuffer(length) (ok, ) = qusb.WriteData(c_data, length) if (not ok): print "***WriteData() failed with error: ", str(Error( qusb.LastError())) else: print "WriteData OK" # Test WriteDataEx length = 1024 c_data = CreateByteBuffer(length) (ok, ) = qusb.WriteDataEx(c_data, length, DataFlags.OutOfOrder) if (not ok): print "***WriteDataEx() failed with error: ", str( Error(qusb.LastError())) else: print "WriteDataEx OK"
qusb = QuickUsb(qusbList[0]) print qusb.Name, qusb.Serial arr = CreateByteBuffer(LEN) totalBytes = 0 stime = time.time() for k in xrange(LOOPS): (ok, bytes) = qusb.ReadData(arr, LEN) if not ok or bytes != LEN: print "ERROR:", qusb.GetLastError(), ", Bytes read:", bytes break totalBytes += bytes etime = time.time() print "Read data rate: ", (totalBytes / (1024 ** 2)) / (etime - stime) totalBytes = 0 stime = time.time() for k in xrange(LOOPS): (ok,) = qusb.WriteData(arr, LEN) if not ok: print "ERROR:", qusb.GetLastError() break totalBytes += LEN etime = time.time() print "Write data rate: ", (totalBytes / (1024 ** 2)) / (etime - stime)
data = 0xAAAA (result, ) = qusb.WritePort(port, data, length) if (result == 0): print "Cannot write %s port A data" % (devName) qusb.Close() sys.exit() data = 0x5555 (result, ) = qusb.WritePort(port, data, length) if (result == 0): print "Cannot write %s port A data" % (devName) qusb.Close() sys.exit() # Write a 4k block of data length = 4096 bulkdata = CreateByteBuffer(length) for i in xrange(length): bulkdata[i] = i % 256 (result, ) = qusb.WriteData(bulkdata, length) if (result == 0): print "Cannot write data to %s" % (devName) qusb.Close() sys.exit() print "QuickUsbWriteData wrote %d bytes to %s" % (length, devName) # Close the port when you're done with it qusb.Close() print "Done"