Retrieving string characters from CompactFlash

jfls45

Member
Join Date
Mar 2012
Location
Pennsylvania
Posts
76
I'm trying to retrieve string characters from my CompactFlash card. I am able to save to the card no problem.

I have a String Tag called "RecipeName". It saves to the CF card, example, ROT2.500.125

I want to be able to retrieve this full name without stripping out the "ROT".

I see there is a TextToInt and TextToFloat, but no TextToString. Is there a way of doing this?

Thanks in advance for help.

Jfls45
 
I see there is a TextToInt and TextToFloat, but no TextToString.
That would be redundant since text and strings are essentially the same. Data read from a file is by default imported as a string. If you want some other format, that's when you have to use the conversion commands. For example, if you use a command like "StringVar:=ReadFileLine(hFile)", StringVar needs to be a string-type tag (or a local cstring declared in a program).
 
Ok, I got that working. The next thing I need to figure out is how to combine this one string tag when I have integer tags on the same text line on my CF.

That would be redundant since text and strings are essentially the same. Data read from a file is by default imported as a string. If you want some other format, that's when you have to use the conversion commands. For example, if you use a command like "StringVar:=ReadFileLine(hFile)", StringVar needs to be a string-type tag (or a local cstring declared in a program).
 
Last edited:
I'm able to retrieve my string using the ReadFileLine(hfile) function, but how do I use this at the same time I am already using ReadFileLine(hfile) to retrieve data for my recipes? I've been trying different syntax but it's hanging my HMI.
 
I don't quite understand your problem. Are you trying to read data from two different files simultaneously? Or are you trying to read from the same file multiple times? Generally in recipe applications you should read all the data from the file in one shot, using ReadFileLine() within a looping construct, and store the data in arrays.
 
I'm trying to read from one file. All of my parameters are numbers. I am saving AsText and retrieving using TextToFloat, but once I use the ReadFileLine a second time to read the values I have added the letters to, it doesn't execute.

Does this make sense?

I don't quite understand your problem. Are you trying to read data from two different files simultaneously? Or are you trying to read from the same file multiple times? Generally in recipe applications you should read all the data from the file in one shot, using ReadFileLine() within a looping construct, and store the data in arrays.
 
The problem I am having is trying to use the ReadFileLine twice in the same program.

This is what my RECIPES.CSV file looks like:

0,ROT2.500.145,2.500,.145,2.756

How Do I pull the ROT2.500 using the ReadFileLine?



[SAVE CODE]

int hfile; //file opened index
int i; //array scanning index
//cstring RecipeName;
// Create a new folder if it doesn't exist
CreateDirectory("/recipes");
//Create the file if it doesn't exist
CreateFile("/recipes/recipe.csv");
//open the file
hfile= OpenFile("/recipes/recipe.csv",1);
//Write each recipe as a line in the file
//Copy each array index as a file line beginning by the recipe index
for (i=0;i<1;i++)
{
WriteFileLine(hfile,RecipeName);
WriteFileLine(hfile,AsText(i)+","
+OutsideDiameter.AsText+","
+WallThickness.AsText+","
+GapRoll1.AsText);
}
//Close the file
CloseFile(hfile);

[/SAVE CODE]

****************************************************************************

[RETRIEVE CODE]

int i, hfile; //Declaration of Variables
cstring CurrentLineStored; //Declaration of Variables
i = 0; //Initialization of Variable (assume at this time that hfile = null
hfile = OpenFile("/RECIPES/RECIPE.CSV",0); //hfile is initialized in this step. The hfile pointer
// is essentially an alias or shorthand so that we don't have to type the function and file paths.
CurrentLineStored = ReadFileLine(hfile);//The CurrentLine stored in this small program is the hfile's
//line zero. The ReadFileLine function will automatically index itself every time it is called.
while(CurrentLineStored !="") // loop until all lines are read

