Program to Email Memory Contents of Redlion HMI for Troubleshooting

The Redlion HMIs have the capability of creating and deleting files on the flash memory card and emailing out files.  The program below is called from a button on a diagnostics screen.  This is used to collect the contents of a group of memory tags (variables), format them so they can be read with a spreadsheet program, store as a file on the flash memory card, then email that file out.

// program to store all the current regression data in a file and email it out

cstring line;
int FileNum, index;
 
//delete old file
FileNum = OpenFile("RegDiags.csv", 1);
Sleep(500); 
DeleteFile(FileNum);
Sleep(500);

// create the file
CreateFile("RegDiags.csv"); 
Sleep(500);
// wait for file to be created
while(GetDriveStatus('C') != 5) {}
// open the file and write the 'main' header information
FileNum = OpenFile("RegDiags.csv", 2); 

//write memory contents to text file
WriteFileLine(FileNum, "Regression1.lastTimeStamp");
WriteFileLine(FileNum, Regression1.lastTimeStamp.AsText);

WriteFileLine(FileNum, "Regression1.period");
WriteFileLine(FileNum, Regression1.period.AsText);

WriteFileLine(FileNum, "Regression1.slope");
WriteFileLine(FileNum, Regression1.slope.AsText);

WriteFileLine(FileNum, "Regression1.slope_scaled");
WriteFileLine(FileNum, Regression1.slope_scaled.AsText);

WriteFileLine(FileNum, "Regression1.slopeValid");
WriteFileLine(FileNum, Regression1.slopeValid.AsText);

// build up heading text line for spreadsheet viewing
line = "Sensor1x,Sensor1y,Sensor2x,Sensor2y,";
// write the line to the file
WriteFileLine(FileNum, line);

//write a line for each element in the array
for (index = 1; index <= 1500; index++){
 line = Regression1.x[index].AsText;
 line += ",";
 line += Regression1.y[index].AsText;
 line += ",";
 line += Regression2.x[index].AsText;
 line += ",";
 line += Regression2.y[index].AsText;
 line += ",";
 WriteFileLine(FileNum, line);
 };

CloseFile(FileNum);
Sleep(500);

//email file to list 1
SendFile(1, "RegDiags.csv");

Notes:

  • The Redlion HMI retains the contents of variables that have the ‘retentive’ option checked, even when a new database is loaded.  Because of this, I was able to load a new database containing this program, and extract all the data I needed.
  • The “.AsText” suffix can be used with any tag to represent the value (integer, float, or binary) as text so it can be written to a file.
This entry was posted in Industrial Automation and tagged , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.