Rewinding automatically a serial communication file in python

Hi guys,

I am working on a project where i acquire data in serial communication and save it in python as a text file. After this, i want the python to rerun the entire serial communication and start over to collect new set of data without clicking on the run key. so what i want is :
1.Run serial communication
2.Open file, save file
3.close file
4.start over from serial communication

I tried to use Seek() but it does not work with serial communication.

What are the other ways in doing this? Kindly help me out. please provide an example...

This is the program i used.

for i in range (1,31,1):
    line = ArdUNO.readline()
    print line
    outb.write(line)
    filename1="MIT_TEMP.txt"
    open
outb.close()
filename2 = filename + ".copy"
filename2="s3_p26.txt"
print filename, "=>", filename2
shutil.copy (filename, filename2)

filename.seek(0,0)

Thanks

I don't understand what you want to do or how much you have already achieved.

It seems like you can already receive data and save it in a file.

It seems, when that is complete, you want to read another set of data and save that in a file.

Do you want to add it to the same file or start a new file.

How many times do you want to do that?
If you want to do it many times to separate files you will need to write code to generate different file names - probably using the date and time (use yyyymmddhhmm format for easy sorting of the files).

How does your program know when it has received all of one set of data?

...R

LsensorRSH:
i want the python to rerun the entire serial communication and start over to collect new set of data without clicking on the run key. so what i want is :
1.Run serial communication
2.Open file, save file
3.close file
4.start over from serial communication

I can't make sense of the question, because I don't know what you mean by "rerun the entire serial communication", "start over to collect new set of data" or "clicking on the run key".

If your Python program has received a stream of data from a serial port and written it to a local text file, and you now want to do some processing to that saved data, you could open and read back the contents of the text file. Depending on the amount of data involved, you might also be able to keep an in-memory copy of the data as you write it to the file, so that you can access it again directly afterwards. If that's not what you're trying to do then you need to have another go at explaining, because at the moment it's not at all clear.

Why are you double posting.

It seems | have been wasting my time trying to help when you have already figured out the solution.

I am asking the Moderator to merge the Threads.

...R

If you wish to take about python programs - DO IT in a python forum, do not do it here. This forum deals with arduino programming. Just because the data came from the arduino make an issue for this forum.

Mark

Robin2:
It seems like you can already receive data and save it in a file.

It seems, when that is complete, you want to read another set of data and save that in a file.

Do you want to add it to the same file or start a new file.

How many times do you want to do that?
If you want to do it many times to separate files you will need to write code to generate different file names - probably using the date and time (use yyyymmddhhmm format for easy sorting of the files).

How does your program know when it has received all of one set of data?

...R

Hi,
I have achieved to the point where i can receive the data and save the file. The next thing is i want to do is read continuous set of data and save it in the same file by overwriting the previous data. this should keep happening continuously until i want to stop it.

Data time format sounds interesting i will try that. I haven't inputted anything in the program that it recognizes the data is collected. Surely, I do not know how to do that.

Robin2:
Why are you double posting.

It seems | have been wasting my time trying to help when you have already figured out the solution.

I am asking the Moderator to merge the Threads.

...R

I don't remember double posting this not in this forum, the link you had on double posting didn't work and i couldn't see any thing. the page was an error.

I am sorry if you feel you have wasted your time by trying to help me and I m pretty sure I have not solved this problem yet.

holmes4:
If you wish to take about python programs - DO IT in a python forum, do not do it here. This forum deals with arduino programming. Just because the data came from the arduino make an issue for this forum.

Mark

Sorry, I just thought since I am using arduino and python together it would be better to ask here as many people will be doing the same. I did enquire in the python forum, but there was no responses and since there are a lot of good programmers here i thought i would seek their help. But since you dont want me asking questions on python programming here, i wont ask anymore.

LsensorRSH:
I don't remember double posting this not in this forum, the link you had on double posting didn't work and i couldn't see any thing. the page was an error.

It looks like I got mixed up. I can't find the other link now either. Sorry.

...R

If you just want to completely over-write the previous data in the file the simplest way is probably to close it and the open it again for writing. You will need to check the proper way to do this in Python.

...R