import serial

#Can be Downloaded from this Link
#https://pypi.python.org/pypi/pyserial

#Global Variables
ser = 0

#Function to Initialize the Serial Port
def init_serial():
    global ser          #Must be declared in Each Function
    ser = serial.Serial()
    ser.baudrate = 57600
    ser.parity=serial.PARITY_NONE
    ser.bytesize=serial.EIGHTBITS
    ser.parity=serial.PARITY_NONE
    ser.stopbits=serial.STOPBITS_ONE
    ser.port = '/dev/ttyUSB0' #If Using Linux
    ser.open()          #Opens SerialPort

    # print port open or closed
    if ser.isOpen():
        print 'Open: ' + ser.portstr
#Function Ends Here
        

#Call the Serial Initilization Function, Main Program Starts from here
init_serial()

#temp = raw_input('Type what you want to send, hit enter:\r\n')
#ser.write(temp)         #Writes to the SerialPort

while 1:    
    bytes = ser.read(4)  #Read from Serial Port
    line = ':'.join('{:02x}'.format(ord(c)) for c in bytes)
    print line
    
#Ctrl+C to Close Python Window
