Page 1 of 1

Calculation problem dspMIAC

Posted: Fri Jan 04, 2019 3:18 pm
by gavo4
Hi Leigh,

Hope all is well!,

I am struggling with a calculation for a SD Card Saving routine.

I want to concatenate the MAINT1.txt file (I can save my Tag reader Serial/ID Number with no issues but I can only save it once using MAINT1.txt in the calculation) and I would like to use the RTC clock as the concatenation "byte" as I doubt very much that I would ever get any duplication. If I use a standard byte I am sure I would get duplicates especially once the unit switches on/off as I will start at 0 and repeat which is bound to have duplicate files. Perhaps you have a better idea?,

Please calculation below, I am not sure if the below will work?

RTC[8] = 0
RTC[7] = RTC[5]
RTC[6] = RTC[4]
RTC[5] = ':'
RTC[4] = RTC[3]
RTC[3] = RTC[2]
RTC[2] = ':'
RTC[1] = RTC[1]
RTC[0] = RTC[0]
.filename = "MAINT1" + RTC[0] + RTC[1] + RTC[2] + RTC[3] + ".TXT"
.filestring = ""


I have also attached the code of which the above is under the Macro of Save_Data

Any help would be greatly appreciated,

Regards,

Gavin

Re: Calculation problem dspMIAC

Posted: Fri Jan 04, 2019 4:04 pm
by LeighM
I don't think you can mix characters and strings, also concatenation has a few issues,
so try something like this ...

Code: Select all

.filename = "MAINT1" 
.filename[6] = RTC[0] 
.filename[7] = RTC[1] 
.filename[8] = RTC[2] 
.filename[9] = RTC[3] 
.filename[10] = 0   // Add a null to re-create a proper string
.filename = .filename  + ".TXT"

Re: Calculation problem dspMIAC

Posted: Fri Jan 04, 2019 4:35 pm
by gavo4
Thanks Leigh!

Re: Calculation problem dspMIAC

Posted: Fri Jan 04, 2019 5:17 pm
by gavo4
Hi Leigh,

I tried it and it keeps crashing, looks like if I use:

.filename = "MAINT"
.filename[5] = RTC[0]
.filename[6] = RTC[1]
.filename[7] = RTC[2]
.filename[8] = RTC[3]
.filename[9] = 0
.filename = .filename + ".TXT"
.filestring = ""

it doesn't crash but will only write the file "MAINT" no string behind the MAINT,

Any ideas why it would crash using:

.filename = "MAINT1"
.filename[6] = RTC[0]
.filename[7] = RTC[1]
.filename[8] = RTC[2]
.filename[9] = RTC[3]
.filename[10] = 0 // Add a null to re-create a proper string
.filename = .filename + ".TXT"
.filestring = ""

Regards,

Gavin

Re: Calculation problem dspMIAC

Posted: Fri Jan 04, 2019 10:38 pm
by mnf
Hi Gavin,

There is some code here : viewtopic.php?f=63&t=19464&hilit=camera (look for linksprite_camera) which outputs sequentially numbered files (and datestamps them) to an SD card

Several things could be wrong here:
How big is the filename buffer - is there room for all the extras (note in the download it is 20 chars which is big enough - but filename may need to be 8.3 format? - in which case your name is too long?
What is stored in RTC - is it ASCII (ie characters) or is it just 'raw' data which needs converting to ascii? (ie is it a long int - which copying to the filename will just insert invalid characters. There is lots of code converting binary to a string on the forum (for example here: viewtopic.php?f=7&t=20583&hilit=string+binary)

Martin

Re: Calculation problem dspMIAC

Posted: Sat Jan 05, 2019 2:22 pm
by gavo4
Thanks Martin!,

I am still learning and thanks for the help!,

I managed to get it working using:

.filename = "M"
.filename[1] = RTC[0]
.filename[2] = RTC[1]
.filename[3] = RTC[3]
.filename[4] = RTC[4]
.filename[5] = RTC[7]
.filename[7] = RTC[8]
.filename[8] = 0 // Add a null to re-create a proper string
.filename = .filename + ".TXT"
.filestring = ""

Regards,

Gavin