Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strings in C - help
11-05-2012, 03:08 PM, (This post was last modified: 11-05-2012, 03:24 PM by KiloOne.)
#15
RE: Strings in C - help
(11-05-2012, 02:46 PM)pingotg Wrote: So, when you copy just 64 bytes, knowing the string is longer than 64, you get a result with no terminating null!!

John,

I think this is fine since the null character is being left in CDCline until CDCline finally gets smaller than 64. The 64 character strings that are printed with CDC.print and are simply added without \r\n to the terminal screen.

When CDCline gets to <64 long it is CDC printed with CDC.println which adds the \r\n so that the terminal program does not have to.

Is that what you were worried about?

Dale

(11-05-2012, 03:08 PM)mf01 Wrote: Hi Dale,

a few minor points. As I noted in an earlier post Sprintf() is the Pinguino version of sprintf. The formatting capabilities are more limited but it does use less resources and may be faster. It is worth a try if you are concerned about time it takes to assemble the "string".

Secondly, you probably don't need to have SD.flush( ) if you are immediately going to close the file with SD.close(). If you look at the corresponding functions in ff.c (f_sync and f_close) you will see that for a file that is open as Read/Write f_close calls f_sync. If you are always going to close the file after writing dropping the SD.flush() may trim some time off the total process. The inclusion of both SD.flush and SD.close in the DataLogger.pde example was to allow for the expansion of the code to cover multiple writes at some separation without the file being "closed". Closing the file after each write should reduce the chances of data being lost due to it still being in a buffer in the event of loss of power supply or other problems.

Finally, I don't know what you are going to do with the data after you have captured it, but including a new line character (\n) or carraige return (\r) at the end of each data line means that the text file can easily be read into a spreadsheet with each string coming on a separate line. This can be done just by including "\n" (or \r or both \n\r) in the format string within sprintf/Sprintf, i.e.:-

Code:
sprintf(storetxt, "%4lu,%s\n", millis()/1000,intxt);

This might also make it easier to look at the data file with just a simple text editor to see if any particular sets of data are getting corrupted.

Regards

Mark,

I will add looking at Sprintf vs sprintf to my 'todo' list.

I will also add removing flush item to my 'todo' list. Off the top of my head I don't think it will change much because the flush data would still have to get flushed by the close and I assume if there is no data to flush, it would flush very quickly.

Good catch, I had removed the \r\n a few iterations ago when I was working on CDC problem and hadn't looked at a file for a while, just noticed all went to one line LOL. The order doesn't matter does it? In my mind I am branded with 'Carriage return Line feed' for a lot of years.

I am a little concerned with having to set aside a second 400 character temporary string to use sprintf() for string concatenating vs strcat() and then yet another 400 character for the CDC printing but I don't see another way.

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply


Messages In This Thread
Strings in C - help - by KiloOne - 10-05-2012, 09:24 PM
RE: Strings in C - help - by mf01 - 10-05-2012, 10:00 PM
RE: Strings in C - help - by KiloOne - 10-05-2012, 10:30 PM
RE: Strings in C - help - by KiloOne - 10-05-2012, 10:06 PM
RE: Strings in C - help - by jpmandon - 10-05-2012, 10:18 PM
RE: Strings in C - help - by mf01 - 10-05-2012, 10:43 PM
RE: Strings in C - help - by KiloOne - 10-05-2012, 10:45 PM
RE: Strings in C - help - by jpmandon - 10-05-2012, 11:30 PM
RE: Strings in C - help - by mf01 - 10-05-2012, 11:32 PM
RE: Strings in C - help - by moreno - 11-05-2012, 06:59 AM
RE: Strings in C - help - by mf01 - 11-05-2012, 09:10 AM
RE: Strings in C - help - by KiloOne - 11-05-2012, 01:38 PM
RE: Strings in C - help - by pingotg - 11-05-2012, 02:46 PM
RE: Strings in C - help - by KiloOne - 11-05-2012, 03:08 PM
RE: Strings in C - help - by mf01 - 11-05-2012, 03:08 PM
RE: Strings in C - help - by pingotg - 11-05-2012, 03:27 PM
RE: Strings in C - help - by KiloOne - 11-05-2012, 03:53 PM
RE: Strings in C - help - by pingotg - 11-05-2012, 07:19 PM
RE: Strings in C - help - by mf01 - 11-05-2012, 03:47 PM
RE: Strings in C - help - by mf01 - 11-05-2012, 03:57 PM
RE: Strings in C - help - by KiloOne - 11-05-2012, 04:23 PM
RE: Strings in C - help - by KiloOne - 11-05-2012, 08:33 PM
RE: Strings in C - help - by moreno - 11-05-2012, 08:53 PM
RE: Strings in C - help - by KiloOne - 13-05-2012, 12:34 AM
RE: Strings in C - help - by pingotg - 11-05-2012, 08:58 PM
RE: Strings in C - help - by KiloOne - 11-05-2012, 09:50 PM
RE: Strings in C - help - by pingotg - 12-05-2012, 09:55 AM
RE: Strings in C - help - by moreno - 12-05-2012, 07:45 AM
RE: Strings in C - help - by KiloOne - 12-05-2012, 03:31 PM
RE: Strings in C - help - by pingotg - 12-05-2012, 05:22 PM
RE: Strings in C - help - by KiloOne - 12-05-2012, 05:40 PM
RE: Strings in C - help - by pingotg - 12-05-2012, 06:11 PM
RE: Strings in C - help - by KiloOne - 12-05-2012, 07:27 PM
RE: Strings in C - help - by pingotg - 13-05-2012, 04:48 PM
RE: Strings in C - help - by bjoernp - 15-05-2012, 05:42 PM
RE: Strings in C - help - by KiloOne - 17-05-2012, 12:09 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)