{
//RecipeName:=ReadFileLine(hfile);
OutsideDiameter:=TextToFloat(Mid(CurrentLineStored,15,5));
WallThickness:=TextToFloat(Mid(CurrentLineStored,21,5));
GapRoll1:=TextToFloat(Mid(CurrentLineStored,27,5));
CurrentLineStored := ReadFileLine(hfile);
}
CloseFile(hfile);
//Do this at after a OpenFile or the program will hangup and the display will need
//physically reset.
[/RETRIEVE CODE]
 
Last edited:
read the values I have added the letters to
I'm still not sure I understand what you're doing. Are you reading the file, then writing to it, then reading it again?

You should be aware that when you write to the CompactFlash, the data isn't written immediately. It's stored in a buffer in the G3's memory and only written on timed intervals. The reason for this is that flash memory has a limited number of write cycles, so high frequency writes could eventually wear out the card. The point being, if you're doing a write and immediately doing a read afterwards, it might look as though the write didn't work.
 
this isn't the case at all. I am trying to store and retrieve recipes to and from the CompactFlash only when necessary. Because I only see TextToFloat and TextToInt, and NO SUCH function called TextToString, because it already is a string, I was told to use the ReadFileLine to retrieve any string characters from my CF card. Hence, my problem, how do I setup this code?




I'm still not sure I understand what you're doing. Are you reading the file, then writing to it, then reading it again?

You should be aware that when you write to the CompactFlash, the data isn't written immediately. It's stored in a buffer in the G3's memory and only written on timed intervals. The reason for this is that flash memory has a limited number of write cycles, so high frequency writes could eventually wear out the card. The point being, if you're doing a write and immediately doing a read afterwards, it might look as though the write didn't work.
 
Last edited:
The problem I am having is trying to use the ReadFileLine twice in the same program.

This is what my RECIPES.CSV file looks like:

0,ROT2.500.145,2.500,.145,2.756

How Do I pull the ROT2.500 using the ReadFileLine?

Looking at your read code:
Code:
//RecipeName[i]:=ReadFileLine(hfile);
OutsideDiameter[i]:=TextToFloat(Mid(CurrentLineStored,15,5));
WallThickness[i]:=TextToFloat(Mid(CurrentLineStored,21,5));
GapRoll1[i]:=TextToFloat(Mid(CurrentLineStored,27,5));
Keep in mind that the current line of data has already been copied into CurrentLineStored, so all references should be to that variable until you're ready to go to the next line. So to get the recipe name you would just use:

Code:
RecipeName[i] := Mid(CurrentLineStored,2,12);
meaning that 12 characters are extracted starting at character #2.
 
Something else I noticed is that you are using AsText to format your data for writing. The potential problem with this is that the character positions will change if the float values go beyond certain ranges. The Mid() functions that you use for data reading will then not work properly.

For example, in your recipe line "0,ROT2.500.145,2.500,.145,2.756", GapRoll1 starts at character 26 (not 27 like you have in your Mid function). But if WallThickness is greater than 0.999, the line will change to "0,ROT2.500.145,2.500,x.xxx,2.756" and now GapRoll1 starts at character 27. Depending on your number ranges it might not be an issue, but I usually use DecToText() instead of AsText to convert floating point values to text, since you can control exactly how they are formatted and the size of the number becomes irrelevant.
 

Similar Topics

Hi, I cannot find the DLCA1764.EXE utilty software for data retrieving. Can someone share the link to download this software. Thanks!
Replies
4
Views
122
I have a strain gauge attached to a load cell. The strain gauge is wired into an analog channel on a ControlLogix 1769 controller at +/-10V. How...
Replies
6
Views
2,428
Hi, On the project i'm working on i'd like to connect Labview to an OPC-UA server on a B&R X20CP3586. After the configuration of the B&R, i...
Replies
3
Views
3,607
I've never had much success uploading a program WITH LABELS from an AB processor. I've just made sure all my backups had labels. I've recently...
Replies
6
Views
2,961
Hi! I have an old project built in TIA portal v11 with a comfort panel in it. Now this project is going to be rebuild and it will not have a...
Replies
1
Views
1,746
Back
Top Bottom