Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a CApp to Start a CPLC
#1
When you want to start a CPLC from the IDE terminal you enter
UserAlgo.RtiCplc = 1 and when you want to stop the execution you enter UserAlgo.RtiCplc = 0. The same is true for background by using the structure UserAlgo.BgCplc[n] where n is the plc number.

If you want a script PLC to enable or disable a CPLC then you can directly use these structures in the script PLC as you use them in the terminal.

If you want a CApp to enable or disable a CPLC then you must send these structures using the API GetResponse(), Command(), or SetPmacVar() so that it passes through the interpreter/parser. For example:

Command("UserAlgo.RtiCplc=1");

In a CApp you are not allowed to change these structures via the shared memory pointer. Doing:

pshm->UserAlgo.RtiCplc=1;

Will not work because internally we must do more than just set the structure = 1 to make the CPLC's run and this extra work is done when the interpreter/parser works on the command UserAlgo.RtiCplc=1.
Reply
#2
Brad,

I tried using the command "UserAlgo.BgCplc[0] = 0" from within my background CPLC to kill itself after running only once. However I get compiler errors:
Error 1 'UserAlgo' undeclared (first use in this function)

I'm assuming that I need to include a .h file, but which one? Here's my code:

#include <RtGpShm.h>
#include <stdio.h>
#include <dlfcn.h>
//#include <rtpmacapi.h> //Not sure if this was needed saw it in an example so I tried it, didn't fix UserAlgo problem
//-------------------------------------------------------------
// The following is a projpp created file from the User defines
//-------------------------------------------------------------
#include "../../Include/pp_proj.h"
#include "../../Include/fswmain.h"

void user_plcc()
{
char *tempstr;

sprintf(tempstr, "This is the sprintf in the bgplc");
Send(SEND1_PORT,tempstr);

stmach_hmi1statusupdate();

sprintf(tempstr, "This is the sprintf after the state machine call");
Send(SEND1_PORT,tempstr);

UserAlgo.BgCplc[0] = 0; // only run once

}
Reply
#3
This first post has this correct. You must use the C Api Command() function. This function's description is available in the IDE help pages.

You can not just write a PPmac structure name directly in C code. You always need to reference it via a pointer or a function call. In this case use either the GetResponse() or Command() function.
Reply
#4
I eventually figured that out yesterday. This thread is the example that steered me wrong:
"How to convert a RT address to user-space address"
http://forums.deltatau.com/showthread.ph...ght=bgcplc

It shows a write to a PPMAC structure in C code. I actually cut and pasted the following line in my code from this example:
UserAlgo.BgCplc[0] = 0; // only run once

Apparently the example was in error.
Reply
#5
Thanks, I fixed the other example.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)