F.open and CSV Files/Datalogging
- CustomFP
- Posts: 41
- Joined: Thu Mar 22, 2012 4:12 pm
F.open and CSV Files/Datalogging
Hello all,
I am trying to display datalog entries to the PV450 screen from a snapshot logger however I am having some troubles.
I am working from Murphy Sample code which can be seen below, it was taken from another thread that was having a similar problem.
What I would like to know is does the 'f.open' function read from the internal memory on the PV450 or is it reading from a USB stick?
I currently have a logger called LadderLog.csv however f.open is not returning a value, leading me to believe it isn't opening.
Is there any extra information you could profile me that might help me work through problems with the datalogger and file objects?
Regards,
//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $Faults.Status.ViewEntryReady$ for main script method
//---------------------------------------------------------------------------------------------
void $Faults.Status.ViewEntryReady$ ()
{
file f;
if( f.open( "EntryFile2.csv", "r" ) >= 0 )
{
int n = 0;
int i = 0;
string line = "";
string str = "";
smRead( VariableIDs.Faults_NumberEntries, n);
for( i = 0; i < n ; i++ )
{
f.readLine( line );
str += i + line + ". ";
}
cultureSetString( StringIDs.Faults_Entry, str, true);
f.close();
}
cultureSetString( StringIDs.Faults_Status, "Faults.ViewEntryReady", true);
}
I am trying to display datalog entries to the PV450 screen from a snapshot logger however I am having some troubles.
I am working from Murphy Sample code which can be seen below, it was taken from another thread that was having a similar problem.
What I would like to know is does the 'f.open' function read from the internal memory on the PV450 or is it reading from a USB stick?
I currently have a logger called LadderLog.csv however f.open is not returning a value, leading me to believe it isn't opening.
Is there any extra information you could profile me that might help me work through problems with the datalogger and file objects?
Regards,
//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $Faults.Status.ViewEntryReady$ for main script method
//---------------------------------------------------------------------------------------------
void $Faults.Status.ViewEntryReady$ ()
{
file f;
if( f.open( "EntryFile2.csv", "r" ) >= 0 )
{
int n = 0;
int i = 0;
string line = "";
string str = "";
smRead( VariableIDs.Faults_NumberEntries, n);
for( i = 0; i < n ; i++ )
{
f.readLine( line );
str += i + line + ". ";
}
cultureSetString( StringIDs.Faults_Entry, str, true);
f.close();
}
cultureSetString( StringIDs.Faults_Status, "Faults.ViewEntryReady", true);
}
- ksaenz
- Enovation Controls Development
- Posts: 263
- Joined: Thu Aug 19, 2010 7:53 am
Re: F.open and CSV Files/Datalogging
Hello CustomFP,
The function f.open() will open a file from internal memory.
What is the Logger Mode of your loader? Standard or Snapshot?
If it is a Standard logger you need to pass the file name you specified to f.open(), in your case it seems to be LadderLog.csv so it would look like this:
instead of this:
If it is a Snapshot logger you can use this to open the entries file:
And this to open the records file:
And the number corresponsd to the position of the logger on the list of data loggers so if that is your only logger the number would be 1 instead of 2.
Regards,
ksaenz
The function f.open() will open a file from internal memory.
What is the Logger Mode of your loader? Standard or Snapshot?
If it is a Standard logger you need to pass the file name you specified to f.open(), in your case it seems to be LadderLog.csv so it would look like this:
Code: Select all
if( f.open( "LadderLog.csv", "r" ) >= 0 )
Code: Select all
if( f.open( "EntryFile2.csv", "r" ) >= 0 )
Code: Select all
if( f.open( "EntryFile2.csv", "r" ) >= 0 )
Code: Select all
if( f.open( "RecordFile2.csv", "r" ) >= 0 )
Regards,
ksaenz
- CustomFP
- Posts: 41
- Joined: Thu Mar 22, 2012 4:12 pm
Re: F.open and CSV Files/Datalogging
Hello Ksaenz,
The logger I am using is a snapshot logger with the ladderlog.csv file. Ok so it is from the internal memory, that is good for this application.
Do I need to initialize the "EntryFile2.csv" file anywhere?
The logger I am using is a snapshot logger with the ladderlog.csv file. Ok so it is from the internal memory, that is good for this application.
Do I need to initialize the "EntryFile2.csv" file anywhere?
- ksaenz
- Enovation Controls Development
- Posts: 263
- Joined: Thu Aug 19, 2010 7:53 am
Re: F.open and CSV Files/Datalogging
The file "EntryFile2.csv" is created automatically.
The number corresponds to the position of the logger in the list of data loggers so if that is the first logger in the list the name of the file will be "EntryFile1.csv" instead of "EntryFile2.csv".
Do you have the box "Store on Active Fault Message" or are you storing the snapshots manually?
Regards,
ksaenz
The number corresponds to the position of the logger in the list of data loggers so if that is the first logger in the list the name of the file will be "EntryFile1.csv" instead of "EntryFile2.csv".
Do you have the box "Store on Active Fault Message" or are you storing the snapshots manually?
Regards,
ksaenz
- CustomFP
- Posts: 41
- Joined: Thu Mar 22, 2012 4:12 pm
Re: F.open and CSV Files/Datalogging
Thanks Ksaenz, this is working now.
I have another question regarding string variables, can you store them in the non-volatile memory like you can with normal variables? A customer would like to store a machine ID on the DMC that is made up of numbers and letters.
Please let me know if I need to create a new thread of this question.
I have another question regarding string variables, can you store them in the non-volatile memory like you can with normal variables? A customer would like to store a machine ID on the DMC that is made up of numbers and letters.
Please let me know if I need to create a new thread of this question.
- ksaenz
- Enovation Controls Development
- Posts: 263
- Joined: Thu Aug 19, 2010 7:53 am
Re: F.open and CSV Files/Datalogging
If the ID is short you can save the ASCII value of the individial characgters in numerical variables or you can write the whole string to a text file and read it when you need it but string variables don't have the option to save to non-volatile memory.
- CustomFP
- Posts: 41
- Joined: Thu Mar 22, 2012 4:12 pm
Re: F.open and CSV Files/Datalogging
Thanks for your help Ksaenz