How to start ,stop and restart a method while a program is still running.??
msiriwardena
Posts: 301
Iam using Autodatalogger by SLRM to log RPM and pressure sensor readings.As I have it in the program it does logg RPM and the pressures continually for 1.0 min.I
can change the logging time prior to starting the program.
What wan't to achieve is to stop and re-start the Datalogger for couple of minutes(as it is now) to logg special events that occur that I need to at that time.
In other words I like to start and stop the Datalogger when necessary.
I tried to start and stop using a button but not successful.That is example: ina[BTN1] == 1 ---> start Datalogger --> cognew(Datalogger,@DataloggerStaclk) and
use the Datalogger Oblects - "stop method" at the end of the required time.This does not work.
I have attached archieved version of my project and The AutoDatalogger Object by SRLM.
I am using the "Memory Stick Datalogger - Prallax ID#27937"
Thanks for your help.
Siri
can change the logging time prior to starting the program.
What wan't to achieve is to stop and re-start the Datalogger for couple of minutes(as it is now) to logg special events that occur that I need to at that time.
In other words I like to start and stop the Datalogger when necessary.
I tried to start and stop using a button but not successful.That is example: ina[BTN1] == 1 ---> start Datalogger --> cognew(Datalogger,@DataloggerStaclk) and
use the Datalogger Oblects - "stop method" at the end of the required time.This does not work.
I have attached archieved version of my project and The AutoDatalogger Object by SRLM.
I am using the "Memory Stick Datalogger - Prallax ID#27937"
Thanks for your help.
Siri
Comments
It looks like when you launch the usb object, it sucks up the last of the cogs, so this code dosen't run at all.
I suggest you adopt a new MAIN method strategy for keeping track of it all.
So to integrate it into your code.
But the new code doesn't change the fact that you may be using all 8 cogs and requesting more.
Try to merge two cogs functions into one, and see it it works.
When I calculate that I've used at least 7 cogs, I usually try to knock the code around to maintain my 7 cog use so I always have 1 free.
You are putting many different elements of code together, when you do this, its gets very confusing.
Especially when you are using almost all cogs.
Make a block diagram to help you understand your program flow, and cog usage.
Take a look at one such block diagram I created for my own project that used 4 prop chips, and almost all cogs in them. 32 cogs... hahaha..
http://forums.parallax.com/attachment.php?attachmentid=68222&d=1267464086
the required 2-3 min. but I wan't to re-start again at alater time.
Siri
in that case.
Looks like you repeat this sequence at the end of your code.
I repeated the entire PUB Datalogger, but changed the second filename to Pressure2.txt
Another way, neater.
How many times do you want to run it?
So if looks like you are trying to run the datalogger when you press a button.
And have it log the data to a new file name.
That requires some code modification.. the string filename needs to increment..
Another person needs to help you at this point.
If the string you pass to the datalogger dosen't require anything but a number, you could try that.
Just make a counter, and convert the decimal to string every cycle and feed that as the string for the filename.
You will need to rename the filenames once in an os.
So if ina[BTN1] == 1 is your trigger. .....?
All i require is to run the datalogger with the same file name at different time because I will replace the thumb drive with different one,so the file name and else do not matter.
I hope some one come up with a solution.
Siri
Since you helped me with logging -ve numbres, I came accross anther issue.
Thae code as it is - loggs data for 1.0min and with the command "USB.Stop" the file is closed and the object/?cog - shuts down.
When I wan't log another 1.0 min,I only way I know to do this is to turn off the prop board and power on again,then it will log data for 1.0min.
What I an trying to achive is to re-start the Datalogger at random to logg the data for another minute- without shutting down the whole system.
I have a pump and pressures sensors in the system and I do not want to stop them as I wan't to collect data from them at that instant.
What your code does is to stop and start at specific or pre-determined intervals.
I would like to start at random - example: When a switch is pressed --? ina[BTN1]==1, so when I need to logg data - i will only need to press the button to collect data for 1.0 min. then again at later time.
I hope I explained clearly if not let me know .
Thanks,
Siri
The USB drive is recognised only if it is plugged into the Memory Stick Datalogger(Parallax #27937) and then the prop board is powered.Then I see the power on LED sequence discribed
in the user manual - (green & red flashes alternately x 2sec.) and once the usb drive is removed both LED's are off.If I re-insert the USB drive nothing happens.(no flshing Led's).
May be I need to put a on/off switch to the power line to the Datalogger.Then ? re-start the Autodatalogger object and the Datalogger Method.
I have the Memory Stick datalogger soldered on to the board so I have ordered anothe one then I can test and come up with the solution.
I was reading the Vinculum data sheet which has a reset pin.It also says it can be used to by an external source.On the Memory Stick - there 3 pins labelled- Rest,
Ground,Program.So is it possible to reset the Vinculum chip by pulling the Rest pin to ground(jump the 2 pins) and re-start the datalogger oblect .
Please let me know what your opinion - that is if this can be resolved with software.
Thanks again.
Siri
P.S : Attached is the Memory Stick Datalogger - Documentaion.and Viculum documentation.
I edited the Autodatalogger - object and also edited my program.The data logger only writes the Header - File names only. No data was written.
I also removed the thumb drive and re-inserted and it was not recognized.If the thumb drive is already inserted and then the prop fired - the
data logger only writes the header and no data.
Thanks again for you help.
Siri
Attached is the archived files.
The next question is - the Autudatalogger object does not have "PUB Closefile method or Pub Openfile method.So how do you use " Openfile/Closefile" to open
a new file and close it when data is logged.
The data is logged safely when "stop" method is called as in the Demo program.
Thanks for your help.
Siri
The expected call sequence is
- init
- addfield (1..N)
- start
- stop (optional)
The init method will open the filename at SPIN level (and will add System Clock to the header), addfield will write the relevant header data for each field you add. Finally, start will close the file - at SPIN level - and give control to the PASM part which will open the file and close it again once the stop call has been received. IOW, when you follow the sequence listed above you won't have to worry about opening/closing the file manually. All you do is provide a filename to init.I have been trying to make it work as you sugested,I must be doing something wrong.
Now writes the headder and write one set of data and quits.I have beev trying to log about one minute of data at different times.
Thanks for your help.
Siri
Attached is the archived program and the copy of the Data file.
The manual mentions append mode (default) which suggests that only the first log attempt actually works (otherwise one would expect several header/single log line pairs due to the extra close call). Is there any error indication (e.g. LED) that subsequent log attempts fail (short of instrumenting the code yourself)? That said, you could manually send commands to see if consecutive open/write/close attempts work. Also, in the data logger there is a subroutine called reply which makes an attempt to analyze a potential error code. If so it calls critical_error which could be used to light an LED or something like that.
As for calling it, you start logging with a sequence of init/addfield/start, i.e. call (the original) log_start. Then you wait for however you long you want to log. At this point you call log_stop. For the next logging sequence you repeat this sequence whenever you need it. I don't personally own a data logger of this type so in a way I must rely on your test results. HTH
I tested the code exactly as you advised.I changed the "Data field : name byte "00000000.log" , 0 to ---> name byte "Pressure.txt" , 0 The title of the file remains- "00000000" - the name "Pressure" was not the title of the file.
Although I added 3 more data columns ,they were not named but comma delineation was there.- you can see it on the attached text file which
was logged.
I was monitoring the progress via PST - which showed : 00000000.log
00000001.log etc to 00000000A.log ---> 000000011.log etc.
Thanks for your patience and great help.
Siri
P.S: The Datalogger Overwrites it does not append.
Then how do you explain that the column header is still there? The file gets closed (and re-opened) between header emission and actual logging.
Anyway, lets resolve the issues raised by PM first and go from there.