USB Device Programming class project. This project allows a Python/Tk program running on a PC host to monitor/control a test-CPU programmed into an altera development board.

Dependencies:   C12832_lcd USBDevice mbed-rtos mbed mmSPI

Committer:
gatedClock
Date:
Sun Sep 01 02:58:57 2013 +0000
Revision:
4:92539904a4ad
Child:
8:db29cce17a33
add the project Python files.  the tab-formatting needs to be redone.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gatedClock 4:92539904a4ad 1 #!/usr/bin/python -tt # tt: detect mixed space/tab.
gatedClock 4:92539904a4ad 2 #---copyright-----------------------------------#-------------------------------
gatedClock 4:92539904a4ad 3 # licensed for personal and academic use.
gatedClock 4:92539904a4ad 4 # commercial use must be approved by the account-holder of
gatedClock 4:92539904a4ad 5 # gated.clock@gmail.com
gatedClock 4:92539904a4ad 6 #-------imports---------------------------------#-------------------------------
gatedClock 4:92539904a4ad 7 import serial # serial over USB.
gatedClock 4:92539904a4ad 8 #=======class===================================#===============================
gatedClock 4:92539904a4ad 9 if (1):
gatedClock 4:92539904a4ad 10 class mmUSBserial(): # USB class.
gatedClock 4:92539904a4ad 11 #-----------------------------------------------#-------------------------------
gatedClock 4:92539904a4ad 12 # constructor.
gatedClock 4:92539904a4ad 13 def __init__(self, idVendor, idProduct):
gatedClock 4:92539904a4ad 14
gatedClock 4:92539904a4ad 15 self.__idVendor = idVendor # promote to object scope.
gatedClock 4:92539904a4ad 16 self.__idProduct = idProduct # promote to object scope.
gatedClock 4:92539904a4ad 17
gatedClock 4:92539904a4ad 18 openSuccess = 1
gatedClock 4:92539904a4ad 19 self.__serialPort = serial.Serial()
gatedClock 4:92539904a4ad 20 self.__serialPort.baudrate = 9600
gatedClock 4:92539904a4ad 21
gatedClock 4:92539904a4ad 22 for portIndex in range(7, -1, -1):
gatedClock 4:92539904a4ad 23 portString = "/dev/ttyACM" + "{}".format(portIndex)
gatedClock 4:92539904a4ad 24 self.__serialPort.port = portString
gatedClock 4:92539904a4ad 25 try:
gatedClock 4:92539904a4ad 26 self.__serialPort.open()
gatedClock 4:92539904a4ad 27 except:
gatedClock 4:92539904a4ad 28 print("failed to open port {}.").format(portString)
gatedClock 4:92539904a4ad 29 openSuccess = 0
gatedClock 4:92539904a4ad 30
gatedClock 4:92539904a4ad 31 if (openSuccess): break
gatedClock 4:92539904a4ad 32 openSuccess = 1
gatedClock 4:92539904a4ad 33
gatedClock 4:92539904a4ad 34 if (openSuccess): print("successfully opened port {}.").format(portString)
gatedClock 4:92539904a4ad 35 else: print("could not open any port.")
gatedClock 4:92539904a4ad 36 #-----------------------------------------------#-------------------------------
gatedClock 4:92539904a4ad 37 def __del__(self): # destructor.
gatedClock 4:92539904a4ad 38 self.__serialPort.close()
gatedClock 4:92539904a4ad 39 print "object destroyed."
gatedClock 4:92539904a4ad 40 #-----------------------------------------------#-------------------------------
gatedClock 4:92539904a4ad 41 def write(self,toWrite): # write a string.
gatedClock 4:92539904a4ad 42 nowWrite = toWrite[:7]
gatedClock 4:92539904a4ad 43 nowWrite = nowWrite + "$"
gatedClock 4:92539904a4ad 44 self.__serialPort.write(nowWrite)
gatedClock 4:92539904a4ad 45 return(nowWrite)
gatedClock 4:92539904a4ad 46 #-----------------------------------------------#-------------------------------
gatedClock 4:92539904a4ad 47 def read(self): # read a string.
gatedClock 4:92539904a4ad 48 gotRead = self.__serialPort.read(8)
gatedClock 4:92539904a4ad 49 return(gotRead)
gatedClock 4:92539904a4ad 50 #-----------------------------------------------#-------------------------------
gatedClock 4:92539904a4ad 51 #===============================================#===============================
gatedClock 4:92539904a4ad 52
gatedClock 4:92539904a4ad 53
gatedClock 4:92539904a4ad 54
gatedClock 4:92539904a4ad 55
gatedClock 4:92539904a4ad 56
gatedClock 4:92539904a4ad 57
gatedClock 4:92539904a4ad 58
gatedClock 4:92539904a4ad 59
gatedClock 4:92539904a4ad 60
gatedClock 4:92539904a4ad 61