Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    def OnBStartButton(self, event):
        try:
            (ok, modules) = QuickUsb.QuickUsb.FindModules()
        except QuickUsb.QuickUsbException:
            return
        if len(modules) == 0:
            return

        self.bStart.Enable(False)
        self.bStop.Enable(True)

        self.testRead = self.rbRead.GetValue()
        self.testPacketSize = 0

        #self.PerformTest()
        #self.thread = threading.Thread(target=self.PerformTest, name='QuickUsb Throughput Test Thread')
        #self.thread.start()

        self.qusb = QuickUsb.QuickUsb(modules[0])
        print modules
        try:
            (ok, ) = self.qusb.Open()
        except QuickUsb.QuickUsbException:
            self.bStart.Enable(True)
            self.bStop.Enable(False)
            return
        self.fptr = open("/dev/qusb/qusb-0", 'r')
        self.timer1.Start(10, True)
Ejemplo n.º 3
0
import QuickUsb
import sys

# 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'
Ejemplo n.º 4
0

# Find modules
(ok, modules) = QuickUsb.QuickUsb.FindModules()
if (len(modules) == 0):
	print 'No QuickUSB modules'
	sys.exit()

# This is to test if the driver can successfully find all modules two times in a row
(ok, modules) = QuickUsb.QuickUsb.FindModules()
if (len(modules) == 0):
	print 'No QuickUSB modules'
	sys.exit()

# Open QuickUSB module
qusb = QuickUsb.QuickUsb(modules[0])
qusb.Open()


# QuickUsb Base API
print 'QuickUsb Base API'

# This is to test if the Mac can successfully find all modules after an open
# Note: QuickUsbOpen gets and stores a handle to the device. QuickUsbFindModules also
#       gets a handle to the device, but it will close it after it is done. This can
#       cause issues if QuickUsbFindModules closes or invalidates the handle from
#       QuickUsbOpen.
print 'FindModules after Open'
(ok, modules) = QuickUsb.QuickUsb.FindModules()
if (len(modules) == 0):
	print 'No QuickUSB modules'
Ejemplo n.º 5
0
import sys
import time
from QuickUsb import *

LEN = int(sys.argv[1])

(ok, qusbList) = QuickUsb.FindModules()

if len(qusbList) == 0:
    print "Cannot find any modules"

qusb = QuickUsb(qusbList[0])
print qusb.Name, qusb.Serial

#qusb.SetTimeout(10000)

arr = CreateByteBuffer(LEN)
stime = time.time()
(ok, bytes) = qusb.ReadData(arr, LEN)
etime = time.time()

print(ok, bytes)
if not ok:
    print "Read failed: ", qusb.LastError()
else:
    print "Data Rate: ", (bytes / (1024.0 * 1024.0)) / (etime - stime), "MB/s"

    if len(sys.argv) > 2 and sys.argv[2] == "show":
        print arr[:]
Ejemplo n.º 6
0
import sys
import time
from QuickUsb import *

LEN = 256 * 1024
LOOPS = 50

(ok, qusbList) = QuickUsb.FindModules()

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:
Ejemplo n.º 7
0
        "epcs"
    )  #("base", "data", "streaming", "fpga", "epcs", "rs232", "i2c", "storage", "command", "spi", "firmware", "stat")
else:
    test = sys.argv[1:]

if "base" in test:
    # Test FindModules
    (ok, nameList) = QuickUsb.FindModules()
    if (not ok):
        print "***FindModules() failed with error: ", str(
            Error(QuickUsb.GetLastError()))
        sys.exit(1)
    else:
        print "FindModules OK"

    qusb = QuickUsb(nameList[0])

    # Test Open
    (ok, ) = qusb.Open()
    if (not ok):
        print "***Open() failed with error: ", str(
            Error(QuickUsb.GetLastError()))
    else:
        print "Open OK"

    # Test GetLastError
    if (QuickUsb.GetLastError()):
        print "***GetLastError() failed with error: ", str(
            Error(QuickUsb.GetLastError()))
    else:
        print "GetLastError OK"
