import serial
import time

#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

to_add=0

line = time.strftime('%X')

while 1:    
    tt = int(time.time())
    bytes = ser.read(4)  #Read from Serial Port
    d_tt=int(time.time()) - tt
    if d_tt > 5:
      line = time.strftime('%X')
    line = line + "  " + ':'.join('{:02x}'.format(ord(c)) for c in bytes)
    to_add= to_add + 1
    if to_add == 9:
      print line
      to_add=0
    
#Ctrl+C to Close Python Window
