Skip to content

Commit

Permalink
Added QuickUsbPy3. Converted QuickUsbPy to Python3.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwisesys committed Jul 31, 2021
1 parent 91b3ecb commit e92a705
Show file tree
Hide file tree
Showing 10 changed files with 5,205 additions and 0 deletions.
Binary file removed Software/QuickUsbDiagFx2DevKit/Images/Thumbs.db
Binary file not shown.
Binary file removed Software/QuickUsbDiagFx2DevKit/Thumbs.db
Binary file not shown.
111 changes: 111 additions & 0 deletions Software/QuickUsbPy3/Console.py
@@ -0,0 +1,111 @@
"""============================================================================
Title : Console.py
Description : QuickUSB Console App Sample
Notes : None
History :
Copyright 2012 Bitwise Systems. All rights reserved.
This software contains confidential information and trade secrets of
Bitwise Systems and is protected by United States and international
copyright laws. Use, disclosure, or reproduction is prohibited without
the prior express written permission of Bitwise Systems, except as agreed
in the QuickUSB Plug-In Module license agreement.
Use, duplication or disclosure by the U.S. Government is subject to
restrictions as provided in DFARS 227.7202-1(a) and 227.7202-3(a)
(1998), and FAR 12.212, as applicable. Bitwise Systems, 6489 Calle Real,
Suite E, Goleta, CA 93117.
Bitwise Systems
6489 Calle Real, Suite E
Goleta, CA 93117
Voice: (805) 683-6469
Fax : (805) 683-4833
Web : www.bitwisesys.com
email: support@bitwisesys.com
============================================================================"""


from QuickUsb import *
import sys


print('Hello QuickUSB World!')

# Find the QuickUSB modules in the system
(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()

# 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
dir = 0xFF
(result,) = qusb.WritePortDir(port, dir)
if (result == 0):
print("Cannot write %s port A direction register" % (devName))
qusb.Close()
sys.exit()

# Loop through a pattern
length = 2
data = CreateByteBuffer(length)
port = 0
print("Writing 128 cycles of 0xAAAA, 0x5555 to %s, port A..." % (devName))
for count in range(128):
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 range(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")
81 changes: 81 additions & 0 deletions Software/QuickUsbPy3/I2C_Demo.py
@@ -0,0 +1,81 @@
"""
============================================================================
Title : Console.py
Description : QuickUSB Console App Sample
Notes : None
History :
Copyright 2012 Bitwise Systems. All rights reserved.
This software contains confidential information and trade secrets of
Bitwise Systems and is protected by United States and international
copyright laws. Use, disclosure, or reproduction is prohibited without
the prior express written permission of Bitwise Systems, except as agreed
in the QuickUSB Plug-In Module license agreement.
Use, duplication or disclosure by the U.S. Government is subject to
restrictions as provided in DFARS 227.7202-1(a) and 227.7202-3(a)
(1998), and FAR 12.212, as applicable.
Bitwise Systems
5276 Hollister Ave Suite 304
Santa Barbara, CA 93111
Voice: (805) 683-6469
Fax : (805) 683-4833
Web : www.bitwisesys.com
email: support@bitwisesys.com
============================================================================
"""
from QuickUsb import *
import sys

print('QuickUSB Console I2C Demo')

# Find the QuickUSB modules in the system
(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
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 range(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")

0 comments on commit e92a705

Please sign in to comment.