Jump to content
OMRON Forums

gather_csv utility program


iclim

Recommended Posts

Hello,

 

The software manual refers to a "gather_csv utility

program" a couple of times.

 

Could someone please tell me

- Where it is located i.e. where the program is in the file directory of the PPMAC

- The arguments to give to the programs

- Where it outputs to

 

Thank you

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

Currently the only customer supported usage is:

gather_csv [-u] [filename]

 

The “-u” will stream the contents of the most recent data gather to the standard output as in the current SSH, Telnet or serial port connection. The “-u” with a file name will stream it to that file. I would suggest using the “/var/ftp/usrflash/” directory as this is already writable and will allow ftp uploads without any permission changes. For example:

gather_csv -u /var/ftp/usrflash/steve

 

This puts the last gathered data in a text file named “steve” in the “/var/ftp/usrflash/” directory where you now have ftp access.

 

Keep in mind the gather files can be very large.

Link to comment
Share on other sites

  • 2 years later...

Currently the only customer supported usage is:

gather_csv [-u] [filename]

Keep in mind the gather files can be very large.

 

is it available the source code of the gather_csv program?

I'd like to make it save data in a more compress way and at the same time immediately readable by numeric postprocessor such as Matlab. HDF5 file format would by my preferred at the moment, since there are already available C libraries.

 

Thanks a lot

gigi

Link to comment
Share on other sites

The way gathering works is simple. When pmac is gathering it puts data into a data array in memory. It can do this in a rotary fashion or one time top to bottom. All the appware “gather” program does is read the pmac memory array and put the data to a file with some formatting. Below I is a starting point from a project I needed to do. This program is simple as I wrote it just to do one thing I needed and the items to gather were well defined and would not change so it does not cover every possible variable format that could be gathered. It could however be a starting point for someone to make a special gather appware.

 

This capp can be used to get gathered data from a rotary gather. It could be improved but it works and is a start.

 

#include // Global Gp Shared memory pointer

//----------------------------------------------------------------------------------

// pp_proj.h is the C header for accessing PMAC Global, CSGlobal, Ptr vars

// _PPScriptMode_ for Pmac Script like access global & csglobal

// global Mypvar - access with "Mypvar"

// global Myparray(32) - access with "Myparray(i)"

// csglobal Myqvar - access with "Myqvar(i)" where "i" is Coord #

// csglobal Myqarray(16) - access with "Myqvar(i,j)" where "j" is index

// _EnumMode_ for Pmac enum data type checking on Set & Get global functions

// Example

// global Mypvar

// csglobal Myqvar

// "SetGlobalVar(Myqvar, data)" will give a compile error because its a csglobal var.

// "SetCSGlobalVar(Mypvar, data)" will give a compile error because its a global var.

//------------------------------------------------------------------------------------

// #define _PPScriptMode_ // uncomment for Pmac Script type access

// #define _EnumMode_ // uncomment for Pmac enum data type checking on Set & Get global functions // uncomment for Pmac Script type access

 

 

//----------------------------------------------------------------------------------

// To use the functions defined in the Libraries folder, create a prototype of the function

// in this file or in a header file that is included in this file.

// For Example:

// If a Library project has been created with the following function and you intend to use

// that function in this C file:

// int MyFunction(int MyVar)

// {

// return MyVar*10;

// }

// Then a prototype of this function must be created in this c file or in a

// header file that is being included in this file. The prototype is the following:

// int MyFunction(int);

//------------------------------------------------------------------------------------

 

#include "../../Include/pp_proj.h"

 

int main(void)

{

//---------------------------------------------------------------------

// Required Startup Code: Insures that this APP is run as an RT or NON

// RT APP otherwise depending upon how it is started it will inherit

// the scheduling priority and policy of the task that started it.

//---------------------------------------------------------------------

//----------------------------------------------

// Uncomment the below #define to run as a RT Linux APP

// #define RUN_AS_RT_APP

// For older F/W uncomment the following if you get a compile error:

// #define BACKGROUND_RT_PRIORITY 50

// #define NANO_5MSEC 5000000

//----------------------------------------------

 

struct sched_param param;

int done = 0;

 

int iGatItems;

int iLineLength;

int iMaxLines;

int i, j, k, iSleep;

//int iReadIndex = 0;

//int iIndexInc[256];

int iTemp;

double dTemp;

int *pGatBuffer;

 

struct timespec sleeptime = {0};

sleeptime.tv_nsec = NANO_5MSEC; // #defines NANO_1MSEC, NANO_5MSEC & NANO_10MSEC are defined

 

#ifndef RUN_AS_RT_APP

//-----------------------------

// Runs as a NON RT Linux APP

//-----------------------------

param.__sched_priority = 0;

pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);

