#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2

    Smile Writing in to excel sheet for every 10 min


    Can some tell me how to write the data in to excel data for every 10 min.COde is written below. let me know changes to be made. Here i found file gets value when counter =5 till then size of byte is 0.


    Code:
    import serial
    import csv
    import os
    import time
    import sys
    import string
    
    
    
    def main():
        pass
    
    if __name__ == '__main__':
        main()
        COUNT=0
        f=open("new.csv","w+");
        result = csv.writer(f,delimiter=',')
        result_statement=("Dir","ACTUATOR_ON_OFF","MODE","DATE","TIME"," TRACKER DESIRED ANGLE"," TRACKER ACTUAL ANGLE")
        result.writerow(result_statement)
    
    
        while(COUNT<=5):
        while((time.sleep(5))):
          #time.sleep(5)
          ser=serial.Serial()
          ser.port=12
          ser.baudrate=9600
          ser.open()
          str=ser.read(150)
          print "string are:\n",str
          print type(str)
          val=str.split(":")
          print "value is:\n",val
          lines=str.split("\r\n")
          print  "line statement are :\n",lines
          COUNT=COUNT+1
    
    
    
          wst=[]
          for line in lines[:-1]:
                parts=line.split(":")
                for p in parts[1:]:
                    wst.append(p)
    
    
                #result = csv.writer(f,delimiter=',')
                #wst.append(parts[1:])
    
          print "wst:\n",wst
    
          result.writerow(wst)
    
    
    
                #print parts
                #f=open("new.csv","a+");
                #result = csv.writer(f,delimiter=',')
    
                #print result_statement
                #f.write("%s," % ":".join(parts[1:])
    f.close()
    ser.close()
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Your code has errors and is not runnable in its current state.

    To do something every x seconds, you do this:

    Code:
    >>> import time
    >>> while True:
    ...     print "hello"   # or do other work
    ...     time.sleep(5)
    hello
    hello
    hello
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2
    i made it working . Opening and closing file @ different intense.

IMN logo majestic logo threadwatch logo seochat tools logo