Writing Into CSV file by gettig data from Serial port - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Writing Into CSV file by gettig data from Serial port

ajit_nayak87ajit_nayak87 chennaiPosts: 1Member

Dear all

I have code as below. output window share output comig from serial port . read data should be written in to csv file

output window>

date is:7/12/16
time is:24-0-0
Zenith:104.85
Azimuth:110.40
Elevation:-14.85
Converted Elevation:15.79

['date is', '7/12/16\r\ntime is', '24-0-0\r\nZenith', '104.85\r\nAzimuth', '110.40\r\nElevation', '-14.85\r\nConverted Elevation', '15.79\r\n']

['date is:7/12/16', 'time is:24-0-0', 'Zenith:104.85', 'Azimuth:110.40', 'Elevation:-14.85', 'Converted Elevation:15.79', '']

actual code

import serial
import csv
import string
import os
import time
import sys

def main():
pass

if name == 'main':
main()
count=0
f=open("test.csv","w+");
result = csv.writer(f,delimiter=',', dialect='excel-tab')

result_statememt=("date","time","Zenith","Azimuth","Elevation","conv_elevation");
result.writerow(result_statememt)
f.close()
while(count<5):
    #time.sleep(60)
    ser=serial.Serial()
    ser.port=2
    ser.baudrate=9600
    ser.open()
    str=ser.read(109)
    print str
    val=str.split(":")
    print val
    print "\n"
    lines=str.split("\r\n")
    print lines
    #k=lines.split('')
    #print k
    line=lines.split
    wst=[]

    #print line
    wst=[]

# for line in lines[:]:
# line=lines.split(":")
# print line

    f=open("test.csv","a+")
    result=csv.writer(f,delimiter=',')

    count=count+1



    #lines=str.split("\r\n")

    #print count
    #f=open("test.txt","a+")
    #result=csv.writer(f,delimiter=',')
    #result.writerow()
    f.close()

f.close()
ser.close()
Tagged:
Sign In or Register to comment.