de     

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
en:projects:ucecho_fpga [2011/04/15 12:35] 84.181.80.212en:projects:ucecho_fpga [2013/01/28 02:29] – Add Python 2.6 Example for UCEcho Host coflynn
Line 377: Line 377:
     return 0;     return 0;
 } }
 +</code>
 +
 +
 +====== Python host software: UCEcho.py ======
 +
 +It is also possible to access the device with other programming languages. In this case the firmware must be loaded using the FWLoader utility included in the SDK. For testing you can run UCEcho.jar first and then run this file. For Python be sure to install [[http://pyusb.sourceforge.net/|PyUSB]].
 +
 +The Python source code of the host software is:
 +
 +<code python>
 +#   ucecho -- uppercase conversion example for ZTEX USB-FPGA Module 1.11c
 +#   Copyright (C) 2013 Colin O'Flynn <coflynn@newae.com>
 +#   Based on work from http://www.ztex.de
 +#
 +#   This program is free software; you can redistribute it and/or modify
 +#   it under the terms of the GNU General Public License version 3 as
 +#   published by the Free Software Foundation.
 +#
 +#   This program is distributed in the hope that it will be useful, but
 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 +#   General Public License for more details.
 +#
 +#   You should have received a copy of the GNU General Public License
 +#   along with this program; if not, see http://www.gnu.org/licenses/.
 +#
 +import sys
 +try:
 +    import usb
 +except:
 +    print "usb import failed. Install pyusb from http://pyusb.sourceforge.net"
 +    sys.exit()
 +    
 +
 +if __name__ == '__main__':               
 +
 +    #Find Device
 +    dev = usb.core.find(idVendor=0x221A, idProduct=0x0100)
 +
 +    if dev is None:
 +        print "Failed to find ZTEX Device, check idVendor & idProduct"
 +        print " You should run UCEcho.jar first, and then without unplugging"
 +        print " USB module run this program to ensure all devices are fully"
 +        print " programmed."
 +        
 +        sys.exit()
 +
 +    # set the active configuration. With no arguments, the first
 +    # configuration will be the active one
 +    dev.set_configuration()
 +
 +    #You can find these from the descriptors - see pyusb doc for an
 +    #example of this. I'm simplifying this because I know exact
 +    #interface & endpoint addresses
 +    writeEP = 0x04
 +    readEP = 0x82
 +    interface = 0
 +
 +    resp = "go"
 +
 +    while resp != "quit":
 +        resp = raw_input("Enter a string or `quit' to exit the program: ")
 +        dev.write(writeEP, resp, interface)
 +        print "Send %d bytes: `%s'"%(len(resp), resp)
 +        ret = dev.read(readEP, len(resp), interface, 100)
 +        retstr = ''.join([chr(x) for x in ret])
 +        print "Read %d bytes: `%s'"%(len(retstr), retstr)
 </code> </code>
  
 
 
Recent changes RSS feed Creative Commons License Powered by PHP Debian Driven by DokuWiki
[ZTEX Home] [Imprint] [Privacy policy]