Jump to content
OMRON Forums

NadirN

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by NadirN

  1. 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)

  2. [quote='JeffLowe' pid='11379' dateline='1534971709'] [quote='NadirN' pid='11376' dateline='1534963754'] [quote='JeffLowe' pid='11373' dateline='1534853435'] [quote='NadirN' pid='11369' dateline='1534791473'] Hello, This is my first post to this forum, so please bear with me. I am using a Power PMAC firmware version 2.1.1.3 and IDE version 2.2.0.39. I am trying to use printf() and send() to debug a Background C application. The code below does not produce any output at the IDE Terminal Window or at the Unsolicited Window, even though I have enabled Buffers 0 through 7 and set the Control Properties to ActivateSendPort 0. Any help will be appreciated. Nadir #include // Global Gp Shared memory pointer #include "../../Include/pp_proj.h" int main(void) { int sendport; sendport = 0; Send(sendport,"Hello\n"); printf("Hello\n"); CloseLibrary(); return 0; } [/quote] The IDE terminal is not a Linux terminal. Use Putty to setup a Linux SSH terminal for your printf statements. Also, building a serial cable and running putty to the serial connection is helpful as this is the Linux error device. [/quote] Hi Jeff, Thank you very much for replying. I downloaded Putty and logged into Linux. I ran the compiled C app "myprint.out"(code shown below.) #include // Global Gp Shared memory pointer #include "../../Include/pp_proj.h" int main(void) { InitLibrary(); printf("Hello\n"); CloseLibrary(); return 0; } The Linux command line is: root@192.168.0.232://# /var/ftp/usrflash/Project/C\ Language/Background\ Programs/myprint.out The Linux response is: Segmentation fault root@192.168.0.232:/var# Any ideas? Nadir [/quote] InitLibrary(); // missing? [/quote] That command was already in the code. I made the following change to make sure the library call returns OK. #include // Global Gp Shared memory pointer #include "../../Include/pp_proj.h" int main(void) { if (InitLibrary() ==0) { printf("Hello\n"); CloseLibrary(); } return 0; } First I got the expected response "Hello". Yay ! But after a few runs, edits, undoing edits and going back to the same code I got "Segmentation fault" again. No run time errors. Something is changing between runs. Any ideas? Thanks, Nadir
  3. [quote='JeffLowe' pid='11373' dateline='1534853435'] [quote='NadirN' pid='11369' dateline='1534791473'] Hello, This is my first post to this forum, so please bear with me. I am using a Power PMAC firmware version 2.1.1.3 and IDE version 2.2.0.39. I am trying to use printf() and send() to debug a Background C application. The code below does not produce any output at the IDE Terminal Window or at the Unsolicited Window, even though I have enabled Buffers 0 through 7 and set the Control Properties to ActivateSendPort 0. Any help will be appreciated. Nadir #include // Global Gp Shared memory pointer #include "../../Include/pp_proj.h" int main(void) { int sendport; sendport = 0; Send(sendport,"Hello\n"); printf("Hello\n"); CloseLibrary(); return 0; } [/quote] The IDE terminal is not a Linux terminal. Use Putty to setup a Linux SSH terminal for your printf statements. Also, building a serial cable and running putty to the serial connection is helpful as this is the Linux error device. [/quote] Hi Jeff, Thank you very much for replying. I downloaded Putty and logged into Linux. I ran the compiled C app "myprint.out"(code shown below.) #include // Global Gp Shared memory pointer #include "../../Include/pp_proj.h" int main(void) { InitLibrary(); printf("Hello\n"); CloseLibrary(); return 0; } The Linux command line is: root@192.168.0.232://# /var/ftp/usrflash/Project/C\ Language/Background\ Programs/myprint.out The Linux response is: Segmentation fault root@192.168.0.232:/var# Any ideas? Nadir
  4. 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)

  5. Hello, This is my first post to this forum, so please bear with me. I am using a Power PMAC firmware version 2.1.1.3 and IDE version 2.2.0.39. I am trying to use printf() and send() to debug a Background C application. The code below does not produce any output at the IDE Terminal Window or at the Unsolicited Window, even though I have enabled Buffers 0 through 7 and set the Control Properties to ActivateSendPort 0. Any help will be appreciated. Nadir #include // Global Gp Shared memory pointer #include "../../Include/pp_proj.h" int main(void) { int sendport; sendport = 0; Send(sendport,"Hello\n"); printf("Hello\n"); CloseLibrary(); return 0; }
×
×
  • Create New...