As Marco wrote: "To run the single C file USB bulk read program properly, you must provide a source of data to the CY7C68013 FIFO bus, like the Simple dual channel A/D system, otherwise the reading call will time out in one second, you will get a bunch of zeros, and the ninth status number will be something negative instead of 512. "
The Python behavior is
bulkRead error: ('usb_reap: timeout error',)
when un-connected.
Ray
At 12:25 AM 8/5/2009 -0700, you wrote:
I'm looking for a Python example for the FX2 USB chip (I'm using the SerMod-100 board http://www.acquiredevices.com/sermod100.jsp). Does anyone have a simple "hello" script to re-enumerate the chip, and then do control or bulk reads with only Python and libusb?
I've found C code and some Python modules that use the FX2, however I'm now using ActivePython 2.6.2.2 and don't have an appropriate compiler (I haven't found out which they use ?).
I've used pure Python/libusb to work with a Ti ADS1271 kit
http://focus.ti.com/docs/toolsw/folders/print/ads1271evm.html
(Ti's demo developer also liked Python BTW!) and it seem that I should be able with this FX2 as well. The catch is that the chip can re-enumerate and needs to be put in command state to accept the binary string, then stopped and re-enumerated.
http://lea.hamradio.si/~s57uuu/uuusb/simple_prg_rd.c looks like I can base work on it. So that's where I'll start if no one pipes up. There was a thread Wander replied in, but no code snip in it.
So far I've read:
http://lea.hamradio.si/~s57uuu/uuusb/uuusb_software.htm
http://github.com/mulicheng/fx2lib/tree/master
http://allmybrain.com/tag/fx2/
http://volodya-project.sourceforge.net/fx2_programmer.php
http://www.fpgaz.com/usbp/
http://www.triplespark.net/elec/periph/USB-FX2/software/
Ray Schumacher
--
http://mail.python.org/mailman/listinfo/python-list
""" To run the single C file USB bulk read program properly, you must provide a source of data to the CY7C68013 FIFO bus, like the Simple dual channel A/D system, otherwise the reading call will time out in one second, you will get a bunch of zeros, and the ninth status number will be something negative instead of 512. """
import sys
import os
import time
import usb
def PrintDevInfo(dev):
"""Print device information."""
print "Device:", dev.filename
print " Device class:",dev.deviceClass
print " Device sub class:",dev.deviceSubClass
print " Device protocol:",dev.deviceProtocol
print " Max packet size:",dev.maxPacketSize
print " idVendor:",dev.idVendor
print " idProduct:",dev.idProduct
print " Device Version:",dev.deviceVersion
print " Device SerialNumber:",dev.iSerialNumber
for config in dev.configurations:
print " Configuration:", config.value
print " Total length:", config.totalLength
print " selfPowered:", config.selfPowered
print " remoteWakeup:", config.remoteWakeup
print " maxPower:", config.maxPower
for intf in config.interfaces:
print " Interface:",intf[0].interfaceNumber
for alt in intf:
print " Alternate Setting:",alt.alternateSetting
print " Interface class:",alt.interfaceClass
print " Interface sub class:",alt.interfaceSubClass
print " Interface protocol:",alt.interfaceProtocol
for ep in alt.endpoints:
print " Endpoint:",hex(ep.address)
print " Type:",ep.type
print " Max packet size:",ep.maxPacketSize
print " Interval:",ep.interval
firmware = [0x90, 0xE6, 0x0B, 0x74, 0x03, 0xF0, ##REVCTL = 0x03
0x90, 0xE6, 0x04, 0x74, 0x80, 0xF0, ##FIFORESET = 0x80
0x74, 0x08, 0xF0, ##FIFORESET =
0x08
0xE4, 0xF0,
##FIFORESET = 0x00
0x90, 0xE6, 0x01, 0x74, 0xCB, 0xF0, ##IFCONFIG = 0xCB
0x90, 0xE6, 0x1B, 0x74, 0x0D, 0xF0, ##EP8FIFOCFG = 0x0D
#0x90, 0xE6, 0x09, 0x74, 0x10, 0xF0, ##FIFOPINPOLAR = 0x10
TRUST!!!
0x80, 0xFE]
##while (1) {}
reset = 0x01
er = []
endpoint = 8
# find all of the USB busses
busses = usb.busses()
#print busses
# Find one device
rdev = None
for bus in busses:
for dev in bus.devices:
if dev.idVendor == 0x04B4 and dev.idProduct == 0x8613:
rdev = dev
if rdev==None:
print "Could not find a CY7C68013\ndev.idVendor == 0x04B4 and
dev.idProduct == 0x8613"
sys.exit()
else:
dev = rdev
#PrintDevInfo(dev)
endpoint=8
current_handle = dev.open()
requestType = 0x40
request = 0xa0
#buffer = ''.zfill(4096)
value=0
index=0
timeout=1000
er.append(('RESET', current_handle.controlMsg(requestType, request, reset,
value, index, timeout) ))##RESET
time.sleep(0.1)
for i in range(len(firmware)):
#er.append(('ctrlMsg', i, current_handle.controlMsg(0x40, 0xa0,
firmware[i], value=i, index=0)))
er.append(('ctrlMsg', i, len(current_handle.controlMsg(0x40, 0xa0,
firmware[i], value=i, index=0))))
er.append(('UNRESET', current_handle.controlMsg(requestType, request, reset+1,
value, index, timeout))) ##UNRESET
time.sleep(0.1)
# we know that there's one config, one interface, and one endpoint
conf = dev.configurations[0]
er.append(( "confs", len(dev.configurations)))
er.append(conf.interfaces.count(0))#, conf.interfaces.index(1)
iface = conf.interfaces[0][1]
er.append( ("ifaces[0]", len(conf.interfaces[0])))
endpoint = iface.endpoints[1]
er.append(( "endpoints", len(iface.endpoints)))
er.append(( "iin", iface.interfaceNumber))
er.append( current_handle.setConfiguration(conf))
er.append( current_handle.claimInterface(iface))
er.append( current_handle.setAltInterface(iface))
try:
er.append( current_handle.bulkRead(endpoint.address, 512, 1000))
except usb.USBError, e:
print ' bulkRead error: ', e.args
print ' return data:'
for e in er: print ' ', e
PrintDevInfo(dev)
sys.exit()
for i in range(512):
print " %02x " % buffer[i],
current_handle.releaseInterface(0)
dev.close()
print "\n status: ", er[-1]
-- http://mail.python.org/mailman/listinfo/python-list
