Datasets Files (Reference) enable reading and writing text-based data files for recipe management, configuration settings, and data exchange with external applications. DatasetFile provides:
Files support ASCII, Unicode, and XML forma
Property | Description | Required |
---|---|---|
Name | Unique file identifier (no spaces) | Yes |
FileName | Full file path (supports tag embedding) | Yes |
FileType | Format: ASCII, Unicode, XML | Yes |
Objects | Tags to read/write | Yes |
XMLSchemaType | XML structure type | For XML only |
Description | Documentation text | No |
Plain text, single-byte encoding:
Tag1=100
Tag2=200.5
Tag3=Active
Multi-byte character support:
??=25.5
??=101.3
??=???
Structured data with schemas:
xml
<Tags>
<Tag Name="Temperature" Value="25.5"/>
<Tag Name="Pressure" Value="101.3"/>
<Tag Name="Status" Value="Running"/>
</Tags>
C:\Recipes\Recipe001.txt
\\Server\Share\Config.xml
C:\Recipes\Recipe{{Tag.RecipeNumber}}.txt
C:\Data\{{Tag.Year}}\{{Tag.Month}}\Data.csv
\\Server\{{Tag.Department}}\Settings.xml
{{ExecutionPath}}\Recipes\Current.txt
{{SolutionPath}}\Data\Config.xml
Simple name-value pairs:
xml
<TagList>
<Tag Name="Tank1_Level" Value="75.5"/>
<Tag Name="Tank1_Temp" Value="22.3"/>
<Tag Name="Pump1_Status" Value="1"/>
</TagList>
Complete tag hierarchy:
xml
<TagTree>
<Folder Name="TankFarm">
<Folder Name="Tank1">
<Tag Name="Level" Value="75.5" Type="Double"/>
<Tag Name="Temp" Value="22.3" Type="Double"/>
</Folder>
</Folder>
</TagTree>
csharp
// Load recipe file
@Dataset.File.Recipe001.Load();
// Check if successful
if (@Dataset.File.Recipe001.Status == "OK")
{
// Tags now contain file values
double temp = @Tag.Temperature;
}
csharp
// Set tag values
@Tag.Temperature = 25.5;
@Tag.Pressure = 101.3;
@Tag.Status = "Running";
// Save to file
@Dataset.File.Recipe001.Save();
csharp
// Change filename at runtime
@Tag.RecipeNumber = 5;
@Dataset.File.RecipeFile.FileName =
string.Format(@"C:\Recipes\Recipe{0}.txt", @Tag.RecipeNumber);
// Load specific recipe
@Dataset.File.RecipeFile.Load();
# Recipe_001.txt
ProductCode=WIDGET-A
Temperature=185.5
Pressure=25.0
MixTime=300
Speed=1500
csharp
public void LoadRecipe(int recipeNumber)
{
// Set dynamic filename
@Tag.CurrentRecipe = recipeNumber;
// Load file
@Dataset.File.RecipeFile.Load();
// Verify loading
if (@Dataset.File.RecipeFile.Status == "OK")
{
@Tag.RecipeLoaded = true;
@Display.MessageBox("Recipe loaded successfully");
}
}
csharp
public void SaveRecipe()
{
// Current values saved to file
@Dataset.File.RecipeFile.Save();
// Create backup
string backup = string.Format(
@"C:\Recipes\Backup\Recipe_{0}.txt",
DateTime.Now.ToString("yyyyMMdd_HHmmss")
);
File.Copy(@Dataset.File.RecipeFile.FileName, backup);
}
csharp
// Export current configuration
@Dataset.File.ConfigExport.FileType = "XML";
@Dataset.File.ConfigExport.XMLSchemaType = "TagObject";
@Dataset.File.ConfigExport.Save();
csharp
// Import from external system
@Dataset.File.ConfigImport.Load();
// Apply imported values
if (@Dataset.File.ConfigImport.Status == "OK")
{
// Values automatically mapped to tags
ApplyConfiguration();
}
If Dataset Files menu is not visible:
Alternative:
csharp
try
{
@Dataset.File.MyFile.Load();
if (@Dataset.File.MyFile.Status != "OK")
{
string error = @Dataset.File.MyFile.ErrorMessage;
LogError(error);
}
}
catch (Exception ex)
{
// Handle file system errors
@Tag.FileError = ex.Message;
}
File not found:
Load/Save fails:
Data corruption:
Missing menu option: