#!/usr/bin/env python
# -*- coding: utf-8 -*-

#import libs
import serial
from time import sleep

# declare variables
port = 'COM5'
baud = 9600
comment=""

# open a serial connection 
ser = serial.Serial(port=port, baudrate=baud, timeout=3)

# wait for the Arduino to start
sleep(2)

while True:

    # control the LED
    try:
        # file available
        myfile = open('server\cgi-bin\light.dat','r')
        comment=myfile.read(1)
        ser.write(comment)
        myfile.close()
    except:
        pass

    # wait a bit
    sleep(0.5)
    
# close the serial port
ser.close()