Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sample C PLC
#1
This is a sample C PLC which shows how use a few of the basic PPmac API functions. The API is already initialized in a CPLC so its functions can be used directly. For a more complete example look into the two sample projects installed with the PPmac IDE.

#include <RtGpShm.h>
#include <stdio.h>
#include <dlfcn.h>

#define CHAR_BUF_SIZE 0x10000

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

//------- 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
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)