Jump to content
OMRON Forums

Sample C App


bradp

Recommended Posts

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 #include // 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; }
Link to comment
Share on other sites

  • 1 year later...
  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Is there an application note for the CAPI? Maybe something similar to the program command specification: ftp://support.deltatau.com/DT-USA/Power%20PMAC%20Documentation/PDFs/Software%20Reference/Power%20PMAC%20Program%20Command%20Specification%202011-01.pdf
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • 2 months later...
[quote='bradp' pid='259' dateline='1259107548'] 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 #include // 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; } [/quote] 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
Link to comment
Share on other sites

[quote='bradp' pid='1877' dateline='1305829307'] 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. [/quote] 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!
Link to comment
Share on other sites

[quote='laaguirre' pid='1876' dateline='1305827119'] Is there an application note for the CAPI? Maybe something similar to the program command specification: ftp://support.deltatau.com/DT-USA/Power%20PMAC%20Documentation/PDFs/Software%20Reference/Power%20PMAC%20Program%20Command%20Specification%202011-01.pdf [/quote] 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.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...