def OnTimer1Timer(self, event): dataSize = int(self.scPacketSize.GetValue()) * ( 1024**self.cbPacketSizeUnit.GetSelection()) if self.testPacketSize != dataSize: self.testPacketSize = dataSize self.array = QuickUsb.CreateByteBuffer(self.testPacketSize) #Start Timing transBytes = 0 startTime = self.GetTime() # Perform R/W if self.testRead: try: #(ok, bytesRead) = self.qusb.ReadData(self.array, self.testPacketSize) self.array = fptr.read(self.testPacketSize) bytesRead = len(self.array) except QuickUsb.QuickUsbException: wx.MessageBox( "QuickUsb.ReadData(%d) failed with exception %s!" % (self.testPacketSize, str(QuickUsb.Error(QuickUsb.QuickUsb.GetLastError()))), "QuickUsb Exception", wx.OK, self) return transBytes += bytesRead else: try: #(ok,) = self.qusb.WriteData(self.array, self.testPacketSize) fptr.write(self.array.raw) except QuickUsb.QuickUsbException: wx.MessageBox( "QuickUsb.WriteData(data, %d) failed with exception %s!" % (self.testPacketSize, str(QuickUsb.Error(QuickUsb.QuickUsb.GetLastError()))), "QuickUsb Exception", wx.OK, self) return transBytes += self.testPacketSize # Calculate the throughput stopTime = self.GetTime() duration = stopTime - startTime if duration != 0.0: self.throughput = float(transBytes) / (1024.0 * 1024.0 * duration) msg = "Throughput: %.2f MB/s" % self.throughput print msg # Allow GUI to update self.stThroughput.Label = msg self.gThroughput.Value = min(35, int(self.throughput)) else: self.throughput = 0.0 self.timer1.Start(10, True)
# Find modules (ok, modules) = QuickUsb.QuickUsb.FindModules() if (len == 0): print 'No QuickUSB modules' sys.exit() # Open QuickUSB module qusb = QuickUsb.QuickUsb(modules[0]) qusb.Open() # Read data from file infile = open('data.bin', 'rb') data = infile.read() size = len(data) print 'Write data' wdata = QuickUsb.CreateByteBuffer(size) i = 0 for x in data: wdata[i] = ord(x) i += 1 print wdata[:] print 'Size:', size (ok, ) = qusb.WriteData(wdata, size) # Read data rdata = QuickUsb.CreateByteBuffer(size) (ok, bytes) = qusb.ReadData(rdata, size) print 'Read data' print rdata[:] print 'Bytes read:', bytes
print '\tTXD_1 - Transmit port 1' print '\nThis test sets the baud rate to 4800, writes data to port 0, and reads data from port 1.' print '\tSetRS232BaudRate to 4800' (ok, ) = qusb.SetRS232BaudRate(4800) print '\t\tReturn:', ok print '\tFlushRS232 both ports' (ok, ) = qusb.FlushRS232(0) print '\t\tReturn 0:', ok (ok, ) = qusb.FlushRS232(1) print '\t\tReturn 1:', ok print '\tWriteRS232 to port 0' size = 64 wdata = QuickUsb.CreateByteBuffer(size) for i in xrange(size): wdata[i] = i (ok, ) = qusb.WriteRS232(0, wdata, size) print '\t\tReturn:', ok print '\tGetNumRS232: Number of characters should be 64.' time.sleep(0.2) (ok, numchar) = qusb.GetNumRS232(1) print '\t\tNumber of characters:', numchar if numchar > 0: print '\tReadRS232: Data should be sequential values from 0 to 63' rdata = QuickUsb.CreateByteBuffer(numchar) (ok, bytes) = qusb.ReadRS232(1, rdata, numchar) print '\t\tData:', rdata[:]
# Check if FPGA is configured correctly print '\tIsFPGAConfigured - Working' (ok, r) = q.IsFpgaConfigured() print '\t\tConfigured:',r if r == 1: # Reset FPGA logic print '\tReset FPGA logic' q.WriteSetting(QuickUsb.Setting.PortA,0x8180) # Set port A bit 0 direction as output and value as 0 q.WriteSetting(QuickUsb.Setting.PortA,0x8181) # Set port A bit 0 value as 1 (ok, r) = q.ReadSetting(QuickUsb.Setting.PortA) print '\t\tPort A setting:',hex(r) # Set loop back mode print '\tSet loop back mode' data = QuickUsb.CreateByteBuffer(1) data[0] = 0x00 q.WriteCommand(0,data,1) (ok, r) = q.ReadCommand(0,data,1) print '\t\tCommand:',r # Set fifo configuration and word wide print '\tWriteSetting - Working' (ok, fifo_config) = q.ReadSetting(QuickUsb.Setting.FifoConfig) t = fifo_config&0xFFFE q.WriteSetting(QuickUsb.Setting.FifoConfig,t) fifo_config = q.ReadSetting(QuickUsb.Setting.FifoConfig) print '\t\tFifo configuration:',fifo_config q.WriteSetting(QuickUsb.Setting.WordWide,1) (ok, word_wide) = q.ReadSetting(QuickUsb.Setting.WordWide) print '\t\tWord wide:',word_wide
qusb.Open() # FPGA Configuration print 'FPGA Configuration' print '\nSet wordwide, turn on FPGA power, set to Altera, and configure FPGA' print '\tWordword should read 0x1.' print '\tPort setting should read 0x80-- where -- could vary, but at least bit 7 should be high.' print '\tFPGA type should read 0x0.' print '\n\tStartFPGAConfiguration' (ok,) = qusb.WriteSetting(QuickUsb.Setting.WordWide, 1) (ok, word_wide) = qusb.ReadSetting(QuickUsb.Setting.WordWide) print '\t\tWord wide:', hex(word_wide) (ok,) = qusb.WritePortDir(0, 0x80) # Set port A bit 7 to output portval = QuickUsb.CreateByteBuffer(1) portval[0] = 0x80 (ok,) = qusb.WritePort(0, portval, 1) # Set port A bit 7 to high to turn on FPGA power (ok, porta) = qusb.ReadSetting(QuickUsb.Setting.PortA) print '\t\tPort A setting:', hex(porta) mask = 0xFE (ok, fpga_type) = qusb.ReadSetting(QuickUsb.Setting.FpgaType) (ok,) = qusb.WriteSetting(QuickUsb.Setting.FpgaType, fpga_type & mask) # Set FPGA type to Altera Passive Serial (ok, fpga_type) = qusb.ReadSetting(QuickUsb.Setting.FpgaType) print '\t\tFpga type:', hex(fpga_type) # This delay is needed before starting the configuration time.sleep(0.2) (ok,) = qusb.StartFpgaConfiguration()
print '\tCTL3 - nREN' print '\tCTL4 - nWEN' print '\tCTL5 - nOE' print '\tRDY0 - nEMPTY' print '\tRDY1 - nFULL' # Check if FPGA is configured print '\nIs FPGA Configured' (ok, configured) = qusb.IsFpgaConfigured() print '\tConfigured:', configured if configured == 0: # Turn on FPGA power and reset FPGA logic print 'Reset FPGA logic' print '\tPort A setting should read 0x81-- where -- could vary, but at least bit 7 and 0 should be high.' val = QuickUsb.CreateByteBuffer(1) val = 0x80 (ok,) = qusb.WritePortDir(0, 0x81) # Set port A bit 7 and 0 as outputs (ok,) = qusb.WritePort(0, val, 1) # Set port A bit 7 high and bit 0 low val = 0x81 (ok,) = qusb.WritePort(0, val, 1) # Set port A bit 0 high (ok, r) = qusb.ReadSetting(QuickUsb.Setting.PortA) print '\tPort A setting:', hex(r) # Set wordwide print 'Set word wide' print '\tWord wide should read 0x1.' (ok,) = qusb.WriteSetting(QuickUsb.Setting.WordWide, 1) (ok, word_wide) = qusb.ReadSetting(QuickUsb.Setting.WordWide) print '\tWord wide:', hex(word_wide)
print 'General-Purpose I/O' # If you change the following port number, you must also change the port for ReadSetting. port = 0 print '\nThe following test sets the port directions as output and toggles the port values' print '\tWritePortDir' t = 0xFF (ok, ) = qusb.WritePortDir(port, t) print '\tReadPortDir: The port direction should read 0xff' (ok, portdir) = qusb.ReadPortDir(port) print '\t\tPort direction:', hex(portdir) print '\tWritePort' portval = QuickUsb.CreateByteBuffer(1) portval[0] = 0xAA (ok, ) = qusb.WritePort(port, portval, 1) print '\tReadPort: The port values should read 0xaa' (ok, r) = qusb.ReadPort(port, portval, 1) print '\t\tPort values:', hex(portval[0]) print '\tRead port setting: The port setting should read 0xffaa' (ok, portsetting) = qusb.ReadSetting(QuickUsb.Setting.PortA) print '\t\tPort setting:', hex(portsetting) print '\tWritePort' portval[0] = 0x55 (ok, ) = qusb.WritePort(port, portval, 1)