Ejemplo n.º 8
0
    def RescanForModules(self):
        """
        Perform a scan of all modules connected to the host and update the
        control with newly added and removed QuickUSB modules
        """
        # Check the ScanOnLoad and ScanEnabled properties and listen to them
        if not self.scanEnabled:
            return False
        if self.loading:
            if not self.scanOnLoad:
                return

        # Find all attached modules
        try:
            (ok, attachedModules) = QuickUsb.FindModules()
        except:
            attachedModules = []

        # Check for lost modules
        arr = self.QuickUsbDict.keys()
        for k in xrange(len(arr)):
            devName = arr[k]

            if self.QuickUsbDict[
                    devName].attached and not devName in attachedModules:
                # Hold a reference to the QuickUSB module
                qusb = self.QuickUsbDict[devName].qusb

                # Remove the module from the listview
                self.DeleteItem(self.FindItem(0, devName))

                # Remove the module from our list
                del self.QuickUsbDict[devName]

                # Send the ModuleDisconnected event
                event = QuickUsbDisconnectedEvent(ModuleName=devName)
                event.SetEventObject(self)
                event.SetId(self.GetId())
                wx.PostEvent(self, event)

                self.AutoResizeByContentAndHeader()

        # Check for new modules
        arr = self.QuickUsbDict.keys()
        alreadyAdded = False
        for devName in attachedModules:
            if devName not in arr:
                # Create a new qusbListInfo item
                listInfo = qusbListInfo()
                listInfo.attached = True
                listInfo.qusb = QuickUsb(devName)
                listInfo.lvi = wx.ListItem()
                listInfo.lvi.SetText(devName)

                # Add the new QuickUSB to the list and listview
                if not alreadyAdded:
                    self.InsertItem(listInfo.lvi)
                    itemId = self.FindItem(0, devName)
                    (ok, Model) = listInfo.qusb.Model
                    (ok, Serial) = listInfo.qusb.Serial
                    (ok, major, minor,
                     rev) = listInfo.qusb.GetFirmwareVersion()
                    self.SetStringItem(itemId, 1, Serial)
                    self.SetStringItem(itemId, 2,
                                       "%i.%i.%i" % (major, minor, rev))
                    self.SetStringItem(itemId, 3, Model)
                    self.QuickUsbDict[devName] = listInfo

                # Send the ModuleConnected event
                event = QuickUsbConnectedEvent(Module=listInfo.qusb,
                                               ModuleName=devName)
                event.SetEventObject(self)
                event.SetId(self.GetId())
                wx.PostEvent(self, event)

                self.AutoResizeByContentAndHeader()
                if self.GetItemCount() == 1:
                    self.Select(0)
Ejemplo n.º 9
0
(len, modules) = QuickUsb.FindModules()

# Check for no modules and bail if we don't find any
if len == 0:
    print "Couldn't find any modules\n"
    sys.exit()

# Just use the first device in the list because it's easy
devName = modules[0]

# Print out the name of each module found
for x in modules:
    print "Found", x

# Open the first device
qusb = QuickUsb(devName)
qusb.Open()

# Read the Command register at address 0
length = 2
command = CreateByteBuffer(length)
address = 0
(result, bytes) = qusb.ReadCommand(address, command, length)
if (result == 0):
    print "Cannot read %s command register" % (devName)
    qusb.Close()
    sys.exit()
print "ReadCommand address %d = %04x %04x" % (address, command[0], command[1])

# Make all the pins outputs for now
port = 0
Ejemplo n.º 10
0
#		3. Run script with "python fpga_test.py"


import QuickUsb
import sys
import time


# Find modules
(ok, modules) = QuickUsb.QuickUsb.FindModules()
if (len(modules) == 0):
	print 'No QuickUSB modules'
	sys.exit()

# Open QuickUSB module
qusb = QuickUsb.QuickUsb(modules[0])
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
Ejemplo n.º 11
0
import QuickUsb
import time
#import sys
#if len(sys.argv) > 1 and sys.argv[1] == 'write':


q = QuickUsb.QuickUsb("QUSB-0")
q.Open()


print 'Loop back test'

# Check if FPGA is configured
print '\tIsFPGAConfigured - Working'
(ok, r) = q.IsFpgaConfigured()
print '\t\tConfigured:',r