#else

//---------------------------------------------------------------

// Runs as a RT Linux APP with the same scheduling policy as the

// Background script PLCs

// To run at a recommended lower priority use BACKGROUND_SCRIPT_PLC_PRIORITY - 10

// To run at a higher priority use BACKGROUND_SCRIPT_PLC_PRIORITY + 1

//---------------------------------------------------------------------

param.__sched_priority = BACKGROUND_RT_PRIORITY - 10;

pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

#endif

 

InitLibrary(); // Requird for accessing Power PMAC library

FILE *pOutputFile;

 

iGatItems = (int) pshm->Gather.Items;

iLineLength = (int) pshm->Gather.LineLength;

iMaxLines = (int) pshm->Gather.MaxLines;

pOutputFile = fopen("/var/ftp/gather/brad.txt","w+");

if(pOutputFile != NULL)

{

 

iSleep = 0;

k = 0;

pGatBuffer = (int *) pshm->Gather.Buffer[0];

for (i = 0; i < iMaxLines; i++)

// for (i = 0; i < 10; i++)

{

for (j = 0; j < iGatItems; j++)

{

iTemp = (int) pshm->Gather.Type[j];

switch (iTemp)

{

case 0:

fprintf(pOutputFile, "%u,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 1:

fprintf(pOutputFile, "%d,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 2:

fprintf(pOutputFile, "%u,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 3:

fprintf(pOutputFile, "%d,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 4:

fprintf(pOutputFile, "%31.20f,", (float) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 5:

pGatBuffer = & (pshm->Gather.Buffer[k]);

dTemp = *((double *) pGatBuffer);

fprintf(pOutputFile, "%31.20f,", dTemp);

k = k + 2;

break;

}

}

fprintf(pOutputFile, "\n");

pshm->P[100]++;

iSleep++;

if(iSleep > 100)

{

iSleep = 0;

nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

}

}

fclose(pOutputFile);

}

CloseLibrary();

return 0;

}

 

 

 

////Put your code here

//pOutputFile = fopen("/var/ftp/gather/brad.txt","w+");

//fprintf(pOutputFile, "%s\n", "brad1");

//fprintf(pOutputFile, "%s\n", "brad2");

//fprintf(pOutputFile, "%s\n", "brad3");

//fclose(pOutputFile);

//pshm->P[100]++;

//

//nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

//done = 1; // while loop only runs once. remove for continues loop

//CloseLibrary();

//return 0;

//}

//

Link to comment
Share on other sites

Hi Brad

 

thanks a lot for the piece of code, I will defenitely start writing my code on top of that.

 

Many thanks

gigi

 

 

The way gathering works is simple. When pmac is gathering it puts data into a

...

Link to comment
Share on other sites

  • 1 year later...

The way gathering works is simple. When pmac is gathering it puts data into a data array in memory. It can do this in a rotary fashion or one time top to bottom. All the appware “gather” program does is read the pmac memory array and put the data to a file with some formatting. Below I is a starting point from a project I needed to do. This program is simple as I wrote it just to do one thing I needed and the items to gather were well defined and would not change so it does not cover every possible variable format that could be gathered. It could however be a starting point for someone to make a special gather appware.

 

This capp can be used to get gathered data from a rotary gather. It could be improved but it works and is a start.

 

#include // Global Gp Shared memory pointer

//----------------------------------------------------------------------------------

// pp_proj.h is the C header for accessing PMAC Global, CSGlobal, Ptr vars

// _PPScriptMode_ for Pmac Script like access global & csglobal

// global Mypvar - access with "Mypvar"

// global Myparray(32) - access with "Myparray(i)"

// csglobal Myqvar - access with "Myqvar(i)" where "i" is Coord #

// csglobal Myqarray(16) - access with "Myqvar(i,j)" where "j" is index

// _EnumMode_ for Pmac enum data type checking on Set & Get global functions

// Example

// global Mypvar

// csglobal Myqvar

// "SetGlobalVar(Myqvar, data)" will give a compile error because its a csglobal var.

// "SetCSGlobalVar(Mypvar, data)" will give a compile error because its a global var.

//------------------------------------------------------------------------------------

// #define _PPScriptMode_ // uncomment for Pmac Script type access

// #define _EnumMode_ // uncomment for Pmac enum data type checking on Set & Get global functions // uncomment for Pmac Script type access

 

 

//----------------------------------------------------------------------------------

// To use the functions defined in the Libraries folder, create a prototype of the function

// in this file or in a header file that is included in this file.

// For Example:

// If a Library project has been created with the following function and you intend to use

// that function in this C file:

// int MyFunction(int MyVar)

// {

// return MyVar*10;

// }

// Then a prototype of this function must be created in this c file or in a

// header file that is being included in this file. The prototype is the following:

// int MyFunction(int);

//------------------------------------------------------------------------------------

 

#include "../../Include/pp_proj.h"

 

int main(void)

{

//---------------------------------------------------------------------

// Required Startup Code: Insures that this APP is run as an RT or NON

// RT APP otherwise depending upon how it is started it will inherit

// the scheduling priority and policy of the task that started it.

//---------------------------------------------------------------------

//----------------------------------------------

// Uncomment the below #define to run as a RT Linux APP

// #define RUN_AS_RT_APP

// For older F/W uncomment the following if you get a compile error:

// #define BACKGROUND_RT_PRIORITY 50

// #define NANO_5MSEC 5000000

//----------------------------------------------

 

struct sched_param param;

int done = 0;

 

int iGatItems;

int iLineLength;

int iMaxLines;

int i, j, k, iSleep;

//int iReadIndex = 0;

//int iIndexInc[256];

int iTemp;

double dTemp;

int *pGatBuffer;

 

struct timespec sleeptime = {0};

sleeptime.tv_nsec = NANO_5MSEC; // #defines NANO_1MSEC, NANO_5MSEC & NANO_10MSEC are defined

 

#ifndef RUN_AS_RT_APP

//-----------------------------

// Runs as a NON RT Linux APP

//-----------------------------

param.__sched_priority = 0;

pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);

#else

//---------------------------------------------------------------

// Runs as a RT Linux APP with the same scheduling policy as the

// Background script PLCs

// To run at a recommended lower priority use BACKGROUND_SCRIPT_PLC_PRIORITY - 10

// To run at a higher priority use BACKGROUND_SCRIPT_PLC_PRIORITY + 1

//---------------------------------------------------------------------

param.__sched_priority = BACKGROUND_RT_PRIORITY - 10;

pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

#endif

 

InitLibrary(); // Requird for accessing Power PMAC library

FILE *pOutputFile;

 

iGatItems = (int) pshm->Gather.Items;

iLineLength = (int) pshm->Gather.LineLength;

iMaxLines = (int) pshm->Gather.MaxLines;

pOutputFile = fopen("/var/ftp/gather/brad.txt","w+");

if(pOutputFile != NULL)

{

 

iSleep = 0;

k = 0;

pGatBuffer = (int *) pshm->Gather.Buffer[0];

for (i = 0; i < iMaxLines; i++)

// for (i = 0; i < 10; i++)

{

for (j = 0; j < iGatItems; j++)

{

iTemp = (int) pshm->Gather.Type[j];

switch (iTemp)

{

case 0:

fprintf(pOutputFile, "%u,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 1:

fprintf(pOutputFile, "%d,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 2:

fprintf(pOutputFile, "%u,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 3:

fprintf(pOutputFile, "%d,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 4:

fprintf(pOutputFile, "%31.20f,", (float) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 5:

pGatBuffer = & (pshm->Gather.Buffer[k]);

dTemp = *((double *) pGatBuffer);

fprintf(pOutputFile, "%31.20f,", dTemp);

k = k + 2;

break;

}

}

fprintf(pOutputFile, "\n");

pshm->P[100]++;

iSleep++;

if(iSleep > 100)

{

iSleep = 0;

nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

}

}

fclose(pOutputFile);

}

CloseLibrary();

return 0;

}

 

 

 

////Put your code here

//pOutputFile = fopen("/var/ftp/gather/brad.txt","w+");

//fprintf(pOutputFile, "%s\n", "brad1");

//fprintf(pOutputFile, "%s\n", "brad2");

//fprintf(pOutputFile, "%s\n", "brad3");

//fclose(pOutputFile);

//pshm->P[100]++;

//

//nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

//done = 1; // while loop only runs once. remove for continues loop

//CloseLibrary();

//return 0;

//}

//

 

Hi Brad,

Thank you for this example. Below is the code I have been

running, which is essentially identical. The issue I am having is that the text file that is generated is all zeroes, though the actual gather buffer contains true non-zero data. The file size is as expected, so I think the issue is within the case statements. Any help will be appreciated.

Nadir

 

#include // Global Gp Shared memory pointer

//----------------------------------------------------------------------------------

// pp_proj.h is the C header for accessing PMAC Global, CSGlobal, Ptr vars

// _PPScriptMode_ for Pmac Script like access global & csglobal

// global Mypvar - access with "Mypvar"

// global Myparray(32) - access with "Myparray(i)"

// csglobal Myqvar - access with "Myqvar(i)" where "i" is Coord #

// csglobal Myqarray(16) - access with "Myqvar(i,j)" where "j" is index

// _EnumMode_ for Pmac enum data type checking on Set & Get global functions

// Example

// global Mypvar

// csglobal Myqvar

// "SetGlobalVar(Myqvar, data)" will give a compile error because its a csglobal var.

// "SetCSGlobalVar(Mypvar, data)" will give a compile error because its a global var.

//------------------------------------------------------------------------------------

// #define _PPScriptMode_ // uncomment for Pmac Script type access

//#define _EnumMode_ // uncomment for Pmac enum data type checking on Set & Get global functions // uncomment for Pmac Script type access

//----------------------------------------------------------------------------------

// To use the functions defined in the Libraries, create a prototype of the function

// in this file or in a header file that is included in this file.

// For Example:

// If a Library project has been created with the following function and you intend to use

// that function in this C file:

// int MyFunction(int MyVar)

// {

// return MyVar*10;

// }

// Then a prototype of this function must be created in this c file or in a

// header file that is being included in this file. The prototype is the following:

// int MyFunction(int);

//------------------------------------------------------------------------------------

#include "../../Include/pp_proj.h"

int main(void)

{

//---------------------------------------------------------------------

// Required Startup Code: Insures that this APP is run as an RT or NON

// RT APP otherwise depending upon how it is started it will inherit

// the scheduling priority and policy of the task that started it.

//---------------------------------------------------------------------

//----------------------------------------------

// Uncomment the below #define to run as a RT Linux APP

// #define RUN_AS_RT_APP

// For older F/W uncomment the following if you get a compile error:

// #define BACKGROUND_RT_PRIORITY 50

// #define NANO_5MSEC 5000000

//----------------------------------------------

struct sched_param param;

int done = 0;

int iGatItems;

int iLineLength;

int iMaxLines;

int i,j,k, sleep;

int iTemp;

double dTemp;

int *pGatBuffer;

#ifndef RUN_AS_RT_APP

//-----------------------------

// Runs as a NON RT Linux APP

//-----------------------------

param.__sched_priority = 0;

pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);

#else

//---------------------------------------------------------------

// Runs as a RT Linux APP with the same scheduling policy as the

// Background script PLCs

// To run at a recommended lower priority use BACKGROUND_SCRIPT_PLC_PRIORITY - 10

// To run at a higher priority use BACKGROUND_SCRIPT_PLC_PRIORITY + 1

//---------------------------------------------------------------------

param.__sched_priority = BACKGROUND_RT_PRIORITY - 10;

pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

#endif

InitLibrary(); // open access to library

FILE *pOutputFile;

iGatItems = (int) pshm->Gather.Items;

iLineLength = (int) pshm->Gather.LineLength;

iMaxLines = (int) pshm->Gather.MaxLines;

pOutputFile = fopen("/var/ftp/gather/eventlog.txt","w+");

if(pOutputFile != NULL)

{

isleep = 0;

k = 0;

pGatBuffer = (int *) pshm->Gather.Buffer[0];

for (i = 0 ; i < iMaxLines ; i++)

{

for (j = 0 ; j < iGatItems ; j++)

{

iTemp = (int) pshm->Gather.Type[j];

switch (iTemp)

{

case 0:

fprintf(pOutputFile, "%u", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 1:

fprintf(pOutputFile, "%d", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 2:

fprintf(pOutputFile, "%u", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 3:

fprintf(pOutputFile, "%d", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 4:

fprintf(pOutputFile, "%31.20f", (float) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 5:

pGatBuffer = & (pshm->Gather.Buffer[k]);

dTemp = * ((double *) pGatBuffer);

fprintf(pOutputFile, "%31.20f", dTemp);

k = k + 2;

break;

} // end of switch iTemp

} //end of j loop

fprintf(pOutputFile, "\n");

pshm->P[100]++;

iSleep++;

if(iSleep > 100)

{

iSleep = 0;

nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

}

} // end of i loop

fclose(pOutputFile);

} // if(pOutputFile != NULL)

CloseLibrary();

return 0;

} // int main (void)

Link to comment
Share on other sites

The way gathering works is simple. When pmac is gathering it puts data into a data array in memory. It can do this in a rotary fashion or one time top to bottom. All the appware “gather” program does is read the pmac memory array and put the data to a file with some formatting. Below I is a starting point from a project I needed to do. This program is simple as I wrote it just to do one thing I needed and the items to gather were well defined and would not change so it does not cover every possible variable format that could be gathered. It could however be a starting point for someone to make a special gather appware.

 

This capp can be used to get gathered data from a rotary gather. It could be improved but it works and is a start.

 

#include // Global Gp Shared memory pointer

//----------------------------------------------------------------------------------

// pp_proj.h is the C header for accessing PMAC Global, CSGlobal, Ptr vars

// _PPScriptMode_ for Pmac Script like access global & csglobal

// global Mypvar - access with "Mypvar"

// global Myparray(32) - access with "Myparray(i)"

// csglobal Myqvar - access with "Myqvar(i)" where "i" is Coord #

// csglobal Myqarray(16) - access with "Myqvar(i,j)" where "j" is index

// _EnumMode_ for Pmac enum data type checking on Set & Get global functions

// Example

// global Mypvar

// csglobal Myqvar

// "SetGlobalVar(Myqvar, data)" will give a compile error because its a csglobal var.

// "SetCSGlobalVar(Mypvar, data)" will give a compile error because its a global var.

//------------------------------------------------------------------------------------

// #define _PPScriptMode_ // uncomment for Pmac Script type access

// #define _EnumMode_ // uncomment for Pmac enum data type checking on Set & Get global functions // uncomment for Pmac Script type access

 

 

//----------------------------------------------------------------------------------

// To use the functions defined in the Libraries folder, create a prototype of the function

// in this file or in a header file that is included in this file.

// For Example:

// If a Library project has been created with the following function and you intend to use

// that function in this C file:

// int MyFunction(int MyVar)

// {

// return MyVar*10;

// }

// Then a prototype of this function must be created in this c file or in a

// header file that is being included in this file. The prototype is the following:

// int MyFunction(int);

//------------------------------------------------------------------------------------

 

#include "../../Include/pp_proj.h"

 

int main(void)

{

//---------------------------------------------------------------------

// Required Startup Code: Insures that this APP is run as an RT or NON

// RT APP otherwise depending upon how it is started it will inherit

// the scheduling priority and policy of the task that started it.

//---------------------------------------------------------------------

//----------------------------------------------

// Uncomment the below #define to run as a RT Linux APP

// #define RUN_AS_RT_APP

// For older F/W uncomment the following if you get a compile error:

// #define BACKGROUND_RT_PRIORITY 50

// #define NANO_5MSEC 5000000

//----------------------------------------------

 

struct sched_param param;

int done = 0;

 

int iGatItems;

int iLineLength;

int iMaxLines;

int i, j, k, iSleep;

//int iReadIndex = 0;

//int iIndexInc[256];

int iTemp;

double dTemp;

int *pGatBuffer;

 

struct timespec sleeptime = {0};

sleeptime.tv_nsec = NANO_5MSEC; // #defines NANO_1MSEC, NANO_5MSEC & NANO_10MSEC are defined

 

#ifndef RUN_AS_RT_APP

//-----------------------------

// Runs as a NON RT Linux APP

//-----------------------------

param.__sched_priority = 0;

pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);

#else

//---------------------------------------------------------------

// Runs as a RT Linux APP with the same scheduling policy as the

// Background script PLCs

// To run at a recommended lower priority use BACKGROUND_SCRIPT_PLC_PRIORITY - 10

// To run at a higher priority use BACKGROUND_SCRIPT_PLC_PRIORITY + 1

//---------------------------------------------------------------------

param.__sched_priority = BACKGROUND_RT_PRIORITY - 10;

pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

#endif

 

InitLibrary(); // Requird for accessing Power PMAC library

FILE *pOutputFile;

 

iGatItems = (int) pshm->Gather.Items;

iLineLength = (int) pshm->Gather.LineLength;

iMaxLines = (int) pshm->Gather.MaxLines;

pOutputFile = fopen("/var/ftp/gather/brad.txt","w+");

if(pOutputFile != NULL)

{

 

iSleep = 0;

k = 0;

pGatBuffer = (int *) pshm->Gather.Buffer[0];

for (i = 0; i < iMaxLines; i++)

// for (i = 0; i < 10; i++)

{

for (j = 0; j < iGatItems; j++)

{

iTemp = (int) pshm->Gather.Type[j];

switch (iTemp)

{

case 0:

fprintf(pOutputFile, "%u,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 1:

fprintf(pOutputFile, "%d,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 2:

fprintf(pOutputFile, "%u,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 3:

fprintf(pOutputFile, "%d,", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 4:

fprintf(pOutputFile, "%31.20f,", (float) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 5:

pGatBuffer = & (pshm->Gather.Buffer[k]);

dTemp = *((double *) pGatBuffer);

fprintf(pOutputFile, "%31.20f,", dTemp);

k = k + 2;

break;

}

}

fprintf(pOutputFile, "\n");

pshm->P[100]++;

iSleep++;

if(iSleep > 100)

{

iSleep = 0;

nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

}

}

fclose(pOutputFile);

}

CloseLibrary();

return 0;

}

 

 

 

////Put your code here

//pOutputFile = fopen("/var/ftp/gather/brad.txt","w+");

//fprintf(pOutputFile, "%s\n", "brad1");

//fprintf(pOutputFile, "%s\n", "brad2");

//fprintf(pOutputFile, "%s\n", "brad3");

//fclose(pOutputFile);

//pshm->P[100]++;

//

//nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

//done = 1; // while loop only runs once. remove for continues loop

//CloseLibrary();

//return 0;

//}

//

 

Hi Brad,

Thank you for this example. Below is the code I have been

running, which is essentially identical. The issue I am having is that the text file that is generated is all zeroes, though the actual gather buffer contains true non-zero data. The file size is as expected, so I think the issue is within the case statements. Any help will be appreciated.

Nadir

 

#include // Global Gp Shared memory pointer

//----------------------------------------------------------------------------------

// pp_proj.h is the C header for accessing PMAC Global, CSGlobal, Ptr vars

// _PPScriptMode_ for Pmac Script like access global & csglobal

// global Mypvar - access with "Mypvar"

// global Myparray(32) - access with "Myparray(i)"

// csglobal Myqvar - access with "Myqvar(i)" where "i" is Coord #

// csglobal Myqarray(16) - access with "Myqvar(i,j)" where "j" is index

// _EnumMode_ for Pmac enum data type checking on Set & Get global functions

// Example

// global Mypvar

// csglobal Myqvar

// "SetGlobalVar(Myqvar, data)" will give a compile error because its a csglobal var.

// "SetCSGlobalVar(Mypvar, data)" will give a compile error because its a global var.

//------------------------------------------------------------------------------------

// #define _PPScriptMode_ // uncomment for Pmac Script type access

//#define _EnumMode_ // uncomment for Pmac enum data type checking on Set & Get global functions // uncomment for Pmac Script type access

//----------------------------------------------------------------------------------

// To use the functions defined in the Libraries, create a prototype of the function

// in this file or in a header file that is included in this file.

// For Example:

// If a Library project has been created with the following function and you intend to use

// that function in this C file:

// int MyFunction(int MyVar)

// {

// return MyVar*10;

// }

// Then a prototype of this function must be created in this c file or in a

// header file that is being included in this file. The prototype is the following:

// int MyFunction(int);

//------------------------------------------------------------------------------------

#include "../../Include/pp_proj.h"

int main(void)

{

//---------------------------------------------------------------------

// Required Startup Code: Insures that this APP is run as an RT or NON

// RT APP otherwise depending upon how it is started it will inherit

// the scheduling priority and policy of the task that started it.

//---------------------------------------------------------------------

//----------------------------------------------

// Uncomment the below #define to run as a RT Linux APP

// #define RUN_AS_RT_APP

// For older F/W uncomment the following if you get a compile error:

// #define BACKGROUND_RT_PRIORITY 50

// #define NANO_5MSEC 5000000

//----------------------------------------------

struct sched_param param;

int done = 0;

int iGatItems;

int iLineLength;

int iMaxLines;

int i,j,k, sleep;

int iTemp;

double dTemp;

int *pGatBuffer;

#ifndef RUN_AS_RT_APP

//-----------------------------

// Runs as a NON RT Linux APP

//-----------------------------

param.__sched_priority = 0;

pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);

#else

//---------------------------------------------------------------

// Runs as a RT Linux APP with the same scheduling policy as the

// Background script PLCs

// To run at a recommended lower priority use BACKGROUND_SCRIPT_PLC_PRIORITY - 10

// To run at a higher priority use BACKGROUND_SCRIPT_PLC_PRIORITY + 1

//---------------------------------------------------------------------

param.__sched_priority = BACKGROUND_RT_PRIORITY - 10;

pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

#endif

InitLibrary(); // open access to library

FILE *pOutputFile;

iGatItems = (int) pshm->Gather.Items;

iLineLength = (int) pshm->Gather.LineLength;

iMaxLines = (int) pshm->Gather.MaxLines;

pOutputFile = fopen("/var/ftp/gather/eventlog.txt","w+");

if(pOutputFile != NULL)

{

isleep = 0;

k = 0;

pGatBuffer = (int *) pshm->Gather.Buffer[0];

for (i = 0 ; i < iMaxLines ; i++)

{

for (j = 0 ; j < iGatItems ; j++)

{

iTemp = (int) pshm->Gather.Type[j];

switch (iTemp)

{

case 0:

fprintf(pOutputFile, "%u", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 1:

fprintf(pOutputFile, "%d", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 2:

fprintf(pOutputFile, "%u", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 3:

fprintf(pOutputFile, "%d", (int) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 4:

fprintf(pOutputFile, "%31.20f", (float) pshm->Gather.Buffer[k]);

k = k + 1;

break;

case 5:

pGatBuffer = & (pshm->Gather.Buffer[k]);

dTemp = * ((double *) pGatBuffer);

fprintf(pOutputFile, "%31.20f", dTemp);

k = k + 2;

break;

} // end of switch iTemp

} //end of j loop

fprintf(pOutputFile, "\n");

pshm->P[100]++;

iSleep++;

if(iSleep > 100)

{

iSleep = 0;

nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

}

} // end of i loop

fclose(pOutputFile);

} // if(pOutputFile != NULL)

CloseLibrary();

return 0;

} // int main (void)

 

// Application Overview:

// 1. Gather position data on four motors at the servo rate, waiting for a position corruption event.

// 2. Run 24/7 using the rotary gather mode and a large gather buffer allocated at the User Buffer.

// 3. When the event occurs, stop gathering after a few seconds delay.

// 4. Upload the complete data from the gather buffer, both pre-event and post-event, into a text file for further analysis.

//

Gather.UserBufStart = Sys.Idata[4096].a // This will start the servo gather storage at 4096 * 4 = 16,384 bytes from the start of the user shared memory buffer

Gather.UserBufSize = 10000 // for testing only

Gather.Addr[0]= Sys.ServoCount.a // Gather.Type = 0:32-bit integer, unsigned. 4 bytes.

Gather.Addr[1]= Motor[4].ActPos.a // for testing only. Gather.Type = 5:64-bit floating-point (double-precision). 8 bytes

Gather.Items = 2 // for testing only !

Gather.Period = 1 // 10KHz sampling rate

Gather.Enable = 1 // causes Power PMAC to calculate the number of words required to store each sample (Gather.LineLength)

// and the number of samples that can be stored (Gather.MaxLines).

Gather.MaxSamples=Gather.MaxLines // collect maximum possible number of samples

Gather.Enable = 3 // enable gathering in rotary mode

//

//

// When the event occurs, a monitoring PLC issues Gather.Enable = 0, and the user is prompted to execute the followind C app.

//

//

//******************************************************************************

//

// The issue is that the first gathered item (an int, Gather.Addr[0]= Sys.ServoCount.a) is written properly to the file,

// but the second gathered item (a double Gather.Addr[1]= Motor[4].ActPos.a) writes only zeroes to the file, even though

// that item looks correct when viewd via Sys.Data at the IDE terminal.

//

 

 

#include // Global Gp Shared memory pointer

//----------------------------------------------------------------------------------

// pp_proj.h is the C header for accessing PMAC Global, CSGlobal, Ptr vars

//

// _PPScriptMode_ for Pmac Script like access global & csglobal

// global Mypvar - access with "Mypvar"

// global Myparray(32) - access with "Myparray(i)"

// csglobal Myqvar - access with "Myqvar(i)" where "i" is Coord #

// csglobal Myqarray(16) - access with "Myqvar(i,j)" where "j" is index

//

// _EnumMode_ for Pmac enum data type checking on Set & Get global functions

// Example

// global Mypvar

// csglobal Myqvar

// "SetGlobalVar(Myqvar, data)" will give a compile error because its a csglobal var.

// "SetCSGlobalVar(Mypvar, data)" will give a compile error because its a global var.

//------------------------------------------------------------------------------------

#define _PPScriptMode_ // uncomment for Pmac Script type access

//#define _EnumMode_ // uncomment for Pmac enum data type checking on Set & Get global functions // uncomment for Pmac Script type access

//----------------------------------------------------------------------------------

// To use the functions defined in the Libraries, create a prototype of the function

// in this file or in a header file that is included in this file.

// For Example:

// If a Library project has been created with the following function and you intend to use

// that function in this C file:

// int MyFunction(int MyVar)

// {

// return MyVar*10;

// }

// Then a prototype of this function must be created in this c file or in a

// header file that is being included in this file. The prototype is the following:

// int MyFunction(int);

//------------------------------------------------------------------------------------

#include "../../Include/pp_proj.h"

int main(void)

{

//---------------------------------------------------------------------

// Required Startup Code: Insures that this APP is run as an RT or NON

// RT APP otherwise depending upon how it is started it will inherit

// the scheduling priority and policy of the task that started it.

//---------------------------------------------------------------------

//----------------------------------------------

// Uncomment the below #define to run as a RT Linux APP

// #define RUN_AS_RT_APP

// For older F/W uncomment the following if you get a compile error:

// #define BACKGROUND_RT_PRIORITY 50

// #define NANO_5MSEC 5000000

//----------------------------------------------

struct sched_param param;

//int done = 0;

int iGatItems;

int iLineLength;

int iMaxLines;

int i,j,k, iSleep;

int iTemp;

double dTemp;

int *pGatBuffer;

int pGatBuffer1;

double pGatBuffer2;

struct timespec sleeptime = {0};

sleeptime.tv_nsec = NANO_5MSEC;

//int *MyUshmIntVar;

//#ifndef RUN_AS_RT_APP

//-----------------------------

// Runs as a NON RT Linux APP

//-----------------------------

param.__sched_priority = 0;

pthread_setschedparam(pthread_self(), SCHED_OTHER, &param);

// #else

//---------------------------------------------------------------

// Runs as a RT Linux APP with the same scheduling policy as the

// Background script PLCs

// To run at a recommended lower priority use BACKGROUND_SCRIPT_PLC_PRIORITY - 10

// To run at a higher priority use BACKGROUND_SCRIPT_PLC_PRIORITY + 1

//---------------------------------------------------------------------

// param.__sched_priority = BACKGROUND_RT_PRIORITY - 10;

// pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

// #endif

InitLibrary(); // open access to library

FILE *pOutputFile;

iGatItems = (int) pshm->Gather.Items;

pTest10 = (double) iGatItems; // for testing

iLineLength = (int) pshm->Gather.LineLength;

pTest11 = (double) iLineLength; // for testing

iMaxLines = (int) pshm->Gather.MaxLines;

pTest12 = (double) iMaxLines; // for testing

pOutputFile = fopen("/var/ftp/gather/eventlog.txt","w+");

pTest13 = (double) 0; // for testing, i loop

pTest14 = (double) 0; // for testing, j loop

pTest15 = (double) 0; // for testing, k

pTest17 = (double) 0; // for testing

pTest18 = (double) 0; // for testing

 

if(pOutputFile != NULL)

{

iSleep = 0;

k = 0;

for (i = 0 ; i < iMaxLines ; i++)

{

pTest13 = (int) i; // for testing

for (j = 0 ; j < iGatItems ; j++)

{

pTest14 = (int) j; // for testing

iTemp = (int) pshm->Gather.Type[j];

switch (iTemp)

{

case 0:

pGatBuffer1 = * ((int *) ((( int *) pushm + 4096 + k)));

printf( "%u , ", (int) pGatBuffer1);

fprintf(pOutputFile, "%u ,", (int) pGatBuffer1);

k = k + 1;

pTest15 = (double) k;

break;

case 1:

pGatBuffer1 = * ((int *) ((( int *) pushm + 4096 + k)));

printf( "%u , ", (int) pGatBuffer1);

fprintf(pOutputFile, "%u ,", (int) pGatBuffer1);

k = k + 1;

pTest15 = (double) k;

break;

case 2:

pGatBuffer1 = * ((int *) ((( int *) pushm + 4096 + k)));

printf( "%u , ", (int) pGatBuffer1);

fprintf(pOutputFile, "%u ,", (int) pGatBuffer1);

k = k + 1;

pTest15 = (double) k;

break;

case 3:

pGatBuffer1 = * ((int *) ((( int *) pushm + 4096 + k)));

printf( "%u , ", (int) pGatBuffer1);

fprintf(pOutputFile, "%u ,", (int) pGatBuffer1);

k = k + 1;

pTest15 = (double) k;

break;

case 4:

pGatBuffer1 = * ((int *) ((( int *) pushm + 4096 + k)));

printf( "%u , ", (int) pGatBuffer1);

fprintf(pOutputFile, "%u ,", (int) pGatBuffer1);

k = k + 1;

pTest15 = (double) k;;

break;

case 5:

pGatBuffer2 = * ((double *) ((( double *) pushm + 4096 + k)));

printf( "%u , ", (double) pGatBuffer2);

printf( "%30.10f \n", (double) pGatBuffer2);

fprintf(pOutputFile, "%u ,", (double) pGatBuffer2);

k = k + 2;

pTest15 = (double) k;

break;

} // end of switch iTemp

} //end of j loop

fprintf(pOutputFile, "\n");

iSleep++;

if(iSleep > 100)

{

iSleep = 0;

nanosleep(&sleeptime,NULL); // sleep and yield to LINUX scheduler

}

} // end of i loop

fclose(pOutputFile);

} // if(pOutputFile != NULL)

CloseLibrary();

return 0;

} // int main (void)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...