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
Diff: mmPython/mmUSBserial.txt
- Revision:
- 8:db29cce17a33
- Parent:
- 4:92539904a4ad
--- a/mmPython/mmUSBserial.txt Sun Sep 01 03:48:07 2013 +0000 +++ b/mmPython/mmUSBserial.txt Sun Sep 01 03:55:03 2013 +0000 @@ -1,52 +1,52 @@ -#!/usr/bin/python -tt # tt: detect mixed space/tab. +#!/usr/bin/python -tt # tt: detect mixed space/tab. #---copyright-----------------------------------#------------------------------- # licensed for personal and academic use. # commercial use must be approved by the account-holder of # gated.clock@gmail.com #-------imports---------------------------------#------------------------------- -import serial # serial over USB. +import serial # serial over USB. #=======class===================================#=============================== if (1): - class mmUSBserial(): # USB class. + class mmUSBserial(): # USB class. #-----------------------------------------------#------------------------------- - # constructor. - def __init__(self, idVendor, idProduct): + # constructor. + def __init__(self, idVendor, idProduct): - self.__idVendor = idVendor # promote to object scope. - self.__idProduct = idProduct # promote to object scope. + self.__idVendor = idVendor # promote to object scope. + self.__idProduct = idProduct # promote to object scope. - openSuccess = 1 - self.__serialPort = serial.Serial() - self.__serialPort.baudrate = 9600 + openSuccess = 1 + self.__serialPort = serial.Serial() + self.__serialPort.baudrate = 9600 - for portIndex in range(7, -1, -1): - portString = "/dev/ttyACM" + "{}".format(portIndex) - self.__serialPort.port = portString - try: - self.__serialPort.open() - except: - print("failed to open port {}.").format(portString) - openSuccess = 0 + for portIndex in range(7, -1, -1): + portString = "/dev/ttyACM" + "{}".format(portIndex) + self.__serialPort.port = portString + try: + self.__serialPort.open() + except: + print("failed to open port {}.").format(portString) + openSuccess = 0 - if (openSuccess): break - openSuccess = 1 + if (openSuccess): break + openSuccess = 1 - if (openSuccess): print("successfully opened port {}.").format(portString) - else: print("could not open any port.") + if (openSuccess): print("successfully opened port {}.").format(portString) + else: print("could not open any port.") #-----------------------------------------------#------------------------------- - def __del__(self): # destructor. - self.__serialPort.close() - print "object destroyed." + def __del__(self): # destructor. + self.__serialPort.close() + print "object destroyed." #-----------------------------------------------#------------------------------- - def write(self,toWrite): # write a string. + def write(self,toWrite): # write a string. nowWrite = toWrite[:7] - nowWrite = nowWrite + "$" - self.__serialPort.write(nowWrite) - return(nowWrite) + nowWrite = nowWrite + "$" + self.__serialPort.write(nowWrite) + return(nowWrite) #-----------------------------------------------#------------------------------- - def read(self): # read a string. - gotRead = self.__serialPort.read(8) - return(gotRead) + def read(self): # read a string. + gotRead = self.__serialPort.read(8) + return(gotRead) #-----------------------------------------------#------------------------------- #===============================================#=============================== @@ -59,3 +59,14 @@ + + + + + + + + + + +