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
#2
Is there an application note for the CAPI? Maybe something similar to the program command specification:
http://ftp.support.deltatau.com/DT-USA/P...011-01.pdf
Reply
#3
There is the IDE Help and two sample projects that get installed with the IDE. The sample projects contain examples of most API calls. I say most since the API might have updates not part of the IDE installation you use.
Reply
#4
(11-24-2009, 05:05 PM)bradp Wrote: 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;
}


Why I can't set ACC66E's datareg throw C app,the main code was here:
while(1)
{
GateIO = GetGateIOMemPtr(4);
if(GateIO)
{
GateIO->DataReg[3] = (unsigned)pshm->P[1] << 8;
GateIO->DataReg[4] = (unsigned)pshm->P[2] ;
pshm->P[5] +=1;
}
usleep(1000000 + pshm->P[3] );
pshm->P[4] +=1;

And I make sure the program was downloaded correctly.Then I change P1 and p2,GateIo[4].DataReg[3] andGateIo[4].DataReg[4],have nothing. Why?

Thanks
Reply
#5
Of course the first question is do you see P5 counting up? And P4?
Reply
#6
(05-19-2011, 11:21 AM)bradp Wrote: There is the IDE Help and two sample projects that get installed with the IDE. The sample projects contain examples of most API calls. I say most since the API might have updates not part of the IDE installation you use.

First, I can't find the sample projects in my IDE. Can you explain where to find them? I have version 2011-04-18, 1.3.1.46.

Second, is there a way to search this help? Search seems to only work for the Visual Studio itself.

Third, is there a way to extract all this help so I can put it into a single file that I can search, edit, and print?

Fourth, is there anything written up that provides a general explanation of using the C API?

Thanks for any help on this!
Reply
#7
(05-19-2011, 10:45 AM)laaguirre Wrote: Is there an application note for the CAPI? Maybe something similar to the program command specification:
http://ftp.support.deltatau.com/DT-USA/P...011-01.pdf

I was searching for C API documentation when I came across your post. While I haven't found a Users Manual yet, I have come across something which I think will help. I found the C API help text in C:\Program Files\Delta Tau Data Systems Inc\2.0\Power PMAC Suite\PowerPMACHelp\PowerPMACCLanguageManual.chm. There is also a .hxs file there. Since this .chm file is identified as type compiled html help, I thought that maybe I could open it in a browser. No luck, but FireFox copied it to the desktop. I clicked the icon, and it opened in a help application.

Having the help file outside of the IDE environment is potentially very helpful. First, it is in an independent window I can keep open. Second is that I can search through the help, and I can get an index, which I couldn't do in Visual Studio.

But, before I figured out that I could search the help, I copied most of the entries to a Word document, so I could search there. What I left out is the Macro stuff, since we won't be using it. If you want this file, just let me know. It's 76 pages long. I've printed it for my binders, and it's really all I've got on the C API, so I think a few hours work will probably be productive.
Reply
#8
horacevan,

You can download all the Power PMAC manuals from the following location: http://ftp.support.deltatau.com/DT-USA/P...tion/PDFs/
Sina Sattari
Chief Engineer
Delta Tau Data Systems, Inc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)