Hi all,
I have an application where I need to read in parameters from an SD card to PIC variables. I want to write the parameters on to the SD card on a PC.
I am thinking of using notepad to write the files and saving them as .txt files
Say I have 2 lists of parameters saved as Type1.txt and Type2.txt. Each text file has (say) 8 variables, a mixture of char (8bit) and int (16 bit).
How would I list the variables in each text file to make it simple to retrieve them?
For example Type1.txt may have 50 232 1035 877 22 123 55 1122 to be stored.
Any help appreciated.
Thanks,
Dave.
SD card files
Moderator: Benj
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SD card files
Hi Dave,
It sounds like you need a method of parsing through the text file data.
First of all I would recommend using a state machine approach, this should make the problem easier to handle.
https://www.matrixtsl.com/wiki/index.ph ... ateMachine
You might want to store all the values into the same type of variable e.g. if your max variable is a UINT then simply have an array of UINT that you store all the values in. This certainly would help to simplify a bit.
I can make you a simple example if that would help.
It sounds like you need a method of parsing through the text file data.
First of all I would recommend using a state machine approach, this should make the problem easier to handle.
https://www.matrixtsl.com/wiki/index.ph ... ateMachine
You might want to store all the values into the same type of variable e.g. if your max variable is a UINT then simply have an array of UINT that you store all the values in. This certainly would help to simplify a bit.
I can make you a simple example if that would help.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times
Re: SD card files
Hi Benj,
Thanks for that. I'll have a read of the state machine info. Good point about making all variables the same.
Yes please, a simple example would be very helpful.
Thanks again,
Dave.
Thanks for that. I'll have a read of the state machine info. Good point about making all variables the same.
Yes please, a simple example would be very helpful.
Thanks again,
Dave.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SD card files
Hi Dave,
Here is a simple example that I hope will get you started.
Here is a simple example that I hope will get you started.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times
Re: SD card files
Wow, I'm glad you only did a "simple" example Benj! It'll take me some time to get my head around that.
Thanks very much for taking the time to do it. (I may well be back with a few questions)
Dave.
Thanks very much for taking the time to do it. (I may well be back with a few questions)
Dave.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SD card files
Hi Dave,
I start by populating a string variable with the data to parse. In your program you probably wouldn't use a string variable and you would instead read the data direct from a file on an SD card. Instead of storing the length of the string in StrLength I would store the number of bytes in the file which I believe there is a function for in the FAT component.
After the loop the VarIndex variable will tell you how many numeric values have been parsed.
Let me know how you get on and please ask away if there is anything you would like more info on.
I start by populating a string variable with the data to parse. In your program you probably wouldn't use a string variable and you would instead read the data direct from a file on an SD card. Instead of storing the length of the string in StrLength I would store the number of bytes in the file which I believe there is a function for in the FAT component.
After the loop the VarIndex variable will tell you how many numeric values have been parsed.
Let me know how you get on and please ask away if there is anything you would like more info on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times
Re: SD card files
Hi Benj,
Most of this makes sense to me with the help of the simulator. Struggling with these two lines
What is the *10 doing? Also the -'0'?
Thanks,
Dave.
Most of this makes sense to me with the help of the simulator. Struggling with these two lines
Code: Select all
NumericData[VarIndex] = NumericData[VarIndex] * 10
NumericData[VarIndex] = NumericData[VarIndex] + (StrData[StrIndex] - '0')
Thanks,
Dave.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SD card files
Hi Dave,
Let's take for example the string "123"
The variable starts with the value initialised to 0. We multiply by 10 to shift the previous value up a digit.
Var = Var * 10 = 0
We then add the current number to the variable as a decimal. We subtract '0' because the string contains ASCII numeric characters which are actually in the range of 48 to 57. Having '0' quotes around a character gives us the value of the ASCII character so '1' - '0' = 1.
https://www.asciitable.com/
Var = Var + (StrData[0] - '0') is equal to Var = Var + 1
So repeating again for the other two characters in the string.
Var = Var * 10 = 10
Var = Var + 2 = 12
Var = Var * 10 = 120
Var = Var + 3 = 123
Let's take for example the string "123"
The variable starts with the value initialised to 0. We multiply by 10 to shift the previous value up a digit.
Var = Var * 10 = 0
We then add the current number to the variable as a decimal. We subtract '0' because the string contains ASCII numeric characters which are actually in the range of 48 to 57. Having '0' quotes around a character gives us the value of the ASCII character so '1' - '0' = 1.
https://www.asciitable.com/
Var = Var + (StrData[0] - '0') is equal to Var = Var + 1
So repeating again for the other two characters in the string.
Var = Var * 10 = 10
Var = Var + 2 = 12
Var = Var * 10 = 120
Var = Var + 3 = 123
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times