Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.