Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sample C App
#1
This is a sample C application which shows how use a few of the basic PPmac API functions. For a more complete example look into the two sample projects installed with the PPmac IDE.

//--------------------------------------------------------------------------------
#include <gplib.h>
#include <RtGpShm.h> // Global Rt/Gp Shared memory pointers
//-------------------------------------------------------------
// The following is a projpp created file from the User defines
//-------------------------------------------------------------
#include "../../Include/pp_proj.h"

#define CHAR_BUF_SIZE 0x10000

int main(void)
{
double dMtr1Kp, dSysDdata1, dPartNum, dGateIOData, PPmacData;
char response[CHAR_BUF_SIZE];
volatile GateArray1* Gate1;
volatile GateIOStruct* GateIO;
int result;

if(InitLibrary()) // Access to PPmac API plus shared memory pointers
{ // pshm accesses PPmac structures like Motor[1].Servo.Kp and P-var array
// pushm accesses PPmac user buffer like Sys.Ddata[]

//------- Shared Memory Pointer Examples ------------------------------------------
dMtr1Kp = pshm->Motor[1].Servo.Kp; // read Motor[1].Servo.Kp
dSysDdata1 = *((double *) (((double *) pushm) + 1)); // read Sys.Ddata[1]

Gate1 = GetGate1MemPtr(4); // use CAPI to get pointer to the Gate1[4] structure
if(Gate1)
{
dPartNum = Gate1->AdcStrobe >> 8; // lower 8-bits are not used in Gate1
}

GateIO = GetGateIOMemPtr(0); // use CAPI to get pointer to the GateIO[0] structure
if(GateIO)
{
dGateIOData = GateIO->DataReg[0] >> 8; // lower 8-bits are not used in GateIO
}

//------- PPmac API Examples ------------------------------------------------------
result = Command((char*) "#1"); // Send string to command processor with no response desired
result = GetResponse((char*) "Motor[1].Servo.Kp", response, CHAR_BUF_SIZE, 0); // Send string to command processor and get an ASCII response
result = GetPmacVar("Motor[1].Servo.Kp", &PPmacData); // Send string to command processor and get a numeric response


CloseLibrary();
}
return 0;
}
Reply


Messages In This Thread
Sample C App - bradp - 11-24-2009, 05:05 PM
RE: Sample C App - laaguirre - 05-19-2011, 10:45 AM
RE: Sample C App - horacevan - 08-25-2011, 05:02 PM
RE: Sample C App - bradp - 05-19-2011, 11:21 AM
RE: Sample C App - horacevan - 08-24-2011, 07:04 PM
RE: Sample C App - dzrong - 08-18-2011, 02:28 AM
RE: Sample C App - bradp - 08-18-2011, 03:16 AM
RE: Sample C App - Sina - 08-30-2011, 10:16 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)