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;
}
//--------------------------------------------------------------------------------
#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;
}