This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
en:projects:ucecho_fpga [2011/04/15 12:35] – 84.181.80.212 | en: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; | ||
} | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== 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:// | ||
+ | |||
+ | The Python source code of the host software is: | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | # | ||
+ | # Based on work from http:// | ||
+ | # | ||
+ | # 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 | ||
+ | # | ||
+ | # | ||
+ | # This program is distributed in the hope that it will be useful, but | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # You should have received a copy of the GNU General Public License | ||
+ | # along with this program; if not, see http:// | ||
+ | # | ||
+ | import sys | ||
+ | try: | ||
+ | import usb | ||
+ | except: | ||
+ | print "usb import failed. Install pyusb from http:// | ||
+ | sys.exit() | ||
+ | | ||
+ | |||
+ | if __name__ == ' | ||
+ | |||
+ | #Find Device | ||
+ | dev = usb.core.find(idVendor=0x221A, | ||
+ | |||
+ | if dev is None: | ||
+ | print " | ||
+ | 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 = " | ||
+ | |||
+ | while resp != " | ||
+ | resp = raw_input(" | ||
+ | dev.write(writeEP, | ||
+ | print "Send %d bytes: `%s'" | ||
+ | ret = dev.read(readEP, | ||
+ | retstr = '' | ||
+ | print "Read %d bytes: `%s'" | ||
</ | </ | ||