Reports Generation (Tutorial) teaches you to:
Prerequisites:
We'll create a shift report showing tank status.
ShiftReport
Text
C:\Reports\Shift_{Info.Date}.txt
ShiftReport
from dropdown================================
TANK FARM SHIFT REPORT
Date: {Info.Date}
Time: {Info.Time}
Operator: {Client.UserName}
================================
TANK STATUS SUMMARY
-------------------
Tank 1:
Level: {Tag.TankFarm/Tank1/Level} ft
Temperature: {Tag.TankFarm/Tank1/Temp} °F
Pressure: {Tag.TankFarm/Tank1/Pressure} PSI
Status: {Tag.TankFarm/Tank1/Status}
Tank 2:
Level: {Tag.TankFarm/Tank2/Level} ft
Temperature: {Tag.TankFarm/Tank2/Temp} °F
Pressure: {Tag.TankFarm/Tank2/Pressure} PSI
Status: {Tag.TankFarm/Tank2/Status}
PRODUCTION METRICS
------------------
Total Volume: {Tag.TankFarm/Metrics/TotalVolume} gal
Flow Rate: {Tag.TankFarm/Metrics/FlowRate} gpm
Daily Production: {Tag.TankFarm/Metrics/DailyProduction} gal
================================
End of Report
csharp
public void TestReport()
{
// Set some test values
@Tag.TankFarm/Tank1/Level = 75.5;
@Tag.TankFarm/Tank1/Temp = 68.2;
@Tag.TankFarm/Tank1/Pressure = 14.7;
@Tag.TankFarm/Tank1/Status = "Normal";
// Generate report
@Report.Form.ShiftReport.Save();
// Show confirmation
@Info.Trace("Report saved to: " +
@Report.Form.ShiftReport.SavedFileName);
}
C:\Reports\
for generated text fileNow we'll send tank data to an external system.
TankDataAPI
JSON
https://api.example.com/tankdata
TankDataAPI
json
{
"timestamp": "{Info.Date} {Info.Time}",
"facility": "TankFarm-01",
"tanks": [
{
"id": "Tank1",
"level": {Tag.TankFarm/Tank1/Level},
"temperature": {Tag.TankFarm/Tank1/Temp},
"pressure": {Tag.TankFarm/Tank1/Pressure},
"status": "{Tag.TankFarm/Tank1/Status}"
},
{
"id": "Tank2",
"level": {Tag.TankFarm/Tank2/Level},
"temperature": {Tag.TankFarm/Tank2/Temp},
"pressure": {Tag.TankFarm/Tank2/Pressure},
"status": "{Tag.TankFarm/Tank2/Status}"
}
],
"metrics": {
"totalVolume": {Tag.TankFarm/Metrics/TotalVolume},
"flowRate": {Tag.TankFarm/Metrics/FlowRate}
}
}
csharp
public async void SendTankData()
{
// For testing, save to file instead of API
@Report.WebData.TankDataAPI.SaveFileName =
@"C:\Reports\TankData.json";
// Save JSON with current tag values
@Report.WebData.TankDataAPI.Save();
@Info.Trace("JSON data saved");
}
Create scheduled task for shift reports:
ShiftReportSchedule
Server.Hour
csharp
public void GenerateShiftReport()
{
// Generate at 6:00, 14:00, 22:00 (shift changes)
if (@Server.Hour == 6 || @Server.Hour == 14 || @Server.Hour == 22)
{
// Calculate shift metrics
@Tag.TankFarm/Metrics/DailyProduction =
@Tag.TankFarm/Tank1/Level * 1000 +
@Tag.TankFarm/Tank2/Level * 1000;
// Generate report
@Report.Form.ShiftReport.Save();
// Log generation
@Alarm.AuditTrail.AddCustomMessage(
"Shift report generated", null, null, null, null, null, null);
}
}
Display the generated report:
btnViewReport
csharp
public void btnViewReport_Click(object sender, EventArgs e)
{
// Open report in default text editor
string reportPath = @Report.Form.ShiftReport.SavedFileName;
if (System.IO.File.Exists(reportPath))
{
System.Diagnostics.Process.Start(reportPath);
}
else
{
MessageBox.Show("No report found. Generate one first.");
}
}
@Report.Form.ShiftReport.Save()