Datalogger - writing requirement question
![xanatos](https://forums.parallax.com/uploads/userpics/416/n3HKAG8I3I8DH.jpg)
I am writing a set of numbers to a datalogger and I want to save variables in doing so. The data length is several words in length, consisting of several individual hex bytes. The output file is a comma delimited text file.
The question is - can I open the file, and use a for/next loop to write each var, terminating the last entry with a lf and a cr, or do I need to write each line as as a complete line? An example of the desired file line as viewed later in something like notepad would look like:
76,09,07,02,16,54,09,30
I want to open once, write many, and close once, then sleep the logger until I issue another WKD and repeat the whole process. Am I thinking correctly? I'd just try this - but I am on my iPod Touch about 200 miles away from the hardware I could test this on! Thanks for the info!!!
Dave
The question is - can I open the file, and use a for/next loop to write each var, terminating the last entry with a lf and a cr, or do I need to write each line as as a complete line? An example of the desired file line as viewed later in something like notepad would look like:
76,09,07,02,16,54,09,30
I want to open once, write many, and close once, then sleep the logger until I issue another WKD and repeat the whole process. Am I thinking correctly? I'd just try this - but I am on my iPod Touch about 200 miles away from the hardware I could test this on! Thanks for the info!!!
Dave
Comments
since you're going to read this on Windows, you'd need to delimit each line with CRLF
when you say 'write many' how many is that - you said 'several words in length' earlier, but that's not many. Normally, if the write is in batches and is huge chunks (as in 100k bytes plus) you open, write, flush buffer, write, flush, etc. close. Or open, write, close, pause, open write close.
If it's just a few lines like 76,09...30, just open, write, and close
> I open the file, and use a for/next loop to write each var, terminating the last entry with a lf and a cr,
> or do I need to write each line as as a complete line?
Depends on the language and the write [noparse]:)[/noparse]
I'd do it like this:
hth
- Howard
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (CounterRotatingProps) : 7/5/2009 10:37:39 PM GMT
Here's an example of a line I am writing in full:
SEROUT TX, Baud, [noparse][[/noparse]$8,$20,$0,$0,$0,$2C,CR,"08,06,18,09,19,31,09,00",CR,$0A]
I know the 6th value in that package needs to be teh exact byte count in hex (in this example, it is the $2C element, which is probably NOT correct for the example, but I digress...). What I need to be able to do, and it sounds like you have confirmed this as correct above, is something like (loose approximation of code...):
open file
for x = 1 to TotalBytesToWrite
X = first var
SEROUT TX, Baud, [noparse][[/noparse]$8,$20,$0,$0,$0,$01 + X + ","]
X = second var
SEROUT TX, Baud, [noparse][[/noparse]$8,$20,$0,$0,$0,$01 + X + ","]
X = third var
SEROUT TX, Baud, [noparse][[/noparse]$8,$20,$0,$0,$0,$01 + X + ","]
etc... until all the vars have been written into the file dataline, then
SEROUT TX, Baud, [noparse][[/noparse]$8,$20,$0,$0,$0,$01 + ,CR,$0A]
Then a line to put the datalogger back into sleep mode until the next time the need comes up to write data.
Why am I doing this? I have more data to write than I have variables left for my stamp. I want to use one variable to pick up a byte, drop it into the file, go back, get the next byte (different var in a different location), drop IT into the datalogger, and so on until all the requisite vars are read in, then just close the file and - have lunch. Or dinner as will be the case in about 10 minutes... It sounds like I can do this, I just wanted to be as specific as I can be without having the hardware here to test it with, as I am writing a large code block relatively blind here and when I get back to the hardware I want to hit the ground running as it were.
Thanks very much for your help.
Dave
PS., Just to clarify, normally I'd just make a single string variable that would contain the whole thing by setting someVar = var1 + ", " + var2 + ", " + var3... etc., but I don't have enough space left for that fat string variable with everything else I am doing...· I have only 3 bytes left! :-)
Post Edited (xanatos) : 7/5/2009 11:05:37 PM GMT
I'd encourage you verify that the Data Logger sleep mode works
properly.
When I ran the Parallax demo code a while back, the Data Logger
never woke up. That might have been fixed with the latest firmware
update.
Something else I found useful is the addition of some sort of visual
indicator showing when the file is open or closed. Shutting down
power with an open file leads to loss of data.
phil
Thanks for the heads-up about the sleep issue. If that turns out to be a problem, this thing is on mains power, with battery backup, so I'll just leave it awake and bored!
Dave
Post Edited (xanatos) : 7/5/2009 11:58:16 PM GMT
It is not as you showed in your message just above where you opened the file and then had separate SEROUT statements each with the command to send one byte. After opening for write, there needs to be one statement telling it how many bytes in total to expect. Subsequently the values can be spread out over many SEROUT commands either in line or in a loop, followed by the command to close the file.
That could be extended over several lines of data, but they all need to be covered by the one $8 WRF command with its count of Nvalues plus punctuation.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks again,
Dave
First, here's the vars/IOs I have set up:
DLRX CON 1 ' P1 assigned TO SERIN on Datalogger
DLTX CON 0 ' P0 assigned TO SEROUT on Datalogger
Baud CON 240 ' 9600 bps (BS2sx)
DLBaud CON 500 ' Datalogger 4800 baud (BS2sx)
Now - I need to have this thing run with the USB drive inserted for hours at a time - probably 24 hours at a time. During that time, there will be the intermittant writes as described above in previous posts. At some point, someone will pull the USB drive, copy the file to their PC, and re-insert the USB drive (I intend to have the USB Drive.
I have taken the code from the SimpleLog.bs2 demo code from the product page, and combined a little from the Vinculum manual to see how the code works, and what the shortened command set allows, etc. I have placed the following code in the "Initializations" section of my code:
DEBUG "Initializing USB Logger... "
SEROUT DLTX, Baud, [noparse][[/noparse]"IPA", CR]
PAUSE 200
SEROUT DLTX, Baud, [noparse][[/noparse]"SCS", CR]
PAUSE 200
SEROUT DLTX, Baud, [noparse][[/noparse]$14,$20,$71,$02,$00,$0D] 'SET BAUD TO 4800
SERIN DLRX, DLBaud, [noparse][[/noparse]WAIT(">")]
DEBUG "Initialized ",CR
PAUSE 200
It never goes beyond the debug of the "Initializing USB Logger... ". Just sits there.
Doe sthat code look correct, or is there something previous to that that needs to happen?
I have tried this code with the USB Drive both inserted and removed.
The SimpleLog.bs2 demo application requires that you remove the drive and reinsert every time you want to write something - this can't work for my application. I need to insert the drive once, and have it accessed multiple times without removal and reinsertion, and likewise, I need the system to be able to initialize and recognize the USB drive on power-up with the drive inserted.
I simply do not understand enough about the workings of this item to recognize what I am doing wrong, and again, I humbly submit my ignorant self before your good graces in the hopes that it will be obvious to you what my code is lacking.
Thanks again, very much!
Dave
PS., the LED on the Datalogger just goes to solid red.
PPS., Here is an edited version of the SimpleLog.bs2 that I have used and that I know works.· It has been edited to simply, in this case, write the same data line over & over again in the USB Drive, as I was planning on replacing that dataline with the variables.· Here's the code that worded on the BS2 (and I have adjusted it for the BS2sx Baudmode settings, etc):
Post Edited (xanatos) : 7/7/2009 12:30:43 AM GMT
to use Simplelog.bs2 this initialization has to be followed , the flash drive should be removed from the datalogger then power applied to both the BS2 and the datalogger simultaneously. The debug screen displays a message once everything has boooted asking for keyboard input , pressing a key is when the datalogger is initialized.
It is not true that the flash drive be removed after each write , once the drive is inserted and verified you can leave it in there as long as you want writing and reading at will.
See if this gets you past the initialization
Jeff T.
Edit: BTW the WRF instruction must end with a CR ($0D) and you must write the exact number that you state in the WRF instruction. I mention this because your example states $2C (44·bytes) and I counted 43 so you are 2 bytes short (the final CR is not counted but needed)
Edit: I miscounted , but it still goes that the final character should be CR so you are in fact 1 byte short
Post Edited (Unsoundcode) : 7/7/2009 2:15:27 AM GMT
Yes, having the memory removed works, but the apparent requirement to do so will make this item unusable in the application.
Is there no way to have the drive initialize without the required removal and reinsertion?
Thanks very much for your efforts on my behalf,
Dave
I always include means for PBASIC to cycle the power to the drive in all my applications. I know what you mean about having to operate unattended, reliably. The power cycling can be done via a single p-channel mosfet, or via a low-power, low dropout voltage regulator with on-off capabilities. Having this capability has three advantages.
1) The initialization becomes super easy. The drive starts in a known state, and PBASIC needs only wait for the prompt.
2) Nearly zero power operation is possible, especially if there will be periods of minutes between writes to the disk. The SUD and SUM commands can get the current drain down to as low as 2 mA, but some disks don't like to be suspended.
3) Power cycling admits an easy route to recover from errors. The drive is very touchy about receiving the correct number of characters and the correct command sequences. If there is a "glitch", or should I say, "when"! the drive has no reset mechanism except the mysterious long series of "E"s for resynchronization. Power cycling recovers operation immediately.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
It's too late for this project, but I'll be considering it for the next one!
Thanks again, very very much. Your information is immensely helpful and appreciated.
Dave X
The drawbacks with the program as it stands are the initialization process and running at 4800 baud. The lower baud rate is more than compensated for by the seamless method of communication.
Initialization is neccessary because the default bootup paramaters require changing via a software command.
Looking at your requirements there are changes I would make that would significantly improve system operation as a whole, in particular the suggestion of using a pin as a cycle power switch.
This brings us back to Initialization , the bootup paramaters of the datalogger can be changed. So instead of the default 9600 , IPH and ECS bootup can be customized to 4800 , IPA and SCS.
Doing the above would eliminate the initialization code completely and cycling power would immediately give us a Datalogger that was ready to go ( as Tracy said "The drive starts in a known state" )
The utilities to customize the firmware are located at the Viniculum web site , don't go rushing into these changes it's simplicity make it dangerous and entering the wrong paramater can render the Datalogger useless.
Jeff T.
Dave
---Update:· I have downloaded from Vinculum the Vinculum Firmware Customiser
Is this the proper item you have referred to?
Thanks again!
Dave X
Post Edited (xanatos) : 7/11/2009 10:57:40 PM GMT
Do not remove the option that checks for firmware upgrades or your stuck .
With the above configuration every succesful command will be answered by the logger with a prompt ">" , that includes cycling power or inserting a thumbdrive so detection of either of those events is a simple
SERIN rx,baud,[noparse][[/noparse]WAIT(">")]
DEBUG "Logger detected"
The docs say to send the two echo commands E and e to synch or you might just send a carriage return which reponds with the prompt ">" disk present or ND no disk present ·but you can probably run quite happily without having to do that.
Jeff T.
EDIT: yes that is the utility , you also need the latest VDAP firmware version from the Viniculum site , it's version 3.68·. You will need the Reflash version which has the FTD extension not the ROM version . The final stage of customization requires you to save and rename the upgrade , which I forget right now what it should be. If you can't find the rename info let me know I have it on a computer somewhere.
Post Edited (Unsoundcode) : 7/11/2009 11:17:48 PM GMT
Thank you greatly!!!
Dave X
PS - I'm stepping away for about an hour - but I'll be back on later this evening... I've got a lot to do!
You're right. Just put the new ROM code (with the right name) on the USB module
and plug it into the Data Logger. When the Data Logger first reads the USB device
it looks for a ROM update file. If present, it upgrades the firmware.
As far as UART vs SPI mode, I don't know if it makes any difference, but I've
always used the SPI mode.
phil
Every time the logger has a drive inserted it searches the drive for a firmware upgrade.
I have a utility I use to monitor the upgrade but that is not neccessary . If you run the Simplelog example (with the flash stick removed ) and then when it says it is safe to insert the memory ,· it will automatically upgrade when you put the memory stick in. After the upgrade the logger will reboot (takes less than a minute)·,·at that point I would power down and set the Stamp up to try the logger with code that has no initialization.
Heres the sequence
Customize Firmware
Rename and save
Copy new file to a known good memory stick
Start a modified Simplelog (remove all the subroutines and references except initialize and detect)
Insert memory stick
Wait for any disk activity to stop
Power down and try with non initializing code
Jeff T.
Now I just need to patiently wait until the delivery arrives! I'll certainly let you know how it goes.
Thanks again. I hope I can return the favor somehow.
Dave X
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Dave
Thanks again for everything!
Dave