if r == 0:
	# Set port and FPGA settings
	print '\tStartFPGAConfiguration - Working'
	q.WriteSetting(QuickUsb.Setting.PortA,0x8080) # Set port A bit 7 to output high to turn on FPGA power
	(ok, r) = q.ReadSetting(QuickUsb.Setting.PortA)
	print '\t\tPort A setting:',hex(r)
	mask = 0xFE
	(ok, fpga_type) = q.ReadSetting(QuickUsb.Setting.FpgaType)
	q.WriteSetting(QuickUsb.Setting.FpgaType,fpga_type&mask) # Set FPGA type to Altera Passive Serial
	(ok, fpga_type) = q.ReadSetting(QuickUsb.Setting.FpgaType)
	print '\t\tFpga type:',fpga_type
	
	# Wait for the FPGA to power up
	time.sleep(0.5)
Ejemplo n.º 12
0
    print '\tvalue: Packet size'
    sys.exit()


# No exceptions
QuickUsb.QuickUsb.SetThrowExceptions(True);


# Find modules
(ok, modules) = QuickUsb.QuickUsb.FindModules()
if (len(modules) == 0):
	print 'No QuickUSB modules'
	sys.exit()

# Open QuickUSB module
qusb = QuickUsb.QuickUsb(modules[0])
qusb.Open()


# HSPP
print 'High-Speed Parallel Port'
print '\tPB[0-7] - FD[7-0]'
print '\tPD[0-7] - FD[15-8]'
print '\tCTL0 - CMD_DATA'
print '\tCTL1 - REN'
print '\tCTL2 - WEN'
print '\tCTL3 - nREN'
print '\tCTL4 - nWEN'
print '\tCTL5 - nOE'
print '\tRDY0 - nEMPTY'
print '\tRDY1 - nFULL'
Ejemplo n.º 13
0
import QuickUsb

WORDWIDE = 0

q = QuickUsb.QuickUsb("QUSB-0")
q.Open()


# QuickUsb Base API
print 'QuickUsb Base API'

print '\tGetStringDescriptor - Working'
r = q.GetStringDescriptor(1)
print '\t\tMake:',r
r = q.GetStringDescriptor(2)
print '\t\tModel:',r
r = q.GetStringDescriptor(3)
print '\t\tSerial:',r

print '\tGetDriverVersion - Working'
r = q.GetDriverVersion()
print '\t\tDriver version:',r

print '\tGetDllVersion - Working'
r = q.GetDllVersion()
print '\t\tDll version:',r

print '\tGetFirmwareVersion - Working'
r = q.GetFirmwareVersion()
print '\t\tFirmware version:',r
Ejemplo n.º 14
0
import sys
import time
from QuickUsb import *

LEN = int(sys.argv[1])

(ok, qusbList) = QuickUsb.FindModules()

if len(qusbList) == 0:
    print "Cannot find any modules"

qusb = QuickUsb(qusbList[0])
print qusb.Name, qusb.Serial

#qusb.SetTimeout(10000)

arr = CreateByteBuffer(LEN)
for k in xrange(LEN):
    arr[k] = k
stime = time.time()
(ok, ) = qusb.WriteData(arr, LEN)
etime = time.time()

print(ok, bytes)
if not ok:
    print "Write failed: ", qusb.LastError()
else:
    print "Data Rate: ", (LEN / (1024.0 * 1024.0)) / (etime - stime), "MB/s"

    if len(sys.argv) > 2 and sys.argv[2] == "show":
        print arr[:]
Ejemplo n.º 15
0
(ok, modules) = QuickUsb.FindModules()

# Check for no modules and bail if we don't find any
if (len == 0):
    print "Couldn't find any modules\n"
    sys.exit()

# Just use the first device in the list because it's easy
devName = modules[0]

# Print out the name of each module found
for x in modules:
    print "Found", x

# Open the first device
qusb = QuickUsb(devName)
qusb.Open()

# 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
Ejemplo n.º 16
0
#		1. Navigate in a terminal to the directory with this script.
#		2. Ensure the latest QuickUsb.py is present in the directory.
#		3. Run script with "python gpio_test.py"

import QuickUsb
import sys
import time

# Find modules
(ok, modules) = QuickUsb.QuickUsb.FindModules()
if (len(modules) == 0):
    print 'No QuickUSB modules'
    sys.exit()

# Open QuickUSB module
qusb = QuickUsb.QuickUsb(modules[0])
qusb.Open()

# General-Purpose I/O
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)