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 22:02:19 2013 +0000
Revision:
12:d10f526ca443
Parent:
8:db29cce17a33
cpu add comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gatedClock 8:db29cce17a33 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 8:db29cce17a33 7 import serial # serial over USB.
gatedClock 4:92539904a4ad 8 #=======class===================================#===============================
gatedClock 4:92539904a4ad 9 if (1):
gatedClock 8:db29cce17a33 10 class mmUSBserial(): # USB class.
gatedClock 4:92539904a4ad 11 #-----------------------------------------------#-------------------------------
gatedClock 8:db29cce17a33 12 # constructor.
gatedClock 8:db29cce17a33 13 def __init__(self, idVendor, idProduct):
gatedClock 4:92539904a4ad 14
gatedClock 8:db29cce17a33 15 self.__idVendor = idVendor # promote to object scope.
gatedClock 8:db29cce17a33 16 self.__idProduct = idProduct # promote to object scope.
gatedClock 4:92539904a4ad 17
gatedClock 8:db29cce17a33 18 openSuccess = 1
gatedClock 8:db29cce17a33 19 self.__serialPort = serial.Serial()
gatedClock 8:db29cce17a33 20 self.__serialPort.baudrate = 9600
gatedClock 4:92539904a4ad 21
gatedClock 8:db29cce17a33 22 for portIndex in range(7, -1, -1):
gatedClock 8:db29cce17a33 23 portString = "/dev/ttyACM" + "{}".format(portIndex)
gatedClock 8:db29cce17a33 24 self.__serialPort.port = portString
gatedClock 8:db29cce17a33 25 try:
gatedClock 8:db29cce17a33 26 self.__serialPort.open()
gatedClock 8:db29cce17a33 27 except:
gatedClock 8:db29cce17a33 28 print("failed to open port {}.").format(portString)
gatedClock 8:db29cce17a33 29 openSuccess = 0
gatedClock 4:92539904a4ad 30
gatedClock 8:db29cce17a33 31 if (openSuccess): break
gatedClock 8:db29cce17a33 32 openSuccess = 1
gatedClock 4:92539904a4ad 33
gatedClock 8:db29cce17a33 34 if (openSuccess): print("successfully opened port {}.").format(portString)
gatedClock 8:db29cce17a33 35 else: print("could not open any port.")
gatedClock 4:92539904a4ad 36 #-----------------------------------------------#-------------------------------
gatedClock 8:db29cce17a33 37 def __del__(self): # destructor.
gatedClock 8:db29cce17a33 38 self.__serialPort.close()
gatedClock 8:db29cce17a33 39 print "object destroyed."
gatedClock 4:92539904a4ad 40 #-----------------------------------------------#-------------------------------
gatedClock 8:db29cce17a33 41 def write(self,toWrite): # write a string.
gatedClock 4:92539904a4ad 42 nowWrite = toWrite[:7]
gatedClock 8:db29cce17a33 43 nowWrite = nowWrite + "$"
gatedClock 8:db29cce17a33 44 self.__serialPort.write(nowWrite)
gatedClock 8:db29cce17a33 45 return(nowWrite)
gatedClock 4:92539904a4ad 46 #-----------------------------------------------#-------------------------------
gatedClock 8:db29cce17a33 47 def read(self): # read a string.
gatedClock 8:db29cce17a33 48 gotRead = self.__serialPort.read(8)
gatedClock 8:db29cce17a33 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
gatedClock 8:db29cce17a33 62
gatedClock 8:db29cce17a33 63
gatedClock 8:db29cce17a33 64
gatedClock 8:db29cce17a33 65
gatedClock 8:db29cce17a33 66
gatedClock 8:db29cce17a33 67
gatedClock 8:db29cce17a33 68
gatedClock 8:db29cce17a33 69
gatedClock 8:db29cce17a33 70
gatedClock 8:db29cce17a33 71
gatedClock 8:db29cce17a33 72