hongchinlin_992x Posted September 3, 2010 Posted September 3, 2010 Is there an example C progrm that read from and write to the ACC-72E CANopen card? Thanks, HC
bradp Posted September 3, 2010 Posted September 3, 2010 I just sent this to Stanly today. //-------------------------------------------------------------------------------- #include #include // Global Rt/Gp Shared memory pointers //------------------------------------------------------------- // The following is a projpp created file from the User defines //------------------------------------------------------------- #include "../../Include/pp_proj.h" int main(void) { double fbDate; double dOutData; int nok; char response[255], cmd[255]; InitLibrary(); // load PPmac API pshm = GetSharedMemPtr(); // Get pointer to shaered memory if(!(nok = GetPmacVar((char*)"Acc72E[0].Date", &fbDate))) // get date back as a double pshm->P[1] = fbDate; // debug write to P1 for easy viewing else { sprintf(response,"GetPmacVar Err# = %d\n", - nok); pshm->P[1] = (double) nok; // debug write to P1 for easy viewing } dOutData = 2.0; if(!(nok = SetPmacVar((char*)"Acc72E[0].Output8[0]", dOutData))) // get date back as a double { sprintf(response,"SetPmacVar Ok = %d\n", - nok); pshm->P[3] = (double) nok; // debug write to P3 for easy viewing } else { sprintf(response,"SetPmacVar Err# = %d\n", - nok); pshm->P[3] = (double) nok; // debug write to P3 for easy viewing } if(!(nok = GetResponse((char*)"Acc72E[0].Date", response, 255, 7))) // get data back as string pshm->P[2] = atof(response); // debug write to P2 for easy viewing else { sprintf(response,"GetResponse Err# = %d\n", - nok); pshm->P[2] = (double) nok; // debug write to P2 for easy viewing } sprintf(cmd, "Acc72E[0].Output8[1]=%d\n", 3); if(!(nok = Command((char*) cmd))) // set data as string { sprintf(response,"Command OK = %d\n", - nok); pshm->P[5] = (double) nok; // debug write to P5 for easy viewing } else { sprintf(response,"Command Err# = %d\n", - nok); pshm->P[5] = (double) nok; // debug write to P5 for easy viewing } CloseLibrary(); return 0; }
Recommended Posts